-
Notifications
You must be signed in to change notification settings - Fork 3k
nrf5x: fix array overflow in gpio configuration code #6021
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…for irq (or output)
User not whitelisted, CI not run. |
@ARMmbed/team-nordic Please review |
What target are you running this on? Do you have a code snippet that triggers this bug? Thanks! |
I'm working with a nrf51 using MCU_NRF51_UNIFIED but anything using TARGET_NRF5 should be affected since #5207 It happens the very first time a I've just replicated it with a new project on nrf51_dk with the following #include <mbed.h>
DigitalIn pin(BUTTON1);
int main(void) {
while (1) ;
} mbed-os updated to master You'll need to be debugging to see the problem, if you apply this patch in diff --git a/targets/TARGET_NORDIC/TARGET_NRF5/TARGET_SDK11/drivers_nrf/gpiote/nrf_drv_gpiote.c b/targets/TARGET_NORDIC/TARGET_NRF5/TARGET_SDK11/drivers_nrf/gpiote/nrf_drv_gpiote.c
index 752c89c9a..417962c68 100644
--- a/targets/TARGET_NORDIC/TARGET_NRF5/TARGET_SDK11/drivers_nrf/gpiote/nrf_drv_gpiote.c
+++ b/targets/TARGET_NORDIC/TARGET_NRF5/TARGET_SDK11/drivers_nrf/gpiote/nrf_drv_gpiote.c
@@ -465,6 +465,7 @@ void nrf_drv_gpiote_in_uninit(nrf_drv_gpiote_pin_t pin)
nrf_gpiote_te_default(channel_port_get(pin));
}
nrf_gpio_cfg_default(pin);
+ __asm("BKPT #0\n");
channel_free((uint8_t)channel_port_get(pin));
pin_in_use_clear(pin);
} If you look in
Where this out of bounds index is actually pointing is program specific so may not be immediately obvious that something's gone wrong, but your runtime is now corrupted. If you enable nordic asserts (aka #6022) there is a check at the top of |
It looks good to me, but to be honest my experience with the gpio_api.c implementation is quite limited. Did you at some point consider adding a catch-all else statement?
|
I don't think we want to reset the pin to defaults at all, this function is simply to detach any used gpiote's before they're reassigned later (if needed) |
I was just looking at the functions inside nrf_drv_gpiote_in_uninit, and saw that nrf_gpio_cfg_default was being called as well. How did this work in the first place then? 😄 |
Ah yes, I see what you mean. Prior to #5207 a gpiote channel was used for every gpio allocation (DigitalIn, DigitalOut, InterruptIn, InterruptOut). This meant that it was always safe to unallocate the gpiote because there was always one allocated. gpiote channels are a limited resource however, hence #5207 (don't use a gpiote channel when not needed for a basic digitalin gpio). |
I see! Thank you for the explanation! |
/morph build |
Build : SUCCESSBuild number : 1213 Triggering tests/morph test |
Exporter Build : SUCCESSBuild number : 884 |
Test : FAILUREBuild number : 1014 |
/morph test |
Test : SUCCESSBuild number : 1022 |
Description
nrf5x: gpiote uninit only needs to be run if input pin is configured for irq (or output)
Refer to #6020 for more details
Status
READY
Migrations
NO
Related PRs
#5207