cancel
Showing results for 
Search instead for 
Did you mean: 

Interrupt Service routine issue. STM32F4-discovery.

anuja
Associate II
Posted on April 18, 2014 at 23:23

Hi,

I'm trying to use interrupt based UART. My code compiles without errors but when I debug it, it does not branch to any ISR in stm32f4xx_it.c from the vector table. I have enabled the interrupt using NVIC_Init function, is there any initializaion that I have missed out.
9 REPLIES 9
Posted on April 19, 2014 at 00:42

I'm trying to use interrupt based UART. My code compiles without errors but when I debug it, it does not branch to any ISR in stm32f4xx_it.c from the vector table. I have enabled the interrupt usingNVIC_Init function, is there any initializaion that I have missed out.

You've almost certainly done something wrong, but it's a little hard to tell what. Compiler errors simple tell you if you've sent them something completely bogus, it is not a validation of the underlying code.

PA9/PA10 USART1 is NOT usable on the STM32F4-DISCO

https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/STM32F4%20USART%20receive%20problem&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B&currentviews=1954

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
michaelmccartyeng
Associate II
Posted on April 19, 2014 at 17:21

Hello Yora,

It's nearly impossible to help you without seeing your code, specifically the initialization of the vector table and your usart init code. The best thing we can do is point you to example code which are already available on the internet. But just guessing did you actually enable the interrupt you want to int on USART_ITConfig()? Did you follow all of the instructions at the top of stm32f4xx_usart.c

[..]
(#) Enable peripheral clock using the following functions
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USARTx, ENABLE) for USART1 and USART6 
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USARTx, ENABLE) for USART2, USART3, 
UART4 or UART5.
(#) According to the USART mode, enable the GPIO clocks using 
RCC_AHB1PeriphClockCmd() function. (The I/O can be TX, RX, CTS, 
or/and SCLK). 
(#) Peripheral's alternate function: 
(++) Connect the pin to the desired peripherals' Alternate 
Function (AF) using GPIO_PinAFConfig() function
(++) Configure the desired pin in alternate function by:
GPIO_InitStruct->GPIO_Mode = GPIO_Mode_AF
(++) Select the type, pull-up/pull-down and output speed via 
GPIO_PuPd, GPIO_OType and GPIO_Speed members
(++) Call GPIO_Init() function
(#) Program the Baud Rate, Word Length , Stop Bit, Parity, Hardware 
flow control and Mode(Receiver/Transmitter) using the USART_Init()
function.
(#) For synchronous mode, enable the clock and program the polarity,
phase and last bit using the USART_ClockInit() function.
(#) Enable the NVIC and the corresponding interrupt using the function 
USART_ITConfig() if you need to use interrupt mode. 
(#) When using the DMA mode 
(++) Configure the DMA using DMA_Init() function
(++) Active the needed channel Request using USART_DMACmd() function
(#) Enable the USART using the USART_Cmd() function.
(#) Enable the DMA using the DMA_Cmd() function, when using DMA mode.

anuja
Associate II
Posted on April 21, 2014 at 17:58

Thank you for replying.

Posted on April 21, 2014 at 19:34

With C++ you're going to need to be particularly conscious of name mangling, and whether your IRQHandler routines are actually the ones being linked via the vector table. Review the .MAP file, review a disassembly.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on April 21, 2014 at 19:36

Let me also reiterate that you can't use PA9 on the STM32F4-DISCO for a USART pin. Please review the schematic.

The STM32F4-DIS-BB demonstrates the use of USART6 via PC6/PC7
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
anuja
Associate II
Posted on April 21, 2014 at 19:47

Thanks clive.Really appreciate the help. Will look into the .MAP file.

anuja
Associate II
Posted on April 22, 2014 at 21:27

I reviewed the Disassembly and the ISRs are not being linked correctly. Can you please guide me on linking the routines correctly.

Posted on April 22, 2014 at 22:09

The USART interrupt routine does not return a value, and you must either use C linkage for the vector table, or insert the C++ mangled name

extern ''C'' void USART2_IRQHandler(void)
{
// ..
}

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
anuja
Associate II
Posted on April 22, 2014 at 23:14

That worked. Thanks Clive!