Tuesday, October 28, 2014

Saga of Off-Line compiling with the STM32 NUCLEO-F401RE

Of the 3 boards, I decided to attempt the NUCLEO-F401RE first. For a program I chose to try to implement a smart autopilot control head using the 10DOF inertial sensor.

Of course nothing is ever simple. First I used the online compiler at mbed.org It would be fine if not for paying for internet access by the byte! Not to mention that it goes off completely for a while several times a week. Usually when I am in the middle of something.

So I began searching for ways to develop, compile and download the code locally on my own machine. There are several web pages describing various commercial and open source IDEs (Integrated Development Environments) all of which are either too limited, don't support the ST micros or only run on Windows! We all know I don't do Windows!

First I tried using the STM32CubeF4 and STM32F4-Discovery_FW_V1.1.0 from st.com according to http://regalis.com.pl/en/arm-cortex-stm32-gnulinux

I didn't have much luck with anything but the blinky Helloworld program. So on with more. I found https://github.com/mbedmicro/mbed a version of the mbed libraries to use locally. After several days I decided I missed something in the fine print.

So I tried gcc4mbed both stand alone and inside of eclipse, which I also downloaded. No luck for several weeks. I went back to th eonline and suffered  some more.

Decided to try off-line one more time when I ran across this instruction page  It worked! Well, almost. The compiler and linker can't find all the mbed libraries in Debug mode. But they can in Checked mode, which still includes the debug code! Great, I am now standalone!!!

So I have 4 different installed copies of gcc for ARM, 5 libraries of code for the STM32-arm micros,  2 manual/Makefile setups with no working makefile except delivered demos and 2 IDEs.

Also I have several utility programs that I'm not sure about, openocd to download and manage a debug session over USB to the micro, stlink to reinstall firmware in the STM32 micros and mri to actively debug the micro over the USB and single step the code. Also have a couple terminal emulators for monitoring output from the print statements in the micro. And 4 workspaces with various non-working pieces of code... I should clean them up.

  1. follow instructions at http://developer.mbed.org/cookbook/eclipse-for-building-and-debugging
  2. Next: https://github.com/adamgreen/gcc4mbed/blob/master/notes/porting.creole#readme
  3. then from mbed.org convert the mbed include to a library
  4. export the project for Nucleo target and GCC (ARM embedded) as the IDE
  5.  I had to make a ../build/NUCLEO_F401RE-device.mk
    and samples/NucIMU_test/makefile is more than just the name change
    the first make compiled all of mbed for NUCLEO.   I copied parts out of the exported Makefile to find the answers for both the device.mk and the project makefile.

Here is the device makefile

# Vendor/device for which the library should be built.
MBED_CLEAN         := $(MBED_DEVICE)-MBED-clean

# Some libraries (mbed and rtos) have device specific source folders.
RTX_TARGET_SRC   := $(GCC4MBED_DIR)/external/mbed/libraries/rtos/rtx/TARGET_M4/TOOLCHAIN_GCC
ETH_TARGET_SRC   := $(GCC4MBED_DIR)/external/mbed/libraries/net/eth/lwip-eth/arch/TARGET_STM

# Compiler flags which are specifc to this device.

C_FLAGS   := -mcpu=cortex-m4 -mthumb -mthumb-interwork
ASM_FLAGS := -mcpu=cortex-m4 -mthumb
LD_FLAGS  := -mcpu=cortex-m4 -mthumb

# Linker script to be used.  Indicates what code should be placed where in memory.

include $(GCC4MBED_DIR)/build/device-common.mk

*** UPDATE * Jan 25, 2015 **** The above makefile has problems with the single precision floating point hardware. Correct the *_FLAGS to this:

C_FLAGS   := -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=softfp -mthumb-interwork
ASM_FLAGS := -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=softfp
LD_FLAGS  := -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=softfp
And the project

PROJECT         := NucIMU_test
DEVICES         := NUCLEO_F401RE
GCC4MBED_DIR    := ../..


OBJECTS = ./main.o ./ADXL345/ADXL345.o ./HMC5883L/HMC5883L.o ./TextLCD/TextLCD.o ./ITG3200/ITG3200.o 
include $(GCC4MBED_DIR)/build/gcc4mbed.mk

Now if only the code got the right answer!