From 4a18b90ab76307bcad6c186ed6a03328b4ae5ace Mon Sep 17 00:00:00 2001 From: bcostm Date: Tue, 8 Apr 2014 15:53:36 +0200 Subject: [PATCH 1/3] [NUCLEO_L152RE] Add more interrupt_in pins --- .../TARGET_NUCLEO_L152RE/gpio_irq_api.c | 65 +++++++++++++------ 1 file changed, 46 insertions(+), 19 deletions(-) diff --git a/libraries/mbed/targets/hal/TARGET_STM/TARGET_NUCLEO_L152RE/gpio_irq_api.c b/libraries/mbed/targets/hal/TARGET_STM/TARGET_NUCLEO_L152RE/gpio_irq_api.c index ed1bc95766..e8c2f06775 100644 --- a/libraries/mbed/targets/hal/TARGET_STM/TARGET_NUCLEO_L152RE/gpio_irq_api.c +++ b/libraries/mbed/targets/hal/TARGET_STM/TARGET_NUCLEO_L152RE/gpio_irq_api.c @@ -39,11 +39,11 @@ #define EDGE_FALL (2) #define EDGE_BOTH (3) -#define CHANNEL_NUM (4) +#define CHANNEL_NUM (7) -static uint32_t channel_ids[CHANNEL_NUM] = {0, 0, 0, 0}; -static uint32_t channel_gpio[CHANNEL_NUM] = {0, 0, 0, 0}; -static uint32_t channel_pin[CHANNEL_NUM] = {0, 0, 0, 0}; +static uint32_t channel_ids[CHANNEL_NUM] = {0, 0, 0, 0, 0, 0, 0}; +static uint32_t channel_gpio[CHANNEL_NUM] = {0, 0, 0, 0, 0, 0, 0}; +static uint32_t channel_pin[CHANNEL_NUM] = {0, 0, 0, 0, 0, 0, 0}; static gpio_irq_handler irq_handler; @@ -51,7 +51,7 @@ static void handle_interrupt_in(uint32_t irq_index) { // Retrieve the gpio and pin that generate the irq GPIO_TypeDef *gpio = (GPIO_TypeDef *)(channel_gpio[irq_index]); uint32_t pin = (uint32_t)(1 << channel_pin[irq_index]); - + // Clear interrupt flag if (EXTI_GetITStatus(pin) != RESET) { @@ -70,10 +70,13 @@ static void handle_interrupt_in(uint32_t irq_index) { } // The irq_index is passed to the function -static void gpio_irq0(void) {handle_interrupt_in(0);} -static void gpio_irq1(void) {handle_interrupt_in(1);} -static void gpio_irq2(void) {handle_interrupt_in(2);} -static void gpio_irq3(void) {handle_interrupt_in(3);} +static void gpio_irq0(void) {handle_interrupt_in(0);} // EXTI line 0 +static void gpio_irq1(void) {handle_interrupt_in(1);} // EXTI line 1 +static void gpio_irq2(void) {handle_interrupt_in(2);} // EXTI line 2 +static void gpio_irq3(void) {handle_interrupt_in(3);} // EXTI line 3 +static void gpio_irq4(void) {handle_interrupt_in(4);} // EXTI line 4 +static void gpio_irq5(void) {handle_interrupt_in(5);} // EXTI lines 5 to 9 +static void gpio_irq6(void) {handle_interrupt_in(6);} // EXTI lines 10 to 15 extern uint32_t Set_GPIO_Clock(uint32_t port_idx); @@ -88,29 +91,53 @@ int gpio_irq_init(gpio_irq_t *obj, PinName pin, gpio_irq_handler handler, uint32 uint32_t pin_index = STM_PIN(pin); // Select irq number and interrupt routine - switch (pin) { - case PC_13: // User button - irq_n = EXTI15_10_IRQn; + switch (pin_index) { + case 0: + irq_n = EXTI0_IRQn; vector = (uint32_t)&gpio_irq0; irq_index = 0; break; - case PB_3: - irq_n = EXTI3_IRQn; + case 1: + irq_n = EXTI1_IRQn; vector = (uint32_t)&gpio_irq1; irq_index = 1; break; - case PB_4: - irq_n = EXTI4_IRQn; + case 2: + irq_n = EXTI2_IRQn; vector = (uint32_t)&gpio_irq2; irq_index = 2; break; - case PB_5: - irq_n = EXTI9_5_IRQn; + case 3: + irq_n = EXTI3_IRQn; vector = (uint32_t)&gpio_irq3; irq_index = 3; break; + case 4: + irq_n = EXTI4_IRQn; + vector = (uint32_t)&gpio_irq4; + irq_index = 4; + break; + case 5: + case 6: + case 7: + case 8: + case 9: + irq_n = EXTI9_5_IRQn; + vector = (uint32_t)&gpio_irq5; + irq_index = 5; + break; + case 10: + case 11: + case 12: + case 13: + case 14: + case 15: + irq_n = EXTI15_10_IRQn; + vector = (uint32_t)&gpio_irq6; + irq_index = 6; + break; default: - error("This pin is not supported with InterruptIn.\n"); + error("InterruptIn error: pin not supported.\n"); return -1; } From ab7cc121563682a94e08223da2159aa6c9b137b8 Mon Sep 17 00:00:00 2001 From: bcostm Date: Tue, 8 Apr 2014 16:05:40 +0200 Subject: [PATCH 2/3] [NUCLEO_F103RB] Add more interrupt_in pins --- .../TARGET_NUCLEO_F103RB/gpio_irq_api.c | 65 +++++++++++++------ 1 file changed, 46 insertions(+), 19 deletions(-) diff --git a/libraries/mbed/targets/hal/TARGET_STM/TARGET_NUCLEO_F103RB/gpio_irq_api.c b/libraries/mbed/targets/hal/TARGET_STM/TARGET_NUCLEO_F103RB/gpio_irq_api.c index 150baf8454..f5237ae83a 100644 --- a/libraries/mbed/targets/hal/TARGET_STM/TARGET_NUCLEO_F103RB/gpio_irq_api.c +++ b/libraries/mbed/targets/hal/TARGET_STM/TARGET_NUCLEO_F103RB/gpio_irq_api.c @@ -39,11 +39,11 @@ #define EDGE_FALL (2) #define EDGE_BOTH (3) -#define CHANNEL_NUM (4) +#define CHANNEL_NUM (7) -static uint32_t channel_ids[CHANNEL_NUM] = {0, 0, 0, 0}; -static uint32_t channel_gpio[CHANNEL_NUM] = {0, 0, 0, 0}; -static uint32_t channel_pin[CHANNEL_NUM] = {0, 0, 0, 0}; +static uint32_t channel_ids[CHANNEL_NUM] = {0, 0, 0, 0, 0, 0, 0}; +static uint32_t channel_gpio[CHANNEL_NUM] = {0, 0, 0, 0, 0, 0, 0}; +static uint32_t channel_pin[CHANNEL_NUM] = {0, 0, 0, 0, 0, 0, 0}; static gpio_irq_handler irq_handler; @@ -51,7 +51,7 @@ static void handle_interrupt_in(uint32_t irq_index) { // Retrieve the gpio and pin that generate the irq GPIO_TypeDef *gpio = (GPIO_TypeDef *)(channel_gpio[irq_index]); uint32_t pin = (uint32_t)(1 << channel_pin[irq_index]); - + // Clear interrupt flag if (EXTI_GetITStatus(pin) != RESET) { @@ -70,10 +70,13 @@ static void handle_interrupt_in(uint32_t irq_index) { } // The irq_index is passed to the function -static void gpio_irq0(void) {handle_interrupt_in(0);} -static void gpio_irq1(void) {handle_interrupt_in(1);} -static void gpio_irq2(void) {handle_interrupt_in(2);} -static void gpio_irq3(void) {handle_interrupt_in(3);} +static void gpio_irq0(void) {handle_interrupt_in(0);} // EXTI line 0 +static void gpio_irq1(void) {handle_interrupt_in(1);} // EXTI line 1 +static void gpio_irq2(void) {handle_interrupt_in(2);} // EXTI line 2 +static void gpio_irq3(void) {handle_interrupt_in(3);} // EXTI line 3 +static void gpio_irq4(void) {handle_interrupt_in(4);} // EXTI line 4 +static void gpio_irq5(void) {handle_interrupt_in(5);} // EXTI lines 5 to 9 +static void gpio_irq6(void) {handle_interrupt_in(6);} // EXTI lines 10 to 15 extern uint32_t Set_GPIO_Clock(uint32_t port_idx); @@ -88,29 +91,53 @@ int gpio_irq_init(gpio_irq_t *obj, PinName pin, gpio_irq_handler handler, uint32 uint32_t pin_index = STM_PIN(pin); // Select irq number and interrupt routine - switch (pin) { - case PC_13: // User button - irq_n = EXTI15_10_IRQn; + switch (pin_index) { + case 0: + irq_n = EXTI0_IRQn; vector = (uint32_t)&gpio_irq0; irq_index = 0; break; - case PB_3: - irq_n = EXTI3_IRQn; + case 1: + irq_n = EXTI1_IRQn; vector = (uint32_t)&gpio_irq1; irq_index = 1; break; - case PB_4: - irq_n = EXTI4_IRQn; + case 2: + irq_n = EXTI2_IRQn; vector = (uint32_t)&gpio_irq2; irq_index = 2; break; - case PB_5: - irq_n = EXTI9_5_IRQn; + case 3: + irq_n = EXTI3_IRQn; vector = (uint32_t)&gpio_irq3; irq_index = 3; break; + case 4: + irq_n = EXTI4_IRQn; + vector = (uint32_t)&gpio_irq4; + irq_index = 4; + break; + case 5: + case 6: + case 7: + case 8: + case 9: + irq_n = EXTI9_5_IRQn; + vector = (uint32_t)&gpio_irq5; + irq_index = 5; + break; + case 10: + case 11: + case 12: + case 13: + case 14: + case 15: + irq_n = EXTI15_10_IRQn; + vector = (uint32_t)&gpio_irq6; + irq_index = 6; + break; default: - error("This pin is not supported with InterruptIn.\n"); + error("InterruptIn error: pin not supported.\n"); return -1; } From aba5d840469944dc31ce7d11afb0c47f3d75f4ed Mon Sep 17 00:00:00 2001 From: bcostm Date: Tue, 8 Apr 2014 16:46:38 +0200 Subject: [PATCH 3/3] [NUCLEO_F030R8] Add more interrupt_in pins --- .../TARGET_NUCLEO_F030R8/gpio_irq_api.c | 39 +++++++++---------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/libraries/mbed/targets/hal/TARGET_STM/TARGET_NUCLEO_F030R8/gpio_irq_api.c b/libraries/mbed/targets/hal/TARGET_STM/TARGET_NUCLEO_F030R8/gpio_irq_api.c index 6981316786..80ffb8483b 100644 --- a/libraries/mbed/targets/hal/TARGET_STM/TARGET_NUCLEO_F030R8/gpio_irq_api.c +++ b/libraries/mbed/targets/hal/TARGET_STM/TARGET_NUCLEO_F030R8/gpio_irq_api.c @@ -51,7 +51,7 @@ static void handle_interrupt_in(uint32_t irq_index) { // Retrieve the gpio and pin that generate the irq GPIO_TypeDef *gpio = (GPIO_TypeDef *)(channel_gpio[irq_index]); uint32_t pin = (uint32_t)(1 << channel_pin[irq_index]); - + // Clear interrupt flag if (EXTI_GetITStatus(pin) != RESET) { @@ -87,25 +87,24 @@ int gpio_irq_init(gpio_irq_t *obj, PinName pin, gpio_irq_handler handler, uint32 uint32_t pin_index = STM_PIN(pin); // Select irq number and interrupt routine - switch (pin) { - case PC_13: // User button - irq_n = EXTI4_15_IRQn; - vector = (uint32_t)&gpio_irq0; - irq_index = 0; - break; - case PA_0: - irq_n = EXTI0_1_IRQn; - vector = (uint32_t)&gpio_irq1; - irq_index = 1; - break; - case PB_3: - irq_n = EXTI2_3_IRQn; - vector = (uint32_t)&gpio_irq2; - irq_index = 2; - break; - default: - error("This pin is not supported\n"); - return -1; + if ((pin_index == 0) || (pin_index == 1)) { + irq_n = EXTI0_1_IRQn; + vector = (uint32_t)&gpio_irq0; + irq_index = 0; + } + else if ((pin_index == 2) || (pin_index == 3)) { + irq_n = EXTI2_3_IRQn; + vector = (uint32_t)&gpio_irq1; + irq_index = 1; + } + else if ((pin_index > 3) && (pin_index < 16)) { + irq_n = EXTI4_15_IRQn; + vector = (uint32_t)&gpio_irq2; + irq_index = 2; + } + else { + error("InterruptIn error: pin not supported.\n"); + return -1; } // Enable GPIO clock