[SOLVED] J-link and AT91SAM7S256: Failed to download application - How configure new project?

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

  • [SOLVED] J-link and AT91SAM7S256: Failed to download application - How configure new project?

    Hi

    I'm trying to write flash in AT91SAM7S256 target using J-link and Embedded Studio. When i has used default configuration I have result as bellow - it always fails for different reasons.
    I tested device using testwspeed command in J-Link Commander and i can write succesfully data into SRAM space but not into flash.
    But when I configured target using "w4" command (disable watchdog and change MCK to 10MHz from PLL), Flash has been also succesfully written.
    I also tried to connect with target using J-Flash and it also works - It can reset, halt and write default registers.

    My question: when in my projet (in Embedded Studio) i can add this actions (write some registers) to run it before writting into flash? Is .jlinkscript file correct place to do this?
    Unfortunatly i can't found any documentation describing this script.

    br/
    Ryszard

    Logs from Segger Embedded Studio:

    Source Code

    1. Connecting ‘J-Link’
    2. Connecting to target adapter
    3. Loaded C:\Program Files (x86)\SEGGER\JLink_V510m\JLinkARM.dll
    4. Firmware Version: J-Link V9 compiled Feb 2 2016 18:43:46
    5. DLL Version: 5.10m
    6. Hardware Version: V9.30
    7. Target Voltage: 3.309
    8. Device "AT91SAM7S256" selected.
    9. TotalIRLen = 4, IRPrint = 0x01
    10. Identifying
    11. ARM7TDMI (0x3F0F0F0F)
    12. CPU is not halted
    13. Preparing target for download
    14. Executing script TargetInterface.resetAndStop(1000)
    15. Using DBGRQ to halt CPU
    16. Resetting TRST in order to halt CPU
    17. Failed to halt CPU core before Reset (SAM7).
    18. Resetting target using RESET pin
    19. TotalIRLen = 4, IRPrint = 0x01
    20. Halting CPU core
    21. Using DBGRQ to halt CPU
    22. Resetting TRST in order to halt CPU
    23. Resetting target using RESET pin
    24. TotalIRLen = 4, IRPrint = 0x01
    25. Halting CPU core
    26. Using DBGRQ to halt CPU
    27. Resetting TRST in order to halt CPU
    28. Unable to halt CPU core
    29. Can not read register 0 (R0) while CPU is running
    30. Can not read register 1 (R1) while CPU is running
    31. Can not read register 2 (R2) while CPU is running
    32. Can not read register 3 (R3) while CPU is running
    33. Can not read register 4 (R4) while CPU is running
    34. Can not read register 5 (R5) while CPU is running
    35. Can not read register 6 (R6) while CPU is running
    36. Can not read register 7 (R7) while CPU is running
    37. Can not read register 10 (R8_USR) while CPU is running
    38. Can not read register 11 (R9_USR) while CPU is running
    39. Can not read register 12 (R10_USR) while CPU is running
    40. Can not read register 13 (R11_USR) while CPU is running
    41. Can not read register 14 (R12_USR) while CPU is running
    42. Can not read register 15 (R13_USR) while CPU is running
    43. Can not read register 16 (R14_USR) while CPU is running
    44. Can not read register 9 (R15 (PC)) while CPU is running
    45. Can not read register 8 (CPSR) while CPU is running
    46. Can not read register 18 (R8_FIQ) while CPU is running
    47. Can not read register 19 (R9_FIQ) while CPU is running
    48. Can not read register 20 (R10_FIQ) while CPU is running
    49. Can not read register 21 (R11_FIQ) while CPU is running
    50. Can not read register 22 (R12_FIQ) while CPU is running
    51. Can not read register 23 (R13_FIQ) while CPU is running
    52. Can not read register 24 (R14_FIQ) while CPU is running
    53. Can not read register 17 (SPSR_FIQ) while CPU is running
    54. Can not read register 26 (R13_SVC) while CPU is running
    55. Can not read register 27 (R14_SVC) while CPU is running
    56. Can not read register 25 (SPSR_SVC) while CPU is running
    57. Can not read register 29 (R13_ABT) while CPU is running
    58. Can not read register 30 (R14_ABT) while CPU is running
    59. Can not read register 28 (SPSR_ABT) while CPU is running
    60. Can not read register 32 (R13_IRQ) while CPU is running
    61. Can not read register 33 (R14_IRQ) while CPU is running
    62. Can not read register 31 (SPSR_IRQ) while CPU is running
    63. Can not read register 35 (R13_UND) while CPU is running
    64. Can not read register 36 (R14_UND) while CPU is running
    65. Can not read register 34 (SPSR_UND) while CPU is running
    66. Erasing all memory
    67. Erase successful
    68. Programming
    69. Programming 0.0 KB of .vectors addresses 00100000 — 0010003b
    70. Programming 0.6 KB of .init addresses 0010003c — 001002af
    71. Programming 0.3 KB of .text addresses 001002b0 — 001003f3
    72. Failed to measure CPU clock frequency
    73. Can not read register 0 (R0) while CPU is running
    74. Can not read register 1 (R1) while CPU is running
    75. Can not read register 2 (R2) while CPU is running
    76. Can not read register 3 (R3) while CPU is running
    77. Can not read register 4 (R4) while CPU is running
    78. Can not read register 5 (R5) while CPU is running
    79. Can not read register 6 (R6) while CPU is running
    80. Can not read register 7 (R7) while CPU is running
    81. Can not read register 10 (R8_USR) while CPU is running
    82. Can not read register 11 (R9_USR) while CPU is running
    83. Can not read register 12 (R10_USR) while CPU is running
    84. Can not read register 13 (R11_USR) while CPU is running
    85. Can not read register 14 (R12_USR) while CPU is running
    86. Can not read register 15 (R13_USR) while CPU is running
    87. Can not read register 16 (R14_USR) while CPU is running
    88. Can not read register 9 (R15 (PC)) while CPU is running
    89. Can not read register 8 (CPSR) while CPU is running
    90. Can not read register 30 (R14_ABT) while CPU is running
    91. Can not read register 28 (SPSR_
    92. Failed to download application.
    93. Generic error.
    94. Please check J-Link and target connection.
    95. Programming completed in 1.1 s — 0 bytes/sec
    96. CPU is not halted
    Display All


    Another fail:

    Source Code

    1. Connecting ‘J-Link’
    2. Connecting to target adapter
    3. Loaded C:\Program Files (x86)\SEGGER\JLink_V510m\JLinkARM.dll
    4. Firmware Version: J-Link V9 compiled Feb 2 2016 18:43:46
    5. DLL Version: 5.10m
    6. Hardware Version: V9.30
    7. Target Voltage: 3.312
    8. Device "AT91SAM7S256" selected.
    9. TotalIRLen = 4, IRPrint = 0x01
    10. Identifying
    11. ARM7TDMI (0x3F0F0F0F)
    12. Preparing target for download
    13. Executing script TargetInterface.resetAndStop(1000)
    14. Programming
    15. Programming 0.0 KB of .vectors addresses 00100000 — 0010003b
    16. Programming 0.6 KB of .init addresses 0010003c — 001002af
    17. Programming 0.3 KB of .text addresses 001002b0 — 001003f3
    18. Failed to download RAMCode.
    19. Failed to download RAMCode!
    20. Write memory error @ address 0x00200000, word access: Memory access timeout.
    21. Could not detect CPU clock speed. Readback of test code downloaded into RAM failed.
    22. Failed to download application.
    23. Generic error.
    24. Please check J-Link and target connection.
    25. Programming completed in 5.7 s — 0 bytes/sec
    26. CPU is not halted
    27. Can not read register 0 (R0) while CPU is running
    28. Can not read register 1 (R1) while CPU is running
    29. Can not read register 2 (R2) while CPU is running
    30. Can not read register 3 (R3) while CPU is running
    31. Can not read register 4 (R4) while CPU is running
    32. Can not read register 5 (R5) while CPU is running
    33. Can not read register 6 (R6) while CPU is running
    34. Can not read register 7 (R7) while CPU is running
    35. Can not read register 10 (R8_USR) while CPU is running
    36. Can not read register 11 (R9_USR) while CPU is running
    37. Can not read register 12 (R10_USR) while CPU is running
    38. Can not read register 13 (R11_USR) while CPU is running
    39. Can not read register 14 (R12_USR) while CPU is running
    40. Can not read register 15 (R13_USR) while CPU is running
    41. Can not read register 16 (R14_USR) while CPU is running
    42. Can not read register 9 (R15 (PC)) while CPU is running
    43. Can not read register 8 (CPSR) while CPU is running
    44. Can not read register 18 (R8_FIQ) while CPU is running
    45. Can not read register 19 (R9_FIQ) while CPU is running
    46. Can not read register 20 (R10_FIQ) while CPU is running
    47. Can not read register 21 (R11_FIQ) while CPU is running
    48. Can not read register 22 (R12_FIQ) while CPU is running
    49. Can not read register 23 (R13_FIQ) while CPU is running
    50. Can not read register 24 (R14_FIQ) while CPU is running
    51. Can not read register 17 (SPSR_FIQ) while CPU is running
    52. Can not read register 26 (R13_SVC) while CPU is running
    53. Can not read register 27 (R14_SVC) while CPU is running
    54. Can not read register 25 (SPSR_SVC) while CPU is running
    55. Can not read register 29 (R13_ABT) while CPU is running
    56. Can not read register 30 (R14_ABT) while CPU is running
    57. Can not read register 28 (SPSR_ABT) while CPU is running
    58. Can not read register 32 (R13_IRQ) while CPU is running
    59. Can not read register 33 (R14_IRQ) while CPU is running
    60. Can not read register 31 (SPSR_IRQ) while CPU is running
    61. Can not read register 35 (R13_UND) while CPU is running
    62. Can not read register 36 (R14_UND) while CPU is running
    63. Can not read register 34 (SPSR_UND) while CPU is running
    64. CPU is not halted
    Display All


    Edit:

    Now I'm confused. I see that if I every time execute power sequence (power off, power on, reset), then I can always succesfully run testwspeed on flash memory, but erase and loadfile never run without errors. (hex file I got from Embedded Studio). Due to problem with erase command I'm not now sure that is problem with configuration in Studio. Another question why addres 0x00200000 is used - it is a SRAM space, not flash in this target.

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

  • Hi,

    Target initialization can be done with a JavaScript file.
    In the project properties -> Target Script Options set the Target Script file to your JavaScript
    and set the Connect Script to the initialization function in your script.
    For more information about the script, refer to studio.segger.com/arm_target_script_TargetInterface.htm

    Best regards
    Johannes
    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.
  • Hi

    Thank you for reply. I tried to run additional scripts on connection but it also fails. Now I think that my problem is not with Embedded studio but with my board or target - so firstly I must investigate it or try another one.

    br/
    Ryszard
  • Hi

    I has checked my target and it works, i found way to successfully write flash, and run program but only in J-Link commander - to write flash I must change target clock to higher - as on init sequence in J-Flash. I tried to add this sequence in Connect Script using TargetInterface.pokeUint32(address, data) and TargetInterface.delay(ms), but problem is earlier - write into memory fails due to unable to halt CPU. In J-Link commander i see that in this case only power sequence (power off, power on) works, and target is halted after reset. Is possible to add power sequence before reset in Embedded Studio?. Now target is always powered - also after disconnect. In J-Flash power is off after disconnect so during connection device is halted after reset.
    Another question - has been Embedded Studio tested with AT91SAM7S* target?

    br/
    Ryszard
  • Hi.

    I think that I has found solution for my problem. AT91SAM7S has inactive reset pin for default, so is impossible to trigger user reset. To trigger software reset CPU must be halted - it is triggered by writing data into register. In conclusion only power on reset can reset CPU. I added enabling user reset (reset pin) after power on reset and now all works fine.
    My configuration

    Source Code

    1. TargetInterface.pokeUint32(0xFFFFFD08, 0xA5000001)
    2. TargetInterface.pokeUint32(0xFFFFFD44, 0x00008000)
    3. TargetInterface.pokeUint32(0xFFFFFF60, 0x00320300)
    4. TargetInterface.pokeUint32(0xFFFFFC20, 0x00000601)
    5. TargetInterface.delay(200)
    6. TargetInterface.pokeUint32(0xFFFFFC2C, 0x00191C05)
    7. TargetInterface.delay(200)
    8. TargetInterface.pokeUint32(0xFFFFFC30, 0x00000007)


    In first line user reset is enabled, next lines trigger disable watchdog, change flash states and change clock to PLL. It need external crystal to be connected.

    Than you for help.
  • Hi,

    Good to read you were able to solve the problem.
    Enabling reset and disabling the watchdog is always a good way to go.

    Regards
    Johannes
    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.