Sunday, 13 January 2019

This week 1/2019 - STM32 microcontroller

Today I'd like to write about my first experiences with STMicroelectronic. My set is Nucleo board with STM32F466RE chipset - 160Mhz with 512k flesh memory.
I started from looking for articles and YouTube tutorials about hardware platrorm. I didn't know difference between Raspberry PI and Andurino. I found a few interesting [in resources] and then I decided to buy STM32 hardware platform with at least 256kB flash memory.
Next step was to choose IDE. I'd like to use IntelliJ because daily I work in this IDE, unfortunately JetBrains has other tool with separate licence and not so popular as other IDEs. Finally I chosen Atollic TrueSTUDIO for STM32 9.2.0 especially it is supported by tool STM32Cube MX.
STM32Cube MX is a tool to generate project for selected IDE with C code initializing selected by developer modules and ports of STM32 processor.
To create and load first program on microchip we need to install compiler. I am using Linux system that's why I executed commands:
sudo apt-get install gcc-arm-none-eabi
sudo apt-get install binutils-arm-linux-gnueabi
sudo apt-get install libnewlib-arm-none-eabi
My hardware platform has integrated ST-link and storage where I can copy my binary file and load it automatically on my STM microchip. No additional tool needed.
At the beginning I used external libraries libopencm3 [5] with examples. However there is no tool to generate initializing methods like STM32Cube MX what it is useful at the beginning.
I watched presentation [10] and I was inspired to create code in C++. Bartosz convincing that C++ takes similar resources. In come cases is even much better then code from C compiler.


Till now I created following projects basing on examples:
  1. Change GPIO port state. Both sources of code have example of blinking LED. I used my own external LED to blink.
  2. Read GPIO port state. We can read state of each pin. For pin 1 it will be value 0 or 1, for pin 2 value 0 or 2 and so on. I closed selected pin with 3.3V source.
  3. Communicate via serial port USART. I get connected using ST-link integrated with nucleo board and by external ST-link module.
  4. Read system time. This operation looks different than in OS Linux system. We need to open timer module of chip and then we can read counter.
  5. Ethernet connection. I have Ethernet module with chip ENC28J60. I connected it to SPI connectors however I couldn't run it. :( After spend some time I found correct example and adopted it in my project [8]. It works fine. However I don't know why one request is processed 4 times. Maybe clock of buffer reader is too fast. I must check it.
  6. DAC - set voltage on output an modulate speaker.
  7. ADC - read voltage on input in range 0-3,3V.
  8. Store and read data from flash memory [9]. I have to change memory mapper file.


Resources:
  1. How to start
  2. STM32 tutorial
  3. List of useful links
  4. STM32 HAL layer - documentation
  5. Alternative library with examples - libopencm3
  6. STM32Cube MX tutorial
  7. Setting STM32 clock speed
  8. Ethernet module - ENC28J60
  9. Read/store data in memory
  10. Bartosz Szurgot - C++ vs C the embedded perspective