This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Cannot control GPIOs on custom board when using SoftDevice

Hi everyone,

my problem is pretty simple: we developed a custom board for the NRF52840 to work using a custom protocol or BLE. A few sensors are connected to the NRF using

I2C, and a few GPIOs are connected to LEDs for debugging. I created a custom board.h file with the pin numbers of my board.

When I use the custom protocol, everything works fine: I can periodically read the sensors, I can switch on, off and toggle the LEDs whenever I need to and there is no issue.

When using the BLE (softdevice S140 V6.0), on the other hand, I cannot switch on/off the LEDs on any of the GPIOs. I tried both the nrf_gpio_pin_set/clear functions and the nrf_gpio_write

functions (which is essentially the same). What puzzles me even more is that the I2C communication works fine with the SoftDevice active, so it seems that my board.h file is accepted either with the SD active.

Is by chance the SD blocking access to GPIOs configurations when active? Do you have any suggestion on what could be wrong?

Thanks for your help.

Lorenzo

Parents
  • I add a new information that may be useful to propose solutions....

    Apparently, I have the same problem with other signals which are on the port P1....so essentially when I use the SoftDevice, it seems that the NRF_GPIO_PIN_MAP function does not work correctly when it needs to configure Port 1.....As said before, when I don't use the SD, there is no problem at all.

    Is there a known issue with NRF_GPIO_PIN_MAP on port 1 when using a softdevice?

  • Hi Lorenzo,

    The Softdevice should not have any impact on this. It does not use any GPIOs. Are there any other differences between these two apart from the Softdevice that you can think of? Can you read back the GPIO configuration registers to confirm they are not overwritten (by bsp_init(), bsp_btn_ble_init(), etc)?  

Reply Children
  • Hi Vidar,

    I don't use any bsp function; I am working on a custom board, so I don't use bsp functions at all.

    This is my main code; as you see there is nothing special. And the myBoard_ functions are the same with or without softdevice.

    /**@brief Function for application main entry.
     */
    int main(void)
      {
        nrf_delay_ms(1000);
        ret_code_t err_code;
    
        log_init();
        APP_ERROR_CHECK(err_code);
    
        // Initialize.
        timers_init();
        myBoard_SetUpGPIOs();
        myBoard_SetupI2C();  
        nrf_delay_ms(500);
    
        power_management_init();
        ble_stack_init();
        gap_params_init();
        gatt_init();
        services_init();
        advertising_init();
        conn_params_init();
        peer_manager_init();
        nrf_ble_pairing_init(); 
    
        APP_ERROR_CHECK(err_code);
        application_timers_start(); 
        advertising_start(false);
    
        // Enter main loop.
        for (;;)
        {
            idle_state_handle();
        }
    }

    As I said before, if I write directly in the P1 registers, I can control the pins normally. If I try using the NRF_GPIO_PIN_MAP function this does not have any effect.

    By the way, my LEDs are on P1.02, P1.04 and P1.06. Even if I avoid using the NRF_GPIO_PIN_MAP and I pass the value of the pin (for example, if I call nrf_gpio_pin_set(34)), there is no effect.

    It seems that for some reason all values > 31 are not taken into account by the gpio functions.....

    Again, if I don't use the SD then all works perfectly.

    For the moment I am using a workaround, but this could create serious problems later, because I have mapped the SPI on 4 pins which are in port P1, and if this does not work properly then I don't know what to do.....

  • I found the problem!

    For some reason in the preprocessor defines, there was an NRF52 before NRF52840_XXAA.

    The NRF52 define was overwriting something, so that the file nrf52832_peripherals.h was included instead of the nrf52840_peripherals.h. Because of this, in nrf_gpio.h the NUMBER_OF_PINS define was set to a wrong value, so essentially the pins > 32 where not taken into account.

    So, essentially, there was nothing wrong with the softdevice, but it was in the setup of our preprocessor definitions. 

Related