Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: mbed_blinky-bmd-200 bmd-200_accel_demo firstRig
Fork of mbed-src by
Diff: targets/hal/TARGET_STM/TARGET_NUCLEO_L152RE/gpio_irq_api.c
- Revision:
- 354:e67efb2aab0e
- Parent:
- 331:098575c6d2c8
- Child:
- 414:ee28a0bed4ad
--- a/targets/hal/TARGET_STM/TARGET_NUCLEO_L152RE/gpio_irq_api.c Thu Oct 16 14:45:07 2014 +0100
+++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_L152RE/gpio_irq_api.c Thu Oct 16 15:00:10 2014 +0100
@@ -46,14 +46,15 @@
static gpio_irq_handler irq_handler;
-static void handle_interrupt_in(uint32_t irq_index) {
+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) {
- EXTI_ClearITPendingBit(pin);
+ if (__HAL_GPIO_EXTI_GET_FLAG(pin) != RESET) {
+ __HAL_GPIO_EXTI_CLEAR_FLAG(pin);
}
if (channel_ids[irq_index] == 0) return;
@@ -67,31 +68,39 @@
}
// The irq_index is passed to the function
-static void gpio_irq0(void) {
+static void gpio_irq0(void)
+{
handle_interrupt_in(0); // EXTI line 0
}
-static void gpio_irq1(void) {
+static void gpio_irq1(void)
+{
handle_interrupt_in(1); // EXTI line 1
}
-static void gpio_irq2(void) {
+static void gpio_irq2(void)
+{
handle_interrupt_in(2); // EXTI line 2
}
-static void gpio_irq3(void) {
+static void gpio_irq3(void)
+{
handle_interrupt_in(3); // EXTI line 3
}
-static void gpio_irq4(void) {
+static void gpio_irq4(void)
+{
handle_interrupt_in(4); // EXTI line 4
}
-static void gpio_irq5(void) {
+static void gpio_irq5(void)
+{
handle_interrupt_in(5); // EXTI lines 5 to 9
}
-static void gpio_irq6(void) {
+static void gpio_irq6(void)
+{
handle_interrupt_in(6); // EXTI lines 10 to 15
}
extern uint32_t Set_GPIO_Clock(uint32_t port_idx);
-int gpio_irq_init(gpio_irq_t *obj, PinName pin, gpio_irq_handler handler, uint32_t id) {
+int gpio_irq_init(gpio_irq_t *obj, PinName pin, gpio_irq_handler handler, uint32_t id)
+{
IRQn_Type irq_n = (IRQn_Type)0;
uint32_t vector = 0;
uint32_t irq_index;
@@ -155,28 +164,10 @@
// Enable GPIO clock
uint32_t gpio_add = Set_GPIO_Clock(port_index);
- // Enable SYSCFG clock
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
-
- // Connect EXTI line to pin
- SYSCFG_EXTILineConfig(port_index, pin_index);
+ // Configure GPIO
+ pin_function(pin, STM_PIN_DATA(STM_MODE_IT_FALLING, GPIO_NOPULL, 0));
- // Configure EXTI line
- EXTI_InitTypeDef EXTI_InitStructure;
- EXTI_InitStructure.EXTI_Line = (uint32_t)(1 << pin_index);
- EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
- EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
- EXTI_InitStructure.EXTI_LineCmd = ENABLE;
- EXTI_Init(&EXTI_InitStructure);
-
- // Enable and set EXTI interrupt to the lowest priority
- NVIC_InitTypeDef NVIC_InitStructure;
- NVIC_InitStructure.NVIC_IRQChannel = irq_n;
- NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0F;
- NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0F;
- NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
- NVIC_Init(&NVIC_InitStructure);
-
+ // Enable EXTI interrupt
NVIC_SetVector(irq_n, vector);
NVIC_EnableIRQ(irq_n);
@@ -184,6 +175,7 @@
obj->irq_n = irq_n;
obj->irq_index = irq_index;
obj->event = EDGE_NONE;
+ obj->pin = pin;
channel_ids[irq_index] = id;
channel_gpio[irq_index] = gpio_add;
channel_pin[irq_index] = pin_index;
@@ -193,79 +185,71 @@
return 0;
}
-void gpio_irq_free(gpio_irq_t *obj) {
+void gpio_irq_free(gpio_irq_t *obj)
+{
channel_ids[obj->irq_index] = 0;
channel_gpio[obj->irq_index] = 0;
channel_pin[obj->irq_index] = 0;
// Disable EXTI line
- EXTI_InitTypeDef EXTI_InitStructure;
- EXTI_StructInit(&EXTI_InitStructure);
- EXTI_Init(&EXTI_InitStructure);
+ pin_function(obj->pin, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, 0));
obj->event = EDGE_NONE;
}
-void gpio_irq_set(gpio_irq_t *obj, gpio_irq_event event, uint32_t enable) {
- EXTI_InitTypeDef EXTI_InitStructure;
-
- uint32_t pin_index = channel_pin[obj->irq_index];
-
- EXTI_InitStructure.EXTI_Line = (uint32_t)(1 << pin_index);
- EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
- EXTI_InitStructure.EXTI_LineCmd = DISABLE; // Default
+void gpio_irq_set(gpio_irq_t *obj, gpio_irq_event event, uint32_t enable)
+{
+ uint32_t mode = STM_MODE_IT_EVT_RESET;
+ uint32_t pull = GPIO_NOPULL;
if (enable) {
if (event == IRQ_RISE) {
- EXTI_InitStructure.EXTI_LineCmd = ENABLE;
if ((obj->event == EDGE_FALL) || (obj->event == EDGE_BOTH)) {
- EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising_Falling;
+ mode = STM_MODE_IT_RISING_FALLING;
obj->event = EDGE_BOTH;
} else { // NONE or RISE
- EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
+ mode = STM_MODE_IT_RISING;
obj->event = EDGE_RISE;
}
}
if (event == IRQ_FALL) {
- EXTI_InitStructure.EXTI_LineCmd = ENABLE;
if ((obj->event == EDGE_RISE) || (obj->event == EDGE_BOTH)) {
- EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising_Falling;
+ mode = STM_MODE_IT_RISING_FALLING;
obj->event = EDGE_BOTH;
} else { // NONE or FALL
- EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
+ mode = STM_MODE_IT_FALLING;
obj->event = EDGE_FALL;
}
}
- }
- else { // Disable
+ } else { // Disable
if (event == IRQ_RISE) {
if ((obj->event == EDGE_FALL) || (obj->event == EDGE_BOTH)) {
- EXTI_InitStructure.EXTI_LineCmd = ENABLE;
- EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
+ mode = STM_MODE_IT_FALLING;
obj->event = EDGE_FALL;
} else { // NONE or RISE
- EXTI_InitStructure.EXTI_LineCmd = DISABLE;
+ mode = STM_MODE_IT_EVT_RESET;
obj->event = EDGE_NONE;
}
}
if (event == IRQ_FALL) {
if ((obj->event == EDGE_RISE) || (obj->event == EDGE_BOTH)) {
- EXTI_InitStructure.EXTI_LineCmd = ENABLE;
- EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
+ mode = STM_MODE_IT_RISING;
obj->event = EDGE_RISE;
} else { // NONE or FALL
- EXTI_InitStructure.EXTI_LineCmd = DISABLE;
+ mode = STM_MODE_IT_EVT_RESET;
obj->event = EDGE_NONE;
}
- }
+ }
}
- EXTI_Init(&EXTI_InitStructure);
+ pin_function(obj->pin, STM_PIN_DATA(mode, pull, 0));
}
-void gpio_irq_enable(gpio_irq_t *obj) {
+void gpio_irq_enable(gpio_irq_t *obj)
+{
NVIC_EnableIRQ(obj->irq_n);
}
-void gpio_irq_disable(gpio_irq_t *obj) {
+void gpio_irq_disable(gpio_irq_t *obj)
+{
NVIC_DisableIRQ(obj->irq_n);
obj->event = EDGE_NONE;
}
