Board definition for STM32F100C8T

Hi there,
I’ve got a custom made board with a STM32F100C8T on it and want to use it together with PlatformIO.
I want to program it with the Arduino Framework and want/must use my ST-LINK V2 for programming/debugging.

So I guess the challenge is similar to STM32F100RET support, still I haven’t been successful, yet.

As the STM32F100C8 has no board definition in PlatformIO yet, but it is supported in STM32duino (2.2.0), I created a custom one by copypasting from various sources:

{
    "build": {
      "core": "stm32",
      "cpu": "cortex-m3",
      "extra_flags": "-DSTM32F100xB -DSTM32F1",
      "f_cpu": "24000000L",
      "mcu": "stm32f100c8t",
      "product_line": "STM32F100xB",
      "variant": "STM32F1xx/F100C(8-B)T"
    },
    "connectivity": [
    ],
    "debug": {
      "jlink_device": "STM32F100C8",
      "openocd_target": "stm32f1x",
      "svd_path": "STM32F100x.svd"
    },
    "frameworks": [
      "stm32cube",
      "arduino"
    ],
    "name": "STM32F100C8 (20k RAM. 64k Flash)",
    "upload": {
      "disable_flushing": false,
      "maximum_ram_size": 20480,
      "maximum_size": 65536,
      "protocol": "stlink",
      "protocols": [
        "jlink",
        "cmsis-dap",
        "stlink",
        "blackmagic",
        "serial",
        "dfu"
      ],
      "require_upload_port": true,
      "use_1200bps_touch": false,
      "wait_for_upload_port": false
    },
    "url": "https://www.st.com/en/microcontrollers-microprocessors/stm32f100c8.html",
    "vendor": "ST"
  }

platformio.ini looks like this:

[env:genericSTM32F100C8]
platform = ststm32
board = genericSTM32F100C8
framework = arduino

Blink example compiles and flashes with OpenOCD, but obviously, it doesn’t run (I tried various Pin settings to rule out that I am stimulating the wrong GPIO).
When trying to debug, it seems that the processor does not even boot up correctly (never reaches setup() method of the blink example) and gets stuck in an “Infinite Loop” routine.

I don’t have injected any custom clock setup code, so I assume it just uses the STM32duino setup, which is (8/4)*6=24 MHz internal clock.

Do you have any hints? Sorry if I am missing something obvious, but I am stuck a this point :frowning:

Hint: When programming with STM32Cube IDE, programming, debugging and running hardware works as expected, so I guess a hardware problem can be ruled out.

Thanks a lot!

What exact .cpp code do you have in the project?

Actually that’s 8MHz (HSI) divided by 2 times 6, so 4*6 = 24MHz. (“(8/4)*6” would equal 12MHz btw, not 24)

That can’t be right. When I’m reading https://www.st.com/resource/en/datasheet/stm32f100c8.pdf I’m getting

With the categories being x4, x6, x8, xB at the end of the chip. Your C8 would have 64KByte flash + 8Kbyte RAM.

Giving PlatformIO the wrong RAM size willl lead to the initial stack pointer (SP) pointing to beyond valid memory (basically SP is set to be at the end of RAM and being used downwards). So likely your crash is from the microcontroller executing a push or pop instruction with an invalid SP set → instant crash in the default handler (ISR) in STM32Duino, which is actually a HardFault.

Try changing this to 8192. Does it work?

Hi Max,
thank you for your quick response :slight_smile:

What exact .cpp code do you have in the project?

I am using the Blink Example Code.

Actually that’s 8MHz (HSI) divided by 2 times 6, so 4*6 = 24MHz. (“(8/4)*6” would equal 12MHz btw, not 24)

yes, sorry :sweat:
So 24 MHz is correct, right? What would be the effect of setting f_cpu to a wrong value?

Try chaing this to 8192. Does it work?

Will do! I’ll report this evening if it helped.

Thanks a lot for your great support! :tada:

Thanks a lot for your help, setting the RAM size to 8192 did the thing - everything works as expected now :slight_smile:

Great! Can you PR in the board JSON file at platform-ststm32/boards at develop · platformio/platform-ststm32 · GitHub? (top right → add file → create new file → fixed genericSTM32F100C8.json.

Oh and before that though, the first macro in

shuold technically be -DSTM32F100x8.

Hi Max,
sure thing, I created a PR (#627, can’t add a link to github somehow).

Setting the flag to -DSTM32F100x8 breaks the build, so I sticked with xB

1 Like

As this is still not merged I would like to add my suggestions.

The extra_flags is correct as F100C8 doesn’t have it’s own macros defined in the Arduino_Core_STM32. Even boards_entry defines product_line as STM32F100xB for the F100C8.

There is one x missing in the svd_path.
I think it supports added frameworks and protocols (not really sure, copied from disco_f100rb.json).
It doesn’t support DFU (AN2606, table 3).
This probably doesn’t really matter, but the mcu is 13 characters long in all other definitions.

The final config:

{
	"build": {
		"core": "stm32",
		"cpu": "cortex-m3",
		"extra_flags": "-DSTM32F100xB -DSTM32F1",
		"f_cpu": "24000000L",
		"mcu": "stm32f100c8t6",
		"product_line": "STM32F100xB",
		"variant": "STM32F1xx/F100C(8-B)T"
	},
	"debug": {
		"default_tools": [
			"stlink"
		],
		"jlink_device": "STM32F100C8",
		"onboard_tools": [
			"stlink"
		],
		"openocd_target": "stm32f1x",
		"svd_path": "STM32F100xx.svd"
	},
	"frameworks": [
		"stm32cube",
		"arduino",
		"cmsis",
		"mbed",
		"libopencm3"
	],
	"name": "STM32F100C8 (8k RAM. 64k Flash)",
	"upload": {
		"maximum_ram_size": 8192,
		"maximum_size": 65536,
		"protocol": "stlink",
		"protocols": [
			"jlink",
			"stlink",
			"blackmagic",
			"serial",
			"cmsis-dap"
		]
	},
	"url": "https://www.st.com/en/microcontrollers-microprocessors/stm32f100c8.html",
	"vendor": "ST"
}