Showing results for 
Search instead for 
Did you mean: 

How to flash an STM32L081 using West Tools, OpenOCD and JLink



I've made a custom board using the Zephyr SDK and a STM32L081 soc. I would like to flash my board using a JLink Debug prog with OpenOCD and GDB.

Compiling works fine but when it comes to using my openocd.cfg file as support for my board, I get this result

Info : Device: STM32L0xx (Cat.5)
Info : STM32L flash has dual banks. Bank (0) size is 96kb, base address is 0x8000000
Warn : target was in unknown state when halt was requested
Info : SWD DPIDR 0x0bc11477
Error: error writing to flash at address 0x08000000 at offset 0x00000000
auto erase enabled

 I attached the full output below.

I made the open ocd config file based on the one from the ST NUCLEO-L011K4 board.

source [find interface/jlink.cfg]

transport select swd

# source [find target/stm32l0.cfg]
source [find target/stm32l0_dual_bank.cfg]

# There is only system reset line and JTAG/SWD command can be issued when SRST
reset_config srst_only

$_TARGETNAME configure -event gdb-attach {
        echo "Debugger attaching: halting execution"
        reset halt
        gdb_breakpoint_override hard

$_TARGETNAME configure -event gdb-detach {
        echo "Debugger detaching: resuming execution"

I know the problem doesn't come from the hardware since I can launch a debug session with STM32CubeIDE and the same JLink probe without error.

Thank you for your help.

ST Employee

Hello @KlaraSrl

From the output I can see that OpenOCD is using the J-Link debugger successfully, The target voltage is within the normal operating range...

thinking to verify the flash size, STM32L081 is a category 5 device with Bank 0 being 96 KB...

Maybe the flash memory is write-protected, have you checked that? Are there any updates on this issue? 

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.