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

Problem debugging bootloader using Ozone

Hi,

I'm trying to debug my bootloader (I2C specifically) using Ozone. However the CPU only seems to halt when trying to debug the bootloader.

Also setting breakpoints only results in the error code:

SetBreakpoint: JLINK API call failed

Settings breakpoints in the application however works fine and when running the application through Ozone does not result in the CPU halting. And I can trigger the breakpoints on the I2C event handler by sending something over I2C.

Based on this link i have modified the AfterTargetDownload and AfterTargetReset accordingly:

void AfterTargetReset (void) {
  unsigned int SP;                                                
  unsigned int PC;                                                
  unsigned int VectorTableAddr;                                   
                                                                  
  VectorTableAddr = Elf.GetBaseAddr();                            
                                                                  
  if (VectorTableAddr == 0xFFFFFFFF) {                            
    Util.Log("Project file error: failed to get program base"); 
  } else {                                                        
    SP = Target.ReadU32(0x0);                         
    Target.SetReg("SP", SP);                                    
                                                                  
    PC = Target.ReadU32(0x0 + 0x4);                     
    Target.SetReg("PC", PC);                                    
  }
}

I'm not really sure where to go from here...

SDK: v15.0

Softdevice: v6.0.0

Br,

Anton

Parents Reply Children
  • Hi Vidar,

    I have tried that, the CPU still halts.

    Here is the main function of the bootloader, I'm expecting it to run forever in the while loop as there is not valid application on the chip.

    int main(void)
    {
        ret_code_t ret;
        bootloader_callbacks_t bootloader_callbacks;
    
        bootloader_callbacks.start_application = start_application;
        bootloader_callbacks.send_i2c_message  = send_i2c_message;
    
        ret = nrf_drv_clock_init();
        APP_ERROR_CHECK(ret);
        nrf_drv_clock_lfclk_request(NULL);
    
        // Protect MBR and bootloader code from being overwritten.
        ret = nrf_bootloader_flash_protect(0, MBR_SIZE, false);
        APP_ERROR_CHECK(ret);
        ret = nrf_bootloader_flash_protect(BOOTLOADER_START_ADDR, BOOTLOADER_SIZE, false);
        APP_ERROR_CHECK(ret);
    
        APP_ERROR_CHECK(NRF_LOG_INIT(NULL));
        NRF_LOG_DEFAULT_BACKENDS_INIT();
    
        APP_ERROR_CHECK(app_timer_init());
    
        NRF_LOG_INFO("Inside main");
    
        bootloader_app_init(&bootloader_callbacks);
        
        if (dfu_enter())
        {
            twi_slave_init();
            send_fw_upgrade_response();
            NRF_LOG_DEBUG("DFU Enter requested. Waiting for FW");
            while(!new_fw_received)
            {
            }
        }
        else
        {
        }
    
        // Either there was no DFU functionality enabled in this project or the DFU module detected
        // no ongoing DFU operation and found a valid main application.
        // Boot the main application.
        //
        NRF_LOG_INFO("Starting application");
        nrf_bootloader_app_start();
    
        // Should never be reached.
        NRF_LOG_INFO("After main");
    }

    / Anton

  • Do you know that the CPU halting only occurs when debugging with Ozone? I've not been able to replicate this with the SDK bootloader. I just downloaded Ozone v2.70e and tested with and without AfterTargetReset() implemented. Can you post a screenshot of the CPU registers and call stack when it has halted?

  • For some reason I have missed looking at the Call stack. Seems like we are stuck in a Hardfault handler.

    Here are the screenshots:

    Edit:

    the CPU halting only occurs when using Ozone. If I upload the hex file using nrfjprog the bootloader start and I can start a DFU upgrade without any issues (logs printed aswell), however with Ozone no logs are printed and the bootloader doesn't react to I2C messages.

    Modified the AfterTargetReset / Download:

    void AfterTargetReset (void) {
    /*
      unsigned int SP;                                                
      unsigned int PC;                                                
      unsigned int VectorTableAddr;                                   
                                                                      
      VectorTableAddr = Elf.GetBaseAddr();                            
                                                                      
      if (VectorTableAddr == 0xFFFFFFFF) {                            
        Util.Log("Project file error: failed to get program base"); 
      } else {                                                        
        SP = Target.ReadU32(0x0);                         
        Target.SetReg("SP", SP);                                    
                                                                      
        PC = Target.ReadU32(0x0 + 0x4);                     
        Target.SetReg("PC", PC);                                    
      }
    */
    }
    

  • The PC is 0xFF..FE so that explains the hardfault. It may even have lead to a lockup reset had you not been in debug mode. Unfortunately, I don't see any obvious reasons to how it could happen. Would it be possible to upload the bootloader .elf/.out so I can try it here?

Related