Embedded Programming

Assignment:

Compare the performance and development workflows for other architectures

The Agenda:

Test out microcomputers available at Fab Lab CEPT

  1. stm32f103c8 Blue pill Development Board

STM32F103c8 blue pill Board

STM32F103C8T6 Datasheet

The STM32F103xx medium-density performance line family incorporates the high-performance ARM®Cortex®-M3 32-bit RISC core operating at a 72 MHz frequency, high-speed embedded memories (Flash memory up to 128 Kbytes and SRAM up to 20 Kbytes), and an extensive range of enhanced I/Os and peripherals connected to two APB buses. All devices offer two 12-bit ADCs, three general purpose 16-bit timers plus one PWM timer, as well as standard and advanced communication interfaces: up to two I2Cs and SPIs, three USARTs, an USB and a CAN.

Specifications:

    ARM®32-bit Cortex®-M3 CPU Core

  • 72 MHz maximum frequency,1.25 DMIPS/MHz (Dhrystone 2.1) performance at 0 wait state memory access
  • Single-cycle multiplication and hardware division

  • Memories

  • 64 or 128 Kbytes of Flash memory
  • 20 Kbytes of SRAM

  • Clock, reset and supply management

  • 2.0 to 3.6 V application supply and I/Os
  • POR, PDR, and programmable voltage detector (PVD)
  • 4-to-16 MHz crystal oscillator
  • Internal 8 MHz factory-trimmed RC
  • Internal 40 kHz RC
  • PLL for CPU clock
  • 32 kHz oscillator for RTC with calibration

  • Low-power

  • Sleep, Stop and Standby modes
  • VBAT supply for RTC and backup registers

    2 x 12-bit, 1 μs A/D converters (up to 16 channels)


  • Conversion range: 0 to 3.6 V
  • Dual-sample and hold capability
  • Temperature sensor

  • DMA

  • 7-channel DMA controller
  • Peripherals supported: timers, ADC, SPIs, I2Cs and USARTs

  • Up to 80 fast I/O ports

  • 26/37/51/80 I/Os, all mappable on 16 external interrupt vectors and almostall 5 V-tolerant

  • Debug mode

  • Serial wire debug (SWD) & JTAG interfaces

  • 7 timers

  • Three 16-bit timers, each with up to 4 IC/OC/PWM or pulse counter and
  • quadrature (incremental) encoder input
  • 16-bit, motor control PWM timer with dead-time generation and emergency
  • stop
  • 2 watchdog timers (Independent and Window)
  • SysTick timer 24-bit downcounter

  • Up to 9 communication interfaces

  • Up to 2 x I2C interfaces (SMBus/PMBus)
  • Up to 3 USARTs (ISO 7816 interface, LIN, IrDA capability, modem control)
  • Up to 2 SPIs (18 Mbit/s)
  • CAN interface (2.0B Active)
  • USB 2.0 full-speed interface

  • CRC calculation unit, 96-bit unique ID

    Packages are ECOPACK®

Programming the STM32F103C8T6 Development board

The STM32F103C8T6 development board comes with all peripheral components on board and Serial/USB and SWIM interface for programming and getting the onboard STM32F103C8T6 chip to work.
All information on these generic STM32F103C8T6 development board, also known as the Blue Pill development board can be found here.

Blue Pill Development
Board for STM32F103C8T6

Pin Out Diagram

Blue Pill Development board Pinout by Rick Kimball

Installing ST-Link v2 Drivers:

The programmer we have at the lab is an ST-Link v2. The drivers for it can be downloaded freely from ST's official Site.

Using STM32Duino to program the Blue Pill Dev. Board

To program the generic blue pill development board I have, I'll be using STM32duino, the arduino Core for STM32.
Installation instructions can be found here.

To use the board manager installation method, the following url needs to be added to the Additional Board Manager URLs,
https://github.com/stm32duino/BoardManagerFiles/raw/master/STM32/package_stm_index.json

Uploading a Blink Code:

The blue pill development board is a minimal one and only has one programmable LED on PC13 for test programming. I wrote a blink code for it and uploaded the program using Arduino. The Connection from the SWIM interface on the blue pill to the JTAG breakout on the ST-Link is explained on the stm32duino wiki. The Pinout is as follows;

    Blue Pill ---------------------ST-Link

  • 3v3--------------------------------------pin 1
  • SWO------------------------------------ pin 7
  • SWCLK-----------------------------------pin 9
  • GND-------------------------------------GND

Pin Diagram for Jtag Connector on ST-Link V2


Code:

Hex footprint:

Surprisingly, the hex footprint to run this small code is 715 lines long. (32,768 bytes)

Output:



Download:

Download STM32duino Project folder(compiled binary included)

Using Arm Mbed to program the Blue Pill Development Board

Mbed is an online embedded device platform which gives you an embedded operating system, transport, security and cloud services to create Embedded solutions. Although it is designed mostly for IoT applications, the generic chinese blue pill development board can also be programmed using it. I think it is an integrated solution that is easy to work on and easy to deploy. More about what is Mbed and how it works, can be found here.

Getting Started with Mbed and the Generic Blue Pill Development board:

Signing Up:

Getting started with Mbed is easy, just sign up for and account at their sign up page.

Adding Hardware for Generic Blue Pill in our console:

After you sign up, You should be able to navigate to your console.Before we can get started with programming, we need to add our device to the hardware list in our console. The generic blue pill development board for the STM32F103C8T6 is not supported officially by mbed. So we have to add it as a Nucleo-F103RB. It uses the same chip but has 128kb flash memory instead of our 64kb board. I found this nifty guide, on how to program our generic board using Mbed.

Mbed Console UI

Using the Online Mbed Compiler

The compiler UI is a bit confusing at first. I would recomend using the many example programs given by Mbed and writing your own code by modifying the templates. First we'll create a new program, and I named it "HelloWorld_blinky" and is based on the 'Display a message on PC using UART' example.
The program project folder will be created along with the 'main.c' file, which we will be editing to write our own code. The example code looks a bit like this, but it didn't work out of the box because the default Serial Tx/Rx pins for the nucleo and the blue pill are different. So after going through the Generic Blue Pill Guide for Mbed, I wrote the following code.

Compiling and optimizing:

The Blue Pill board has 64KB memory, while the nucleo has 128kb. So after we click compile, we have to check on the 'Build Details', and manually ensure the Flash size does not exceed 64kb. For our case, the Flash Size of the build was 27.6kb which was well under 64kb. Once you click compile, the compiled .bin file should automatically downloaded in your browser.

Uploading the Code:

To upload the .bin file we need to download the ST link utility Once downloaded, the utility program can be run and should look like this. Connect your Blue pill with the ST-link, the pinout diagram is the same as when we connected it to upload code using STM32duino.

    Blue Pill ---------------------ST-Link

  • 3v3--------------------------------------pin 1
  • SWO------------------------------------ pin 7
  • SWCLK-----------------------------------pin 9
  • GND-------------------------------------GND

Click on Connect, the device memory table should show up on the utility.
Connecting to Device Using ST-Link
Open the file you want to upload by clicking on open program, this would be the .bin file you downloaded from mbed.
Uploading Program
Now click on Program verify and click 'start', the program should be uploaded.
Program Uploaded

ST-link Verbose Output




Viewing the Output:

To view the UART output, connect the FTDI module with the blue pill dev. board, make sure the FTDI is in 3.3v mode or you'll destroy the board. The connection should be;

    Blue Pill ---------------------FTDI

  • 3v3--------------------------------------3.3v
  • A3--------------------------------------- TX
  • A2----------------------------------------RX
  • GND-------------------------------------GND

Download Project Files:

Download HelloWorld_Blinky_zip_nucleo_f103rb.zip