I have PIC application for STM32F7xx mcu and want to run this application from any flash memory position and debug it in Ozone. The base address of code is 0x08080000 for the compiling time.
For the first i used Project.RelocateSymbols:
unsigned int Offset;
int res;
void OnProjectLoad (void) {
Project.AddPathSubstitute ("***", "$(ProjectDir)");
Project.SetDevice ("STM32F777NI");
Project.SetTargetIF ("SWD");
Project.SetTIFSpeed ("4 MHz");
Project.AddSvdFile ("$(InstallDir)/Config/CPU/Cortex-M7F.svd");
Project.SetOSPlugin ("FreeRTOSPlugin_CM7");
//Offset = 0;
Offset = 0x1000;
Util.LogHex("Offset = ", Offset);
res = Project.RelocateSymbols(".text", Offset);
Util.LogHex("Offset res = ", res);
File.Open ("***.elf");
}
void AfterTargetReset (void) {
_SetupTarget();
}
void AfterTargetDownload (void) {
_SetupTarget();
}
void _SetupTarget(void) {
unsigned int SP;
unsigned int PC;
unsigned int VectorTableAddr;
Util.LogHex("Offset = ", Offset);
VectorTableAddr = Elf.GetBaseAddr();
Util.LogHex("VT = ", VectorTableAddr);
SP = Target.ReadU32(VectorTableAddr);
Util.LogHex("SP = ", SP);
if (SP != 0xFFFFFFFF) {
Target.SetReg("SP", SP);
}
//PC = Target.ReadU32(VT + 0x04);
PC = Elf.GetEntryPointPC();
PC += Offset;
Util.LogHex("Entry Point = ", PC);
if (PC != 0xFFFFFFFF) {
Target.SetReg("PC", PC);
} else {
Util.Error("Project script error: failed to set up entry point PC", 1);
}
}
Display More
But there isn't any offset of code section in the output:
Offset = 0x1000
Project.RelocateSymbols (".text", 4096);
Offset res = 0x0
File.Open ("***.elf");
...
Offset = 0x1000
Elf.GetBaseAddr(); // returns 0x8080000
VT = 0x8080000
Target.ReadU32 (0x08080000); // returns 0x4, data is 0xFFFFFFFF
SP = 0xFFFFFFFF
Elf.GetEntryPointPC(); // returns 0x80A7034
Entry Point = 0x80A8034
Target.SetReg ("PC", 0x80A8034);
.....
Offset = 0x1000
Elf.GetBaseAddr(); // returns 0x8080000
VT = 0x8080000
Target.ReadU32 (0x08080000); // returns 0x4, data is 0x20080000
SP = 0x20080000
Target.SetReg ("SP", 0x20080000);
Elf.GetEntryPointPC(); // returns 0x80A7034
Entry Point = 0x80A8034
Target.SetReg ("PC", 0x80A8034);
Memory map 'after startup completion point' is active
Display More
This strange momemt: Elf.GetBaseAddr(); // returns 0x8080000. There is no offset.
And code doesn't run properly, no any working brakpoints for example. I think, because there is offset of PC and it's working, but there isn't offset of code.
When offset is zero the breakpoints is OK and application running without any probllem.
Offset = 0;
Connected to target device.
Reset: Halt core after reset via DEMCR.VC_CORERESET.
Reset: Reset device via AIRCR.SYSRESETREQ.
Offset = 0x0
Elf.GetBaseAddr(); // returns 0x8080000
VT = 0x8080000
Target.ReadU32 (0x08080000); // returns 0x4, data is 0x20080000
SP = 0x20080000
Target.SetReg ("SP", 0x20080000);
Elf.GetEntryPointPC(); // returns 0x80A6034
Entry Point = 0x80A6034
Target.SetReg ("PC", 0x80A6034);
J-Link: Flash download: Bank 0 @ 0x08000000: Skipped. Contents already match
Offset = 0x0
Elf.GetBaseAddr(); // returns 0x8080000
VT = 0x8080000
Target.ReadU32 (0x08080000); // returns 0x4, data is 0x20080000
SP = 0x20080000
Target.SetReg ("SP", 0x20080000);
Elf.GetEntryPointPC(); // returns 0x80A6034
Entry Point = 0x80A6034
Target.SetReg ("PC", 0x80A6034);
Memory map 'after startup completion point' is active
Display More
So, I add TargetDownload function for bin file to the new address:
void TargetDownload (void) {
Util.Log("Downloading Program.");
unsigned int VectorTableAddr;
VectorTableAddr = Elf.GetBaseAddr();
res = Target.LoadMemory("***.bin", VectorTableAddr + Offset);
Util.LogHex("Load res = ", res);
}
And have the same result - there is no any working breakpoints and no normal running application from new address.
Reset: Reset device via AIRCR.SYSRESETREQ.
Offset = 0x1000
Elf.GetBaseAddr(); // returns 0x8080000
VT = 0x8080000
Target.ReadU32 (0x08080000); // returns 0x4, data is 0xFFFFFFFF
SP = 0xFFFFFFFF
Elf.GetEntryPointPC(); // returns 0x80A7034
Entry Point = 0x80A8034
Target.SetReg ("PC", 0x80A8034);
Downloading Program.
Elf.GetBaseAddr(); // returns 0x8080000
Target.LoadMemory
Load res = 0x0
Offset = 0x1000
Elf.GetBaseAddr(); // returns 0x8080000
VT = 0x8080000
Target.ReadU32 (0x08080000); // returns 0x4, data is 0xFFFFFFFF
SP = 0xFFFFFFFF
Elf.GetEntryPointPC(); // returns 0x80A7034
Entry Point = 0x80A8034
Target.SetReg ("PC", 0x80A8034);
Memory map 'after startup completion point' is active
Display More
When the offset is 0 all is OK. Application run OK, breakpoints working good.
I can run another PIC code application from Eclispe from any address, for example with it's options in attachment - with offset of code 0x1000.
And all is OK, code running and all breakpoints are working.
But my main PIC project isn't created in Eclipse and I can't using Eclipse for debugging. The Ozone is good choise for me in this situation.
So, can I run and debug PIC code application in Ozone such as in Eclipse drom any address? Now I can run and debug this application only without code offset.