This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Why does a do-nothing main.c HardFault when run with a softdevice?

If you have the most trivial main.c possible, with a main() which does nothing at all, compile, link and load it at 0x00000000, it runs fine and does nothing .. that's basically the main.c from the template example.

If you build the same exact code, link it at 0x14000, load a 110 softdevice onto the chip and then flash the code at 0x14000, the device HardFaults. It HardFaults before it even gets to main().

Why is this? I assume that the Softdevice requires one or more of the low-level handlers to be defined and if they're not, ends up branching to nowhere and HardFaulting .. but which are they? It can't be anything which is actually done in main(), it never gets there, so it must be named, linked-in routines which handle interrupts while the Reset_Handler() code is running.

I've debugged it at length. The code always makes it into the Reset_Handler() [at 0x14xxx], it rarely gets out of it. Somewhere during the copy to RAM it HardFaults. If you single step it all the way through, which takes a good long while, it makes it to main(), but if you let it run, it immediately fails. I assume an interrupt the softdevice set up before it branched to the user code Reset_Handler() fires and fails to find something it needs.

The reason I'm trying to do something so stupid is to come up with the simplest template do-nothing main.c which works with or without a loaded softdevice. This is part of the, currently going fairly well, work I'm doing to build natively with Eclipse. I just need the simplest main.c I can which works with or without a softdevice as an example file.

Parents
  • You should make sure that you use the correct system files, for example from the official SDK. The upper 8 kB of RAM is off by default on the nRF51, so if you try to use it without first having enabled it, you'll see a HardFault.

    Also beware that we have an application note showing how to work with Eclipse, and you may also have use in taking a look at this GitHub repository.

  • I must admit that I've never used gdb on the command line - at least not in Windows. I'm going to come back to this a bit later after I make sure I understand the ble_app_lbs app a bit better and do some debugging via a scope. I hate to give up on using gdb for long, but the boss doesn't want to let me spend the time to get it working properly at this point. sigh

Reply
  • I must admit that I've never used gdb on the command line - at least not in Windows. I'm going to come back to this a bit later after I make sure I understand the ble_app_lbs app a bit better and do some debugging via a scope. I hate to give up on using gdb for long, but the boss doesn't want to let me spend the time to get it working properly at this point. sigh

Children
No Data