eren-terzioglu opened a new pull request, #19457:
URL: https://github.com/apache/nuttx/pull/19457
## Summary
<!-- This field should contain a summary of the changes. It will be
pre-filled with the commit's message and descriptions. Adjust it accordingly -->
* Docs/platforms/risc-v: Add CMake ULP build system docs
Add CMake ULP build system docs for esp32[-c6|-p4]
* boards/risc-v/espressif: Add CMake ULP board support
Add CMake ULP board support for esp32[-c6|-p4]
* arch/risc-v/espressif: Add CMake ULP support
Add CMake support for ULP build
## Impact
<!-- Please fill the following sections with YES/NO and provide a brief
explanation -->
Impact on user: Yes, users can build ULP app with using CMake build system
<!-- Does it impact user's applications? How? -->
Impact on build: Yes, ULP application can be built with CMake
<!-- Does it impact on building NuttX? How? (please describe the required
changes on the build system) -->
Impact on hardware: Yes, ULP can be built with using CMake
<!-- Does it impact a specific hardware supported by NuttX? -->
Impact on documentation: Yes, related docs added
<!-- Does it impact the existing documentation? Please provide additional
documentation to reflect that -->
Impact on security: No
<!-- Does it impact NuttX's security? -->
Impact on compatibility: No
<!-- Does it impact compatibility between previous and current versions? Is
this a breaking change? -->
## Testing
<!-- Please provide all the testing procedure. Consider that upstream
reviewers should be able to reproduce the same testing performed internally -->
`esp32c6-devkitc:ulp` and `esp32p4-function-ev-board:ulp` configs used to
test.
### Building
<!-- Provide how to build the test for each SoC being tested -->
ULP processor can be used with 2 ways:
- Using Pre-Built binary
- Using NuttX ULP build system for Espressif
#### Using Pre-Built binary
These commands can be used for pre-built binary example
```
cmake -B build -DBOARD_CONFIG=esp32c6-devkitc:ulp -GNinja && cmake --build
build && ESPTOOL_PORT=/dev/ttyUSB0 cmake --build build -t flash
```
Feature included a pre-built binary which is a blink example. After these
commands it will include `.bin` file under `boards/risc-v/esp32c6/common/etc/`
and GPIO0 will blink after flashing.
#### Using NuttX ULP build system for Espressif
```
.
└── nuttxspace/
├── nuttx
└── apps/
└── external/
├── ...
└── ulp_test/
├── Kconfig
├── CMakeLists.txt
├── ulp_test_main.c
└── ulp/
├── CMakeLists.txt
└── ulp_blink.c
```
Contents of the files:
- Kconfig:
```
config ULP_TEST_APP
bool "ULP test app"
default n
```
- CMakeLists.txt:
```
include(ulp/CMakeLists.txt)
nuttx_add_application(
NAME
${CONFIG_EXAMPLES_ULP_EXAMPLE_PROGNAME}
PRIORITY
${SCHED_PRIORITY_DEFAULT}
STACKSIZE
${CONFIG_DEFAULT_TASK_STACKSIZE}
MODULE
${CONFIG_EXAMPLES_ULP_EXAMPLE}
INCLUDE_DIRECTORIES
${CMAKE_CURRENT_BINARY_DIR}
SRCS
ulp_example.c
DEPENDS
${_ulp_example_deps})
```
- ulp_test_main.c:
```
#include <nuttx/config.h>
#include <fcntl.h>
#include <inttypes.h>
#include <stdio.h>
#include <nuttx/fs/ioctl.h>
#include <sys/ioctl.h>
#include "ulp/ulp/ulp_main.h"
#include "ulp/ulp/ulp_code.h"
#include "nuttx/symtab.h"
#define PIN 0
int main(int argc, char *argv[])
{
int fd;
uint32_t read_result;
struct symtab_s sym =
{
.sym_name = "ulp_blink_gpio_level_previous",
.sym_value = &read_result,
};
fd = open("/dev/ulp", O_WRONLY);
if (fd < 0)
{
printf("Failed to open ULP: %d\n", errno);
return -1;
}
int ret = write(fd, ulp_blink_bin, ulp_blink_bin_len);
if (ret != OK)
{
printf("Write failed \n");
return ERROR;
}
ioctl(fd, FIONREAD, &sym);
/* Chaging LP GPIO status from a variable on HP core */
printf("First GPIO level: %ld\n", read_result);
printf("Expected GPIO level: %ld\n", !read_result);
read_result = !read_result;
ioctl(fd, FIONWRITE, &sym);
return OK;
}
```
- ulp/CMakeLists.txt:
```
set(_ulp_example_deps)
set(ULP_APP_NAME ulp_example)
set(ULP_APP_FOLDER ${CMAKE_CURRENT_LIST_DIR}/ulp)
set(ULP_APP_C_SRCS ulp_main.c)
include(${NUTTX_DIR}/arch/risc-v/src/common/espressif/esp_ulp.cmake)
list(APPEND _ulp_example_deps ulp_example_ulp_bin)
```
- ulp/ulp_blink.c
```
#include <stdint.h>
#include <stdbool.h>
#include "ulp_lp_core_gpio.h"
#define GPIO_PIN 0
#define nop() __asm__ __volatile__ ("nop")
bool gpio_level_previous = true;
int main(void)
{
while (1)
{
ulp_lp_core_gpio_set_level(GPIO_PIN, gpio_level_previous);
/* Delay */
for (int i = 0; i < 10000; i++)
{
nop();
}
}
/* ulp_lp_core_halt() is called automatically when main exits */
return 0;
}
```
Command to build ULP example:
```
cmake -B build -DBOARD_CONFIG=esp32c6-devkitc:nsh -GNinja && kconfig-tweak
--file build/.config -e CONFIG_ESPRESSIF_GPIO_IRQ && kconfig-tweak --file
build/.config -e CONFIG_DEV_GPIO && kconfig-tweak --file build/.config -e
CONFIG_ESPRESSIF_USE_LP_CORE && kconfig-tweak --file build/.config -e
CONFIG_EXAMPLES_ULP_EXAMPLE && cmake --build build -t olddefconfig && cmake
--build build && ESPTOOL_PORT=/dev/ttyUSB0 cmake --build build -t flash
```
### Running
<!-- Provide how to run the test for each SoC being tested -->
Test bin will start to run at startup. Logic analyzer connected to GPIO0.
For ULP example `ulp_test` command used to run.
### Results
<!-- Provide tests' results and runtime logs -->
Blink will start on startup
For ULP example:
```
nsh> ulp_blink
First GPIO level: 1
Expected GPIO level: 0
Pin status: 1
Pin status: 0
Cheking done. Exiting.
nsh>
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]