Pages

Thursday, February 2, 2017

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

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


Scratch build and test of STM32F4 with 176 pins on a home pcb

==============================================

Building a prototype PCB is much easier these days. Draw your design in your favorite CAD software (or even online, for e.g  EasyEDA ) and upload it to the manufacturer. But i gave a try for the old school with a ARM chip. The process i used  is similar to what i described earlier.

Blinking an led on PG14
-add decoupling capacitors (at least 4 of them) and closer to power rails
-place an led on PG14 (to change the pin, go to  the git repository, change pin and recompile)

Firmware: Download 
Trace Layout (mirrored pdf) : Download
Gerber:  Download

ST micros are very robust in my experience and can work even on a home etched single sided board ( far from the specifications mentioned in the ST's application notes) . Here are some pictures and clips from a home etched PCB and an led blink.


Top two boards were failed due to wrong exposure from my diy uv led box

same as previous, the last board is correct one

Etched board and solder mask 

Added solder mask




Testing 


Adding a usb port and micropython for quick prototyping

==========================================

Usb port on top right side, i also added a 4 pin header for st-link on top center part

later in this project i compiled micropython (note= disabled the usb auto detect and for stm32f429iits (the exact micro controller in my project)

Files: github 

There are two binary files and flash them using  flash0.sh & flash1.sh

The board will appear as a usb flash drive and copy the main.py over there

It will keep our PG14 led blinking

You can also compile micropython from scartch

=>  git clone  https://github.com/micropython/micropython

then  set BOARD ?= NUCLEO_F429ZI (in Makefile under ports/stm32)

and  in boards subfolder, edit mpconfigboard.h file to  get the board running without the USB VBUS detection by disabling it

(comment the line #define MICROPY_HW_USB_VBUS_DETECT_PIN (pin_A9))

Testing Video
==========



Overview of parts neede for minimal circuit
===========================
1) BYPASS capacitors on four sides
2) VCAP1 and 2
3) BOOT_0  resistor
4) BYPASS_REG to GND (missed in the layout)
5) VREF+ and VDDA to VDD (missed in layout)
6) PA13 and 14 (for programming/debug)
7) 8 MHZ crystal+load cap (extra, can be omitted)
8) USB port and regulator for 3.3 volt (extra)

Click to see the annotations and details of corrections




2 comments:

  1. Very good, the board was very beautiful! Only 8MB SDRAM was missing to run a 800x480 7 inch TFT display directly!

    ReplyDelete