Thursday, February 2, 2017

Getting started with STM32F4XX with minimal resources and time - NOT USING ECLIPSE [quick start]

ADVERTISEMENT
When we need more processing power and better performance with lower power usage, often we need to move to better and more powerful microcontrollers. I was using AVR and Arduino platform for most of the projects as they do not need much processing requirements. But for doing signal processing, real-time audio /video etc we need to use faster processors. In this post am trying to summarize my efforts in using a 32bit ARM  processor. The idea is to compile and load a bare minimal blink program (GP toggle) and to get the tools ready for further use.

There are several articles and different approaches when it comes to AVR world. So it is a bit confusing at the first time. But again this is a bit complicated than loading "sketches" to Arduino.

Basic needs

  1. Familiarity with GCC compiler and basic Linux commands
  2. Patience
  3. A stm32f4 processor with supporting circuitry. It could be a development board from STM or any eBay boards or DIY boards. To make your own stm32 boards, you could use the electronic engine project from rusefi which has necessary schematic, keycad files etc 
  4.  A programmer (USB to serial will do) but it is worth investing in a STLINK. There are inexpensive clones which also used to work fine (which is basically an STM processor in a small enclosure with necessary firmware to act as a programmer)
A stlink clone on eBay

Pinouts

It is fun to see compared to 28 pins on Arduino, here we have a lot more (100 ). For more details, the datasheet can be accessed from ST

STM32 pins and naming

An inexpensive board is shown below

A simple stm32 board from rusefi project

Some IMPORTANT hardware related points


 Boot modes


This is important and could be the reason why your program is not running even after you have flashed it successfully using STLINK and its software 

At startup, boot pins are used to select one out of three boot options:

Boot from user Flash
• Boot from system memory
• Boot from embedded SRAM


BOOT0=0 BOOT1=x main flash memory boot
BOOT0=1 BOOT1=0 system memory boot (boot loader)
BOOT0=1 BOOT1=1 RAM memory

Compiling and loading a simple led blink
  1. Install the compiler for arm 
  2. Compile the source code
  3. Upload it to the microcontroler
  4. Hook up an led on  a GPIO  pin
  5. Watch the result
  6. Debugging

I used arm gcc as compiler and can be easily installed 

Navigate to launchpad.net and download the one for your operating system

 https://launchpad.net/gcc-arm-embedded  

For ubuntu/debian , you can install it by

 Step1: Inside Ubuntu, open a terminal and input  
     "sudo add-apt-repository ppa:team-gcc-arm-embedded/ppa"  
 Step2: Continue to input  
     "sudo apt-get update"  
 Step3: Continue to input to install toolchain  
     "sudo apt-get install gcc-arm-embedded"  


Now we need to get some tools to upload the compiled binary/hex file in to the flash memory on the stm32 and we can use stlink together with openocd (an opensource program). A nice guide can be read here) or using a software from st microelectronics (windows only, free to download from stm [if you have a windows computer, it is very easy to use]

 cd ~  
 git clone git://git.code.sf.net/p/openocd/code 
 #git clone git://repo.or.cz/openocd.git 
 cd ~/openocd  
 sudo ./bootstrap  
 sudo ./configure --enable-maintainer-mode --disable-werror --enable-ft2232_libftdi  
 sudo make  
 sudo make install  

Now connect your stlink to the usb port and  in the following way

Programmer -> Target
Ground -> GND
SWDIO -> PA13
SWCLK  -> PA14

The code below should connect openocd with your stm32 controller

 while true; do openocd -f /usr/local/share/openocd/scripts/interface/stlink-v2.cfg -f /usr/local/share/openocd/scripts/target/stm32f1x.cfg ; sleep 1;done  

If the connection is successful we could move on to the compiling steps

More on compiling the source and debugging can be read in the following post

No comments:

Post a Comment