Saturday, September 10, 2016

Setting up my ARM Cortex STM32 Development environment on Linux (Ubuntu) 16.04

Setting up my ARM Cortex STM32 Development environment on Linux (Ubuntu)

I was looking for a ARM Cortex development environment that will run on Linux and found the GNU ARM Eclipse plugin for Eclipse.  ref:
As I was familiar with the Eclipse environment and as I was using Eclipse for my Java development it seems to be the best fit for my requirements. 
I had to do the following to install Eclipse.
dont install the default eclipse avalibe from Ubuntu repository as its to ould for this development you need at least vertion 4.5
download eclipse from here
unzip eclipse-cpp-neon-R-linux-gtk-x86_64.tar.gz
Then run eclipse
sudo eclipse
Eclipse Environment
Then updated Eclipse to the latest release.
Select the help menu in Eclipse  help > 'Check for updates' and update.

Select all for update and accept the license.
Get some Coffee as this might take some time to install ;-)
You might have to restart Eclipse when its done.

When complete then select the menu  help > 'Install new software'

Click on add and add the following details.

Then select GNU ARM C/C++ Cross development Tools and click on Next.
Select all 

Select install to complete the plugin install.

Except the warning message and you might have to reboot Eclipse.
We now need to install the toolchain for the ARM processor.
do the following in command line.
sudo add-apt-repository ppa:team-gcc-arm-embedded/ppa
sudo apt-get update
sudo apt-get install gcc-arm-embedded

Now do the following in Eclipse
Then select Menu file > new project > 

Then select your Processor details and click next.

I wanted to do development using the STM32F401C-DISCO development board.
So now I need to add the part where I can deploy the Compiled code to the dev board.
Download the stmlink from here
Then unzip the file unzip
There should now be a directory stlink-master
cd to the directory cd stlink-master
mkdir build && cd build
cmake -DCMAKE_BUILD_TYPE=Debug ..

sudo make install
Then find out where is the comand st-flash
type st-flash 
reply is
st-flash is /usr/local/bin/st-flash
Then start Eclipse again and select the following menu
Run >External tools > External tools configuration

Here is what you need to configure so that Eclipse can see your STM32F401C-DISCO

When you are done with this and you test it will fail because the compiler creates a hex file and you need to change it to create a bin file for your Dev board.

Got to the menu Eclipse Menu project > propertie > settings >

Then start creating you first application.

Compile and then run the external tool configuration that was done above and your application should now run on the Dev board.
STM32F401C-DISCO dev board
Ok we can at least deploy our code to the Dev Board/
We now have to configure the debug capability so we can get feedback from board.
Install the following drivers.
sudo apt-get install libusb-dev libusb-1.0.0-dev libftdi-dev libftdi1
Download the following Eclipse debugger  nuarmeclipse-openocd-debian from this link.
There is a 32 and 64 bit vervion download the one for your operating system

Then unzip the file tar -xvf  gnuarmeclipse-openocd-debian64-0.10.0-201601101000-dev.tgz
cd into the new created directory cd openosd
Then cd into the directory cd 0.10.0-201601101000-dev
Then cd to the bin directory  cd bin
Connect your dev board and the deploy an application with debugging.
Then test the openosd by running this command
sudo ./openocd -f board/stm32f4discovery.cfg
You should see a reply something like this.
GNU ARM Eclipse 64-bits Open On-Chip Debugger 0.10.0-dev-00287-g85cec24-dirty (2016-01-10-10:31)
Licensed under GNU GPL v2
For bug reports, read
Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
adapter speed: 2000 kHz
adapter_nsrst_delay: 100
none separate
srst_only separate srst_nogate srst_open_drain connect_deassert_srst
Info : Unable to match requested speed 2000 kHz, using 1800 kHz
Info : Unable to match requested speed 2000 kHz, using 1800 kHz
Info : clock speed 1800 kHz
Info : STLINK v2 JTAG v17 API v2 SWIM v0 VID 0x0483 PID 0x3748
Info : using stlink api v2
Info : Target voltage: 2.904142

Info : stm32f4x.cpu: hardware has 6 breakpoints, 4 watchpoints

The data coms led on the Dev board should now blink red green.
Stop the command by pressing CTRL -c

We now need to configure Eclipse to use the openosd.
 Start Eclips and go to the following menu.
Run>External tools>'External tools configuration'
OpenOCD configuration
Then run the command menu run > External tools > openocd
you should see something like this in the terminal if everything went ok.

Now select run menu > debug configuration >GDB Hareware Debugging
Browse for your project and select in the project pull down menu.
Select search project under the the Main tab and find your project.

Now select the debug tab
On terminal enter the following command  type arm-none-eabi-gdb  witch will return the path to the GDB
rm-none-eabi-gdb is /usr/bin/arm-none-eabi-gdb
Enter the path in the GDB command text box  /usr/bin/arm-none-eabi-gdb
and then select the Jtag device > and select GNU ARM Openocd.
Enter localhost for host name and port must be 3333

Then select debug to save.
There will then be a pop box asking you if you want to change to the Debug perspective, select yes and everything should then start debugging.

STM32 Emiliuater

There is a QEMU emulator that can simulate your hardware procesor and can be installed into eclipse.
Here is the Steps.
Download the GNU ARM Eclipse QEMU from the link below. (select the 32 or 64 bit version  .tgz)

unzip the file
tar -xvf gnuarmeclipse-qemu-debian64-2.6.0-201607280535.tgz
cd to the directory that was created cd qemu
cd to your vervion directory inside the qemu  cd 2.6.0-201607280535/bin
run the command below in this bin directory.

sudo ./qemu-system-gnuarmeclipse --version

You should get a result like below

GNU ARM Eclipse 64-bits QEMU emulator version 2.6.0

Copyright (c) 2003-2008 Fabrice Bellard

Now configure Eclipse to use the QEMU

Start Eclipse and go to the following menu.
(Window -->) Preferences --> Run/Debug --> Launching --> QEMU
Set the name and binary path to the installed QEMU path done above.
My path was 

QEMU Binary path configuration
We now need to install the QEMU Debugging plug-ins

Still need to add the External tools configure details.

Hope this has helped you getting your environment going :-)

I also found this video that basically explains what I didref :

No comments:

Post a Comment