Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
6 years ago.
How works gpio_init for the targets Nordic nRF5x?
I don't understand how the GPIO initialization is working when considering the following:
The function void gpio_init(gpio_t *obj, PinName pin)
is resetting the configuration for all pins.
nrf_drv_gpiote_init() ... for (i = 0; i < NUMBER_OF_PINS; i++) { pin_in_use_clear(i); }
1 Answer
6 years ago.
Hi David,
We have edited your question to include code tags to improve its readability.
The constructors for DigitalIn and DigitalOut will call gpio_init(), which in turn will call nrf_drv_gpiote_init() for the nRF52 targets. We can see your concern, but you might not have noticed this portion of the function:
if (m_cb.state != NRF_DRV_STATE_UNINITIALIZED) { err_code = NRF_ERROR_INVALID_STATE; NRF_LOG_WARNING("Function: %s, error code: %s.", (uint32_t)__func__, (uint32_t)NRF_LOG_ERROR_STRING_GET(err_code)); return err_code; }
Only on the first pass through the function will the initialization take place. On subsequent calls m_cb.state
equals NRF_DRV_STATE_INITIALIZED
(from line 252), so no initialization will be performed as the function will return prematurely.
Hopefully that satisfies your concern.
Regards, Ralph, Team Mbed