Day: June 14, 2015

Flashing NuttX on SAML21 microcontroller

I was trying to use OpenOCD and STLink-v2 to flash a board powered by Atmel SAML21 microcontroller, using this openocd.cfg:

# SAML21 X Pro Target

# Using stlink as SWD programmer
source [find interface/stlink-v2.cfg]

# SWD as transport
transport select hla_swd

# Use SAML21 target
set WORKAREASIZE 0x4000
source [find target/at91samdXX.cfg]

But OpenOCD was reporting this error:

Warn : UNEXPECTED idcode: 0x0bc11477
Error: expected 1 of 1: 0x4ba00477 

Then I modified at91samdXX.cfg replacing 0x4ba00477 by 0x0bc11477, but the “reset halt” command was failing.

Then I decided to use a J-Link programmer:

$ sudo JLinkExe
SEGGER J-Link Commander V4.98e ('?' for help)
Compiled May  5 2015 11:49:39
DLL version V4.98e, compiled May  5 2015 11:49:35
Firmware: J-Link ARM V8 compiled Nov 28 2014 13:44:46
Hardware: V8.00
S/N: 268006167 
OEM: SEGGER-EDU 
Feature(s): FlashBP, GDB 
VTarget = 3.300V
Info: TotalIRLen = ?, IRPrint = 0x..000000000000000000000000
Info: TotalIRLen = ?, IRPrint = 0x..000000000000000000000000
No devices found on JTAG chain. Trying to find device on SWD.
Info: Found SWD-DP with ID 0x0BC11477
Info: Found Cortex-M0 r0p1, Little endian.
Info: FPUnit: 4 code (BP) slots and 0 literal slots
Info: CoreSight components:
Info: ROMTbl 0 @ 41003000
Info: ROMTbl 0 [0]: 9F0FC000, CID: B105100D, PID: 000BB4C0 ROM Table
Info: ROMTbl 1 @ E00FF000
Info: ROMTbl 1 [0]: FFF0F000, CID: B105E00D, PID: 000BB008 SCS
Info: ROMTbl 1 [1]: FFF02000, CID: B105E00D, PID: 000BB00A DWT
Info: ROMTbl 1 [2]: FFF03000, CID: B105E00D, PID: 000BB00B FPB
Info: ROMTbl 0 [1]: 00003000, CID: B105900D, PID: 001BB932 MTB-M0+
Cortex-M0 identified.
Target interface speed: 100 kHz

J-Link>exec device = ATSAML21J18
Info: Device "ATSAML21J18" selected.

J-Link>loadbin /tmp/nuttx.bin, 0x0
Downloading file [/tmp/nuttx.bin]...
**************************
WARNING: CPU is running at low speed (5301 kHz).
**************************

Info: J-Link: Flash download: Flash programming performed for 1 range (44288 bytes)
Info: J-Link: Flash download: Total time needed: 7.121s (Prepare: 0.698s, Compare: 0.255s, Erase: 0.000s, Program: 6.106s, Verify: 0.009s, Restore: 0.051s)
O.K.
J-Link>

J-Link>r
Reset delay: 0 ms
Reset type NORMAL: Resets core & peripherals via SYSRESETREQ & VECTRESET bit.

J-Link>g

J-Link also detected the same idcode: 0x0bc11477 (I think this is the ID for Cortex-M0 microcontroller), then OpenOCD is correct. Using J-Link I got nuttx.bin flashed correctly.

Now I need to investigate about the STLink-v2 reset issue.