BlocNotes

Notepad of a tinker, maker, hacker or whatever you call it :)

OpenSTM32, OpenOCD and ST-Link debugging

I continue the evaluation of STM32 micro-controllers with a Nucleo-L053R8, a development board for the STM32L0XX family.

I tried to use the OpenSTM32 package to use it with the Eclipse IDE and OpenOCD debugger and had to tinker a bit to be able to debug the target : the debug was working on Keil IDE but not Eclipse. The solution is really simple but drove me crazy for few hours : update the ST-Link firmware embedded inside de Nucleo board with this tool.

The OpenOCD error log:

Open On-Chip Debugger 0.9.0-dev (2015-11-20-15:46)
Licensed under GNU GPL v2
For bug reports, read
	http://openocd.org/doc/doxygen/bugs.html
adapter speed: 300 kHz
adapter_nsrst_delay: 100
Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
srst_only separate srst_nogate srst_open_drain connect_assert_srst
srst_only separate srst_nogate srst_open_drain connect_assert_srst
Info : Unable to match requested speed 300 kHz, using 240 kHz
Info : Unable to match requested speed 300 kHz, using 240 kHz
Info : clock speed 240 kHz
Info : STLINK v2 JTAG v20 API v2 SWIM v4 VID 0x0483 PID 0x374B
Info : using stlink api v2
Info : Target voltage: 3.249836
Info : stm32l0.cpu: hardware has 4 breakpoints, 2 watchpoints
adapter speed: 300 kHz
target state: halted
target halted due to debug-request, current mode: Thread 
xPSR: 0xf1000000 pc: 0x08000384 msp: 0x20002000
STM32L0: Enabling HSI16
adapter speed: 2500 kHz
** Programming Started **
auto erase enabled
Info : STM32L flash size is 64kb, base address is 0x8000000
Warn : couldn't use loader, falling back to page memory writes
wrote 8192 bytes from file Debug/STM32_Test.elf in 3.343717s (2.393 KiB/s)
** Programming Finished **
** Verify Started **
Error: JTAG failure
Error: Error setting register
target state: halted
target halted due to breakpoint, current mode: Handler HardFault
xPSR: 0x61000003 pc: 0x2000002e msp: 0x20002000
Error: JTAG failure
Error: Error setting register
target state: halted
target halted due to breakpoint, current mode: Handler HardFault
xPSR: 0x61000003 pc: 0x2000002e msp: 0x20002000
verified 4256 bytes in 0.203837s (20.390 KiB/s)
** Verified OK **
** Resetting Target **
adapter speed: 300 kHz
shutdown command invoked

For the record, the simple blink source code:

#include "stm32l0xx.h"
#include "stm32l0xx_nucleo.h"
			

int main(void)
{
	HAL_Init();

	// LED clock initialization
	LED2_GPIO_CLK_ENABLE();

	// Initialize LED
	GPIO_InitTypeDef GPIO_InitStruct;
	GPIO_InitStruct.Pin = LED2_PIN;
	GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
	GPIO_InitStruct.Pull = GPIO_PULLUP;
	GPIO_InitStruct.Speed = GPIO_SPEED_FAST;
	HAL_GPIO_Init(LED2_GPIO_PORT, &GPIO_InitStruct);

	while (1) {
		HAL_GPIO_TogglePin(LED2_GPIO_PORT, LED2_PIN); // Toggle the state of LED2
		HAL_Delay(5000); // Delay 
	}
}