You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by "eren-terzioglu (via GitHub)" <gi...@apache.org> on 2026/04/24 07:22:41 UTC

[PR] Feature/esp lp adc [nuttx]

eren-terzioglu opened a new pull request, #18791:
URL: https://github.com/apache/nuttx/pull/18791

   ## 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 -->
   
   * arch/risc-v/espressif: Add LP_ADC support
   
   Add LP_ADC support
   
   ## Impact
   <!-- Please fill the following sections with YES/NO and provide a brief explanation -->
   
   Impact on user: Yes, ADC can be used with ULP on P4
   <!-- Does it impact user's applications? How? -->
   
   Impact on build: No
   <!-- 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: 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 -->
   
   `esp32p4-function-ev-board:ulp` config with these options enabled:
   
   ```
   CONFIG_ESPRESSIF_ADC
   CONFIG_ESPRESSIF_ADC_1_USE_LP
   ```
   
   ### Building
   <!-- Provide how to build the test for each SoC being tested -->
   
   Command to build:
   
   ```
   make distclean && ./tools/configure.sh esp32p4-function-ev-board:ulp && kconfig-tweak -e CONFIG_ESPRESSIF_ADC && kconfig-tweak -e CONFIG_ESPRESSIF_ADC_1_USE_LP && make olddefconfig && make -j && make download ESPTOOL_PORT=/dev/ttyUSB0
   ```
   
   ### Running
   <!-- Provide how to run the test for each SoC being tested -->
   
   Custom app used to test
   
   ULP app:
   
   ```
   #include <stdint.h>
   #include <stdio.h>
   #include <stdbool.h>
   #include <stdbool.h>
   #include "ulp_lp_core_gpio.h"
   #include "ulp_lp_core_lp_adc_shared.h"
   #include "hal/adc_types.h"
   #include "sdkconfig.h"
   
   #define nop()   __asm__ __volatile__ ("nop")
   
   int32_t adc_result = 0;
   
   int main(void)
   {
       while (1)
           {
   #if defined(CONFIG_ARCH_CHIP_ESP32S3) || defined(CONFIG_ARCH_CHIP_ESP32S2)
               adc_result = ulp_riscv_adc_read_channel(ADC_CHANNEL_0, ADC_UNIT_1);
   #else
               lp_core_lp_adc_read_channel_converted(ADC_UNIT_1, ADC_CHANNEL_0, (int *)&adc_result);
   #endif
               /* Delay */
   
               for (int i = 0; i < 1000000; i++)
                   {
                       nop();
                   }
           }
   
       /* ulp_lp_core_halt() is called automatically when main exits */
   
       return 0;
   }
   
   ```
   
   HP App:
   
   ```
   #include <nuttx/config.h>
   
   #include <stdio.h>
   #include <fcntl.h>
   #include <unistd.h>
   #include <sys/ioctl.h>
   #include <inttypes.h>
   
   #include <nuttx/analog/adc.h>
   #include <nuttx/analog/ioctl.h>
   #include "nuttx/symtab.h"
   #include "soc/periph_defs.h"
   #include "hal/adc_periph.h"
   
   #include "ulp/ulp/ulp_main.h"
   #include "ulp/ulp/ulp_code.h"
   #include "espressif/esp_gpio.h"
   
   #define DEFAULT_STATE        INPUT_FUNCTION_2
   #define ADC_RESULT_THRESHOLD 2048
   
   void load_ulp_adc_binary(void)
   {
     int fd;
     fd = open("/dev/ulp", O_WRONLY);
     if (fd < 0)
       {
         printf("Failed to open ULP: %d\n", errno);
         return;
       }
     write(fd, ulp_adc_bin, ulp_adc_bin_len);
   }
   
   int main(int argc, char *argv[])
   {
     int fd;
     int ulp_fd;
     uint8_t gpio = 16;
     uint32_t read_result;
     struct symtab_s sym =
     {
       .sym_name = "ulp_adc_adc_result",
       .sym_value = &read_result,
     };
   
     ulp_fd = open("/dev/ulp", O_WRONLY);
     if (ulp_fd < 0)
       {
         printf("Failed to open ULP: %d\n", errno);
         return ERROR;
       }
   
     fd = open("/dev/adc0", O_RDWR);
     if (fd < 0)
       {
         printf("Failed to open adc unit 1: %d\n", errno);
         return ERROR;
       }
   
     load_ulp_adc_binary();
     esp_configgpio(gpio, INPUT_PULLDOWN | DEFAULT_STATE);
     sleep(2);
   
     ioctl(ulp_fd, FIONREAD, &sym);
     printf("Read result: %ld\n", read_result);
     if (read_result >= ADC_RESULT_THRESHOLD)
       {
         printf("ULP RISCV ADC failed\n");
         return ERROR;
       }
   
     esp_configgpio(gpio, INPUT_PULLUP | DEFAULT_STATE);
     sleep(2);
   
     ioctl(ulp_fd, FIONREAD, &sym);
     printf("Read result: %ld\n", read_result);
     if (read_result < ADC_RESULT_THRESHOLD)
       {
         printf("ULP RISCV ADC failed\n");
         return ERROR;
       }
   
     printf("Cheking done. Exiting.\n");
   
     return OK;
   }
   ```
   
   
   ### Results
   <!-- Provide tests' results and runtime logs -->
   
   ```
   nsh> lp_adc_test_app
   Read result: 900
   Read result: 2203
   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: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] arch/risc-v/espressif: Add LP_ADC support [nuttx]

Posted by "simbit18 (via GitHub)" <gi...@apache.org>.
simbit18 merged PR #18791:
URL: https://github.com/apache/nuttx/pull/18791


-- 
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: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org