Skip to content
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

[nrf5] fix in Digital I/O : a gpioe pin was uninitialized badly #3084

Merged
merged 1 commit into from
Oct 24, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions targets/TARGET_NORDIC/TARGET_NRF5/gpio_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ int gpio_read(gpio_t *obj)
}
}


static void gpio_apply_config(uint8_t pin)
static void gpiote_pin_uninit(uint8_t pin)
{
if (m_gpio_initialized & (1UL << pin)) {
if ((m_gpio_cfg[pin].direction == PIN_OUTPUT) && (!m_gpio_cfg[pin].used_as_irq)) {
Expand All @@ -97,7 +96,10 @@ static void gpio_apply_config(uint8_t pin)
nrf_drv_gpiote_in_uninit(pin);
}
}
}

static void gpio_apply_config(uint8_t pin)
{
if (m_gpio_cfg[pin].used_as_gpio || m_gpio_cfg[pin].used_as_irq) {
if ((m_gpio_cfg[pin].direction == PIN_INPUT)
|| (m_gpio_cfg[pin].used_as_irq)) {
Expand Down Expand Up @@ -147,6 +149,9 @@ static void gpio_apply_config(uint8_t pin)
void gpio_mode(gpio_t *obj, PinMode mode)
{
MBED_ASSERT(obj->pin <= GPIO_PIN_COUNT);

gpiote_pin_uninit(obj->pin); // try to uninitialize gpio before a change.

m_gpio_cfg[obj->pin].pull = mode;
gpio_apply_config(obj->pin);
}
Expand All @@ -155,6 +160,9 @@ void gpio_mode(gpio_t *obj, PinMode mode)
void gpio_dir(gpio_t *obj, PinDirection direction)
{
MBED_ASSERT(obj->pin <= GPIO_PIN_COUNT);

gpiote_pin_uninit(obj->pin); // try to uninitialize gpio before a change.

m_gpio_cfg[obj->pin].direction = direction;
gpio_apply_config(obj->pin);
}
Expand All @@ -172,6 +180,8 @@ int gpio_irq_init(gpio_irq_t *obj, PinName pin, gpio_irq_handler handler, uint32
MBED_ASSERT((uint32_t)pin < GPIO_PIN_COUNT);
(void) nrf_drv_gpiote_init();

gpiote_pin_uninit(pin); // try to uninitialize gpio before a change.

m_gpio_cfg[pin].used_as_irq = true;
m_channel_ids[pin] = id;
obj->ch = pin;
Expand Down