Programming Custom STM32F030C6 Board

I have a STM32F0 Discovery Kit Eval Board and I can successfully program that board. I then wanted to use this eval’s board ST-LINK to program my custom board but I’m not having any luck as can be seen by the terminal output below.

Using the same hardware and connections I can use the STM32CubeIDE and debug the board.

I can also use the STM32 ST-LINK Utility to program the board with the bin filed generated by PIO but that doesn’t seem to run on the board even though program and verify works.

I’m new to the STM32 family and tools so hopefully I’m just missing something obvious. I have the ST-LINK jumpers removed from the eval board and I know my custom board gets programmed because I can test it during a debug session using STM32Cube.

> Executing task in folder 190511-105412-arduino-blink: 
> C:\Users\george\.platformio\penv\Scripts\platformio.exe run --target upload 
> 
> Processing disco_f030r8 (platform: ststm32; board: disco_f030r8; framework: arduino)
> --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
> Verbose mode can be enabled via `-v, --verbose` option
> CONFIGURATION: https://docs.platformio.org/page/boards/ststm32/disco_f030r8.html
> PLATFORM: ST STM32 > ST STM32F0308DISCOVERY
> HARDWARE: STM32F030R8T6 1MHz 8KB RAM (64KB Flash)
> DEBUG: CURRENT(stlink) ON-BOARD(stlink) EXTERNAL(blackmagic, jlink)
> Library Dependency Finder -> http://bit.ly/configure-pio-ldf
> LDF MODES: FINDER(chain) COMPATIBILITY(soft)
> Collected 7 compatible libraries
> Scanning dependencies...
> No dependencies
> Checking size .pioenvs\disco_f030r8\firmware.elf
> Memory Usage -> xxxxxxpio-memory-usage
> DATA:    [=         ]  12.5% (used 1024 bytes from 8192 bytes)
> PROGRAM: [==        ]  15.9% (used 10396 bytes from 65536 bytes)
> Configuring upload protocol...
> AVAILABLE: blackmagic, jlink, stlink
> CURRENT: upload_protocol = stlink
> Uploading .pioenvs\disco_f030r8\firmware.elf
> GNU MCU Eclipse OpenOCD, 64-bitOpen On-Chip Debugger 0.10.0+dev-00593-g23ad80df4 (2019-04-22-20:25)
> Licensed under GNU GPL v2
> For bug reports, read
> http://openocd.org/doc/doxygen/bugs.html
> Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
> adapter speed: 1000 kHz
> adapter_nsrst_delay: 100
> none separate
> srst_only separate srst_nogate srst_open_drain connect_deassert_srst
> Info : clock speed 1000 kHz
> Info : STLINK V2J33S0 (API v2) VID:PID 0483:3748
> Info : Target voltage: 5.761416
> Info : stm32f0x.cpu: hardware has 4 breakpoints, 2 watchpoints
> Info : Listening on port 3333 for gdb connections
> Info : Unable to match requested speed 1000 kHz, using 950 kHz
> Info : Unable to match requested speed 1000 kHz, using 950 kHz
> adapter speed: 950 kHz
> target halted due to debug-request, current mode: Thread
> xPSR: 0xc1000000 pc: 0xfffffffe msp: 0xfffffffc
> Info : Unable to match requested speed 8000 kHz, using 4000 kHz
> Info : Unable to match requested speed 8000 kHz, using 4000 kHz
> adapter speed: 4000 kHz
> ** Programming Started **
> auto erase enabled
> Info : device id = 0x10006444
> Info : flash size = 32kbytes
> Error: error writing to flash at address 0x08000000 at offset 0x00000000
> embedded:startup.tcl:479: Error: ** Programming Failed **
> in procedure 'program'
> in procedure 'program_error' called at file "embedded:startup.tcl", line 538
> at file "embedded:startup.tcl", line 479
> *** [upload] Error 1
> =========================================================================================================== [ERROR] Took 2.93 seconds ===========================================================================================================
> The terminal process terminated with exit code: 1
> 
> Terminal will be reused by tasks, press any key to close it.

5.7 Volts for a 3.3V chip? You grilled it?

This post suggests that modifying the worksize or clock frequency might solve the problem, so you should try some modification to the C:\Users\<user>\.platformio\packages\tool-openocd\scripts\target\stm32f0x.cfg config.

I saw the 5.7V but did know where that came from. I used the exact same setup that worked for the eval board. I can still run a debug session on my board and it works so the chip is fine

Where did you connect the VDD_TARGET pin of your flasher board to? (this page 19)

My target board got connected to the 3V pin (I actually have the STM32F030 Discovery Kit, not the Nucleus).

Then GND, SWDIO, SWDCLK, and nRST are connected

And the multimeter also says 3.3V on the VDD_TARGET pin? Well if it says, I guess openocd just has a bug. I’d still try the configuration changes from above though.

Yes, I’m positive it is 3.3V. 5.7V doesn’t even make any sense since the only connections are USB and that’s 5.0V but the SWD connections are after that on the ST-LINK portion of the board.

I’ll take a look at the stm32f1x.cfg but my target processor is the STM32F030C6

Ups no my mistake, you need the stm32f0x.cfg of course.

OK, I just ran a test and had a good result. In the stm32f0x.cfg config file you’ll find:

# Work-area is a space in RAM used for flash programming
# By default use 4kB
# GI 180521 Comment for testing
#if { [info exists WORKAREASIZE] } {
#   set _WORKAREASIZE $WORKAREASIZE
#} else {
#   set _WORKAREASIZE 0x1000
#}

#GI 180521 Test Code
set _WORKAREASIZE 0x1000

In the forum post they talked about changing WORKAREASIZE to 0x1000 and you can see that there’s a condition check to set it to that size but I commented it out and just hard coded the size to 0x1000 and that did in fact allow my custom board to get programmed.

But, all is not happy as my board is not running my program. I have PC13 defined as an input with a pull-up and I’m not seeing a high on that pin. I took the exact same program and programmed the Eval Board and the program works as expected.

I know my target board works because I have a similar program in STM32CubeIDE and after some searching I found how to create a HEX file and using that and the STM32 ST-LINK Utility program I was able to program my target board and it works.

So I’m stumped as to what is going on

Here’s the output of the programming.

CURRENT: upload_protocol = stlink
Uploading .pioenvs\disco_f030r8\firmware.elf
GNU MCU Eclipse OpenOCD, 64-bitOpen On-Chip Debugger 0.10.0+dev-00593-g23ad80df4 (2019-04-22-20:25)
Licensed under GNU GPL v2
For bug reports, read
xxxx.openocd.org/doc/doxygen/bugs.html
Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
adapter speed: 1000 kHz
adapter_nsrst_delay: 100
none separate
srst_only separate srst_nogate srst_open_drain connect_deassert_srst
Info : clock speed 1000 kHz
Info : STLINK V2J33S0 (API v2) VID:PID 0483:3748
Info : Target voltage: 5.758584
Info : stm32f0x.cpu: hardware has 4 breakpoints, 2 watchpoints
Info : Listening on port 3333 for gdb connections
Info : Unable to match requested speed 1000 kHz, using 950 kHz
Info : Unable to match requested speed 1000 kHz, using 950 kHz
adapter speed: 950 kHz
target halted due to debug-request, current mode: Thread
xPSR: 0xc1000000 pc: 0x08001f14 msp: 0x20002000
Info : Unable to match requested speed 8000 kHz, using 4000 kHz
Info : Unable to match requested speed 8000 kHz, using 4000 kHz
adapter speed: 4000 kHz
** Programming Started **
auto erase enabled
Info : device id = 0x10006444
Info : flash size = 32kbytes
wrote 11264 bytes from file .pioenvs\disco_f030r8\firmware.elf in 0.604384s (18.200 KiB/s)
** Programming Finished **
** Verify Started **
verified 10608 bytes in 0.065824s (157.380 KiB/s)
** Verified OK **
** Resetting Target **
Info : Unable to match requested speed 1000 kHz, using 950 kHz
Info : Unable to match requested speed 1000 kHz, using 950 kHz
adapter speed: 950 kHz
shutdown command invoked

Does it work when you program your custom board using the eval board and the exact same code you have in PlatformIO? What is that code?

Well unfortunately I was experimenting with different tools and code. I started with Arduino and PIO which works with the eval board but not with my custom board (which BTW is just the STM32 on a breakout board with the bypass caps and BOOT0 pull-down).

When I couldn’t program my custom board with PIO I installed the ST tools and used STM32Cube HAL code in that environment.

Here’s the code I have in PIO

#include <Arduino.h>

#ifndef LED_BUILTIN
  #define LED_BUILTIN PC9
#endif
#define my_Pin PB2

void setup()
{
  // initialize LED digital pin as an output.
  pinMode(LED_BUILTIN, OUTPUT);
  pinMode(PC8, OUTPUT);
  pinMode(PC13, INPUT_PULLUP);
  pinMode(my_Pin, OUTPUT); //ULN2803 Drive
  digitalWrite(my_Pin, HIGH);
}

void loop()
{
  if(digitalRead(PC13) == LOW) {
    digitalWrite(PC8, HIGH);
    digitalWrite(my_Pin, HIGH); // Thermostat made a call
  }  else {
       digitalWrite(PC8, LOW);
       digitalWrite(my_Pin, LOW); // Don't drive ULN2803
     }
}

I just took the HAL version of this code which does work on my custom board when using the ST utilities to program. I get the same results, PIO thinks that it programmed the device correctly yet the code isn’t running.

Here’s the terminal output from PIO when compiling and programming my custom board with the HAL code:

> Executing task in folder 190521-093414-stm32cube-hal-blink: C:\Users\george\.platformio\penv\Scripts\platformio.exe run --target upload <

Processing disco_f030r8 (platform: ststm32; board: disco_f030r8; framework: stm32cube)
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/ststm32/disco_f030r8.html
PLATFORM: ST STM32 > ST STM32F0308DISCOVERY
HARDWARE: STM32F030R8T6 48MHz 8KB RAM (64KB Flash)
DEBUG: CURRENT(stlink) ON-BOARD(stlink) EXTERNAL(blackmagic, jlink)
Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF MODES: FINDER(chain) COMPATIBILITY(soft)
Collected 6 compatible libraries
Scanning dependencies...
No dependencies
Compiling .pioenvs\disco_f030r8\src\main.o
Compiling .pioenvs\disco_f030r8\FrameworkBSP\stm32f0308_discovery.o
Compiling .pioenvs\disco_f030r8\FrameworkHALDriver\Src\stm32f0xx_hal.o
Compiling .pioenvs\disco_f030r8\FrameworkHALDriver\Src\stm32f0xx_hal_adc.o
Compiling .pioenvs\disco_f030r8\FrameworkHALDriver\Src\stm32f0xx_hal_adc_ex.o
Compiling .pioenvs\disco_f030r8\FrameworkHALDriver\Src\stm32f0xx_hal_can.o
Compiling .pioenvs\disco_f030r8\FrameworkHALDriver\Src\stm32f0xx_hal_cec.o
Compiling .pioenvs\disco_f030r8\FrameworkHALDriver\Src\stm32f0xx_hal_comp.o
Compiling .pioenvs\disco_f030r8\FrameworkHALDriver\Src\stm32f0xx_hal_cortex.o
Compiling .pioenvs\disco_f030r8\FrameworkHALDriver\Src\stm32f0xx_hal_crc.o
Compiling .pioenvs\disco_f030r8\FrameworkHALDriver\Src\stm32f0xx_hal_crc_ex.o
src\main.c: In function 'SystemClock_Config':
src\main.c:100:5: warning: implicit declaration of function 'Error_Handler' [-Wimplicit-function-declaration]
Error_Handler();
^~~~~~~~~~~~~
src\main.c: At top level:
src\main.c:155:6: warning: conflicting types for 'Error_Handler'
void Error_Handler(void)
^~~~~~~~~~~~~
src\main.c:100:5: note: previous implicit declaration of 'Error_Handler' was here
Error_Handler();
^~~~~~~~~~~~~
Compiling .pioenvs\disco_f030r8\FrameworkHALDriver\Src\stm32f0xx_hal_dac.o
Compiling .pioenvs\disco_f030r8\FrameworkHALDriver\Src\stm32f0xx_hal_dac_ex.o
Compiling .pioenvs\disco_f030r8\FrameworkHALDriver\Src\stm32f0xx_hal_dma.o
Compiling .pioenvs\disco_f030r8\FrameworkHALDriver\Src\stm32f0xx_hal_flash.o
Compiling .pioenvs\disco_f030r8\FrameworkHALDriver\Src\stm32f0xx_hal_flash_ex.o
C:\Users\george\.platformio\packages\framework-stm32cube\f0\Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_hal_crc.c: In function 'CRC_Handle_8':
C:\Users\george\.platformio\packages\framework-stm32cube\f0\Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_hal_crc.c:475:8: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
*(uint16_t volatile*) (&hcrc->Instance->DR) = ((uint32_t)pBuffer[4*i]<<8) | (uint32_t)pBuffer[4*i+1];
^
C:\Users\george\.platformio\packages\framework-stm32cube\f0\Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_hal_crc.c:479:8: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
*(uint16_t volatile*) (&hcrc->Instance->DR) = ((uint32_t)pBuffer[4*i]<<8) | (uint32_t)pBuffer[4*i+1];
^
C:\Users\george\.platformio\packages\framework-stm32cube\f0\Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_hal_crc.c: In function 'CRC_Handle_16':
C:\Users\george\.platformio\packages\framework-stm32cube\f0\Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_hal_crc.c:511:8: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
*(uint16_t volatile*) (&hcrc->Instance->DR) = pBuffer[2*i];
^
Archiving .pioenvs\disco_f030r8\libFrameworkBSP.a
Compiling .pioenvs\disco_f030r8\FrameworkHALDriver\Src\stm32f0xx_hal_gpio.o
Compiling .pioenvs\disco_f030r8\FrameworkHALDriver\Src\stm32f0xx_hal_i2c.o
Compiling .pioenvs\disco_f030r8\FrameworkHALDriver\Src\stm32f0xx_hal_i2c_ex.o
Compiling .pioenvs\disco_f030r8\FrameworkHALDriver\Src\stm32f0xx_hal_i2s.o
Compiling .pioenvs\disco_f030r8\FrameworkHALDriver\Src\stm32f0xx_hal_irda.o
Compiling .pioenvs\disco_f030r8\FrameworkHALDriver\Src\stm32f0xx_hal_iwdg.o
Compiling .pioenvs\disco_f030r8\FrameworkHALDriver\Src\stm32f0xx_hal_pcd.o
Compiling .pioenvs\disco_f030r8\FrameworkHALDriver\Src\stm32f0xx_hal_pcd_ex.o
Compiling .pioenvs\disco_f030r8\FrameworkHALDriver\Src\stm32f0xx_hal_pwr.o
Compiling .pioenvs\disco_f030r8\FrameworkHALDriver\Src\stm32f0xx_hal_pwr_ex.o
Compiling .pioenvs\disco_f030r8\FrameworkHALDriver\Src\stm32f0xx_hal_rcc.o
Compiling .pioenvs\disco_f030r8\FrameworkHALDriver\Src\stm32f0xx_hal_rcc_ex.o
Compiling .pioenvs\disco_f030r8\FrameworkHALDriver\Src\stm32f0xx_hal_rtc.o
Compiling .pioenvs\disco_f030r8\FrameworkHALDriver\Src\stm32f0xx_hal_rtc_ex.o
Compiling .pioenvs\disco_f030r8\FrameworkHALDriver\Src\stm32f0xx_hal_smartcard.o
Compiling .pioenvs\disco_f030r8\FrameworkHALDriver\Src\stm32f0xx_hal_smartcard_ex.o
Compiling .pioenvs\disco_f030r8\FrameworkHALDriver\Src\stm32f0xx_hal_smbus.o
Compiling .pioenvs\disco_f030r8\FrameworkHALDriver\Src\stm32f0xx_hal_spi.o
Compiling .pioenvs\disco_f030r8\FrameworkHALDriver\Src\stm32f0xx_hal_spi_ex.o
Compiling .pioenvs\disco_f030r8\FrameworkHALDriver\Src\stm32f0xx_hal_tim.o
Compiling .pioenvs\disco_f030r8\FrameworkHALDriver\Src\stm32f0xx_hal_tim_ex.o
Compiling .pioenvs\disco_f030r8\FrameworkHALDriver\Src\stm32f0xx_hal_tsc.o
Compiling .pioenvs\disco_f030r8\FrameworkHALDriver\Src\stm32f0xx_hal_uart.o
Compiling .pioenvs\disco_f030r8\FrameworkHALDriver\Src\stm32f0xx_hal_uart_ex.o
Compiling .pioenvs\disco_f030r8\FrameworkHALDriver\Src\stm32f0xx_hal_usart.o
Compiling .pioenvs\disco_f030r8\FrameworkHALDriver\Src\stm32f0xx_hal_wwdg.o
Compiling .pioenvs\disco_f030r8\FrameworkHALDriver\Src\stm32f0xx_ll_adc.o
Compiling .pioenvs\disco_f030r8\FrameworkHALDriver\Src\stm32f0xx_ll_comp.o
Compiling .pioenvs\disco_f030r8\FrameworkHALDriver\Src\stm32f0xx_ll_crc.o
Compiling .pioenvs\disco_f030r8\FrameworkHALDriver\Src\stm32f0xx_ll_crs.o
Compiling .pioenvs\disco_f030r8\FrameworkHALDriver\Src\stm32f0xx_ll_dac.o
Compiling .pioenvs\disco_f030r8\FrameworkHALDriver\Src\stm32f0xx_ll_dma.o
Compiling .pioenvs\disco_f030r8\FrameworkHALDriver\Src\stm32f0xx_ll_exti.o
Compiling .pioenvs\disco_f030r8\FrameworkHALDriver\Src\stm32f0xx_ll_gpio.o
Compiling .pioenvs\disco_f030r8\FrameworkHALDriver\Src\stm32f0xx_ll_i2c.o
Compiling .pioenvs\disco_f030r8\FrameworkHALDriver\Src\stm32f0xx_ll_pwr.o
Compiling .pioenvs\disco_f030r8\FrameworkHALDriver\Src\stm32f0xx_ll_rcc.o
Compiling .pioenvs\disco_f030r8\FrameworkHALDriver\Src\stm32f0xx_ll_rtc.o
Compiling .pioenvs\disco_f030r8\FrameworkHALDriver\Src\stm32f0xx_ll_spi.o
Compiling .pioenvs\disco_f030r8\FrameworkHALDriver\Src\stm32f0xx_ll_tim.o
Compiling .pioenvs\disco_f030r8\FrameworkHALDriver\Src\stm32f0xx_ll_usart.o
Compiling .pioenvs\disco_f030r8\FrameworkHALDriver\Src\stm32f0xx_ll_utils.o
Compiling .pioenvs\disco_f030r8\FrameworkCMSISDevice\gcc\startup_stm32f030x8.o
Compiling .pioenvs\disco_f030r8\FrameworkCMSISDevice\system_stm32f0xx.o
Archiving .pioenvs\disco_f030r8\libFrameworkCMSISDevice.a
Archiving .pioenvs\disco_f030r8\libFrameworkHALDriver.a
Linking .pioenvs\disco_f030r8\firmware.elf
Checking size .pioenvs\disco_f030r8\firmware.elf
Memory Usage -> http://bit.ly/pio-memory-usage
DATA:    [          ]   0.4% (used 36 bytes from 8192 bytes)
PROGRAM: [          ]   4.4% (used 2912 bytes from 65536 bytes)
Configuring upload protocol...
AVAILABLE: blackmagic, jlink, stlink
CURRENT: upload_protocol = stlink
Uploading .pioenvs\disco_f030r8\firmware.elf
GNU MCU Eclipse OpenOCD, 64-bitOpen On-Chip Debugger 0.10.0+dev-00593-g23ad80df4 (2019-04-22-20:25)
Licensed under GNU GPL v2
For bug reports, read
xxxx.openocd.org/doc/doxygen/bugs.html
Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
adapter speed: 1000 kHz
adapter_nsrst_delay: 100
none separate
srst_only separate srst_nogate srst_open_drain connect_deassert_srst
Info : clock speed 1000 kHz
Info : STLINK V2J33S0 (API v2) VID:PID 0483:3748
Info : Target voltage: 5.747816
Info : stm32f0x.cpu: hardware has 4 breakpoints, 2 watchpoints
Info : Listening on port 3333 for gdb connections
Info : Unable to match requested speed 1000 kHz, using 950 kHz
Info : Unable to match requested speed 1000 kHz, using 950 kHz
adapter speed: 950 kHz
target halted due to debug-request, current mode: Thread
xPSR: 0xc1000000 pc: 0x08000c14 msp: 0x20004000
Info : Unable to match requested speed 8000 kHz, using 4000 kHz
Info : Unable to match requested speed 8000 kHz, using 4000 kHz
adapter speed: 4000 kHz
** Programming Started **
auto erase enabled
Info : device id = 0x10006444
Info : flash size = 32kbytes
wrote 4096 bytes from file .pioenvs\disco_f030r8\firmware.elf in 0.238362s (16.781 KiB/s)
** Programming Finished **
** Verify Started **
verified 3112 bytes in 0.036901s (82.357 KiB/s)
** Verified OK **
** Resetting Target **
Info : Unable to match requested speed 1000 kHz, using 950 kHz
Info : Unable to match requested speed 1000 kHz, using 950 kHz
adapter speed: 950 kHz
shutdown command invoked
========================================================================================================== [SUCCESS] Took 3.19 seconds ==========================================================================================================

Terminal will be reused by tasks, press any key to close it.

Does the PIO firmware work when the .bin image is flashed with the ST tools? Do you reboot your board after that? Checked the BOOT0?

I’ll have to check again but I believe I’ve tried using the ST-LINK Utility to flash the PIO bin and it flashed but didn’t run.

Yes, BOOT0 is pulled down with a 10k and I’ve power cycled my board.

If I have time today I guess I could flash the board with PIO, do a memory dump, then flash with ST-LINK Utility and compare memory dumps?

Perhaps PIO is just using the wrong starting address? Seems odd though since PIO works with the ST Eval board so maybe the STM32 that’s on the eval board (STM32F051R8T6) maps differently thatn the STM32F030C6 that’s on my board.