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 /* mbed Microcontroller Library
hudakz 0:2577a4fb6e72 2 *******************************************************************************
hudakz 0:2577a4fb6e72 3 * Copyright (c) 2014, STMicroelectronics
hudakz 0:2577a4fb6e72 4 * All rights reserved.
hudakz 0:2577a4fb6e72 5 *
hudakz 0:2577a4fb6e72 6 * Redistribution and use in source and binary forms, with or without
hudakz 0:2577a4fb6e72 7 * modification, are permitted provided that the following conditions are met:
hudakz 0:2577a4fb6e72 8 *
hudakz 0:2577a4fb6e72 9 * 1. Redistributions of source code must retain the above copyright notice,
hudakz 0:2577a4fb6e72 10 * this list of conditions and the following disclaimer.
hudakz 0:2577a4fb6e72 11 * 2. Redistributions in binary form must reproduce the above copyright notice,
hudakz 0:2577a4fb6e72 12 * this list of conditions and the following disclaimer in the documentation
hudakz 0:2577a4fb6e72 13 * and/or other materials provided with the distribution.
hudakz 0:2577a4fb6e72 14 * 3. Neither the name of STMicroelectronics nor the names of its contributors
hudakz 0:2577a4fb6e72 15 * may be used to endorse or promote products derived from this software
hudakz 0:2577a4fb6e72 16 * without specific prior written permission.
hudakz 0:2577a4fb6e72 17 *
hudakz 0:2577a4fb6e72 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
hudakz 0:2577a4fb6e72 19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
hudakz 0:2577a4fb6e72 20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
hudakz 0:2577a4fb6e72 21 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
hudakz 0:2577a4fb6e72 22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
hudakz 0:2577a4fb6e72 23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
hudakz 0:2577a4fb6e72 24 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
hudakz 0:2577a4fb6e72 25 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
hudakz 0:2577a4fb6e72 26 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
hudakz 0:2577a4fb6e72 27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
hudakz 0:2577a4fb6e72 28 *******************************************************************************
hudakz 0:2577a4fb6e72 29 */
hudakz 0:2577a4fb6e72 30 #ifndef MBED_PINNAMES_H
hudakz 0:2577a4fb6e72 31 #define MBED_PINNAMES_H
hudakz 0:2577a4fb6e72 32
hudakz 0:2577a4fb6e72 33 #include "cmsis.h"
hudakz 0:2577a4fb6e72 34 #include "PinNamesTypes.h"
hudakz 0:2577a4fb6e72 35
hudakz 0:2577a4fb6e72 36 #ifdef __cplusplus
hudakz 0:2577a4fb6e72 37 extern "C" {
hudakz 0:2577a4fb6e72 38 #endif
hudakz 0:2577a4fb6e72 39
hudakz 0:2577a4fb6e72 40 typedef enum {
hudakz 0:2577a4fb6e72 41 ALT0 = 0x100,
hudakz 0:2577a4fb6e72 42 ALT1 = 0x200,
hudakz 0:2577a4fb6e72 43 ALT2 = 0x300,
hudakz 0:2577a4fb6e72 44 ALT3 = 0x400
hudakz 0:2577a4fb6e72 45 } ALTx;
hudakz 0:2577a4fb6e72 46
hudakz 0:2577a4fb6e72 47 typedef enum {
hudakz 0:2577a4fb6e72 48 PA_0 = 0x00,
hudakz 0:2577a4fb6e72 49 PA_1 = 0x01,
hudakz 0:2577a4fb6e72 50 PA_2 = 0x02,
hudakz 0:2577a4fb6e72 51 PA_3 = 0x03,
hudakz 0:2577a4fb6e72 52 PA_4 = 0x04,
hudakz 0:2577a4fb6e72 53 PA_5 = 0x05,
hudakz 0:2577a4fb6e72 54 PA_6 = 0x06,
hudakz 0:2577a4fb6e72 55 PA_7 = 0x07,
hudakz 0:2577a4fb6e72 56 PA_7_ALT0 = 0x07 | ALT0,
hudakz 0:2577a4fb6e72 57 PA_8 = 0x08,
hudakz 0:2577a4fb6e72 58 PA_9 = 0x09,
hudakz 0:2577a4fb6e72 59 PA_10 = 0x0A,
hudakz 0:2577a4fb6e72 60 PA_11 = 0x0B,
hudakz 0:2577a4fb6e72 61 PA_12 = 0x0C,
hudakz 0:2577a4fb6e72 62 PA_13 = 0x0D,
hudakz 0:2577a4fb6e72 63 PA_14 = 0x0E,
hudakz 0:2577a4fb6e72 64 PA_15 = 0x0F,
hudakz 0:2577a4fb6e72 65
hudakz 0:2577a4fb6e72 66 PB_0 = 0x10,
hudakz 0:2577a4fb6e72 67 PB_0_ALT0 = 0x10 | ALT0,
hudakz 0:2577a4fb6e72 68 PB_1 = 0x11,
hudakz 0:2577a4fb6e72 69 PB_1_ALT0 = 0x11 | ALT0,
hudakz 0:2577a4fb6e72 70 PB_2 = 0x12,
hudakz 0:2577a4fb6e72 71 PB_3 = 0x13,
hudakz 0:2577a4fb6e72 72 PB_4 = 0x14,
hudakz 0:2577a4fb6e72 73 PB_5 = 0x15,
hudakz 0:2577a4fb6e72 74 PB_6 = 0x16,
hudakz 0:2577a4fb6e72 75 PB_7 = 0x17,
hudakz 0:2577a4fb6e72 76 PB_8 = 0x18,
hudakz 0:2577a4fb6e72 77 PB_9 = 0x19,
hudakz 0:2577a4fb6e72 78 PB_10 = 0x1A,
hudakz 0:2577a4fb6e72 79 PB_11 = 0x1B,
hudakz 0:2577a4fb6e72 80 PB_12 = 0x1C,
hudakz 0:2577a4fb6e72 81 PB_13 = 0x1D,
hudakz 0:2577a4fb6e72 82 PB_14 = 0x1E,
hudakz 0:2577a4fb6e72 83 PB_15 = 0x1F,
hudakz 0:2577a4fb6e72 84
hudakz 0:2577a4fb6e72 85 PC_0 = 0x20,
hudakz 0:2577a4fb6e72 86 PC_1 = 0x21,
hudakz 0:2577a4fb6e72 87 PC_2 = 0x22,
hudakz 0:2577a4fb6e72 88 PC_3 = 0x23,
hudakz 0:2577a4fb6e72 89 PC_4 = 0x24,
hudakz 0:2577a4fb6e72 90 PC_5 = 0x25,
hudakz 0:2577a4fb6e72 91 PC_6 = 0x26,
hudakz 0:2577a4fb6e72 92 PC_7 = 0x27,
hudakz 0:2577a4fb6e72 93 PC_8 = 0x28,
hudakz 0:2577a4fb6e72 94 PC_9 = 0x29,
hudakz 0:2577a4fb6e72 95 PC_10 = 0x2A,
hudakz 0:2577a4fb6e72 96 PC_11 = 0x2B,
hudakz 0:2577a4fb6e72 97 PC_12 = 0x2C,
hudakz 0:2577a4fb6e72 98 PC_13 = 0x2D,
hudakz 0:2577a4fb6e72 99 PC_14 = 0x2E,
hudakz 0:2577a4fb6e72 100 PC_15 = 0x2F,
hudakz 0:2577a4fb6e72 101
hudakz 0:2577a4fb6e72 102 PD_2 = 0x32,
hudakz 0:2577a4fb6e72 103
hudakz 0:2577a4fb6e72 104 // ADC internal channels
hudakz 0:2577a4fb6e72 105 ADC_TEMP = 0xF0,
hudakz 0:2577a4fb6e72 106 ADC_VREF = 0xF1,
hudakz 0:2577a4fb6e72 107
hudakz 0:2577a4fb6e72 108 // PCB printout
hudakz 0:2577a4fb6e72 109 A0 = PA_0,
hudakz 0:2577a4fb6e72 110 A1 = PA_1,
hudakz 0:2577a4fb6e72 111 A2 = PA_2,
hudakz 0:2577a4fb6e72 112 A3 = PA_3,
hudakz 0:2577a4fb6e72 113 A4 = PA_4,
hudakz 0:2577a4fb6e72 114 A5 = PA_5,
hudakz 0:2577a4fb6e72 115 A6 = PA_6,
hudakz 0:2577a4fb6e72 116 A7 = PA_7,
hudakz 0:2577a4fb6e72 117 A8 = PA_8,
hudakz 0:2577a4fb6e72 118 A9 = PA_9,
hudakz 0:2577a4fb6e72 119 A10 = PA_10,
hudakz 0:2577a4fb6e72 120 A11 = PA_11,
hudakz 0:2577a4fb6e72 121 A12 = PA_12,
hudakz 0:2577a4fb6e72 122 A15 = PA_15,
hudakz 0:2577a4fb6e72 123
hudakz 0:2577a4fb6e72 124 B0 = PB_0,
hudakz 0:2577a4fb6e72 125 B1 = PB_1,
hudakz 0:2577a4fb6e72 126 B2 = PB_2,
hudakz 0:2577a4fb6e72 127 B3 = PB_3,
hudakz 0:2577a4fb6e72 128 B4 = PB_4,
hudakz 0:2577a4fb6e72 129 B5 = PB_5,
hudakz 0:2577a4fb6e72 130 B6 = PB_6,
hudakz 0:2577a4fb6e72 131 B7 = PB_7,
hudakz 0:2577a4fb6e72 132 B8 = PB_8,
hudakz 0:2577a4fb6e72 133 B9 = PB_9,
hudakz 0:2577a4fb6e72 134 B10 = PB_10,
hudakz 0:2577a4fb6e72 135 B11 = PB_11,
hudakz 0:2577a4fb6e72 136 B12 = PB_12,
hudakz 0:2577a4fb6e72 137 B13 = PB_13,
hudakz 0:2577a4fb6e72 138 B14 = PB_14,
hudakz 0:2577a4fb6e72 139 B15 = PB_15,
hudakz 0:2577a4fb6e72 140
hudakz 0:2577a4fb6e72 141 C13 = PC_13,
hudakz 0:2577a4fb6e72 142 C14 = PC_14,
hudakz 0:2577a4fb6e72 143 C15 = PC_15,
hudakz 0:2577a4fb6e72 144
hudakz 0:2577a4fb6e72 145 // STDIO for console print
hudakz 0:2577a4fb6e72 146 #ifdef MBED_CONF_TARGET_STDIO_UART_TX
hudakz 0:2577a4fb6e72 147 STDIO_UART_TX = MBED_CONF_TARGET_STDIO_UART_TX,
hudakz 0:2577a4fb6e72 148 #else
hudakz 0:2577a4fb6e72 149 STDIO_UART_TX = PA_2,
hudakz 0:2577a4fb6e72 150 #endif
hudakz 0:2577a4fb6e72 151 #ifdef MBED_CONF_TARGET_STDIO_UART_RX
hudakz 0:2577a4fb6e72 152 STDIO_UART_RX = MBED_CONF_TARGET_STDIO_UART_RX,
hudakz 0:2577a4fb6e72 153 #else
hudakz 0:2577a4fb6e72 154 STDIO_UART_RX = PA_3,
hudakz 0:2577a4fb6e72 155 #endif
hudakz 0:2577a4fb6e72 156
hudakz 0:2577a4fb6e72 157 // Generic signals namings
hudakz 0:2577a4fb6e72 158 LED1 = PC_13,
hudakz 0:2577a4fb6e72 159 LED2 = PC_13,
hudakz 0:2577a4fb6e72 160 LED3 = PC_13,
hudakz 0:2577a4fb6e72 161 LED4 = PC_13,
hudakz 0:2577a4fb6e72 162 SERIAL_TX = STDIO_UART_TX,
hudakz 0:2577a4fb6e72 163 SERIAL_RX = STDIO_UART_RX,
hudakz 0:2577a4fb6e72 164 USBTX = STDIO_UART_TX,
hudakz 0:2577a4fb6e72 165 USBRX = STDIO_UART_RX,
hudakz 0:2577a4fb6e72 166 I2C_SCL = PB_6,
hudakz 0:2577a4fb6e72 167 I2C_SDA = PB_7,
hudakz 0:2577a4fb6e72 168 SPI_MOSI = PA_7,
hudakz 0:2577a4fb6e72 169 SPI_MISO = PA_6,
hudakz 0:2577a4fb6e72 170 SPI_SCK = PA_5,
hudakz 0:2577a4fb6e72 171 SPI_CS = PA_4,
hudakz 0:2577a4fb6e72 172 PWM_OUT = PB_5,
hudakz 0:2577a4fb6e72 173
hudakz 0:2577a4fb6e72 174 //USB pins
hudakz 0:2577a4fb6e72 175 USB_DM = PA_11,
hudakz 0:2577a4fb6e72 176 USB_DP = PA_12,
hudakz 0:2577a4fb6e72 177
hudakz 0:2577a4fb6e72 178 // Not connected
hudakz 0:2577a4fb6e72 179 NC = (int)0xFFFFFFFF
hudakz 0:2577a4fb6e72 180 } PinName;
hudakz 0:2577a4fb6e72 181
hudakz 0:2577a4fb6e72 182 #ifdef __cplusplus
hudakz 0:2577a4fb6e72 183 }
hudakz 0:2577a4fb6e72 184 #endif
hudakz 0:2577a4fb6e72 185
hudakz 0:2577a4fb6e72 186 #endif