We’ll continue with our little project. In my last post I mentioned that it was posible to use CooCox with the STM32F0-Discovery board, so we can code our applications without paying a single penny for the compiler, and bring to our future projects all the GCC’s compiler power. And more over, we also can use the FreeRTOS operating system. Now it’s time to get our hands dirty.
Don’t plug the board until to do so. If it’s already plugged, then unplug it.
Instructables (for Windows only, without FreeRTOS)
1.- Download these packages, but not try to install them until to do so.
Save these packages in a common folder, so you can easily access them.
CooCox IDE (through CoCenter, so look at the end of the webpage.)
ST-Link driver (Click on “Design support” tab and look at the end of the webpage for the “SW drivers”.)
STM32F0 board support package (V2). This BSP was a bit tricky and obscure to get it. I got it from a russian guy (aka Ant-On), but I’ve made it public for the masses.
a) Install the GNU-GCC compiler
I changed the default location to something more compact:
b) Install the CoCenter installer (it’s usefull for installing more stuff later on).
c) Run the CoCenter app and choose to download and install “CooCox CoIDE”. Don’t install anything else from here.
Note: While installing the CoCox IDE you might experience some strange behavior. Don’t panic. If an error screen pops-up, don’t do anything, wait until the installation completes, then you can close it.
d) Install the ST-Link driver.
e) Open the CooCox IDE and instruct it to use the GNUARM compiler.
Go to menu Project->Select toolchain path->Browse, and look for the compiler’s bin folder location. For example, I choose c:\GNUARM for its location, so this is what I got:
Then click on Ok button.
Perhaps the window won’t close, so close it using the upper-right cross (X). The path is saved, so don’t worry.
f) Before going further it’s good idea to test the compiler.
In the IDE’s main page there is a list with some major MCU vendors. Choose ST, and the screen will change to show some members of the STM32 family. You won’t find anything about STM32F0, but don’t worry, we’re just testing the stuff. So choose, e.g. STM32F103C4 chip.
The screen will change again (step 3 at its top you can read). We’re just testing, so check these boxes:
CMSIS core, RCC, PWR
After choosing the first one you’ll be asked for creating a new project. Write “test” in “Project name”, let the default location, and click on “Finish”.
Open the main.c file (bottom-left, in Project tab). There is nothing fancy in there, just press F7 key. If everything was ok, then you would be able to compile such a test project. This is what I got:
... some more messages ... Program Size: text data bss dec hex filename 1004 0 1024 2028 7ec test.elf BUILD SUCCESSFUL Total time: 11 seconds
We’re ready to go on.
g) Install the STM32F0 BSP package
For some obscure reasons the BSP is not included in this CooCox IDE release, so we need to install it by hand. Uncompress the CoIDE_STM32F0.7z file in the folder where CooCox IDE lives. In my machine I uncompress it in this folder:
Say “Yes to all” to your uncompress software if it asks for.
h) Create a project for the STM32F051 MCU
We already have a project opened, remember? We don’t need it anymore.
(Step 1) Choose ST
(Step 2) Choose the STM32f051R8
(Step 3) Choose these boxes: M0 CMSIS core, CMSIS_boot, GPIO, RCC, DBGMCU, SYSCFG.
Again, you’ll be asked for creating a new project, so choose whatever project’s name you want, and click Ok.
You might want to go to the “Drivers” tab and choose some drivers, however I will not for this tutorial.
You can always go back for including things you forget or you want to add as your projects grows-up.
Download this main.c file and copy and paste its contents or replace the main’s project file, whatever is easier to you.
Press F7 and pray for the project to compile. If so, you’re one step away from success. Before going to the last step, take a break and return in few minutes.
i) Download and debug onto the STM32f0-Discovery board
Are you ready? Take your board and plug it into a PC’s USB free port. Are you nervous? I was the first time!!
A “New hardware found” window will show up warning you about new hardware, so say Yes, and then let the drivers will be installed. Seconds later, if a bubble shows up saying “Your new hardware is up and ready…” (or something else, I have the spanish version) you have succeeded, Cheers!!
Back into the IDE go to Debug->Debug configuration, and in the Debugger tab look for “Hardware” combo box and choose “St-Link”. Finally click on “Apply” and “Close”.
It’s time for debugging: Look for the small bug icon, or press Ctrl-F5, or go to Debug->Debug, and the debugging session will start. The code is uploaded into the MCU’s FLASH and the cursor is set at the first sentence in your main.c file. From here you can debug step by step, set breakpoints, or just let the program to run (F5), until you pause it.
Press F5 and both leds on board will start blinking.
Congratulations!! You made it.
Next post I’ll show you how to include and use FreeRTOS into your projects. Meanwhile let me know your success stories, or doubts or comments, or feelings, whatever you want to share.