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 /**
hudakz 0:2577a4fb6e72 2 ******************************************************************************
hudakz 0:2577a4fb6e72 3 * @file stm32f1xx.h
hudakz 0:2577a4fb6e72 4 * @author MCD Application Team
hudakz 0:2577a4fb6e72 5 * @version V4.2.0
hudakz 0:2577a4fb6e72 6 * @date 31-March-2017
hudakz 0:2577a4fb6e72 7 * @brief CMSIS STM32F1xx Device Peripheral Access Layer Header File.
hudakz 0:2577a4fb6e72 8 *
hudakz 0:2577a4fb6e72 9 * The file is the unique include file that the application programmer
hudakz 0:2577a4fb6e72 10 * is using in the C source code, usually in main.c. This file contains:
hudakz 0:2577a4fb6e72 11 * - Configuration section that allows to select:
hudakz 0:2577a4fb6e72 12 * - The STM32F1xx device used in the target application
hudakz 0:2577a4fb6e72 13 * - To use or not the peripheral’s drivers in application code(i.e.
hudakz 0:2577a4fb6e72 14 * code will be based on direct access to peripheral’s registers
hudakz 0:2577a4fb6e72 15 * rather than drivers API), this option is controlled by
hudakz 0:2577a4fb6e72 16 * "#define USE_HAL_DRIVER"
hudakz 0:2577a4fb6e72 17 *
hudakz 0:2577a4fb6e72 18 ******************************************************************************
hudakz 0:2577a4fb6e72 19 * @attention
hudakz 0:2577a4fb6e72 20 *
hudakz 0:2577a4fb6e72 21 * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
hudakz 0:2577a4fb6e72 22 *
hudakz 0:2577a4fb6e72 23 * Redistribution and use in source and binary forms, with or without modification,
hudakz 0:2577a4fb6e72 24 * are permitted provided that the following conditions are met:
hudakz 0:2577a4fb6e72 25 * 1. Redistributions of source code must retain the above copyright notice,
hudakz 0:2577a4fb6e72 26 * this list of conditions and the following disclaimer.
hudakz 0:2577a4fb6e72 27 * 2. Redistributions in binary form must reproduce the above copyright notice,
hudakz 0:2577a4fb6e72 28 * this list of conditions and the following disclaimer in the documentation
hudakz 0:2577a4fb6e72 29 * and/or other materials provided with the distribution.
hudakz 0:2577a4fb6e72 30 * 3. Neither the name of STMicroelectronics nor the names of its contributors
hudakz 0:2577a4fb6e72 31 * may be used to endorse or promote products derived from this software
hudakz 0:2577a4fb6e72 32 * without specific prior written permission.
hudakz 0:2577a4fb6e72 33 *
hudakz 0:2577a4fb6e72 34 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
hudakz 0:2577a4fb6e72 35 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
hudakz 0:2577a4fb6e72 36 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
hudakz 0:2577a4fb6e72 37 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
hudakz 0:2577a4fb6e72 38 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
hudakz 0:2577a4fb6e72 39 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
hudakz 0:2577a4fb6e72 40 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
hudakz 0:2577a4fb6e72 41 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
hudakz 0:2577a4fb6e72 42 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
hudakz 0:2577a4fb6e72 43 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
hudakz 0:2577a4fb6e72 44 *
hudakz 0:2577a4fb6e72 45 ******************************************************************************
hudakz 0:2577a4fb6e72 46 */
hudakz 0:2577a4fb6e72 47
hudakz 0:2577a4fb6e72 48 /** @addtogroup CMSIS
hudakz 0:2577a4fb6e72 49 * @{
hudakz 0:2577a4fb6e72 50 */
hudakz 0:2577a4fb6e72 51
hudakz 0:2577a4fb6e72 52 /** @addtogroup stm32f1xx
hudakz 0:2577a4fb6e72 53 * @{
hudakz 0:2577a4fb6e72 54 */
hudakz 0:2577a4fb6e72 55
hudakz 0:2577a4fb6e72 56 #ifndef __STM32F1XX_H
hudakz 0:2577a4fb6e72 57 #define __STM32F1XX_H
hudakz 0:2577a4fb6e72 58
hudakz 0:2577a4fb6e72 59 #ifdef __cplusplus
hudakz 0:2577a4fb6e72 60 extern "C" {
hudakz 0:2577a4fb6e72 61 #endif /* __cplusplus */
hudakz 0:2577a4fb6e72 62
hudakz 0:2577a4fb6e72 63 /** @addtogroup Library_configuration_section
hudakz 0:2577a4fb6e72 64 * @{
hudakz 0:2577a4fb6e72 65 */
hudakz 0:2577a4fb6e72 66
hudakz 0:2577a4fb6e72 67 /**
hudakz 0:2577a4fb6e72 68 * @brief STM32 Family
hudakz 0:2577a4fb6e72 69 */
hudakz 0:2577a4fb6e72 70 #if !defined (STM32F1)
hudakz 0:2577a4fb6e72 71 #define STM32F1
hudakz 0:2577a4fb6e72 72 #endif /* STM32F1 */
hudakz 0:2577a4fb6e72 73
hudakz 0:2577a4fb6e72 74 /* Uncomment the line below according to the target STM32L device used in your
hudakz 0:2577a4fb6e72 75 application
hudakz 0:2577a4fb6e72 76 */
hudakz 0:2577a4fb6e72 77
hudakz 0:2577a4fb6e72 78 #if !defined (STM32F100xB) && !defined (STM32F100xE) && !defined (STM32F101x6) && \
hudakz 0:2577a4fb6e72 79 !defined (STM32F101xB) && !defined (STM32F101xE) && !defined (STM32F101xG) && !defined (STM32F102x6) && !defined (STM32F102xB) && !defined (STM32F103x6) && \
hudakz 0:2577a4fb6e72 80 !defined (STM32F103xB) && !defined (STM32F103xE) && !defined (STM32F103xG) && !defined (STM32F105xC) && !defined (STM32F107xC)
hudakz 0:2577a4fb6e72 81 /* #define STM32F100xB */ /*!< STM32F100C4, STM32F100R4, STM32F100C6, STM32F100R6, STM32F100C8, STM32F100R8, STM32F100V8, STM32F100CB, STM32F100RB and STM32F100VB */
hudakz 0:2577a4fb6e72 82 /* #define STM32F100xE */ /*!< STM32F100RC, STM32F100VC, STM32F100ZC, STM32F100RD, STM32F100VD, STM32F100ZD, STM32F100RE, STM32F100VE and STM32F100ZE */
hudakz 0:2577a4fb6e72 83 /* #define STM32F101x6 */ /*!< STM32F101C4, STM32F101R4, STM32F101T4, STM32F101C6, STM32F101R6 and STM32F101T6 Devices */
hudakz 0:2577a4fb6e72 84 /* #define STM32F101xB */ /*!< STM32F101C8, STM32F101R8, STM32F101T8, STM32F101V8, STM32F101CB, STM32F101RB, STM32F101TB and STM32F101VB */
hudakz 0:2577a4fb6e72 85 /* #define STM32F101xE */ /*!< STM32F101RC, STM32F101VC, STM32F101ZC, STM32F101RD, STM32F101VD, STM32F101ZD, STM32F101RE, STM32F101VE and STM32F101ZE */
hudakz 0:2577a4fb6e72 86 /* #define STM32F101xG */ /*!< STM32F101RF, STM32F101VF, STM32F101ZF, STM32F101RG, STM32F101VG and STM32F101ZG */
hudakz 0:2577a4fb6e72 87 /* #define STM32F102x6 */ /*!< STM32F102C4, STM32F102R4, STM32F102C6 and STM32F102R6 */
hudakz 0:2577a4fb6e72 88 /* #define STM32F102xB */ /*!< STM32F102C8, STM32F102R8, STM32F102CB and STM32F102RB */
hudakz 0:2577a4fb6e72 89 /* #define STM32F103x6 */ /*!< STM32F103C4, STM32F103R4, STM32F103T4, STM32F103C6, STM32F103R6 and STM32F103T6 */
hudakz 0:2577a4fb6e72 90 #define STM32F103xB /*!< STM32F103C8, STM32F103R8, STM32F103T8, STM32F103V8, STM32F103CB, STM32F103RB, STM32F103TB and STM32F103VB */
hudakz 0:2577a4fb6e72 91 /* #define STM32F103xE */ /*!< STM32F103RC, STM32F103VC, STM32F103ZC, STM32F103RD, STM32F103VD, STM32F103ZD, STM32F103RE, STM32F103VE and STM32F103ZE */
hudakz 0:2577a4fb6e72 92 /* #define STM32F103xG */ /*!< STM32F103RF, STM32F103VF, STM32F103ZF, STM32F103RG, STM32F103VG and STM32F103ZG */
hudakz 0:2577a4fb6e72 93 /* #define STM32F105xC */ /*!< STM32F105R8, STM32F105V8, STM32F105RB, STM32F105VB, STM32F105RC and STM32F105VC */
hudakz 0:2577a4fb6e72 94 /* #define STM32F107xC */ /*!< STM32F107RB, STM32F107VB, STM32F107RC and STM32F107VC */
hudakz 0:2577a4fb6e72 95 #endif
hudakz 0:2577a4fb6e72 96
hudakz 0:2577a4fb6e72 97 /* Tip: To avoid modifying this file each time you need to switch between these
hudakz 0:2577a4fb6e72 98 devices, you can define the device in your toolchain compiler preprocessor.
hudakz 0:2577a4fb6e72 99 */
hudakz 0:2577a4fb6e72 100
hudakz 0:2577a4fb6e72 101 #if !defined (USE_HAL_DRIVER)
hudakz 0:2577a4fb6e72 102 /**
hudakz 0:2577a4fb6e72 103 * @brief Comment the line below if you will not use the peripherals drivers.
hudakz 0:2577a4fb6e72 104 In this case, these drivers will not be included and the application code will
hudakz 0:2577a4fb6e72 105 be based on direct access to peripherals registers
hudakz 0:2577a4fb6e72 106 */
hudakz 0:2577a4fb6e72 107 #define USE_HAL_DRIVER
hudakz 0:2577a4fb6e72 108 #endif /* USE_HAL_DRIVER */
hudakz 0:2577a4fb6e72 109
hudakz 0:2577a4fb6e72 110 /**
hudakz 0:2577a4fb6e72 111 * @brief CMSIS Device version number V4.2.0
hudakz 0:2577a4fb6e72 112 */
hudakz 0:2577a4fb6e72 113 #define __STM32F1_CMSIS_VERSION_MAIN (0x04) /*!< [31:24] main version */
hudakz 0:2577a4fb6e72 114 #define __STM32F1_CMSIS_VERSION_SUB1 (0x02) /*!< [23:16] sub1 version */
hudakz 0:2577a4fb6e72 115 #define __STM32F1_CMSIS_VERSION_SUB2 (0x00) /*!< [15:8] sub2 version */
hudakz 0:2577a4fb6e72 116 #define __STM32F1_CMSIS_VERSION_RC (0x00) /*!< [7:0] release candidate */
hudakz 0:2577a4fb6e72 117 #define __STM32F1_CMSIS_VERSION ((__STM32F1_CMSIS_VERSION_MAIN << 24)\
hudakz 0:2577a4fb6e72 118 |(__STM32F1_CMSIS_VERSION_SUB1 << 16)\
hudakz 0:2577a4fb6e72 119 |(__STM32F1_CMSIS_VERSION_SUB2 << 8 )\
hudakz 0:2577a4fb6e72 120 |(__STM32F1_CMSIS_VERSION_RC))
hudakz 0:2577a4fb6e72 121
hudakz 0:2577a4fb6e72 122 /**
hudakz 0:2577a4fb6e72 123 * @}
hudakz 0:2577a4fb6e72 124 */
hudakz 0:2577a4fb6e72 125
hudakz 0:2577a4fb6e72 126 /** @addtogroup Device_Included
hudakz 0:2577a4fb6e72 127 * @{
hudakz 0:2577a4fb6e72 128 */
hudakz 0:2577a4fb6e72 129
hudakz 0:2577a4fb6e72 130 #if defined(STM32F100xB)
hudakz 0:2577a4fb6e72 131 #include "stm32f100xb.h"
hudakz 0:2577a4fb6e72 132 #elif defined(STM32F100xE)
hudakz 0:2577a4fb6e72 133 #include "stm32f100xe.h"
hudakz 0:2577a4fb6e72 134 #elif defined(STM32F101x6)
hudakz 0:2577a4fb6e72 135 #include "stm32f101x6.h"
hudakz 0:2577a4fb6e72 136 #elif defined(STM32F101xB)
hudakz 0:2577a4fb6e72 137 #include "stm32f101xb.h"
hudakz 0:2577a4fb6e72 138 #elif defined(STM32F101xE)
hudakz 0:2577a4fb6e72 139 #include "stm32f101xe.h"
hudakz 0:2577a4fb6e72 140 #elif defined(STM32F101xG)
hudakz 0:2577a4fb6e72 141 #include "stm32f101xg.h"
hudakz 0:2577a4fb6e72 142 #elif defined(STM32F102x6)
hudakz 0:2577a4fb6e72 143 #include "stm32f102x6.h"
hudakz 0:2577a4fb6e72 144 #elif defined(STM32F102xB)
hudakz 0:2577a4fb6e72 145 #include "stm32f102xb.h"
hudakz 0:2577a4fb6e72 146 #elif defined(STM32F103x6)
hudakz 0:2577a4fb6e72 147 #include "stm32f103x6.h"
hudakz 0:2577a4fb6e72 148 #elif defined(STM32F103xB)
hudakz 0:2577a4fb6e72 149 #include "stm32f103xb.h"
hudakz 0:2577a4fb6e72 150 #elif defined(STM32F103xE)
hudakz 0:2577a4fb6e72 151 #include "stm32f103xe.h"
hudakz 0:2577a4fb6e72 152 #elif defined(STM32F103xG)
hudakz 0:2577a4fb6e72 153 #include "stm32f103xg.h"
hudakz 0:2577a4fb6e72 154 #elif defined(STM32F105xC)
hudakz 0:2577a4fb6e72 155 #include "stm32f105xc.h"
hudakz 0:2577a4fb6e72 156 #elif defined(STM32F107xC)
hudakz 0:2577a4fb6e72 157 #include "stm32f107xc.h"
hudakz 0:2577a4fb6e72 158 #else
hudakz 0:2577a4fb6e72 159 #error "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)"
hudakz 0:2577a4fb6e72 160 #endif
hudakz 0:2577a4fb6e72 161
hudakz 0:2577a4fb6e72 162 /**
hudakz 0:2577a4fb6e72 163 * @}
hudakz 0:2577a4fb6e72 164 */
hudakz 0:2577a4fb6e72 165
hudakz 0:2577a4fb6e72 166 /** @addtogroup Exported_types
hudakz 0:2577a4fb6e72 167 * @{
hudakz 0:2577a4fb6e72 168 */
hudakz 0:2577a4fb6e72 169 typedef enum
hudakz 0:2577a4fb6e72 170 {
hudakz 0:2577a4fb6e72 171 RESET = 0,
hudakz 0:2577a4fb6e72 172 SET = !RESET
hudakz 0:2577a4fb6e72 173 } FlagStatus, ITStatus;
hudakz 0:2577a4fb6e72 174
hudakz 0:2577a4fb6e72 175 typedef enum
hudakz 0:2577a4fb6e72 176 {
hudakz 0:2577a4fb6e72 177 DISABLE = 0,
hudakz 0:2577a4fb6e72 178 ENABLE = !DISABLE
hudakz 0:2577a4fb6e72 179 } FunctionalState;
hudakz 0:2577a4fb6e72 180 #define IS_FUNCTIONAL_STATE(STATE) (((STATE) == DISABLE) || ((STATE) == ENABLE))
hudakz 0:2577a4fb6e72 181
hudakz 0:2577a4fb6e72 182 typedef enum
hudakz 0:2577a4fb6e72 183 {
hudakz 0:2577a4fb6e72 184 ERROR = 0,
hudakz 0:2577a4fb6e72 185 SUCCESS = !ERROR
hudakz 0:2577a4fb6e72 186 } ErrorStatus;
hudakz 0:2577a4fb6e72 187
hudakz 0:2577a4fb6e72 188 /**
hudakz 0:2577a4fb6e72 189 * @}
hudakz 0:2577a4fb6e72 190 */
hudakz 0:2577a4fb6e72 191
hudakz 0:2577a4fb6e72 192
hudakz 0:2577a4fb6e72 193 /** @addtogroup Exported_macros
hudakz 0:2577a4fb6e72 194 * @{
hudakz 0:2577a4fb6e72 195 */
hudakz 0:2577a4fb6e72 196 #define SET_BIT(REG, BIT) ((REG) |= (BIT))
hudakz 0:2577a4fb6e72 197
hudakz 0:2577a4fb6e72 198 #define CLEAR_BIT(REG, BIT) ((REG) &= ~(BIT))
hudakz 0:2577a4fb6e72 199
hudakz 0:2577a4fb6e72 200 #define READ_BIT(REG, BIT) ((REG) & (BIT))
hudakz 0:2577a4fb6e72 201
hudakz 0:2577a4fb6e72 202 #define CLEAR_REG(REG) ((REG) = (0x0))
hudakz 0:2577a4fb6e72 203
hudakz 0:2577a4fb6e72 204 #define WRITE_REG(REG, VAL) ((REG) = (VAL))
hudakz 0:2577a4fb6e72 205
hudakz 0:2577a4fb6e72 206 #define READ_REG(REG) ((REG))
hudakz 0:2577a4fb6e72 207
hudakz 0:2577a4fb6e72 208 #define MODIFY_REG(REG, CLEARMASK, SETMASK) WRITE_REG((REG), (((READ_REG(REG)) & (~(CLEARMASK))) | (SETMASK)))
hudakz 0:2577a4fb6e72 209
hudakz 0:2577a4fb6e72 210 #define POSITION_VAL(VAL) (__CLZ(__RBIT(VAL)))
hudakz 0:2577a4fb6e72 211
hudakz 0:2577a4fb6e72 212
hudakz 0:2577a4fb6e72 213 /**
hudakz 0:2577a4fb6e72 214 * @}
hudakz 0:2577a4fb6e72 215 */
hudakz 0:2577a4fb6e72 216
hudakz 0:2577a4fb6e72 217 #if defined (USE_HAL_DRIVER)
hudakz 0:2577a4fb6e72 218 #include "stm32f1xx_hal.h"
hudakz 0:2577a4fb6e72 219 #endif /* USE_HAL_DRIVER */
hudakz 0:2577a4fb6e72 220
hudakz 0:2577a4fb6e72 221
hudakz 0:2577a4fb6e72 222 #ifdef __cplusplus
hudakz 0:2577a4fb6e72 223 }
hudakz 0:2577a4fb6e72 224 #endif /* __cplusplus */
hudakz 0:2577a4fb6e72 225
hudakz 0:2577a4fb6e72 226 #endif /* __STM32F1xx_H */
hudakz 0:2577a4fb6e72 227 /**
hudakz 0:2577a4fb6e72 228 * @}
hudakz 0:2577a4fb6e72 229 */
hudakz 0:2577a4fb6e72 230
hudakz 0:2577a4fb6e72 231 /**
hudakz 0:2577a4fb6e72 232 * @}
hudakz 0:2577a4fb6e72 233 */
hudakz 0:2577a4fb6e72 234
hudakz 0:2577a4fb6e72 235
hudakz 0:2577a4fb6e72 236
hudakz 0:2577a4fb6e72 237
hudakz 0:2577a4fb6e72 238 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/