cancel
Showing results for 
Search instead for 
Did you mean: 

stm32f429-disco and interrupt initialization question

mail239955
Associate II
Posted on June 23, 2014 at 18:10

Dear experts,

as a beginner I am starting on a stm32f429-disco board using eclipse with the gnu-arm-plugin and the gnu-arm-eabi toolchain in linux. I adopted the example from ''STM32Cube_FW_F4_V1.1.0/Projects/STM32F429I-Discovery/Examples/GPIO/GPIO_EXTI'' to my toolchain. I want to get an interrupt when the button is pressed an turn on a LED - but nothing happens when the button is pressed ! In debug mode I found that it never enters the callback-function. I guess there is something missing, but what ? I saw other examples where the interrupts are initialized with function like ''

SYSCFG_EXTILineConfig

(

EXTI_PortSourceGPIOA

,

EXTI_PinSource0

);

or

''EXTI_InitStructure

.

EXTI_Line

=

EXTI_Line0

;

''

are used with includes like

#include ''stm32f4xx_gpio.h''

#include ''stm32f4xx_exti.h'' but these functinos are not used in the example NOR these includes are available in my toolchain using STM32Cube_FW_F4_V1.1.0 ? All includes available includes are called ''

stm32f4xx_hal_......h''

- Why ? Please help me understanding the issue with the interrupt and the different include files - Thanx! Below is the code:

//
// This file is part of the GNU ARM Eclipse distribution.
// Copyright (c) 2014 Liviu Ionescu.
//
// ----------------------------------------------------------------------------
#include <
stdio.h
>
#include ''diag/Trace.h''
#include ''cmsis_device.h''
#include ''cortexm/ExceptionHandlers.h''
#include ''stm32f4xx.h''
#include ''stm32f4xx_hal.h''
// ----- main() ---------------------------------------------------------------
// Sample pragmas to cope with warnings. Please note the related line at
// the end of this function, used to pop the compiler diagnostics status.
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored ''-Wunused-parameter''
#pragma GCC diagnostic ignored ''-Wmissing-declarations''
#pragma GCC diagnostic ignored ''-Wreturn-type''
int main(int argc, char* argv[])
{
/*** GPIO INITIALIZATION ***/
GPIO_InitTypeDef GPIO_InitStructure;
// Initialize green LEDs on PG13 and PG14
// Enable GPIO Peripheral clock on Port G for LEDs
__GPIOG_CLK_ENABLE();
// Configure pin in output push/pull mode
GPIO_InitStructure.Pin = GPIO_PIN_13;
GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStructure.Speed = GPIO_SPEED_FAST;
GPIO_InitStructure.Pull = GPIO_PULLUP;
HAL_GPIO_Init(GPIOG, &GPIO_InitStructure);
// Configure pin in output push/pull mode
GPIO_InitStructure.Pin = GPIO_PIN_14;
GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStructure.Speed = GPIO_SPEED_FAST;
GPIO_InitStructure.Pull = GPIO_PULLUP;
HAL_GPIO_Init(GPIOG, &GPIO_InitStructure);
// Initialize Pushbutton on PA0 as interrupt driven
__GPIOA_CLK_ENABLE();
__SYSCFG_CLK_ENABLE();
//Configure Button pin as input on PA0
GPIO_InitStructure.Pin = GPIO_PIN_0;
GPIO_InitStructure.Mode = GPIO_MODE_IT_RISING_FALLING;
//GPIO_InitStructure.Mode = GPIO_MODE_INPUT;
GPIO_InitStructure.Speed = GPIO_SPEED_FAST;
GPIO_InitStructure.Pull = GPIO_PULLDOWN;;
HAL_GPIO_Init(GPIOA, &GPIO_InitStructure);
/* Enable and set EXTI Line0 Interrupt to the lowest priority */
HAL_NVIC_SetPriority(EXTI0_IRQn, 2, 0);
HAL_NVIC_EnableIRQ(EXTI0_IRQn);
/*** While loop ***
*/
//initialize LED state
HAL_GPIO_WritePin(GPIOG,GPIO_PIN_13, GPIO_PIN_RESET); // green OFF
HAL_GPIO_WritePin(GPIOG,GPIO_PIN_14, GPIO_PIN_RESET); // red OFF
// Infinite loop
while (1)
{
}
// Infinite loop, never return.
}
// ----- External Interrupt () ------------------------------------------------
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
if(GPIO_Pin == GPIO_PIN_0)
{
HAL_GPIO_WritePin(GPIOG,GPIO_PIN_13, GPIO_PIN_SET); // green ON
}
}
#pragma GCC diagnostic pop
// ----------------------------------------------------------------------------

4 REPLIES 4
mail239955
Associate II
Posted on June 24, 2014 at 17:06

The question on the different libraries was answered.

As I have installed the ''stm32Cube'' libs, I need to use the HAL_ functions for programing.

The older tutorials need to be modified if i do not install the standard peripheral libs in parallel to the ''stm32Cube''.

Thx to Mayla !

Please can anyone advice me how to initialize the interrupt correctly in the above example with ''stm32Cube'' only. It cannot be a big deal as this example is delivered with the ''stm32Cube'' firmware package.

I just moved all code from the example into the main.c.

It just does not enter the callback function ;-(

What is missing ?

Anyone, please ...

mail239955
Associate II
Posted on June 25, 2014 at 22:42

The ''stm32cube'' - function ''HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)'' is never called when the interrupt occurs.

What happens is that the CMSIS-function EXTI0_IRQHandler() is called.

If I manually do:

void EXTI0_IRQHandler(void) {

    HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_0);

}

Then it works !

Is the stm32cube buggy ?

The same problem exists with the stm32cube - HAL_IncTick() function used by HAL_Delay().

One has to be manually add it to the CMSIS SysTick_Handler() function. to get it work.

This complete stm32cube-hal setup does not make any sense, or am I missing something ?

mail239955
Associate II
Posted on June 26, 2014 at 21:52

Problem solved when adding ''stm32f4xx_it.c'' from the stm32cube example to the project.

I was not aware that there are the function callbacks from the CMSIS libs are used to call the stm32cube-callback functions.

Why not using the CMSIS callback directly ?

Well this is a topic to be discussed elsewhere .....

Posted on June 26, 2014 at 22:34

Is the stm32cube buggy ?

Yes, and unstable.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..