cancel
Showing results for 
Search instead for 
Did you mean: 

IAR Project -> ARM GCC Project

lohit shivanna
Associate II
Posted on November 17, 2017 at 05:00

Hello Dave,

This is the request not related to the topic above. I wanted to build the source code for steval-esc001 using AC6 GCC compiler can i build it or should be built only using IAR. please share if you have any idea about it or help me out regarding the issue. because i am using steval-spin32 building using AC6. I dont have license for IAR. more relaying on opensource GCC.

lohit

3 REPLIES 3
Posted on November 17, 2017 at 13:50

The trick here is to understand the tools you have chosen.

You might have to experiment yourself pulling the files and structure of the IAR project across, get the defines set up correctly, and any other metadata from your project, and then the GNU/GCC specific startup.s file, examples of which should be in the CMSIS Device directories.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Dave McCoy
Associate II
Posted on November 17, 2017 at 14:49

Iohit,

Hello, I decided to branch this topic to make it easier to find.

I was successful in porting an IAR based project to a GCC based project that can be built from the command line but I don't think I did it the best way possible. Perhaps someone more experienced in this process can help people like us out to accomplish this better. I also did this on an Ubuntu box, so I don't know how this can be applied to a windows box.

High Level Steps:

  • Create a project from STM32CubeMX with a Makefile output that matched the IAR based project as closely as possible. Take the Makefile, Linker script and startup asm file from the generated project and move them to your project.
  • Modify the Makefile
    • Replace all the c files within C_SOURCES variable.
    • Replace all the c file directories within the SOURCES_DIR
    • Replace all the include directories within the C_INCLUDES
    • Depending on your environment maybe remove reference to 'BINPATH'
  • Programming and Debugging
    • Debugging is more challenging without IAR. You will need an STLINK and a software tool like st-utils or openocd

Create a project from STM32CubeMX:

Generate a new project with the STM32CubeMX tool with the same board, or, if that board is not available with the same processor. Within the project settings specify a 'Makefile' build. From the output of the STM32CubeMX take the linker script (.ld file), the Makefile and the asm startup file (.s file) and put them into the base of your IAR project directory.

Note to ST: The example IAR projects are great to get started but would you please include a STM32CubeMX configuration file that will help me configure the MCU in the same way that it was configured for the project.

Modify the Makefile

Adding the files to your 'C_SOURCES' variable

Your project probably has a bunch of c files that you will need to add to your Makefile.Here is a command that will generate a file called 'temp.txt' that will have a list of all the source files within your project folders.

$ cd <base project directory>
$ find -name '*.c' > temp.txt�?�?�?�?�?

Within this temp.txt file are the list of all the files. you will probably need to copy that list into the Makefile, specifically where the 'C_SOURCES'. You may not need all of them and it will probably make your build extra long if you do add them all but on my first try I just added them all. There is probably some trick with the output map file that can be used to figure out which files are not needed but I didn't spend the time figuring this out.

Modify SOURCES_DIR variable

You will need to modify this variable to point to all the directories where the source files reside. A simple way to do this is similar to the above 'find' script:

$ cd <base project directory>
$ find -name'*.c' -printf '%h
'�?�?�?�?�?�?

This will have a lot of copies of the same directories but you only need one of each different directory under the 'SOURCES_DIR' variable.

Modify C_INCLUDES

Similar to the 'SOURCES_DIR' procedure do the same for this but with:

$ cd <base project directory>
$ find -name'*.h' -printf '%h
'�?�?�?�?�?�?�?�?�?�?

Modify BINPATH variable

I built the project with the 'arm-none-eabi-gcc' you can get from ubuntu apt tool. I installed the toolchain with the following command:

sudo apt install gcc-arm-none-eabi gdb-arm-none-eabi�?

This gave me an error when running 'make', specifically the 'cross-tool' section of the Makefile expects the user to specify the path to the arm toolchain. You can do that but since the toolchain is already in your default path you can just modify the Makefile to remove the bin path, specifically change this section from this:

#######################################
# binaries
#######################################
BINPATH = 
PREFIX = arm-none-eabi-
CC = $(BINPATH)/$(PREFIX)gcc
AS = $(BINPATH)/$(PREFIX)gcc -x assembler-with-cpp
CP = $(BINPATH)/$(PREFIX)objcopy
AR = $(BINPATH)/$(PREFIX)ar
SZ = $(BINPATH)/$(PREFIX)size
HEX = $(CP) -O ihex
BIN = $(CP) -O binary -S�?�?�?�?�?�?�?�?�?�?�?�?

to this:

#######################################
# binaries
#######################################
BINPATH =
PREFIX = arm-none-eabi-
CC = $(PREFIX)gcc
AS = $(PREFIX)gcc -x assembler-with-cpp
CP = $(PREFIX)objcopy
AR = $(PREFIX)ar
SZ = $(PREFIX)size
HEX = $(CP) -O ihex
BIN = $(CP) -O binary -S�?�?�?�?�?�?�?�?�?�?�?�?

Programming and Debugging:

I like this tool for uploading code from the command line:

https://github.com/texane/stlink

You can also get openocd from 'apt'

sudo apt install openocd�?

here is the command I used to upload the generated main.bin file

st-flash write build/main.bin 0x8000000�?

You can also use 'openocd' to do the same:

openocd -f interface/stlink-v2.cfg -f target/stm32fx.cfg -c 'program buid/main.elf verify reset'�?

When debugging you will need to start a server you can use both of the above tools but I prefer openocd:

openocd -f interface/stlink-v2.cfg -f target/stm32f3x.cfg�?

You will need to change the name of your MCU config file though.

Then you can interface using GDB in a separate terminal

arm-none-eabi-gdb build/main.elf�?

When it starts up you will need to attach to the GDB server you started above. There are a lot of tools that wrap around GDB like 'DDD' or whatever but for me I ended up using GDB command line and looking between my source code and GDB itself.

target remove localhost:3333
load
monitor reset
monitor halt
c�?�?�?�?�?ontinue�?�?�?�?�?

I must emphasize that you should run the commands 'monitor reset' and 'monitor halt' these commands actually reset the MCU (I think). If you don't use them you may not get a clean reset. I ran into an issue where the I2C bus was not behaving correctly and it wasn't until I started using those commands when things started to work correctly.

Final note:

AGAIN I am not an expert, I'm just trying to get a project working but maybe this can start a discussion on how to get things can be done correctly. I'm sure there will be people that are looking at this and 'face palming' at my silly approach and perhaps someone is going to just provide a simple link on how to do all this stuff but I didn't find the resources I needed from ST or the internet to do what I wanted so this is the result.

Dave

Posted on November 19, 2017 at 14:25

Hello Dave,

Thank you for the reply. Will try to implement it on GCC using the above guidance even i am using ubuntu box. Will update if i have achieve building it using GCC compiler. Once again thanks for the reply.

Lohit.S