Difference between revisions of "Start debug session with bootloader"

From SEGGER Wiki
Jump to: navigation, search
(Created page with "__TOC__ Whenever a new project is created with Ozone, Ozone will assume that the .elf file you opened also points to the starting point of your application. This is usually t...")
 
(How to)
Line 53: Line 53:
 
</pre>
 
</pre>
   
Where ''<PCLocation>'' and ''<SPLocation>'' are the addresses (e.g. 0x00000000) where PC and SP are stored. For Cortex-M target this is usually at ''ProgramBaseAddr + 0x0'' for SP and ''ProgramBaseAddr + 0x4'' for PC.
+
Where ''<PCLocation>'' and ''<SPLocation>'' are the addresses (e.g. 0x00000000) where PC and SP are stored. For Cortex-M target this is usually at ''BootloaderBaseAddr + 0x0'' for SP and ''BootloaderBaseAddr + 0x4'' for PC.
   
 
= Example project =
 
= Example project =

Revision as of 16:28, 22 October 2018

Whenever a new project is created with Ozone, Ozone will assume that the .elf file you opened also points to the starting point of your application. This is usually the case. However should you have e.g. a bootloader that needs to be executed first the Ozone project must be edited accordingly.

How to

Each Ozone project is saved as a .jebug file. The Ozone project itself is written in a C-like scripting language and can be edited if needed. Per default functions AfterTargetDownload() and AfterTargetReset() will be populated with the following code lines for Cortex-M:

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(VectorTableAddr);                         
  Target.SetReg("SP", SP);                                    
                                                                
  PC = Target.ReadU32(VectorTableAddr + 4);                     
  Target.SetReg("PC", PC);                                    
}

And the following for ARM or Cortex-A/R:

unsigned int PC; 
unsigned int CPSR;  
                                                                 
PC = Elf.GetBaseAddr();                                         
                                                                  
if (PC != 0xFFFFFFFF) {                                         
  Target.SetReg("PC", PC);                                    
} else {                                                        
  Util.Log("Project file error: failed to get program base"); 
}

Either way the PC will be set to a wrong position if first a bootloader needs to be executed. To counter this the .jdebug default values need to be edited as follows:

unsigned int SP;                            
unsigned int PC;                            
                                            
SP = Target.ReadU32(<SPLocation>);     
Target.SetReg("SP", SP);                
                                            
PC = Target.ReadU32(<PCLocation>);
Target.SetReg("PC", PC);   

Where <PCLocation> and <SPLocation> are the addresses (e.g. 0x00000000) where PC and SP are stored. For Cortex-M target this is usually at BootloaderBaseAddr + 0x0 for SP and BootloaderBaseAddr + 0x4 for PC.

Example project

Example projects can be found for the following devices: