You are viewing an older revision! See the latest version
Using mbed with gcc and eclipse
mbed officially supports two offline IDEs based on Eclipse and GCC:
Additionally, you can also use the latest ARM developed GCC toolchain:
A full list of the officially supported offline toolchains is here: Offline toolchains.
legacy 2011 instructions
These are the legacy instructions written by Pierre Emmibed in 2011, before the release of the official mbed offline toolchains.
wrote:
I'm writing these instructions for:
- Ubuntu 10.10
- Eclipse Helios SR1 with CDT
- Code Sourcery Sourcery G++ Lite 2010.09-51
If you use other versions YMMV
- Download the required files
- Eclipse
- Goto http://www.eclipse.org/downloads/
- download the package 'Eclipse IDE for C/C++ Developers'
- GCC
- Goto http://www.codesourcery.com/sgpp/lite/arm/portal/subscription3053
- Download the package 'Sourcery G++ Lite 2010.09-51'
- CMSIS (Cortex Microcontroller Software Interface Standard) contains headers specific to the LPC17xx series
- Goto http://www.onarm.com/download/download395.asp ( broken link )
- Download 'CMSIS_V1P30.ZIP'
- GNU ARM Eclipse Plugin
- Goto http://sourceforge.net/projects/gnuarmeclipse/
- Click 'Download Now'
- Don't Extract It!
- Eclipse
- Extract and retrieve the required files.
- Extract eclipse (I extracted it to '/mbedDevelopment')
- Extract GCC (I extracted it to '/mbedDevelopment' also)
- Extract CMSIS (I extracted it to '/mbedDevelopment' too)
- Your directory now probably looks like this:
<<code>>
`ls /mbedDevelopment` arm-2010.09 CMSIS_V1P30 eclipse <</code>
- Configure Eclipse and your first project
- So we have a nice place to put it all, and to do the initial setup and configuration we are going to create a "hello world" project in eclipse
- Start Eclipse (it may ask where you want to load the workspace, If it does and you want to follow my steps exactly, tell it to use '/mbedDevelopment/projects' as the workspace)
- Now we do a little preconfiguration
- Goto Help->Install New Software...
- Click Add...
- Click Archive...
- Browse to the GNU ARM downloaded zip file
- Give it a name in the upper box (I used "GNU ARM" but anything works, but I do recommend a descriptive name)
- Click OK
- In the center box you should now see 'CDT GNU Cross Development Tools' Check it and click Next >
- Click through the wizard.
- Ignore the security warning and continue anyways
- Choose Restart Now
- Choose Window->Preferences
- Goto C/C++ -> Build -> Environment click Select... Choose
PATH
click OK - Edit
PATH
and add'/home/dejagerd/mbedDevelopment/arm-2010.09/bin:'
to the BEGINNING of the line - Click OK
You now have a cross compiling eclipse setup!
- Now we create the project
- Goto File -> New... -> C++ Project
- Give it a name (I'm gonna call mine "HelloWorldProject")
- Under Project Type choose ARM Cross Target Application -> Empty Project
Under Toolchains choose ARM Linux GCC (Sourcery G++ Lite) - Click Finish
Woo! Getting there!
- Time to configure the project.
While this may seem like a lot of effort to go through, it is worth it; also once done, you can just copy HelloWorldProject to get a new project with the same settings.- Right click your project and select Properties...
- Goto C/C++ Build -> Discovery Options
- Click Manage Configurations...
- Delete Debug and click OK
- Change Discovery Profiles Scope to Configuration Wide
- Change Compiler invocation command to "arm-none-eabi-gcc"
- Switch to C/C++ Build -> Settings
- For each of the tools (click it's heading) change the command from "arm-elf-*" to "arm-none-eabi-*"
e.g. arm-elf-gcc to arm-none-eabi-gcc - For each compiler (C and C++) I like to change the optimization to none, and the language standard(under miscellaneous) to the newest version with GNU extensions (my rationale is that it causes the compiler to be the most forgiving)
- Goto the linker settings and then the general section. make sure to check Do not use standard start files (we will be supplying our own)
- Change the flash image tool to binary, and check both boxes on the sections page.
- Click OK
- Let's make the project!
Remember the CMSIS folder? You will need several files out of it. Also, I like to keep my source files somewhat organized, I like to put my source files in a folder called 'src' The files that will be common to all the projects I put in 'src/system'- copy:
/mbedDevelopment/CMSIS_V1P30/CM3/CoreSupport/core_cm3.c to HelloWorldProject/src/system
rename
/mbedDevelopment/CMSIS_V1P30/CM3/CoreSupport/core_cm3.h to HelloWorldProject/src/system
/mbedDevelopment/CMSIS_V1P30/CM3/DeviceSupport/NXP/LPC17xx/system_LPC17xx.c to HelloWorldProject/src/system
/mbedDevelopment/CMSIS_V1P30/CM3/DeviceSupport/NXP/LPC17xx/system_LPC17xx.h to HelloWorldProject/src/system
/mbedDevelopment/CMSIS_V1P30/CM3/DeviceSupport/NXP/LPC17xx/LPC17xx.h to HelloWorldProject/src/system
/mbedDevelopment/CMSIS_V1P30/CM3/Example/Sourcery G++Lite/LPC17xx/startup_LPC17xx.s to HelloWorldProject/src/system
/mbedDevelopment/CMSIS_V1P30/CM3/Example/Sourcery G++Lite/LPC17xx/LPC17xx.ld to HelloWorldProject/src/system
/mbedDevelopment/CMSIS_V1P30/CM3/Example/Sourcery G++Lite/LPC17xx/main_LPC17xx.c to HelloWorldProject/srcsystem/startup_LPC17xx.s
tosystem/startup_LPC17xx.S
(Capitol S) Quirky I know, but it's needed... - Go back into the project properties, and under C/C++ Build -> Settings and ARM Linux GCC C++ Linker -> General Browse for the Linker Script
LPC17xx.ld
- Go to the C/C++ General -> Paths and Symbols page
- Click Add.. check all three boxes then click Workspace... and choose
HelloWorldProject/src
Click OK twice. - Repeat for
HelloWorldProject/src/system
- Click OK
- copy:
- Edit
system/system_LPC17xx.c
and alter line 393 from ...32000UL... to ...32768UL... (the RTC crystal on the mbed is 32768hz) - Edit
system/LPC17xx.ld
remove line 21 (it compiles in libraries that we don't have) - Edit
system/startup_LPC_17xx.S
edit line 126 to read "LDR R0,=main
" - Edit main_LPC17xx.c change the value on line 51 to 0xffffffff
Change the values on lines 83 and 85 to 0xffffffff At the beginning of main(), add the line
SystemCoreClockUpdate(); - Save all the files
- Build the project!
- Click the hammer icon on the toolbar. If I wrote these instructions correctly, you should have a .hex file in
HelloWorldProject/Release
- Click the hammer icon on the toolbar. If I wrote these instructions correctly, you should have a .hex file in
- Upload to mbed.
You will need to rename the file to end with ".bin" to get the mbed to recognize it. It is in the proper format, however it just has the wrong extension. - If all is well, you should have all the LEDs flashing at 5 hz
- So we have a nice place to put it all, and to do the initial setup and configuration we are going to create a "hello world" project in eclipse
Please note that for whatever reason, at least my mbed will not take the new firmware until the power is cycled. YMMV
This info was the final bit that I needed to be able to put this guide together: http://dev.frozeneskimo.com/notes/compiling_your_own_cmsis_code_for_the_mbed
edit:
NOTE: you will need to call SystemCoreClockUpdate()
as the very first line in your main
function. This will update the various registers and constants to allow accurate timing.
If you include the following files in you compilation and include the call SerialInit(UART0,9600);
in your main function, you *should* be able to use uart_putchar(char,NULL)
to output individual characters to the USB UART, and use putst(const char * s);
to output a whole string.
/users/danielmiester/notebook/serialhpp/
/users/danielmiester/notebook/newlibminimalh/