Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
6 years, 4 months ago.
Explicit interrupt handler attach required in C++, but not C? (Nucleo-32F042)
I'm working with a UART console in MBED OS2 using STMicro's HAL libraries as opposed to the MBED Serial class. I could not get receive to work(the RX handler was not getting called, and further evidence showed that the program was going "in the weeds" on a receive character. I decided to make a small test program just to echo characters received, all in one main.c file. It works, however, if I change just the name of the file to main.cpp, RX stops working. After a lot of trial and error I found that adding this:
NVIC_SetVector(USART2_IRQn, (uint32_t)&USART2_IRQHandler); Attach interrupt handler
to the init code then fixed the RX operation. I thought USART2_IRQHandler, was a default predefined handler(somewhere in the STM32 HAL). Why do I get the attach for "free" in C, but in C++, I'm required to call NVIC_SetVector? This may be a STM HAL specific thing but I thought I'd post it here to see if anyone knew the "why" and so anyone else having this issue would have something to try that worked for me...
1 Answer
6 years, 4 months ago.
Hello Douglas,
Can you take a look at this question and see if it is relevant to what you are looking for?:
https://electronics.stackexchange.com/questions/279524/stm32-interrupts-and-c-dont-go-well-together
Looks like it could be due to C vs C++ name mangling. Hope this helps!
-Karen, team Mbed
If this solved your question, please make sure to click the "Thanks" link below!