Flashing STM32 via serial line on Linux – stm32flash

For Windows users there is a tool called “Flash Loader Demonstrator”. This obviously does not run on Linux, but there is also a possibility to natively flash a binary (or hex file) in case you cannot use the WIZnet update tools that use the bootloader. So this is basically needed when you want to upgrade the bootloader. In case you don’t have subversion installed you need to do the following in a console:
tw@kallisto:~# sudo apt-get update && sudo apt-get install subversion

After that you have to first checkout the latest sourcecode of the tool

tw@kallisto:~$ svn checkout http://stm32flash.googlecode.com/svn/trunk/ stm32flash

Then you can compile and install the tool

tw@kallisto:~$ cd stm32flash && make && sudo make install

Bildschirmfoto vom 2015-03-18 14:17:16

Now you have to bring the board into boot mode. There is usually some BootEnable pin. Hold that booten pin during power up or reset of the module. After that, the module is waiting for the following command:
tw@kallisto:~$ stm32flash –w combine.bin –v /dev/ttyS0

Bildschirmfoto-Namenloses Fenster

Generate Padding for the Bootloader

There is one important difference between the Windows version of Flashloader Demo and the stm32flash. In the current version of the stm32flash the complete flash is erased before programming. As long as you have only one binary for the application this is no issue. But in case you have a bootloader and an application the bootloader is erased when you flash the application.
As a workaround for this you have to combine the two files.
How to combine Bootloader and Application file.

As an example i’ll show how to combine the bootloader and application file of WIZ550web. As per note on http://wizwiki.net/wiki/doku.php?id=products:wiz550web:wiz550web_download the bootloader shall go to the adress 0x8000000 and the application shall go to 0x8006000. So as we will copy both files together the bootload needs some padding to be exactly 0x6000 = 24576 in size.

Bildschirmfoto vom 2015-03-18 14:30:56So first we find out the size of the bootloader. In this example it is 23312 bytes in size. So we just calculate 0x6000 – 23312 = 1264. To get the padding we just dump 1264 bytes from the device /dev/zero which contains an unlimited number of zeros into some file, e.g., zeroes.bin.

tw@kallisto:~$ dd if=/dev/zero of=zeroes.bin bs=1 count=1264

After that, we just add these zeroes.bin to the bootloader file.

tw@kallisto:~$ cat zeroes.bin >> WIZ550web_Boot.bin

If you check now with ls, you can see that the size is now exactly 0x6000 = 24576 bytes.

Bildschirmfoto vom 2015-03-18 14:48:01

Now we can combine bootloader and application file in the same way. Later when you compile only the application, you can reuse the padded bootloader file, and only need this last step.

tw@kallisto:/tmp$ cp WIZ550web_Boot.bin combine.bin && cat WIZ550web_App.bin >> combine.bin

Bildschirmfoto vom 2015-03-18 14:55:16

tw@kallisto:~$ stm32flash –w combine.bin –v /dev/ttyS0

There is one important difference between the Windows version of Flashloader Demo and the stm32flash. In the current version of the stm32flash the complete flash is erased before programming. As long as you have only one binary for the application this is no issue. But in case you have a bootloader and an application the bootloader is erased when you flash the application.
As a workaround for this you have to combine the two files.

How to combine Bootloader and Application file.

As an example i’ll show how to combine the bootloader and application file of WIZ550web. As per note on http://wizwiki.net/wiki/doku.php?id=products:wiz550web:wiz550web_download the bootloader shall go to the adress 0x8000000 and the application shall go to 0x8006000. So as we will copy both files together the bootload needs some padding to be exactly 0x6000 = 24576 in size.

Bildschirmfoto vom 2015-03-18 14:30:56So first we find out the size of the bootloader. In this example it is 23312 bytes in size. So we just calculate 0x6000 – 23312 = 1264. To get the padding we just dump 1264 bytes from the device /dev/zero which contains an unlimited number of zeros into some file, e.g., zeroes.bin.

tw@kallisto:~$ dd if=/dev/zero of=zeroes.bin bs=1 count=1264

After that, we just add these zeroes.bin to the bootloader file.

tw@kallisto:~$ cat zeroes.bin >> WIZ550web_Boot.bin

If you check now with ls, you can see that the size is now exactly 0x6000 = 24576 bytes.

Bildschirmfoto vom 2015-03-18 14:48:01

Now we can combine bootloader and application file in the same way. Later when you compile only the application, you can reuse the padded bootloader file, and only need this last step.

tw@kallisto:~$ cp WIZ550web_Boot.bin combine.bin && cat WIZ550web_App.bin >> combine.bin

Bildschirmfoto vom 2015-03-18 14:55:16

by TW

Advertisements

Install Eclipse and Compiler for STM32 with W5500 on Linux

This installation was done on Debian Wheezy

Contents Installation and Configuration of

  • Build Essential
  • GNU GCC ARM Embedded tool chain
  • Oracle Java SE
  • Eclipse
  • GNU ARM Eclipse Plugins

Tool Chain – Install Build Essential

First you have to install the essential tool chain. Go to a root terminal,e.g., with “su” and do the following:

root@kallisto:~# apt-get update && apt-get install build-essential

Tool Chain – Install GCC ARM Embedded GNU

Go to https://launchpad.net/gcc-arm-embedded and download the latest “Linux installation tarball”. Then extract it. Most likely your filename will not be exactly gcc-arm-none-eabi-4_9-2014q4-20141203-linux.tar.bz2 but a little bit different – so adjust this command line to name of the downloaded one.
root@kallisto:/home/tw/Downloads# mkdir /usr/local/arm && tar xjvf gcc-arm-none-eabi-4_9-2014q4-20141203-linux.tar.bz2 -C /usr/local/arm

If you want to have it available for you users without the need for absolute pathes you can symbolic link it to the folder /usr/local/bin

root@kallisto:~# ln -s /usr/local/arm/gcc-arm-none-eabi-4_9-2014q4/bin/arm-none-eabi-* /usr/local/bin/

If you like, you can check this from the user account:

gccversion

JAVA SE Installation

There are no Oracle Java SDK repositories for Debian Wheezy, but you can add the ubuntu repository.

root@kallisto:~# echo "deb http://ppa.launchpad.net/webupd8team/java/ubuntu precise main" >> /etc/apt/sources.list && echo "deb-src http://ppa.launchpad.net/webupd8team/java/ubuntu precise main" >> /etc/apt/sources.list && apt-key adv --keyserver keyserver.ubuntu.com --recv-keys EEA14886

then install Oracle JAVA 8 after updating the repository:

root@kallisto:~# apt-get update && apt-get install oracle-java8-installer

If you like, you can check this from the user account:

Bildschirmfoto vom 2015-03-18 11:18:53

Eclipse Installation

First go to  http://eclipse.org/downloads/ and download the latest Version of “Eclipse IDE for C / C ++ Developers” – depending on the Java Version you installed you should go for 32bit or 64bit. As my Java is 64bit I’ll go for 64bit.

Bildschirmfoto vom 2015-03-18 11:29:22

Now extract eclipse:

root@kallisto:/home/tw/Downloads# tar xzvf eclipse-cpp-luna-SR2-linux-gtk-x86_64.tar.gz -C /usr/local/

Bildschirmfoto vom 2015-03-18 12:40:48

On my Debian Wheezy Eclipse Luna crashed during start (https://bugs.eclipse.org/bugs/show_bug.cgi?id=430736) . So in case your eclipse doesn’t start either you also have to execute “export SWT_GTK3=0” before the start of eclipse. You can make this persistent with:

tw@kallisto:~$ echo "export SWT_GTK3=0" >> ~/.profile

GNU ARM Eclipse Plugins

On the eclipse IDE, go to the Menu line and select  “Help” -> “Install New Software”. The following window will appear, where you have to click “Add”.

Bildschirmfoto vom 2015-03-18 12:56:37

There you have to enter the following data.
Name: GNU ARM Eclipse Plugins
Location: http://gnuarmeclipse.sourceforge.net/updates

On the next page, just select “GNU ARM C/C++ Cross Development Tools” and after some “Next” and “Finish” clicks the installation is finished.