Thank you Hertaville
I set up this tutorial using a lot of resources I found at Hertaville. Thanks, thanks, thanks!
1 – get the GCC compiler
Download toolchain from https://launchpad.net/gcc-arm-embedded/ and add directory with ‘arm-none-eabi-gcc’ and others to path
Linux: get the TAR with the binaries, and extract somewhere. I put them in Documents. Yes, I know that that is not a sensible location, you could do otherwise if you’d like to. I changed the path to point to the binaries.
gedit ~/.bashrc
For me: PATH="/home/victor/Documents/gcc-arm-none-eabi-4_7-2012q4/bin:/usr/local/bin:/usr/bin:/bin:/usr/games:/opt/msp430-gcc-4.4.3/bin"
Under Windows, just run the installer, everything will be fine. At the end of the installer, let the PATH be adapted (option box selected).
2 – get OpenOCD, part of the debugging solution
Go to the OpenOCD site and download the sources. For windows: there’s a binary installer available somewhere, check Hertavilles site.
Linux: unpack,
./configure
make
sudo make install
3 – install Code::Blocks if you hadn’t already
Download Code::Blocks from their website, installation instructions are here.
For linux (my distro refuses to update to 11.20) you’ll have to install the archives that BerliOS provides, windows users can easily install the binaries.
4 – Download the important source files
OK; we’re getting somewhere!
From the ST website download this, and unpack in your folder-of-choice. For me: /home/victor/Dropbox/ARM/ST
From Hertaville, take the ‘toggleiom0’, I unzipped it in /home/victor/Dropbox/ARM/workspace/iotogglem0/:
Configuring Code::Blocks for compilation
- Start Code::Blocks, create a new empty project in the iotogglem0 folder
- Select ’empty Project’
- Name: iotogglem0
- Remove extra ‘iotogglem0’ in ‘directory’ and ‘resulting filename’.
- Next
- Compiler: GNU ARM C, and leave everything else default, Finish
- You’ll get some warnings from Code::Blocks, we’re going to fix those in a minute
- Right-Click on the bold ‘iotogglem0’ in the left pane, and choose ‘Add files recursively’
- Go one folder up, and select the iotogglem0 folder
- OK,OK
- In the same way add the files from the ‘Libraries’ folders from the Standard Peripheral Libraries:
- Close,OK
- Do the same with the files in the …/ARM/ST/STM32F0xx_StdPeriph_Lib_V1.0.0/Libraries/CMSIS folder.
Change compiler settings
- Go to project-> build options
- Select ‘iotogglem0’ in the left pane
- Click the tab ‘other options’
- Add the following line:
-mcpu=cortex-m0 -gdwarf-2 -mthumb -fomit-frame-pointer -Wall -Wstrict-prototypes -fverbose-asm -Os
- At the tab ‘#defines’ add these lines:
STM32F0XX
USE_STDPERIPH_DRIVER - at the tab linker settings, add this in ‘other options’:
-mthumb -nostartfiles -Tstm32f0_linker.ld -Wl,-Map=iotogglem0.map,--cref,--no-warn-mismatch
- Search directories, compiler:
- Search directories, linker: add linker directory (~/Dropbox/ARM/workspace/iotogglem0/linker in my case)
- Pre/post build steps: add post-build steps:
arm-none-eabi-size $(TARGET_OUTPUT_FILE)
arm-none-eabi-objcopy $(TARGET_OUTPUT_FILE) -O ihex $(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).hex
- OK
Change compiler command
- Settings->Compiler
- Change drop-down to GNU ARM
- Toolchain executables tab
Enable debugging from Code::Blocks
- From the openocd source directory copy the file stm32f0discovery.cfg (in ./tcl/board/) to your output directory (~/Dropbox/ARM/workspace/iotogglem0/bin/Debug in my case)
- In Code::Blocks, change the settings for debugging by making an ARM-GDB setting:
- Settings->Debugger: turn on ‘full-debug-log’ to get more info of what is happening, if that’s what you like (I do).
- In the left pane, select GDB/CDB Debugger, and press the button ‘Create Config’. Type in the new config name, I chose ‘ARM OpenOCD’
- Click ‘ARM OpenOCD’ in the left pane, change settings as shown below
Changed items are: executable, ‘do not run’
- Close
- Click ‘Project->Properties’
- Go to the Debugger tab
- Choose ”, and apply presets as below:
- The following options are set to load the correct output file in the microcontroller:
- actual settings should be:
monitor halt
load ./bin/Debug/iotogglem0
file ./bin/Debug/iotogglem0
monitor sleep 1000
monitor reset
- OK
- Choose Debug->Active Debuggers->GDB/CDB Debugger: ARM OpenOCD
- Open a terminal and go to your output directory (for me: /home/victor/Dropbox/ARM/workspace/iotogglem0/bin/Debug) and type
openocd -f stm32f0discovery.cfg
- Start debugging by pressing the red arrow (Run / continue) in the debugging toolbar
I really love your blog. You write about very interesting things. Thanks for all your tips and information.
Dear Van De Dam,
thank you for this nice tutorial. Unfortunately I am a newbie with ARM compiling and Code::Blocks too.
I’ve tried to follow your instructions, but when I compile I receive the following message “../../ST/STM32F0xx_StdPeriph_Lib_V1.0.0/Libraries/CMSIS/Device/ST/STM32F0xx/Source/Templates/arm/startup_stm32f0xx.s|1|Error: junk at end of line, first unrecognized character is `*’| ”
There ara several of these errors! I don’t know how to avoid this!
Any help will be very appreciated 🙂
A side note: in your tutorial, you wrote nothing under “at the tab linker settings:”… is this normal?
hi,
I have the same problem. lots of errors: -Error: junk at end of line, first unrecognized character is `*’|
Can you please tell how to solve this.
Thanks.
I have a problem. Which are the linker libraries? It’s not stipulated. => “Search directories, linker: add linker directory”. Please clarify. Thanks.
Benzol
Hello Benzol,
Thanks for the comment. I’ve updated it, it’s the linker directory in the iotogglem0 folder (~/Dropbox/ARM/workspace/iotogglem0/linker in my case).
We encountered some problems related to divisions after using this tutorial to set up the toolchain and codeblocks.
The execution got stuck in the HardFault_Handler.
Solution:
https://answers.launchpad.net/gcc-arm-embedded/+question/233519
“You must also include -mcpu=cortex-m0 in your linker command line, to let it link libraris for cortex-m0.”
In our case, in Codeblocks
-mthumb -mcpu=cortex-m0 -nostartfiles -Tstm32f0_linker.ld -Wl,-Map=iotogglem0.map,–cref,–no-warn-mismatch
instead of:
-mthumb -nostartfiles -Tstm32f0_linker.ld -Wl,-Map=iotogglem0.map,–cref,–no-warn-mismatch
Hello,
I set up CB with ARM GNU tools per your tutorial and it works great. I just added “monitor halt” after “monitor reset” line in gdb commands list. Without it, CB debugger thought my target is halted after debugger started (offering continue button, as well as single step buttons – but no “break debugger” button), however it was actaully running. I had to click “continue” to get access to “break debugger” button.
Now, my target is properly stopped after loading.
Now, I’m curious, how can I display the values of hardware registers in watch window? Let’s say I want to observe state of GPIOA->IDR register. Is it possible?
well,I got something very very…different
i haven’t use codeblocks for a long time,so ,i can now built and flash the program in command line
but just couldn’t do it via cb
yeah,i must admire that i just get the example from github.
but I just didn’t know how to do something in the cb
basically,i follow your step to set and build a project in cb
but,it didn’t success
something different
1.i need a .bin file,not hex,and i don’t understand why it just build it to a hex
2.then i found that it seems that didnt use your command,so i use the pre built command.
but,it just tells me that ,,well,it’s hard for me to say,i think i should give you the build result
yeah,the last sentence is ,i work it under ubuntu 12.04,and my cb is 10.05
i didn’t found someway to get the newest 13.10
Running target pre-build steps
arm-none-eabi-size bin/Debug/CB
arm-none-eabi-size: ‘bin/Debug/CB’: No such file
Process terminated with status 1 (0 minutes, 0 seconds)
0 errors, 0 warnings
i,er,i just so upset as i try all the day,and the,,as that before i use almost half a year to get success to do this things under linux….
and i search the internet many times,but just….if you can help,please.
Hi,
I have STlinkV2 which uses a configuration script file.
I am using now the crappy impossible eclipse, and in
debugger settings I am setting local configuration for
openocd. Where do I configure this in CB.
Thank you
I’ve been working with TI’s MSP430, Stellaris & Tiva for two years now and ever since with OpenOCD + GDB but over Terminal. At some point of time I found the C::B the most useful and lightweight dev IDE but haven’t set up the debugging due to bad examples. Thanks to you I can now stay in the C::B for the debugging too. Big THANK YOU, that’s the easiest how-to I saw.