Why isn't my SysTick_Handler() being called in my C++ Project?

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Why isn't my SysTick_Handler() being called in my C++ Project?

3,228件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by tdl on Tue Dec 17 14:25:25 MST 2013
I have created a C++ project for an LPC1227 using LPCExpresso 6.1.0. The project, up until now, builds and runs fine. I have not made any changes to cr_startup_lpc12xx.cpp.

I would like to add a SysTick_Handler(). In my main.cpp I have added a method:

void SysTick_Handler(void)
{
    timerCounter++;  // these variables are all declared globally in main.cpp
    timer_10ms_tick = true;
    if ((timerCounter % 10) == 0)  //every 100ms
    {
        timer_100ms_tick = true;
    }
    if ((timerCounter % 100) == 0)  //every 1000ms
    {
        timer_1000ms_tick = true;
    }
}   

I have also add the following line in my main() method:

SysTick_Config(12000000/100);  


When I run my code via debug, the interrupt is firing, but it is getting stuck in the default SysTick_Handler() that is inside of cr_startup_lpc12xx.cpp (which is just an infinite while loop). If I delete the default SysTick_Handler from cr_startup_lpc12xx.cpp, my program hard faults.

I have looked at the Blinky example (which is C, not C++) and it adds a new handler into main.cpp without deleting the handler from the startup file.

Can anyone suggest why my overriding handler is not being called? Is this a C++ difference?
0 件の賞賛
返信
2 返答(返信)

2,295件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by tdl on Tue Dec 17 19:20:20 MST 2013
Thank you.  This solved the problem.
0 件の賞賛
返信

2,295件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Tue Dec 17 14:41:46 MST 2013
Try:
#ifdef __cplusplus
[color=#f00]extern "C" {[/color]
#endif
//SysTick
void SysTick_Handler(void) //SysTick handler
{
 ...blablabla...
}//end SysTick handler
#ifdef __cplusplus
[color=#f00]}[/color]
#endif


Otherwise C++ is 'Name Mangling' your function 

See: http://www.geeksforgeeks.org/extern-c-in-c/