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

BusFault exception when debugging nrf9160 with segger ozone

Hi,

I have written one application with logging disabled to save power.

However, when I tried to debug the code with Ozone, during startup, it raises BusFault exception.

According to call stack, it happened after calling nordisemi_nrf91_init in nrf91 soc.c file.

I loaded with the zephyr.elf file and chosen M33 as the target, with SWD 4MHz.

NCS 1.2.0 is used and I want to avoid any upgrade if it is possible.

Do you have any idea what leads to this weird behavior? And do you have the same issue on your side?

Thanks!

  • Hi,

     

    Ozone loads the start address and MSP from the .elf file itself, and not from the start of the flash (ie: the secure "spm" image), which will give you some strange behavior if you do not use "attach to running target".

    You can fix this by editing the ozone project (save as -> open the file in a editor) and manually pointing the project to load the SP and PC from address 0.

     Please see this page on how to change this:

    https://wiki.segger.com/Debug_on_a_Target_with_Bootloader

     

    Note: you should edit the two function AfterTargetDownload() and AfterTargetReset().

    Originally, you will see this line:

    VectorTableAddr = Elf.GetBaseAddr();

     

    Which should be changed to:

    VectorTableAddr = 0;

     

    Could you try this, and see if the debug session gives another behavior?

     

    Kind regards,

    Håkon

  • Hi,

    Thanks for the response, but seems that does not fix the issue. Still get the same error.

  • Hi,

     

    What does the "console" show now?

    In your original image, you can clearly see that it does not load from address 0:

     

    Here it uses 0x18200 as the base address, even when you do a reset from ozone. This will cause faults.

     

    Kind regards,

    Håkon

  • Hi,

    Just to follow up on this. I too had exactly the same problem when I started using Ozone. Again the documentation from Nordic on this is not exactly stellar on what to do. Nordic suggested to use Ozone but then you're left to your own devices to work out why it hard faults all the time when you reset.

    Anyway, here's what I had to do to get Ozone working. As the answer below suggests you have to edit the generated .jdebug project file. There is a jump table at address 0 which needs to be read in order to get the starting PC and SP addresses. So all I had to do to get this working was to set VectorTableAddr = 0; in _SetupTarget.

    So my _SetupTarget looks like this.

    void _SetupTarget(void) {
      unsigned int SP;
      unsigned int PC;
      unsigned int VectorTableAddr;
    
      VectorTableAddr = 0; // <- change this to 0
      //
      // Set up initial stack pointer
      //
      SP = Target.ReadU32(VectorTableAddr);
      if (SP != 0xFFFFFFFF) {
        Target.SetReg("SP", SP);
      }
      //
      // Set up entry point PC
      //
      PC = Target.ReadU32(VectorTableAddr + 4);
      if (PC != 0xFFFFFFFF) {
        Target.SetReg("PC", PC);
      } else {
        Util.Error("Project script error: failed to set up entry point PC", 1);
      }
    }
    

    Hopefully this should work for you. It did for me on the nrf9160dk with the bootloader. As suggested below you can see the addresses that the debugger is using to set the PC and SP to on a reset. So you can hopefully work out what you need to set.

    Regards,

    Paul

Related