Reply
Posts: 7
Registered: ‎02-10-2016

Blink example with toolchain under linux

Hello everyone,

 

Im trying to get the following toolchain working under linux: (Vim) ; arm-none-eabi-gcc ; SDK from github ; make ; gdb ; segger jlink. I'm using a STK3200 (Arm Cortex M0+) for testing, connected via USB.

 

I'm trying to setup a project template, which I can use later as a starting point for other projects. For that purpose I use the blink.c example of the SDK to get started.

 

Right now I got it compiled (by hand), after copying a bunch of files from the SDK to the directory of blink.c. After that, linking failed with unknown references and that is where I got stuck.

 

The next steps I want to archive is to separate the header and source files in different folders (copied from the SDK) and got it compiled using a Makefile. But here I need some inspiration:

 

Can someone help me out with a minimal Makefile for this?

 

I'm also very interested in peoples workflow using this kind of toolchain.

 

I would appreciate any help!

 

   FM41

 

Posts: 579
Registered: ‎09-18-2015

Re: Blink example with toolchain under linux

Hi @fm41,

 

Any reason why you cannot use Simplicity Studio? It does run under Linux.

 

You may not like the answer, but the best guide for what you want to do IS to install Simplicity Studio and look at how it does things

 

Check the project settings for the blinky project under C/C++ Build → Settings → Tool Settings and look at each section. You can see how Studio constructs the command lines for gcc and the linker. I'd also suggest building the project and looking at the out in the binary artifacts directory to see what's generated along the way.

 

John

Posts: 7
Registered: ‎02-10-2016

Re: Blink example with toolchain under linux

Hi @JohnB,

 

it's just a matter of taste. I like small and separated tools, which is another approach than using an IDE. So you are in charge of handling the whole workflow.

 

But looking at the Simplicity settings is a great idea. I will give it a try and see if its getting me further.

 

FM41

Posts: 579
Registered: ‎09-18-2015

Re: Blink example with toolchain under linux

Hi @fm41,

 

it's just a matter of taste. I like small and separated tools, which is another approach than using an IDE. So you are in charge of handling the whole workflow.

 

Yeah, I understand that having been a Linux hacker of sorts in a previous life. You might want to search our forums here for some topics related to using a traditional make/GCC build flow as I think some other folks have done it here.

 

I will admit to being spoiled by Studio doing things like constructing the GCC command lines and generating linker scripts. It would be a bit of a pain to do that by hand as I was used to in Linux Land Smiley Happy

 

John

Posts: 7
Registered: ‎02-10-2016

Re: Blink example with toolchain under linux

I switched from make to scons, which I find easier to handle. The following SConstruct file should do the trick. Finally I was able to download the resulting blink.bin to the mcu (using JLinkExe) and it let it run.

 

So far I do not used it for a "real" project, but it should be a good starting point.

 

However, any feedback is welcome:

 

 

#
# SConstruct file for EFM32ZG Blink example on STK3200
# 10.08.2017, FM41
#
# inspired by:
#
#    +  https://elektronotes.wordpress.com/2015/02/05/
#       using-scons-with-gnu-toolchain-for-arm-on-windows-part-3-the-scons-script/
#
#    +  Makefile of the blink example
#
#    +  http://scons.org/doc/production/HTML/scons-user.html
#
#    +  Project parameters of Simplicity studio, thanks to JohnB
#
#
# Direcotry structure:
#
#     blink: SConstruct (this file) ; run scons to build and scons -c to clean
#      |     
#      +--build : binary to download on mcu
#      |
#      +--src : blink.c 
#          |
#          +--lib : em_gpio.h, em_gpio.c, startup_efm32zg.S ...
#	   |
#          +--bsp : bsp_stk_leds.c ...           

# Projectname
bin = 'blink'

# Files to compile
cfiles 	= Split("""src/blink.c
		   src/lib/em_assert.c
		   src/lib/em_cmu.c
		   src/lib/em_emu.c
		   src/lib/em_gpio.c
		   src/lib/startup_efm32zg.S
		   src/lib/system_efm32zg.c
		   src/bsp/bsp_stk_leds.c 
 		""")

# Include the following directories
includes = Split("""src/bsp 
                    src/lib
		 """)

# Paths to tools
env = Environment()
env['CC']	= '/opt/gcc-arm-none-eabi/bin/arm-none-eabi-gcc'
env['LINK']	= '/opt/gcc-arm-none-eabi/bin/arm-none-eabi-gcc'
env['AS']	= '/opt/gcc-arm-none-eabi/bin/arm-none-eabi-gcc'
env['OBJCOPY']	= '/opt/gcc-arm-none-eabi/bin/arm-none-eabi-objcopy'

# Flags for compiler, linker, assembler
ccflags  = Split('-g -c -mcpu=cortex-m0plus -mthumb -DEFM32ZG222F32 -Wall')
ldflags  = Split('--specs=nano.specs --specs=nosys.specs -mthumb -T "src/lib/efm32zg.ld" -g -mcpu=cortex-m0plus -Xlinker')
asflags  = Split('-g -c -mthumb -mcpu=cortex-m0plus -x assembler-with-cpp -DEFM32ZG222F32')


# NOTHING TO CHANGE BELOW THIS LINE
# Set the flags env['CPPPATH'] = includes env['CCFLAGS'] = ccflags env['LINKFLAGS'] = ldflags env['ASFLAGS'] = asflags env['PROGRAMSUFFIX'] = '.axf' # Using the build directory as output bin_build = 'build/' + bin VariantDir('build', 'src', duplicate=0) # Compile and link prg = env.Program(bin_build, cfiles) # Builder to create binary for mcu, copied from elektronotes def arm_generator(source, target, env, for_signature): return '$OBJCOPY -O binary %s %s'%(source[0], target[0]) env.Append(BUILDERS = { 'Objcopy': Builder( generator=arm_generator, suffix='.bin', src_suffix='.axf' ) }) # Create binary for mcu env.Objcopy(prg)

 

FM41

 

Posts: 8
Registered: ‎07-24-2017

Re: Blink example with toolchain under linux

Hi there, I was/am exactly in your boat, wanting a make-based system.  I have had some success in this regard, with a STK3700.  I have also used SS4 on Linux.  Drop me a line.