Hard fault handler issue (HardfaultHandler.S)

Hello All, 

I am developing an nRF52840 MCU base thread product. 

For this I am using nRF52840-Dev_kit for Development and SDK - nRF5_SDK_for_Thread_and_Zigbee_v4.0.0_dc7186b. 

For my project, I am going to use an external COAP server stack and this external stack is built on C++ libraries. And in SEGGER Embedded Studio for ARM 4.16 I am not able to find some .h files for example unistd.h, memory. h and many more. 

So, I decided to build the code from scratch and followed the https://wiki.segger.com/Use_an_external_Toolchain_with_Embedded_Studio link to build the code using an external toolchain. 

I followed the steps and was able to create the project successfully using mentioned steps from the link. 

Since my project depends on nordic stack/libraries and KNX_IoT COAP libraries. So before I make links to or add external COAP libraries (KNX_IoT libraries), I just included the Nordic thread libraries in my project. First added the freeRTOS and Thread libraries in the project. For this, I referred to the freeRTOS_coap_server example.

Code successfully built without any error so next, I did is tried to run the code on the nRF52840-Dev kit. But after thread_init(&thread_configuration); it enters into hard fault handler. 

Attached is the image of the hard fault file and code halt at the marked point. 

Also, sharing the project file for reference. Please find the attached files. 

testing2_20211007.zip

I tried several steps to debug and find the possible cause but I am not pointing to the exact issue. I tried by checking the SP register, going to step by step in assembly code. 

One thing I observed is SysTick_handler could be the problem but again I am not sure. Also, there are files differences between SDK inbuilt code and external built code.  Those are ses_startup_nrf52840.s, thumb_cr0.s, ses_nrf_commoon.s and system_nrf52840.c file which are present in built-in SDK code but in External code there is SEGGER_THUMB_Startup, startup_ARMCM_GCC.s files. 

And vector tables from both external and built-in SDK codes differ. But unable to narrow the cause for hard fault. 

It is very urgent for me to solve it because after this as I said I have to include external KNX libraries. 

Let me know what did wrong in building the project. 

Thanks in advance 

Regards

Rohit R

 

Parents
  • Hello,

    I am not familiar with these KNX libraries, unfortunately. What do they do? Are they controlling any hardware registers? If so, are you sure that they will work on the nRF? 

    I assume the project that you sent here is not made by modifying one of the examples from SDK4.0.0, since they have the different startup files? I suggest that you start with one of the examples, and then try to add the external library. If that is what you did, when/why did you change the startup files?

    Best regards,

    Edvin

  • Hi Edvin, 

    Thanks for the response, 

    I am not familiar with these KNX libraries, unfortunately. What do they do? Are they controlling any hardware registers? If so, are you sure that they will work on the nRF? 

    - yeah, I know you guys don't know about the KNX so didn't mention it in the code. It is the latter part that I will take care of. You do not need to worry about the KNX part. 

    I assume the project that you sent here is not made by modifying one of the examples from SDK4.0.0, since they have the different startup files? I suggest that you start with one of the examples, and then try to add the external library.

    - I tried in the initial stage of development to build the code using an inbuilt example. But as I told there are C++ libraries in KNX (again in the latter part not included in current code because we are going step by step increment) that are not supported by the inbuilt segger toolchain. So, we built the code using an external toolchain. 

    - Second, yes, I got the start-up difference, so I thought this was the main problem for hard fault where ISR is not handled correctly. I compared both the ses_startup file and ARMC_GCC startup file there is a difference in vector table ISR include. 

    If you tell me how I can link the segger startup files in the code with an external toolchain and build/develop the code successfully. 

    Or let me know how to handle this ISR in start-up file means a procedure to include ISR in vector table and assigning handler to them like ses_startup file. 

    I think if I map the start-up file correctly, maybe we can run the code without a hard fault issue. 

    Again, I can not use inbuilt code to develop KNX libraries because of differences and since we are going step by step increment in current code KNX is not included. So let me know the finding cause for hard fault and resolving procedure. 

    Thanks for understanding

    Regards

    Rohit R

Reply
  • Hi Edvin, 

    Thanks for the response, 

    I am not familiar with these KNX libraries, unfortunately. What do they do? Are they controlling any hardware registers? If so, are you sure that they will work on the nRF? 

    - yeah, I know you guys don't know about the KNX so didn't mention it in the code. It is the latter part that I will take care of. You do not need to worry about the KNX part. 

    I assume the project that you sent here is not made by modifying one of the examples from SDK4.0.0, since they have the different startup files? I suggest that you start with one of the examples, and then try to add the external library.

    - I tried in the initial stage of development to build the code using an inbuilt example. But as I told there are C++ libraries in KNX (again in the latter part not included in current code because we are going step by step increment) that are not supported by the inbuilt segger toolchain. So, we built the code using an external toolchain. 

    - Second, yes, I got the start-up difference, so I thought this was the main problem for hard fault where ISR is not handled correctly. I compared both the ses_startup file and ARMC_GCC startup file there is a difference in vector table ISR include. 

    If you tell me how I can link the segger startup files in the code with an external toolchain and build/develop the code successfully. 

    Or let me know how to handle this ISR in start-up file means a procedure to include ISR in vector table and assigning handler to them like ses_startup file. 

    I think if I map the start-up file correctly, maybe we can run the code without a hard fault issue. 

    Again, I can not use inbuilt code to develop KNX libraries because of differences and since we are going step by step increment in current code KNX is not included. So let me know the finding cause for hard fault and resolving procedure. 

    Thanks for understanding

    Regards

    Rohit R

Children
No Data
Related