ATSAM SWD communication issue

Go To Last Post
5 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi all,

I made a custom board with ATSAM4LC2AA, successfully flashed a blinking LED program with openocd and a cmsis-dap adapter, but when I tried increasing the clock speed to the RCFAST I probably made a mistake in the program. Now openocd fails to connect to the board and prints "Error: Could not initialize the debug port".

 

I serached online but I could not find many info on how to unbrick an ATSAM MCU.

 

Can anyone suggest a solution to get the chip to talk to openocd again?

Attachment(s): 

This topic has a solution.
Last Edited: Mon. Oct 19, 2020 - 06:00 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

fred11 wrote:
I tried increasing the clock speed

did you increase it to a point where waitstates are required ... ?

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I don't think it's a wait state issue, I tried to configure the RCFAST for 12MHz but I forgot to set the UNLOCK register so the RCFAST is likely not even started and the the CPU is stuck without a clock.

 

Considering that the ATSAM4L puts so much emphasis on low power operation (which is why I'm interested in those chips) I guess there must be a way to force an SWD connection to a chip with the clock halted, or at least I hope.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I checked the datasheet and found this which seems what I'm looking for:

8.7.8 SMAP Core Reset Request Source
The EDP has the ability to send a request to the SMAP for a Cortex-M4 Core reset. The procedure to do so is to hold TCK low until RESET_N is released. This mechanism aims at halting the CPU to prevent it from changing the system configuration while the SMAP is operating.

If I can halt the CPU immediately after reset, then it can't run the code that stops the clock. I have checked with a logic analyzer and TCK/SWCLK is high when RESET rises.

 

Now the problem is how to convince openocd to hold SWCLK low while deasserting RESET. Anyone has encountered a similar situation while debugging an ATSAM?

This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ok, I can confirm that holding SWCLK low when RESET is rising halts the CPU and prevents it from executing code that would prevent SWD communication.

 

I still don't know how to do it in openocd, I did it manually. I'm leaving the procedure should someone else encounter the same issue:

- unplug the cmsis-dap USB connection (I'm using a bluepill board flashed with a cmsis-dap firmware and assuming it also powers the target board)

- disconnect RESET and SWCLK from the cmsis-dap and connect them to ground

- plug in the USB connection

- disconnect RESET from ground and leave it open (do not connect it to the reset line of the cmsis-dap). This is where we provide the RESET rising edge while SWCLK is grounded

- disconnect SWCLK from ground and attach it to the cmsis-dap

- run openocd, now it should find the chip

- attach with gdb and run:

monitor reset halt  # This command usually fails to reset the chip, I still don't know why, but in this case it worked, maybe it's the core being already reset?

monitor flash write_image erase main.bin 0x4000

If everything goes well you should have unbricked your ATSAM.

 

Although it works, it's a bit time consuming. If an openocd expert knows how to do the reset sequence in code with a tcl script instead of manually, that would be an improvement.