Saturday 31 December 2016

STM32-Arduino -STM32f103c8t6 Programming Guide

This boards costs around 1.7$ ( including shipment all over the world  ) in aliexpress.com..  low cost , extremely powerful controller than normal Arduino


  • 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, I2 Cs and USARTs
  • Up to 80 fast I/O ports
    • 26/37/51/80 I/Os, all mappable on 16 external interrupt vectors and almost all 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 I2 C 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

1.Install the latest version of  Arduino

2.Arm Compiler Installation 
  In arduino menu Go to "Tools" -> "Boards" -> "Boards Manager"  & click "install."
( This board uses same gcc compiler used by Atmel SAM boards )


If you fail to install the compiler , you get an error message like this 
exec: "/bin/arm-none-eabi-g++": file does not exist Error compiling for board Generic STM32F103C series.


Installation takes some time


3. Once Installation is over goto  https://github.com/rogerclarkmelbourne/Arduino_STM32    & download it 

4.Extract the zip file  ,and copy it in to "C:\Program Files (x86)\Arduino\hardware"    folder..  [if you have installed Arduino in to other place of your choice , copy it there .

Windows XP or other 32 bit OS path will be , 
C:\Program Files \Arduino\hardware

5. Connection is made like this 


You can use any serial adapter with 3.3V level ... FTDI , CH340G works fine


6.  Now Open Arduino  & "Tools" Menu  and Select 

Board :Generic STM32F103C Series
Variant: STM32F103C8 (20k,RAM.64k Flash)
Upload Method:Serial
Port : (based on your USB to Serial device)

7.Copy & compile the below code

#define pinLED PC13

void setup() {
  Serial.begin(9600);
  pinMode(pinLED, OUTPUT);
  Serial.println("START");  
}

void loop() {
  digitalWrite(pinLED, HIGH);
  delay(1000);
  digitalWrite(pinLED, LOW);
    delay(1000);
  Serial.println("Hello World");  
}

if everything is fine it will compile ..

8. on the board set the BOOT0 to 1 


Power ON the USB and before start uploading , press 'RESET' button once .. and click "upload"

Reset button & jumper setting  force the controller to go to bootloder mode.
Incase if you have not pressed the reset button /jumper setting is not set proper , you get an error message like this " Failed to init device"




If everything goes fine you get a message like this 


Now you should be able to see the LED blinking ..

Once programming is done ,board runs automatically , no need to change the jumber ..If you are just debugging your code, leave the jumper as it is ..  Otherwise once programming is done, move it back to the previous position.  

No comments:

Post a Comment