How can I run and debug PIC(position intepended code) on ARM CM7 mcu from any address?

    This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

    • How can I run and debug PIC(position intepended code) on ARM CM7 mcu from any address?

      New

      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:

      C Source Code

      1. unsigned int Offset;
      2. int res;
      3. void OnProjectLoad (void) {
      4. Project.AddPathSubstitute ("***", "$(ProjectDir)");
      5. Project.SetDevice ("STM32F777NI");
      6. Project.SetTargetIF ("SWD");
      7. Project.SetTIFSpeed ("4 MHz");
      8. Project.AddSvdFile ("$(InstallDir)/Config/CPU/Cortex-M7F.svd");
      9. Project.SetOSPlugin ("FreeRTOSPlugin_CM7");
      10. //Offset = 0;
      11. Offset = 0x1000;
      12. Util.LogHex("Offset = ", Offset);
      13. res = Project.RelocateSymbols(".text", Offset);
      14. Util.LogHex("Offset res = ", res);
      15. File.Open ("***.elf");
      16. }
      17. void AfterTargetReset (void) {
      18. _SetupTarget();
      19. }
      20. void AfterTargetDownload (void) {
      21. _SetupTarget();
      22. }
      23. void _SetupTarget(void) {
      24. unsigned int SP;
      25. unsigned int PC;
      26. unsigned int VectorTableAddr;
      27. Util.LogHex("Offset = ", Offset);
      28. VectorTableAddr = Elf.GetBaseAddr();
      29. Util.LogHex("VT = ", VectorTableAddr);
      30. SP = Target.ReadU32(VectorTableAddr);
      31. Util.LogHex("SP = ", SP);
      32. if (SP != 0xFFFFFFFF) {
      33. Target.SetReg("SP", SP);
      34. }
      35. //PC = Target.ReadU32(VT + 0x04);
      36. PC = Elf.GetEntryPointPC();
      37. PC += Offset;
      38. Util.LogHex("Entry Point = ", PC);
      39. if (PC != 0xFFFFFFFF) {
      40. Target.SetReg("PC", PC);
      41. } else {
      42. Util.Error("Project script error: failed to set up entry point PC", 1);
      43. }
      44. }
      Display All

      But there isn't any offset of code section in the output:

      Source Code

      1. Offset = 0x1000
      2. Project.RelocateSymbols (".text", 4096);
      3. Offset res = 0x0
      4. File.Open ("***.elf");
      5. ...
      6. Offset = 0x1000
      7. Elf.GetBaseAddr(); // returns 0x8080000
      8. VT = 0x8080000
      9. Target.ReadU32 (0x08080000); // returns 0x4, data is 0xFFFFFFFF
      10. SP = 0xFFFFFFFF
      11. Elf.GetEntryPointPC(); // returns 0x80A7034
      12. Entry Point = 0x80A8034
      13. Target.SetReg ("PC", 0x80A8034);
      14. .....
      15. Offset = 0x1000
      16. Elf.GetBaseAddr(); // returns 0x8080000
      17. VT = 0x8080000
      18. Target.ReadU32 (0x08080000); // returns 0x4, data is 0x20080000
      19. SP = 0x20080000
      20. Target.SetReg ("SP", 0x20080000);
      21. Elf.GetEntryPointPC(); // returns 0x80A7034
      22. Entry Point = 0x80A8034
      23. Target.SetReg ("PC", 0x80A8034);
      24. Memory map 'after startup completion point' is active
      Display All
      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;

      Source Code

      1. Connected to target device.
      2. Reset: Halt core after reset via DEMCR.VC_CORERESET.
      3. Reset: Reset device via AIRCR.SYSRESETREQ.
      4. Offset = 0x0
      5. Elf.GetBaseAddr(); // returns 0x8080000
      6. VT = 0x8080000
      7. Target.ReadU32 (0x08080000); // returns 0x4, data is 0x20080000
      8. SP = 0x20080000
      9. Target.SetReg ("SP", 0x20080000);
      10. Elf.GetEntryPointPC(); // returns 0x80A6034
      11. Entry Point = 0x80A6034
      12. Target.SetReg ("PC", 0x80A6034);
      13. J-Link: Flash download: Bank 0 @ 0x08000000: Skipped. Contents already match
      14. Offset = 0x0
      15. Elf.GetBaseAddr(); // returns 0x8080000
      16. VT = 0x8080000
      17. Target.ReadU32 (0x08080000); // returns 0x4, data is 0x20080000
      18. SP = 0x20080000
      19. Target.SetReg ("SP", 0x20080000);
      20. Elf.GetEntryPointPC(); // returns 0x80A6034
      21. Entry Point = 0x80A6034
      22. Target.SetReg ("PC", 0x80A6034);
      23. Memory map 'after startup completion point' is active
      Display All
      So, I add TargetDownload function for bin file to the new address:

      C Source Code

      1. void TargetDownload (void) {
      2. Util.Log("Downloading Program.");
      3. unsigned int VectorTableAddr;
      4. VectorTableAddr = Elf.GetBaseAddr();
      5. res = Target.LoadMemory("***.bin", VectorTableAddr + Offset);
      6. Util.LogHex("Load res = ", res);
      7. }
      And have the same result - there is no any working breakpoints and no normal running application from new address.

      Source Code

      1. Reset: Reset device via AIRCR.SYSRESETREQ.
      2. Offset = 0x1000
      3. Elf.GetBaseAddr(); // returns 0x8080000
      4. VT = 0x8080000
      5. Target.ReadU32 (0x08080000); // returns 0x4, data is 0xFFFFFFFF
      6. SP = 0xFFFFFFFF
      7. Elf.GetEntryPointPC(); // returns 0x80A7034
      8. Entry Point = 0x80A8034
      9. Target.SetReg ("PC", 0x80A8034);
      10. Downloading Program.
      11. Elf.GetBaseAddr(); // returns 0x8080000
      12. Target.LoadMemory
      13. Load res = 0x0
      14. Offset = 0x1000
      15. Elf.GetBaseAddr(); // returns 0x8080000
      16. VT = 0x8080000
      17. Target.ReadU32 (0x08080000); // returns 0x4, data is 0xFFFFFFFF
      18. SP = 0xFFFFFFFF
      19. Elf.GetEntryPointPC(); // returns 0x80A7034
      20. Entry Point = 0x80A8034
      21. Target.SetReg ("PC", 0x80A8034);
      22. Memory map 'after startup completion point' is active
      Display All
      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.
      Images
      • Eclipse PIC.png

        95.17 kB, 1,258×978, viewed 22 times

      The post was edited 3 times, last by Aleksei ().