Selected for you
 
Articles Hierarchy
 
How to begin with STM32 and why - tutorial


AVR, ATMega, ATTiny, PIC, Arduino... these are very searching words in google and I asked myself "Why?". Yes, AVR by Atmel or PIC by Microchip family is popular, but we can program better (modern, faster, more low-power, more peripherals) microcontrollers than AVR or PIC.
A lot of tutorials are for AVR or PIC and therefore I would like to describe "How to begin with STM32".
Yes, I could choose microcontrollers by TI or Renesas, but I think that STM32 is better, because this microcontrollers family has a lot of types of microcontrollers and development boards. This STM32.

Why: At first, why begin with STM32. That was question and answer is easy. As I wrote - modern, faster, more low-power, more peripherals - SPI, I2C, UART, CAN, USB, Ethernet etc.
Development boards contain programmer and debugger (you can see actual data from microcontroller or stop your code on active line - breakpoint)
ST company offers a lot of type of microcontrollers and so you can find other microcontrollers exactly for your project. You can buy very low-power microcontroller, microcontroller with a lot of peripherals, easy microcontroller in TSSOP package and making of PCB for these microcontrollers isn't problem.

Price: A lot of people say that new microcontrollers are so expensive. It is not true.
One example: STM32F030F4P6. Microcontroller with ARM Cortex-M0 core, max frenquency is 48 MHz, contains I2C, SPI and UART in TSSOP package (20 pins) costs $1.14 (*1 August 2015). The microcontroller has 16 kB FLASH nad 4 kB RAM and is supllied with 3.3V, but a lot of GPIOs is 5V tolerant. You can use a few DMA, 11x timer, watchdog etc.
If you want more GPIOs and FLASH, you can buy STM32F030C6T6 which costs $1.57 (*2 August 2015). 48 GPIO, 32 kB FLASH and 4 kB RAM.

If you need USB interface and bigger RAM (6kB) you can buy STM32F070C6T6 which costs $2.12 (*3 August 2015).
And what is power consumption? Standby mode with LSI OFF and IWDG OFF - 1.4uA
LSI ON and IWDG ON - 2.2uA. With high speed oscillator (48MHz) is power consumption 24mA (HSI or HSE clock, PLL on).

And now low-power microcontrollers STM32L152C6T6A - $3.56 (*4 August 2015)
0.3uA in Standby mode - 3 WakeUp pins or
0.9uA - Standby + RTC
9uA v Low-power run mode

If you need more power, you can choose STM32F407, 429 or new STM32F746.

Development tools: You can make AVR programmer, but why? You can buy development board with programmer and debugger for a few $.
ST company offers own development boards. They have two types of development boards (for common makers).
Discovery Kit: with programmer and debugger contains another components as e.g. accelerometer, LCD display, gyroscope and other.
Nucleo: It contains only two buttons (reset and user), LEDs, Arduino Like connectors and Morpho connectors by ST.
It means, if you want to use Arduino shields, you can, no problem. And next advantage is ST-LINK/V2-1. Board is connected like "flash disk" to the laptop and you can load your program to microcontroller as copying binary file to this "flash disk".

A lot of Nucleos cost $11.87 e.g.:
NUCLEO-L152RE
NUCLEO-L152RE
NUCLEO-F072RB
NUCLEO-F103RB
NUCLEO-F030R8

Or Discovery Kit:
STM32L-DISCOVERY with STM32L152RBT6
STM32F4DISCOVERY witch STM32F407 which costs $14.88 (*6 august 2015)
STM32F0DISCOVERY which costs $8.88 (*7 srpen 2015)
in offer is more development boards.

Cheap boards with STM32 which are supported in Arduino IDE. Link https://time4ee.com/articles.php?article_id=51

Development Tools (IDE): It can be free. E.g. free Keil - its limitations is 32 kB code or AC6 System Workbench for STM32 by openstm32.org - Unlimited.
Or you can try IAR.
Yes, Arduino is very popular, but you can use more powerful and low-power microcontroller than ATMega328, Arduino based on STM32. IDE for STM32 Arduino can be Maple IDE available for Windows, Linux and Mac OSX as AC6 System Workbench for STM32.
If you don't want to use Maple IDE which is based on old version of Arduino IDE, you can use Arduino IDE directly. Download the *.json file from https://github.com/stm32duino to Arduino IDE. There je supported a lot of STM32 microcontrollers.
Cheap boards with STM32 which are supported in Arduino IDE. Link https://time4ee.com/articles.php?article_id=51

Coding: Yes, you can code STM32 as Arduino, but you can use other way how to program it.
You can use HAL, it's program layer, where you can write your code with functions by ST.
Similar is Standard Peripheral Library, but HAL replaces Standard Peripheral Library because HAL is effective. You shall to expectes bigger final code, on the other side, STM32 has big FLASH and RAM.
A bigger helper is CubeMX which can help you to faster making your project.

Other way is using of Low-Layer API. API which controls peripherals like GPIO, I2C, SPI etc.

At last sentences, you can easily port your code to another microcontrollers, based on ARM architecture.

I hope that this articles was help for you with begin STM32 and you will think about it.

(*1) http://www.newark.com/stmicroelectronics/stm32f030f4p6/mcu-32bit-cortex-m0-48mhz-tssop/dp/39X0183
(*2) http://www.newark.com/stmicroelectronics/stm32f030c6t6/mcu-32bit-cortex-m0-48mhz-lqfp/dp/39X0181?searchRef=SearchLookAhead
(*3) http://www.newark.com/stmicroelectronics/stm32f070c6t6/mcu-32bit-cortex-m0-48mhz-lqfp/dp/52Y1095?searchRef=SearchLookAhead
(*4) http://www.newark.com/stmicroelectronics/stm32l152c6t6a/mcu-32bit-cortex-m3-32mhz-lqfp/dp/42Y1083?searchRef=SearchLookAhead
(*6) http://www.newark.com/stmicroelectronics/stm32f4discovery/stm32-f4-series-discovery-kit/dp/87T3791?categoryId=800000004005
(*7) http://www.newark.com/stmicroelectronics/stm32f0discovery/evaluation-board-cortex-m0-stm32f0/dp/94T6483?searchRef=SearchLookAhead