[SOLVED] How to halt the program immediately after download and reset? How JLinkScript can be reused both in J-Link GDB Server and Ozone?

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

  • [SOLVED] How to halt the program immediately after download and reset? How JLinkScript can be reused both in J-Link GDB Server and Ozone?

    I have a SmartFusion2 based custom board which requires external DDR. SoftConsole and OpenOCD I have been used before with some cheap internal debugger.
    Since this board has Pin tracing available and by design it was made to be able to use J-Trace Pro Cortex-M for traceability, I started to use J-Trace with Ozone.

    First, I translated the DDR memory controller initialization part from OpenOCD compatible script to JLinkScript. I added all the register write operations in int AfterResetTarget() function. When I try to debug with Ozone, I see that the memory controller initialization and memory remapping it happens as it should be.
    Unfortunately the "Download & Reset Program" does not halt in the first instruction, and does not reach to call main. Here is what I see in the Console area:

    Source Code

    1. P[0]: AHB-AP (IDR: 0x24770011)
    2. Iterating through AP map to find AHB-AP to use
    3. AP[0]: Core found
    4. AP[0]: AHB-AP ROM base: 0xE00FF000
    5. CPUID register: 0x412FC231. Implementer code: 0x41 (ARM)
    6. Found Cortex-M3 r2p1, Little endian.
    7. FPUnit: 6 code (BP) slots and 2 literal slots
    8. CoreSight components:
    9. ROMTbl[0] @ E00FF000
    10. [0][0]: E000E000 CID B105E00D PID 000BB000 SCS
    11. [0][1]: E0001000 CID B105E00D PID 003BB002 DWT
    12. [0][2]: E0002000 CID B105E00D PID 002BB003 FPB
    13. [0][3]: E0000000 CID B105E00D PID 003BB001 ITM
    14. [0][4]: E0040000 CID B105900D PID 003BB923 TPIU-Lite
    15. [0][5]: E0041000 CID B105900D PID 003BB924 ETM-M3
    16. Connected to target device.
    17. J-Link/J-Trace serial number: 932000486
    18. Reset: Halt core after reset via DEMCR.VC_CORERESET.
    19. Reset: Reset device via AIRCR.SYSRESETREQ.
    20. AfterResetTarget() start
    21. DDR2 Init...
    22. DDR2 Init done
    23. AfterResetTarget() end - Took 122ms
    24. Elf.GetBaseAddr(); // returns 0x0
    25. Target.ReadU32 (0x00000000); // returns 0x4, data is 0x4
    26. Target.SetReg ("SP", 0x4);
    27. Elf.GetEntryPointPC(); // returns 0x21EE0
    28. Target.SetReg ("PC", 0x21EE0);
    29. Elf.GetBaseAddr(); // returns 0x0
    30. Target.ReadU32 (0x00000000); // returns 0x4, data is 0x4
    31. Target.SetReg ("SP", 0x4);
    32. Elf.GetEntryPointPC(); // returns 0x21EE0
    33. Target.SetReg ("PC", 0x21EE0);
    34. Executed J-Link command "SelectTraceSource=1"
    35. Memory map 'after startup completion point' is active
    Display All
    The PC and SP values seems correct.

    Then I started somehow the firmware by SoftConsole. Since I have a switch to connect from internal debugger to external one, then I can "Attach & Halt program" in Ozone using J-Trace. From here I can see the counters alongside the sourcecode are working, I can break it and continue. Just the Timeline remain empty.
    Unfortunately this unusual way to switch from one debugger to Ozone is not without error. Sometimes I have to try several times until it catches correctly.

    What I would like to achieve, to find a solution to load the elf file by Ozone, use that memory remapping written in JLinkScript, which seems to work also, than after "Download & Reset Program" I would like to halt immediately and from there I can debug what is wrong with the startup that now with Ozone always enter in a wrong state right from the beginning.

    I also tried to launch a J-Link GDB Server, pass the same JLinkScript file and debug from SoftConsole. There it seems to start correctly, despite I don't see the output from my JLinkScript. When I use J-Link GDB Server, do I see the output of JLinkScript, or that is possible to see only in the specially enabled log file which we pass to the GDB Server?

    Just to converge the topics what I want to achieve, here are my two questions:
    - How can I load a program in Ozone, then immediately halt?
    - How I can use the JLinkScript for J-Link GDB Server, including to see the output in console or log file? In my case the DDR init and memory remapping has to be written in a script and I guess is there a way that both Ozone and J-Link GDB Server can share the same portion.
  • fefu wrote:



    - How can I load a program in Ozone, then immediately halt?
    I found the answer to mMy first question.
    By reading the UG, the following 3 places together :
    - 5.6.1.1 Reset Mode
    - 7.9.12.9 Debug.SetResetMode
    - 7.2.8 Reset Modes
    tells me that if I manually insert Debug.SetResetMode(RM_RESET_HALT); in .jdebug file

    Source Code

    1. void OnProjectLoad (void) {
    2. //
    3. // Dialog-generated settings
    4. //
    5. .......
    6. //
    7. // User settings
    8. //
    9. Debug.SetResetMode(RM_RESET_HALT);
    10. .......
    11. }
    Display All
    then it works. My execution is halted in reset handler function at the beginning.
  • After I used Debug.SetResetMode(RM_RESET_HALT); as described above, I could observe that the DDR controller was initialized but the memory remapping registers were not enabling the memory remapping, therefore was wrong.
    Once I added those register settings, I could Load and Debug with Ozone and I see RTOS aware view and the Timeline also works.

    Still remained unsolved the case when I just use a J-Link GDB Server and use SoftConsole IDE which connect to gdb server local ip and port. It starts the debug process but looks like the JLinkScript which initializes the DDR controller and does the remapping works just in Ozone.
  • Hi refu,

    good to see that you already found the answer to your question in the Ozone user's manual. That's what we made the documentation for.

    Since your single remaining open point is not related to Ozone, please consider posting that inquiry in the J-Link forum.

    We will consider this thread here as closed now.

    Best regards and happy debugging
    -- AlexD
    Please read the forum rules before posting.

    Keep in mind, this is *not* a support forum.
    Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
    Should you be entitled to support you can contact us via our support system: segger.com/ticket/

    Or you can contact us via e-mail.