Bluepill STM32F103C8 support for Mbed OS 6

Bluepill board support for Mbed OS 6

Warning

It does not work with the Mbed Online Compiler.

This is an example of configuration for the Bluepill board for Mbed OS 6.

It shows how to create a custom board support based on Mbed OS and how to compile a simple Blinky application.

Note this project makes use of the full Mbed OS with RTOS included. It's possible to make changes in the configuration to support the Baremetal profile and reduce memory requirements - see this.

Example application

This repository includes blinky.cpp as an example application to demonstrate how to use the Bluepill custom board support. It's expected to work out of the box using both Mbed CLI and Mbed Studio. Note this test application can be ignored using the MBED_BLINKY_EXAMPLE macro in mbed_app.json, so you can add your own files and application on top of this project.

You can follow these steps to import and compile with Mbed CLI:

mbed import https://os.mbed.com/users/hudakz/code/mbed-os-bluepill
mbed compile -t GCC_ARM -m bluepill

Bluepill and Mbed OS version support

BluepillMbed OS (hash)Status
preview6.2.0 (#a2ada74770 )Compiles and runs ok

Updating Mbed OS

Note not every version of Mbed OS is being tested, therefore update at your own risk. Unless strictly required, you should stick to versions of Mbed OS that are known to work ok.

If you do want to udpate Mbed OS, then follow these steps:

cd mbed-os
mbed update <mbed-os hash / tag>

Testing

This application has been tested on the Bluepill board and runs ok: it blinks and LED and sends a message over the serial port (115200 bauds - see mbed_app.json).

However, it's recomended to run regression tests based on the Greentea framework whether possible (more details to be added).

Programming with STLink programming utility

The Bluepill board doesn't have a programming interface on board. However, it's easy to connect an external adapter such as the STLink/V2 and get it working in minutes.

Use the STM32 ST-Link utility to program the binary into the device.

https://os.mbed.com/media/uploads/hudakz/stlink-prog.png

Wire the Bluepill to the STLink and serial adapter as follow:

BluepillSTLink (20-pin JTAG)Serial adapter
SDWIO (CN4)7-
SWCLK (CN4)9-
RESET15-
GND4GND
TX (PA_2)-RX
RX (PA_3)-TX

ST-LINK/V2 JTAG pintout
https://os.mbed.com/media/uploads/hudakz/jtag_pinout.png

This is the pinout of the Bluepill board: /media/uploads/hudakz/stm32f103c8t6_pinout_voltage01.png

https://os.mbed.com/media/uploads/hudakz/connections.jpg

Additional example programs

Bare metal on Bluepill
Bare metal with EventQueue on Bluepill

Warning

The examples above are not meant to be compiled with the online compiler. Follow these steps to import and compile them with Mbed CLI:

mbed import Program's_URL
mbed compile -t GCC_ARM -m bluepill

Known issues

  • Please check the issues reported.
Committer:
hudakz
Date:
Wed May 13 12:25:39 2020 +0000
Revision:
0:2577a4fb6e72
Bluepill STM32F103C8 support for Mbed OS 6

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hudakz 0:2577a4fb6e72 1 /* Linker script to configure memory regions. */
hudakz 0:2577a4fb6e72 2 /* 0xEC reserved for vectors - 8byte aligned = 0xF0 */
hudakz 0:2577a4fb6e72 3
hudakz 0:2577a4fb6e72 4 #if !defined(MBED_BOOT_STACK_SIZE)
hudakz 0:2577a4fb6e72 5 #define MBED_BOOT_STACK_SIZE 0x400
hudakz 0:2577a4fb6e72 6 #endif
hudakz 0:2577a4fb6e72 7
hudakz 0:2577a4fb6e72 8 STACK_SIZE = MBED_BOOT_STACK_SIZE;
hudakz 0:2577a4fb6e72 9
hudakz 0:2577a4fb6e72 10 MEMORY
hudakz 0:2577a4fb6e72 11 {
hudakz 0:2577a4fb6e72 12 FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 64K
hudakz 0:2577a4fb6e72 13 RAM (rwx) : ORIGIN = 0x200000F0, LENGTH = 20K - (0xEC+0x4)
hudakz 0:2577a4fb6e72 14 }
hudakz 0:2577a4fb6e72 15
hudakz 0:2577a4fb6e72 16 /* Linker script to place sections and symbol values. Should be used together
hudakz 0:2577a4fb6e72 17 * with other linker script that defines memory regions FLASH and RAM.
hudakz 0:2577a4fb6e72 18 * It references following symbols, which must be defined in code:
hudakz 0:2577a4fb6e72 19 * Reset_Handler : Entry of reset handler
hudakz 0:2577a4fb6e72 20 *
hudakz 0:2577a4fb6e72 21 * It defines following symbols, which code can use without definition:
hudakz 0:2577a4fb6e72 22 * __exidx_start
hudakz 0:2577a4fb6e72 23 * __exidx_end
hudakz 0:2577a4fb6e72 24 * __etext
hudakz 0:2577a4fb6e72 25 * __data_start__
hudakz 0:2577a4fb6e72 26 * __preinit_array_start
hudakz 0:2577a4fb6e72 27 * __preinit_array_end
hudakz 0:2577a4fb6e72 28 * __init_array_start
hudakz 0:2577a4fb6e72 29 * __init_array_end
hudakz 0:2577a4fb6e72 30 * __fini_array_start
hudakz 0:2577a4fb6e72 31 * __fini_array_end
hudakz 0:2577a4fb6e72 32 * __data_end__
hudakz 0:2577a4fb6e72 33 * __bss_start__
hudakz 0:2577a4fb6e72 34 * __bss_end__
hudakz 0:2577a4fb6e72 35 * __end__
hudakz 0:2577a4fb6e72 36 * end
hudakz 0:2577a4fb6e72 37 * __HeapLimit
hudakz 0:2577a4fb6e72 38 * __StackLimit
hudakz 0:2577a4fb6e72 39 * __StackTop
hudakz 0:2577a4fb6e72 40 * __stack
hudakz 0:2577a4fb6e72 41 * _estack
hudakz 0:2577a4fb6e72 42 */
hudakz 0:2577a4fb6e72 43 ENTRY(Reset_Handler)
hudakz 0:2577a4fb6e72 44
hudakz 0:2577a4fb6e72 45 SECTIONS
hudakz 0:2577a4fb6e72 46 {
hudakz 0:2577a4fb6e72 47 .text :
hudakz 0:2577a4fb6e72 48 {
hudakz 0:2577a4fb6e72 49 KEEP(*(.isr_vector))
hudakz 0:2577a4fb6e72 50 *(.text*)
hudakz 0:2577a4fb6e72 51 KEEP(*(.init))
hudakz 0:2577a4fb6e72 52 KEEP(*(.fini))
hudakz 0:2577a4fb6e72 53
hudakz 0:2577a4fb6e72 54 /* .ctors */
hudakz 0:2577a4fb6e72 55 *crtbegin.o(.ctors)
hudakz 0:2577a4fb6e72 56 *crtbegin?.o(.ctors)
hudakz 0:2577a4fb6e72 57 *(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors)
hudakz 0:2577a4fb6e72 58 *(SORT(.ctors.*))
hudakz 0:2577a4fb6e72 59 *(.ctors)
hudakz 0:2577a4fb6e72 60
hudakz 0:2577a4fb6e72 61 /* .dtors */
hudakz 0:2577a4fb6e72 62 *crtbegin.o(.dtors)
hudakz 0:2577a4fb6e72 63 *crtbegin?.o(.dtors)
hudakz 0:2577a4fb6e72 64 *(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors)
hudakz 0:2577a4fb6e72 65 *(SORT(.dtors.*))
hudakz 0:2577a4fb6e72 66 *(.dtors)
hudakz 0:2577a4fb6e72 67
hudakz 0:2577a4fb6e72 68 *(.rodata*)
hudakz 0:2577a4fb6e72 69
hudakz 0:2577a4fb6e72 70 KEEP(*(.eh_frame*))
hudakz 0:2577a4fb6e72 71 } > FLASH
hudakz 0:2577a4fb6e72 72
hudakz 0:2577a4fb6e72 73 .ARM.extab :
hudakz 0:2577a4fb6e72 74 {
hudakz 0:2577a4fb6e72 75 *(.ARM.extab* .gnu.linkonce.armextab.*)
hudakz 0:2577a4fb6e72 76 } > FLASH
hudakz 0:2577a4fb6e72 77
hudakz 0:2577a4fb6e72 78 __exidx_start = .;
hudakz 0:2577a4fb6e72 79 .ARM.exidx :
hudakz 0:2577a4fb6e72 80 {
hudakz 0:2577a4fb6e72 81 *(.ARM.exidx* .gnu.linkonce.armexidx.*)
hudakz 0:2577a4fb6e72 82 } > FLASH
hudakz 0:2577a4fb6e72 83 __exidx_end = .;
hudakz 0:2577a4fb6e72 84
hudakz 0:2577a4fb6e72 85 __etext = .;
hudakz 0:2577a4fb6e72 86 _sidata = .;
hudakz 0:2577a4fb6e72 87
hudakz 0:2577a4fb6e72 88 .data : AT (__etext)
hudakz 0:2577a4fb6e72 89 {
hudakz 0:2577a4fb6e72 90 __data_start__ = .;
hudakz 0:2577a4fb6e72 91 _sdata = .;
hudakz 0:2577a4fb6e72 92 *(vtable)
hudakz 0:2577a4fb6e72 93 *(.data*)
hudakz 0:2577a4fb6e72 94
hudakz 0:2577a4fb6e72 95 . = ALIGN(8);
hudakz 0:2577a4fb6e72 96 /* preinit data */
hudakz 0:2577a4fb6e72 97 PROVIDE_HIDDEN (__preinit_array_start = .);
hudakz 0:2577a4fb6e72 98 KEEP(*(.preinit_array))
hudakz 0:2577a4fb6e72 99 PROVIDE_HIDDEN (__preinit_array_end = .);
hudakz 0:2577a4fb6e72 100
hudakz 0:2577a4fb6e72 101 . = ALIGN(8);
hudakz 0:2577a4fb6e72 102 /* init data */
hudakz 0:2577a4fb6e72 103 PROVIDE_HIDDEN (__init_array_start = .);
hudakz 0:2577a4fb6e72 104 KEEP(*(SORT(.init_array.*)))
hudakz 0:2577a4fb6e72 105 KEEP(*(.init_array))
hudakz 0:2577a4fb6e72 106 PROVIDE_HIDDEN (__init_array_end = .);
hudakz 0:2577a4fb6e72 107
hudakz 0:2577a4fb6e72 108
hudakz 0:2577a4fb6e72 109 . = ALIGN(8);
hudakz 0:2577a4fb6e72 110 /* finit data */
hudakz 0:2577a4fb6e72 111 PROVIDE_HIDDEN (__fini_array_start = .);
hudakz 0:2577a4fb6e72 112 KEEP(*(SORT(.fini_array.*)))
hudakz 0:2577a4fb6e72 113 KEEP(*(.fini_array))
hudakz 0:2577a4fb6e72 114 PROVIDE_HIDDEN (__fini_array_end = .);
hudakz 0:2577a4fb6e72 115
hudakz 0:2577a4fb6e72 116 KEEP(*(.jcr*))
hudakz 0:2577a4fb6e72 117 . = ALIGN(8);
hudakz 0:2577a4fb6e72 118 /* All data end */
hudakz 0:2577a4fb6e72 119 __data_end__ = .;
hudakz 0:2577a4fb6e72 120 _edata = .;
hudakz 0:2577a4fb6e72 121
hudakz 0:2577a4fb6e72 122 } > RAM
hudakz 0:2577a4fb6e72 123
hudakz 0:2577a4fb6e72 124 .bss :
hudakz 0:2577a4fb6e72 125 {
hudakz 0:2577a4fb6e72 126 . = ALIGN(8);
hudakz 0:2577a4fb6e72 127 __bss_start__ = .;
hudakz 0:2577a4fb6e72 128 _sbss = .;
hudakz 0:2577a4fb6e72 129 *(.bss*)
hudakz 0:2577a4fb6e72 130 *(COMMON)
hudakz 0:2577a4fb6e72 131 . = ALIGN(8);
hudakz 0:2577a4fb6e72 132 __bss_end__ = .;
hudakz 0:2577a4fb6e72 133 _ebss = .;
hudakz 0:2577a4fb6e72 134 } > RAM
hudakz 0:2577a4fb6e72 135
hudakz 0:2577a4fb6e72 136 .heap (COPY):
hudakz 0:2577a4fb6e72 137 {
hudakz 0:2577a4fb6e72 138 __end__ = .;
hudakz 0:2577a4fb6e72 139 end = __end__;
hudakz 0:2577a4fb6e72 140 *(.heap*)
hudakz 0:2577a4fb6e72 141 . = ORIGIN(RAM) + LENGTH(RAM) - STACK_SIZE;
hudakz 0:2577a4fb6e72 142 __HeapLimit = .;
hudakz 0:2577a4fb6e72 143 } > RAM
hudakz 0:2577a4fb6e72 144
hudakz 0:2577a4fb6e72 145 /* .stack_dummy section doesn't contains any symbols. It is only
hudakz 0:2577a4fb6e72 146 * used for linker to calculate size of stack sections, and assign
hudakz 0:2577a4fb6e72 147 * values to stack symbols later */
hudakz 0:2577a4fb6e72 148 .stack_dummy (COPY):
hudakz 0:2577a4fb6e72 149 {
hudakz 0:2577a4fb6e72 150 *(.stack*)
hudakz 0:2577a4fb6e72 151 } > RAM
hudakz 0:2577a4fb6e72 152
hudakz 0:2577a4fb6e72 153 /* Set stack top to end of RAM, and stack limit move down by
hudakz 0:2577a4fb6e72 154 * size of stack_dummy section */
hudakz 0:2577a4fb6e72 155 __StackTop = ORIGIN(RAM) + LENGTH(RAM);
hudakz 0:2577a4fb6e72 156 _estack = __StackTop;
hudakz 0:2577a4fb6e72 157 __StackLimit = __StackTop - STACK_SIZE;
hudakz 0:2577a4fb6e72 158 PROVIDE(__stack = __StackTop);
hudakz 0:2577a4fb6e72 159
hudakz 0:2577a4fb6e72 160 /* Check if data + heap + stack exceeds RAM limit */
hudakz 0:2577a4fb6e72 161 ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed with stack")
hudakz 0:2577a4fb6e72 162 }
hudakz 0:2577a4fb6e72 163