Zoltan Hudak / STM32F103C8T6_Hello Featured

Using low cost STM32F103C8T6 boards with mbed.

Dependencies:   mbed-STM32F103C8T6 mbed

STM32F103C8T6 board, alias Blue Pill

It provides an affordable (about $2 on eBay) and flexible way for users to try out new ideas and build prototypes. The board is equipped with an STM32F103C8T6 microcontroller compatible with the NUCLEO-F103RB platform.

Microcontroller features

Board features

Board pinout

Zoom in
/media/uploads/hudakz/stm32f103c8t6_pinout_voltage01.png

Maximum allowed I/O voltage levels (next to pin names) are courtesy of Thorsten to help you avoid board damage. For more details on pin definitions see Table 5 in the Datasheet.

Information

Only the labels printed in blue/white or green/white (i.e. PC_13, PB_9, A0, D14 ...) must be used in your code. The other labels are given as information (alternate-functions, power pins, ...). You can also use these additional pin names:

LED1=PC_13  SERIAL_TX=PA_2  I2C_SCL=PB_8  SPI_MOSI=PA_7  PWM_OUT=PB_3
            SERIAL_RX=PA_3  I2C_SDA=PB_9  SPI_MISO=PA_6
                                          SPI_SCK =PA_5
                                          SPI_CS  =PB_6

Please notice that in order to fit the small size board, the leading 'P' and the '_' characters are omitted from labels indicated on the board (e.g. Instead of 'PA_1' you can find the label 'A1' on the board). Arduino (green/white) and the additional naming labels are not indicated on the board.
Also notice that the on-board LED is connected to pin PC_13 and, via a resistor, to +3.3V. So to turn the LED on or off you have to set the DigitalOut to 0 or 1 respectively.


Schematic

Zoom in /media/uploads/hudakz/stm32f103c8t6_schematic.png

Using the mbed on-line compiler to build programs for the STM32F103C8T6 board

Blinking on-board LED:

#include "stm32f103c8t6.h"
#include "mbed.h"
  
int main() {
    confSysClock();     //Configure system clock (72MHz HSE clock, 48MHz USB clock)
    
    Serial      pc(PA_2, PA_3);
    DigitalOut  myled(LED1);
    
    while(1) {
        // The on-board LED is connected, via a resistor, to +3.3V (not to GND). 
        // So to turn the LED on or off we have to set it to 0 or 1 respectively
        myled = 0;      // turn the LED on
        wait_ms(200);   // 200 millisecond
        myled = 1;      // turn the LED off
        wait_ms(1000);  // 1000 millisecond
        pc.printf("Blink\r\n");
    }
}


Warning

/media/uploads/hudakz/stm32f103c8c6_build.pngKeep in mind that the on-line compiler is cheking for 128kB maximum flash size. However, the STM32F103C8T6 is equipped with only 64kB. So once the compilation is complete (started by clicking on the Build only button in the Compile drop list or by pressing Ctrl+B) you have to visually check the size of used flash memory in the Program details - Build tab. In order to fit into an STM32F103C8T6 board the used Flash must not exceed 64kB! Try to optimize your program until it's using less than 64kB flash memory. Have a look at mbed-STM32F030F4 and Andy's hints for some good tips on how to do it.



Programming the STM32F103C8T6 board

You can use the NUCLEO virtual disk to program the STM32F103C8T6 board (drag and drop programming). To do that, an additional NUCLEO board is needed (any type equipped with ST-LINK/V2-1 will do).

/media/uploads/hudakz/nucleo_c4.png/media/uploads/hudakz/stm32f103c8t6_debug_con.png
NUCLEO board
CN4 connector
STM32F103C8T6
debug connector
STM32F103C8T6
board
SWCLK<=>DCLK
GND<=>GND
SWDIO<=>DIO
NRST<=>RESET

Using serial port (for debugging)

/media/uploads/hudakz/stm32f103c8t6_hookup.jpg Zoom in

Sending debug messages over the ST-Link virtual com port

In case you would like to spare the external USB-Serial converter for other purposes then there is available an alternative solution proposed by X M (bitman). You can use the ST-Link virtual com port also for debugging of programs running on the STM32F103C8T6 board. However, that will require a soldering iron (and probably some soldering skills). According to the User Manual, chapter 6.8 "USART communication", solder bridges (on the back side of the NUCLEO board) SB62 and SB63 should be ON, SB13 and SB14 should be OFF. In such case it is possible to connect another USART to the NUCLEO (ST-Link) CN3 connector using flying wires. For instance on STM32F103C8T6 board it is possible to use USART2 available on PA_2 (TX) and PA_3 (RX). Two flying wires shall be connected as follows:

STM32F103C8T6 board, pin PA_2 (Serial2 TX)<=>NUCLEO board CN3 connector, pin RX
STM32F103C8T6 board, pin PA_3 (Serial2 RX)<=>NUCLEO board CN3 connector, pin TX

A smart trick proposed by Nothing Special makes even soldering needless.
The point is to redirect the UART on the NUCLEO board by software (without modifying the solder bridges on the back side of the NUCLEO board) and convert it into a "Debugger". On the NUCLEO board that you are going to use as programmer/ debugger, choose any Serial port other than Serial2 (other than the default port used for standard UART) to be initialized as standard UART. In the program below (using NUCLEO-F103RB as programmer/debugger) Serial1 (PA_9, PA_10) was selected.

Debugger

#include "mbed.h" 

// declarations needed to change the parameters of stdio UART 
extern serial_t     stdio_uart; 
extern int          stdio_uart_inited; 

int main() {
    serial_init(&stdio_uart, PA_9, PA_10); // other than Serial2
    stdio_uart_inited = 1; 
    printf("Ready for debugging\r\n");
}


Once compiled (remember to select the NUCLEO board used for programing/debugging as target for the on-line compiler), download the "Debugger" program to the NUCLEO board. Please make sure you have the two jumpers in place on the CN2 connector when programming the NUCLEO board. Once the "Debugger" binary has been downloaded to the NUCLEO board, remove the two jumpers again.



Off-line compilation and debugging with CooCox CoIDE

/media/uploads/hudakz/export.png

Warning

It seems that at the present mbed is having some issues with exporting projects to CoIDE. As a result Serial is not getting initialized correctly and the program hangs. Hopefully this is going to be fixed soon. Meanwhile a work around is to use the default serial port for printf (no Serial object is needed) which is available at pins PA_2, PA_3 (Tx pin, Rx pin) as below:

#include "stm32f103c8t6.h"
#include "mbed.h"
  
int main() {
    confSysClock();     //Configure system clock (72MHz HSE clock, 48MHz USB clock)
    
    //Serial      pc(PA_2, PA_3);
    DigitalOut  myled(LED1);
    
    while(1) {
        // The on-board LED is connected, via a resistor, to +3.3V (not to GND). 
        // So to turn the LED on or off we have to set it to 0 or 1 respectively
        myled = 0;      // turn the LED on
        wait_ms(200);   // 200 millisecond
        myled = 1;      // turn the LED off
        wait_ms(1000);  // 1000 millisecond
        //pc.printf("Blink\r\n");
        printf("Blink\r\n");
    }
}



Download repository: zip gz

Files at revision 10:4b88be251088

Name Size Actions
[up]
main.cpp 628 Revisions Annotate
mbed-STM32F103C8T6.lib 67 Revisions Annotate
mbed.bld 65 Revisions Annotate