Using low cost Bluepill (STM32F103C8T6) boards with mbed.

Dependencies:   mbed

Dependents:   STM32F103C8T6_Chicharronera_4CV2 STM32F103C8T6_Portada

You are viewing an older revision! See the latest version

Homepage

STM32F103C8T6 board

It provides an affordable (less than $3 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

  • STM32F103C8T6 in LQFP48 package
  • ARM®32-bit Cortex®-M3 CPU
  • 72 MHz max CPU frequency
  • VDD from 2.0 V to 3.6 V
  • 64 KB Flash
  • 20 KB SRAM
  • GPIO (32) with external interrupt capability
  • 12-bit ADC (2) with 10 channels
  • RTC
  • Timers (4)
  • I2C (2)
  • USART (3)
  • SPI (2)
  • USB 2.0 full-speed
  • CAN

Board features

  • Small foot-print
  • Flexible board power supply: USB VBUS or external source (3.3V, 5V)
  • User LED: LED1
  • One push button: RESET
  • Programming/Debug port
  • Micro-B USB connector

Board pinout

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

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

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

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

  • Create a program as if it was for a NUCLEO-F103RB board (select NUCLEO-F103RB as target platform in the on-line compiler).
    Or click here to import this demo into your on-line compiler (then you can skip the following two steps).
  • Add #include "stm32f103c8t6.h" to main.cpp before #include "mbed.h" (the position matters!) and call confSysClock function at the begin of main function.

Blinking on-board LED:

#include "stm32f103c8t6.h"
#include "mbed.h"

Serial      pc(PA_2, PA_3);
DigitalOut  myled(LED1);

int main() {
    confSysClock();     // Configure system clock (to 72MHz HSE clock and 36MHz APB1 peripheral clock)
    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(0.2);      // 200 ms
        myled = 1;      // turn the LED off
        wait(1.0);      // 1 sec
        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.


Additional example programs using the STM32F103C8T6 board:



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).

  • Remove the two jumpers from the CN2 connector as illustrated in Figure 8: /media/uploads/hudakz/nucleo_prog.png

/media/uploads/hudakz/nucleo_c4.png/media/uploads/hudakz/stm32f103c8t6_debug_con.png
  • Connect the NUCLEO board CN4 connector to the STM32F103C8T6 board using flying wires as follows:
NUCLEO board
CN4 connector
STM32F103C8T6
debug connector
STM32F103C8T6
board
SWCLK<=>DCLK
GND<=>GND
SWDIO<=>DIO
NRST<=>RESET
  • Provide power for the STM32F103C8T6 board through a 3.3V pin, 5V pin or over a USB cable. (The VDD_TARGET pin on the NUCLEO board CON4 does not work as source of power).

  • Connect the NUCLEO board to your PC over a USB cable.

  • To program the STM32F103C8T6 board, click on the Compile button and save the binary to the NUCLEO virtual disk .

    For more details have a look at the User Manual, chapter 6.2.4 Using ST-LINK/V2-1 to program and debug an external STM32 application.

Using serial port (for debugging)

  • Connect an FTDI or similar USB to Serial TTL converter to your PC and to an on-board serial port (for example PA_2, PA_3). Make sure you connect the on-board TX pin to the converter's RX pin and the on-board RX pin to the converter's TX pin.

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

  • In your code, create a Serial object (using TX and RX pin names of the connected serial port).
  • Use printf function to send serial messages to the connected PC.

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



Off-line compilation and debugging with CooCox CoIDE

  • Keep the NUCLEO board ( ST-LINK) connected to the STM32F103C8T6 board as in the set-up for on-line programming.
  • Export your program from the mbed on-line compiler to CooCox CoIDE.

/media/uploads/hudakz/export.png

  • Save the file into a folder on you PC's hard drive and unzip.

  • Run CoIDE and open the project.

  • Go to the Configuration and in the Link tab click on the Edit button to open the Scatter File for editing.
    /media/uploads/hudakz/edit_scatter.png

  • Once the stm32f103xb.ld file is open change the legth of available FLASH from 128K to 64K:

/* Linker script to configure memory regions. */
MEMORY
{ 
  FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 64K
  RAM (rwx) : ORIGIN = 0x200000EC, LENGTH = 20K - 0xEC
}
  • Save the change and close the file. From now on, the off-line compiler will compare the size of used Flash memory with 64kB maximum Flash size and we'll get an error message in case it's exceeded.

  • To setup the debugger, open the Debugger tab and use the following settings:
    /media/uploads/hudakz/debugger_settings.png


  • To ensure that the execution of instructions during debugging is performed in the foreseen sequence, go to the Compile tab and select None (-O0) optimization . /media/uploads/hudakz/stm32f103ct6_off-line_compile.png

  • Open main.cpp for editing and comment out the confSysClock function at the begin of main function. It is not needed when building the project off-line. Then rebuild the project by clicking on the Rebuild button. /media/uploads/hudakz/stm32f103ct6_off-line_recompile.png

  • Reprogram the board by clicking on the Download Code To Flash button.
    NOTE: Any time you launch the debugger the program is getting recompiled and the board reprogrammed. So you can skip this step. I included it just to illustrate how easily you can (re)program the board off-line. /media/uploads/hudakz/stm32f103ct6_off-line_program.png

  • Set up some debug points and launch the debugger by clicking on the Start Debug button. /media/uploads/hudakz/stm32f103ct6_off-line_debug.png

  • You can execute the instructions step by step (or run to the next debug point) and observe the variables and outputs whether they are changing as expected... /media/uploads/hudakz/stm32f103ct6_off-line_debugging.png
    Happy coding and debugging.

All wikipages