C++ exception handler on gnu arm cortex m4 with freertos

前端 未结 3 2372
小蘑菇
小蘑菇 2021-02-20 02:03

Update 2016-12 There is now also a minimal example for this behavior: https://community.nxp.com/message/862676


I\'m using a ARM Cortex M4 with fr

相关标签:
3条回答
  • 2021-02-20 02:16

    From the RTOS side of things, C++ exceptions are just a glorified jump. As long as they're jumping from one bit of your code to another, they don't interfere with the RTOS. So you can write a try { } catch(std::exception) { }.

    When there is no C++ handler, the RTOS indeed will have to step in as your C++ code stops running.

    0 讨论(0)
  • 2021-02-20 02:19

    After successfully creating a blank project with default settings in freescales Kinetis, and asking the same problem on the nxp community, Alice_Yang , an NXP engineer (assuming by the NXP badge), told me the answer:

    By default new projects link to newlib-nano which has it exception support disabled.

    The libstdc++ built along with newlib-nano have exception handling disabled.

    So the solution is to link simply to newlib. This can be done by simply removing the line "-specs=nano.specs" in "other linker flags" and also make sure the check box which adds the same option is also disabled. Then everything works as expected. Only the code increased by 27 kB in ROM/text size and 2kB in RAM/data.

    0 讨论(0)
  • By fault, most of your exceptions will execute the default handler, so the first thing you need to do is determine which exception is actually executing. You can see the "Determining Which Exception Handler is Executing" section on the following page: http://www.freertos.org/Debugging-Hard-Faults-On-Cortex-M-Microcontrollers.html

    I would guess, since you are not using a peripheral in your code, that it will be a fault handler, probably the hard fault. The same page (see link above) gives instructions on debugging that too.

    Other than that - ensure you do the normal FreeRTOS debug things, like ensure you have configASSERT() defined, and that you have stack overflow checking on. Info on those topics is found on this page: http://www.freertos.org/FAQHelp.html

    0 讨论(0)
提交回复
热议问题