Category: Embedded

SDCC went from worst STM8 compiler to best in a very short time

I never used STM8 but I’m impressed with this achievement of SDCC compiler.

The ST marketing materials put STM8 Dhrystone performance at 0.29 DMIPS / Mhz.

Commercial compilers as Raisonance achieves 0.289 DMIPS / Mhz, Cosmic achieves 0.296 DMIPS / Mhz and IAR achieves 0.347 DMIPS / Mhz. See benchmark comparison here: http://colecovision.eu/stm8/compilers.shtml

SDCC 3.5.0 achieves 0.151 DMIPS / Mhz and SDCC 3.6.0 achieve 0.167 DMIPS / Mhz.

Now the SDCC in the repository (Revision #9652) outperforms them all at 0.355 DMIPS / Mhz.

If you want to use STM8 on Linux, these links could be useful:
http://embedonix.com/articles/linux/setting-up-development-and-programming-for-stm8-on-linux/
http://www.cnx-software.com/2015/04/13/how-to-program-stm8s-1-board-in-linux/

Source: Philipp Klaus Krause email in the SDCC mailing list “STM8 Dhrystone performance – new record at 0.355 DMIPS / Mhz using SDCC”.

Using JLinkExe to flash a new firmware into STM32F407

These are the commands I use to flash a nuttx.bin firmware in the STM32F407 microcontroller:

$ JLinkExe -if SWD
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 = 0.200V
J-Link>exit

$ 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 = 9, IRPrint = 0x0011
Info: Found Cortex-M4 r0p1, Little endian.
Info: FPUnit: 6 code (BP) slots and 2 literal slots
Info: CoreSight components:
Info: ROMTbl 0 @ E00FF000
Info: ROMTbl 0 [0]: FFF0F000, CID: B105E00D, PID: 000BB00C SCS
Info: ROMTbl 0 [1]: FFF02000, CID: B105E00D, PID: 003BB002 DWT
Info: ROMTbl 0 [2]: FFF03000, CID: B105E00D, PID: 002BB003 FPB
Info: ROMTbl 0 [3]: FFF01000, CID: B105E00D, PID: 003BB001 ITM
Info: ROMTbl 0 [4]: FFF41000, CID: B105900D, PID: 000BB9A1 TPIU
Info: ROMTbl 0 [5]: FFF42000, CID: B105900D, PID: 000BB925 ETM
Found 2 JTAG devices, Total IRLen = 9:
 #0 Id: 0x4BA00477, IRLen: 04, IRPrint: 0x1, CoreSight JTAG-DP (ARM)
 #1 Id: 0x06413041, IRLen: 05, IRPrint: 0x1, STM32 Boundary Scan
Cortex-M4 identified.
Target interface speed: 100 kHz

J-Link> device stm32f407ve
Info: Device "STM32F407VE" selected.
Reconnecting to target...
Info: TotalIRLen = 9, IRPrint = 0x0011
Info: TotalIRLen = 9, IRPrint = 0x0011
Info: Found Cortex-M4 r0p1, Little endian.
Info: FPUnit: 6 code (BP) slots and 2 literal slots
Info: CoreSight components:
Info: ROMTbl 0 @ E00FF000
Info: ROMTbl 0 [0]: FFF0F000, CID: B105E00D, PID: 000BB00C SCS
Info: ROMTbl 0 [1]: FFF02000, CID: B105E00D, PID: 003BB002 DWT
Info: ROMTbl 0 [2]: FFF03000, CID: B105E00D, PID: 002BB003 FPB
Info: ROMTbl 0 [3]: FFF01000, CID: B105E00D, PID: 003BB001 ITM
Info: ROMTbl 0 [4]: FFF41000, CID: B105900D, PID: 000BB9A1 TPIU
Info: ROMTbl 0 [5]: FFF42000, CID: B105900D, PID: 000BB925 ETM

J-Link> loadbin ./nuttx.bin 0
Halting CPU for downloading file.
Downloading file [./nuttx.bin]...Info: J-Link: Flash download: Flash programming performed for 1 range (65536 bytes)
Info: J-Link: Flash download: Total time needed: 9.917s (Prepare: 0.678s, Compare: 0.016s, Erase: 1.447s, Program: 7.687s, Verify: 0.006s, Restore: 0.081s)
O.K.
J-Link>

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.