Go Down

Topic: Flash problem with SAMD21G18A using OpenOCD SWD (Read 712 times) previous topic - next topic

biccius

Hi,

I state that I did a lot of research on the problem but I didn't find a solution so I try here.

I have a MKRZERO board (SAMD21G18A) and i want to flash my application using SWD interface.

I use a OLIMEX ARM USB OCD H (https://www.olimex.com/Products/ARM/JTAG/ARM-USB-OCD-H/) as flasher with a JTAG to SWD adapter connected to the board using the following pins :



The Openocd version i use is 0.9.0-rc1 for Windows taken from the previous link of the Olimex website.

The command i use is the following:
Code: [Select]
openocd.exe -f interface/ftdi/olimex-arm-usb-ocd-h.cfg -f interface/ftdi/olimex-arm-jtag-swd.cfg -f target/at91samdXX.cfg -f openocd.cfg


The connections seems to work properly and the samd microcontroller target is detected.

Code: [Select]

Open On-Chip Debugger 0.9.0-rc1 (2015-04-24-22:09)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
Info : FTDI SWD mode enabled
adapter speed: 500 kHz
adapter_nsrst_delay: 100
cortex_m reset_config sysresetreq
Info : clock speed 500 kHz
Info : SWD IDCODE 0x0bc11477
Info : at91samd.cpu: hardware has 4 breakpoints, 2 watchpoints


Then i open a telnet connection to localhost:4444 to send line command to openocd

-------------
> halt
target state: halted
target halted due to debug-request, current mode: Thread
xPSR: 0x61000000 pc: 0x000002c6 msp: 0x20007fe0
> at91samd chip-erase
chip erased
> at91samd bootloader 0
> reset

at91samd.cpu -- clearing lockup after double fault
target state: halted
target halted due to debug-request, current mode: Handler HardFault
xPSR: 0x61000003 pc: 0xfffffffe msp: 0xffffffd8
Polling target at91samd.cpu failed, trying to reexamine
at91samd.cpu: hardware has 4 breakpoints, 2 watchpoints
> targets
    TargetName         Type       Endian TapName            State
--  ------------------ ---------- ------ ------------------ ------------
 0* at91samd.cpu       cortex_m   little at91samd.cpu       halted
> program LED_NO_BOOT.bin verify reset
target state: halted
target halted due to debug-request, current mode: Thread
xPSR: 0x61000000 pc: 0xfffffffe msp: 0xfffffffc
** Programming Started **
auto erase enabled
SAMD MCU: SAMD21G18A (256KB Flash, 32KB RAM)
wrote 16384 bytes from file LED_NO_BOOT.bin in 1.560009s (10.256 KiB/s)
** Programming Finished **
** Verify Started **
verified 11184 bytes in 0.920014s (11.871 KiB/s)
** Verified OK **
** Resetting Target **
> reset run



After the last command the microcontroller enter in a infinite reset loop.

The application flashed is a simple 1000 ms blink test

The linker script of this application was modified to never use the bootloader but starting directly with the application :

Code: [Select]
{
  FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 0x00040000
  RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x00008000
}



I think i'm missing something stupid but i can't find a solution.
Any help?

westfw

Did you do a HARWARE reset after the bootloader 0 command?
Worth a try...

biccius

Hi westfw

I tried as your suggestion by pressing the RST button on the board

---
> at91samd chip-erase
chip erased
> at91samd bootloader 0
Polling target at91samd.cpu failed, trying to reexamine
Examination failed, GDB will be halted. Polling again in 100ms
Polling target at91samd.cpu failed, trying to reexamine
Examination failed, GDB will be halted. Polling again in 300ms
Polling target at91samd.cpu failed, trying to reexamine
Examination failed, GDB will be halted. Polling again in 700ms
Polling target at91samd.cpu failed, trying to reexamine
Examination failed, GDB will be halted. Polling again in 1500ms
Polling target at91samd.cpu failed, trying to reexamine
Examination failed, GDB will be halted. Polling again in 3100ms
SWD IDCODE 0x0bc11477
Polling target at91samd.cpu failed, trying to reexamine
SWD IDCODE 0x0bc11477
at91samd.cpu: hardware has 4 breakpoints, 2 watchpoints
---

Then i have to close and re-open the connection.
Target is halted so i can start the flashing

---
Open On-Chip Debugger
> targets
    TargetName         Type       Endian TapName            State
--  ------------------ ---------- ------ ------------------ ------------
 0* at91samd.cpu       cortex_m   little at91samd.cpu       halted
> program LED_NO_BOOT.bin verify reset
target state: halted
target halted due to debug-request, current mode: Thread
xPSR: 0xf1000000 pc: 0xfffffffe msp: 0xfffffffc
** Programming Started **
auto erase enabled
SAMD MCU: SAMD21G18A (256KB Flash, 32KB RAM)
wrote 16384 bytes from file LED_NO_BOOT.bin in 1.579873s (10.127 KiB/s)
** Programming Finished **
** Verify Started **
verified 11184 bytes in 0.920010s (11.871 KiB/s)
** Verified OK **
** Resetting Target **
> reset run
SWD IDCODE 0x0bc11477
> targets
    TargetName         Type       Endian TapName            State
--  ------------------ ---------- ------ ------------------ ------------
 0* at91samd.cpu       cortex_m   little at91samd.cpu       reset
---



But after run command the micro is in a infinite reset loop state

Code: [Select]

Open On-Chip Debugger 0.9.0-rc1 (2015-04-24-22:09)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
Info : FTDI SWD mode enabled
adapter speed: 500 kHz
adapter_nsrst_delay: 100
cortex_m reset_config sysresetreq
Info : clock speed 500 kHz
Info : SWD IDCODE 0x0bc11477
Info : at91samd.cpu: hardware has 4 breakpoints, 2 watchpoints
Polling target at91samd.cpu failed, trying to reexamine
Info : SWD IDCODE 0x0bc11477
Info : at91samd.cpu: hardware has 4 breakpoints, 2 watchpoints
Polling target at91samd.cpu failed, trying to reexamine
Info : SWD IDCODE 0x0bc11477
Info : at91samd.cpu: hardware has 4 breakpoints, 2 watchpoints
Polling target at91samd.cpu failed, trying to reexamine
Info : SWD IDCODE 0x0bc11477
Info : at91samd.cpu: hardware has 4 breakpoints, 2 watchpoints
Polling target at91samd.cpu failed, trying to reexamine
Info : SWD IDCODE 0x0bc11477
Info : at91samd.cpu: hardware has 4 breakpoints, 2 watchpoints
Polling target at91samd.cpu failed, trying to reexamine
Info : SWD IDCODE 0x0bc11477
Info : at91samd.cpu: hardware has 4 breakpoints, 2 watchpoints
Polling target at91samd.cpu failed, trying to reexamine
Info : SWD IDCODE 0x0bc11477
Info : at91samd.cpu: hardware has 4 breakpoints, 2 watchpoints
Polling target at91samd.cpu failed, trying to reexamine
Info : SWD IDCODE 0x0bc11477
Info : at91samd.cpu: hardware has 4 breakpoints, 2 watchpoints



The code i'm testing is the following:

Code: [Select]

#include "Arduino.h"

void setup()
{
pinMode ( LED_BUILTIN , OUTPUT );
}

void loop()
{
//Add your repeated code here
delay(100);
digitalWrite ( LED_BUILTIN  , HIGH );
delay(100);
digitalWrite ( LED_BUILTIN  , LOW );
}



The compiled binaries are available here
https://drive.google.com/open?id=1fkLqsVlhNNRfRW0MaiZYCuESBeiydTx2

Any suggestion will be appreciate

Thanks

biccius

Maybe i've solved updating openocd from 0.9 version to 0.10 last release and reducing the speed of the adapter from 400Khz to 40Khz.

There is still something strange because when I load a blink test everything works correctly but if I put custom binaries the application seems to go but the connection with opencod is lost so every binaries flash i have to do i have to disconnect and reconnect the olimex adapter.

I have to do other tests

kimguo

Industrial flow meters, also called industrial flow sensors. Flow Measurement is the process of measuring fluid in your plant or industry. Here

Go Up