[STM32]: Setting STM32 development environment on Arch Linux - Part 1
I have bought STM32F103C8T6 aka “Blue-Pill” and ST Link V2 from Aliexpress long time back. I did not get time earlier to explore this MCU. The price of this board is just 1.81$
in case you buy it from Aliexpress.
Key Features
- ARM® 32-bit Cortex® -M3 CPU Core
72 MHz maximum frequency,1.25 DMIPS/MHz (Dhrystone 2.1) performance at 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 - CRC calculation unit, 96-bit unique ID
For more information, go to STMicroelectronics product page
Install gcc and newlib
Install stlink and openocd
stlink is a tool to download the compiled binary to the microcontroller and OpenOCD is an on-chip debugger. I shall cover OpenOCD in future tutorials.
install libopencm3
Libopencm3 is a nice opensource C
library for cortex M0/M1/M3 and other MCUs.
This should compile without any issue.
Write your blink LED sketch
The onboard LED on board is connect at port GPIO13
of GPIOC
.
gpio_toggle()
is the function to toggle the state of GPIOs and we would be using this function to blink the onboard led.
svn
command can be used to download complete blink sample code.
You might need to modify the libopencm3
repo path in libopencm3-examples-rules.mk
. In my case, it is set to $(HOME)/repos/libopencm3.
Build the blink program.
Uploading the program
You will need ST Link V2 programmer to upload the code.
You should see GREEN LED blinking.
Blink led on stm32 works. #stm32 pic.twitter.com/NfrgWu2dmr
— FAITH + 1 (@amitesh_singh) February 21, 2017