eren-terzioglu opened a new pull request, #17218: URL: https://github.com/apache/nuttx/pull/17218
## 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 --> * Documentation/risc-v/esp32[c6]: Add multiple ULP bin docs for esp32c6 Add multiple ULP bin docs for esp32c6 * boards/risc-v/esp32[c6]: Add multiple ULP bin board support for esp32c6 Add multiple ULP bin board support for esp32c6 * arch/risc-v/esp32[c6]: Add multiple ULP bin support for esp32c6 Add multiple ULP bin support for esp32c6 * Documentation/xtensa/esp32[-s2|-s3]: Add multiple ULP RISC-V bin docs Add multiple ULP RISC-V bin docs for esp32s2 and esp32s3 * boards/xtensa/esp32[-s2|-s3]: Add multiple ULP RISC-V bin board support Add multiple ULP RISC-V bin board support for esp32s2 and esp32s3 * arch/xtensa/esp32[-s2|-s3]: Add multiple ULP RISC-V bin support Add multiple ULP RISC-V bin support for esp32s2 and esp32s3 * arch/risc-v/espressif: Add ULP as char device to support multiple ULP bins Add ULP as char device to change binary that runs on ULP ## Impact <!-- Please fill the following sections with YES/NO and provide a brief explanation --> Impact on user: Yes, users can change ULP code during runtime <!-- Does it impact user's applications? How? --> Impact on build: Yes, ULP build system changed from automatically source code finding to makefile <!-- Does it impact on building NuttX? How? (please describe the required changes on the build system) --> Impact on hardware: No <!-- Does it impact a specific hardware supported by NuttX? --> Impact on documentation: Yes, new build system docs for ULP 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: Yes, ULP build system for esp devices are changing <!-- 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 --> [External apps guide followed](https://nuttx.apache.org/docs/latest/guides/customapps.html#extend-the-apps-directory-to-include-a-new-custom-directory) to extend app directory. After that, a folder created called `ulp_test`. Test example directory tree looks like this: ``` . └── nuttxspace/ ├── nuttx └── apps/ └── external/ ├── ... └── ulp_test/ ├── Kconfig ├── Make.defs ├── Makefile ├── ulp_test_main.c └── ulp/ ├── Makefile └── ulp_blink.c ``` Contents of the files: - Kconfig: ``` config ULP_TEST_APP bool "ULP test app" default n ``` - Make.defs ``` ifneq ($(CONFIG_ULP_TEST_APP),) CONFIGURED_APPS += $(APPDIR)/external/ulp_test endif ``` - Makefile: ``` include $(APPDIR)/Make.defs Custom Hello built-in application info PROGNAME = ulp_test PRIORITY = 100 STACKSIZE = $(CONFIG_DEFAULT_TASK_STACKSIZE) MODULE = $(CONFIG_CUSTOM_APPS_CUSTOM_HELLO) Custom Hello MAINSRC = ulp_test_main.c include $(APPDIR)/Application.mk include ulp/Makefile ``` - 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/Makefile: ``` ULP_APP_NAME = ulp_blink ULP_APP_FOLDER = $(APPDIR)/external/testing/ulp_test/ulp ULP_APP_C_SRCS = ulp_blink.c include $(TOPDIR)/arch/$(CONFIG_ARCH)/src/common/espressif/esp_ulp.mk ``` - 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; } ``` Here is an example of a single ULP application. However, support is not limited to just one application. Similar to how NuttX supports multiple applications, multiple ULP applications are also supported. By following the same guideline, multiple ULP application creation and loading is possible by using `write` POSIX call. Each NuttX application can build one ULP application. Therefore, to support multiple ULP applications, multiple NuttX application needed to create and load ULP binary. ULP binary can be included in NuttX application by adding `#include "ulp/ulp/ulp_code.h"` line. Then, the ULP binary is accessible by using the ULP application prefix (defined by the `ULP_APP_NAME` variable in the ULP application Makefile) with the `bin` keyword to access the binary data (e.g., if `ULP_APP_NAME` is ulp_test, the binary variable will be `ulp_test_bin`) and `bin_len` keyword to access its length (e.g., `ulp_test_bin_len` for `ULP_APP_NAME` is ulp_test). ### Building <!-- Provide how to build the test for each SoC being tested --> ``` make -j distclean && ./tools/configure.sh esp32c6-devkitc:ulp && kconfig-tweak -e CONFIG_ULP_TEST_APP && make olddefconfig -s -j && make ESPTOOL_BINDIR=./ -s -j ``` ### Running <!-- Provide how to run the test for each SoC being tested --> `ulp_test` command used to run the example. ### Results <!-- Provide tests' results and runtime logs --> GPIO0 should blink for once. -- 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]
