Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unkown hardfault when running C++ on B-L072Z-LRWAN1 #116

Open
Dond96 opened this issue Dec 9, 2021 · 2 comments
Open

Unkown hardfault when running C++ on B-L072Z-LRWAN1 #116

Dond96 opened this issue Dec 9, 2021 · 2 comments

Comments

@Dond96
Copy link

Dond96 commented Dec 9, 2021

This is an issue I ran into earlier but haven't reported yet I just continued in C.
When trying to build an application with the stack using C++ for the B-L072Z-LRWAN1 it crashes before calling the bootstrap function. I had to figure this out using a debugger. The debugger doesn't give much information about the crash. The code does compile it just crashes runtime. I've also added a picture of the callstack the debugger shows and the local variables of the __hardfault_handler function of stm32_common_system.c where the reason of the crash is "optimized out".

extern "C"
{
  #include "d7ap.h"
  #include "d7ap_fs.h"
  #include "log.h"

  void bootstrap()
  {
    d7ap_fs_init();
    d7ap_init();
    log_print_string("Test");
  }
}

afbeelding

stack in the __hardfault_handler function
afbeelding

@glennergeerts
Copy link
Contributor

I have never tried running a C++ application on the stack for embedded, but I would expect name mangling difference between C and C++ being the issue here. I saw that you added an extern "C" block around the code, but I wonder if the bootstrap function itself would need to be declared with extern "C" as wel? A long time ago we where able to run the stack as part of an OMNET++ based simulation, which meant it was useable from within a C++ program, but this was on the PC host not on the embedded target. You can still see the __LINK_C define from link_c.h being used in function definitions. My guess is that it would need to be added for bootstrap() and probably others as well. If you comment to call to bootstrap() do you still crash? Can you break in __framework_bootstrap() ?

@Dond96
Copy link
Author

Dond96 commented Dec 13, 2021

I looked a bit further into the problem and the code seems to crash on assembly code. The code crashed in the init_clock() function of stm32_common_mcu.c file when initialising the RCC structs. The debugger would go into memset assembly code where the program would throw a hardfault. The structs can be seen in the image below. I did put the = {0) in comments so the code would continue.
afbeelding

Later the code would crash in stm32l0xx_hal_rcc.h line 1201 that line of code would also lead to an assembly file because of calculation with unsigned 32 bit integers. It would lead to __aeabi_dadd.csdasm and would crash on the line of code which can be seen in the figure below.
afbeelding

So when compiling C++ for the B-L072Z-LRWAN1 the code does crash before the main loop is even called.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants