Zephyr + NRF5340: change GPIO function in runtime

The project uses nRF5340. A signal is connected to P0.27/AIN6, and during "normal" mode the pin is used as an ADC.

Before going into sleep mode we would need this pin to become a GPIO Input with enabled interrupt, so as to waking up the MCU (and then back again to ADC during "normal mode").

Some previous posts state that Zephyr did not allow for runtime configuration of pins. Is that still the case? If this is not available and we use direct configuration of the MCU's registers, what are the "special concerns" in the device tree that we have to take in order not to mess up Zephyr usage of the pin?

Parents
  • I did some testing and was able to make this work by disconnecting the positive ADC channel.

    1. First I setup ADC using adc_channel_setup() and triggered adc_sample() right after
      • I used AIN0 as positive input (P0.04)
      • I succesfully got an ADC measurement
    2. Then I ran NRF_SAADC->CH[0].PSELP = 0x00
    3. Then I set up a GPIO interrupt, similar to how it's done in \zephyr\samples\basic\button\src\main.c
    4. I attached P0.04 and successfully got an interrupt
    5. Then I waited 10 seconds and set up ADC as in 1. and got an ADC measurement

    Here is the sample (NCS v1.8.0):

    6013.adc_gpio_interrupt_same_pin.zip

    Best regards,

    Simon

     

Reply
  • I did some testing and was able to make this work by disconnecting the positive ADC channel.

    1. First I setup ADC using adc_channel_setup() and triggered adc_sample() right after
      • I used AIN0 as positive input (P0.04)
      • I succesfully got an ADC measurement
    2. Then I ran NRF_SAADC->CH[0].PSELP = 0x00
    3. Then I set up a GPIO interrupt, similar to how it's done in \zephyr\samples\basic\button\src\main.c
    4. I attached P0.04 and successfully got an interrupt
    5. Then I waited 10 seconds and set up ADC as in 1. and got an ADC measurement

    Here is the sample (NCS v1.8.0):

    6013.adc_gpio_interrupt_same_pin.zip

    Best regards,

    Simon

     

Children
No Data
Related