Step by step working with STM32F407 and Coocox
Ok, you got your STM32F407 DIscovery board and you don’t know how to use it. In this tutorial I will explain how to use this board with CooCox IDE. I prefer install from their CoCenter. You will need to download ARM GCC from here. There is also youtube tutorial, make sure you did all correct.
Unlike the 8-bit microcontrollers, the STM32F4 is somewhat more difficult the operate. I’ll show here how you can get your STM32F4 up and running very quickly. The most difficult part is the setup of the MCU’s clock and debugging to a remote terminal (PC). Let’s start with the easy part.
Install CooCox, ARM GCC and ST-LINK.
1. Download ARM GCC, CoIDE and STM32 ST-LINK utility
2. Install ARM-GCC first, all default parameters are OK.
3. Install CoIDE
4. Install STM32 ST-LINK utility.
5. Configure CoIDE to use ARM GCC
Create a first project with blinking leds.
In our first project we’ll create a small program that is capable to blink the four leds on the discovery board and we’ll demonstrate semihosting. Semihosting is a mechanism that enables code running on an ARM target to communicate and use the I/O facilities on a host computer that is running a debugger. In other words send data back over the ST-LINK back to your computer.
Fig.1. LED interface
1. Prepared LED connection interface
2. Click Create Project and name it Blinker
3. Choose Chip (board could also do if your board is listed)
4. Choose ST and STM32F407VG; click Finish
In the Repository window’s Peripherals, click on GPIO (M4 CMSIS Core, CMSIS BOOT and RCC are auto-selected)
Again in the Repository window, click on Semihosting (C Library and Retarget printf are auto-selected)
So, you have finished installing CoIDE. Open it and click Project -> New project. Choose your project name and project path and click Next. In the next step choose Chip and Next.
Fig. 2. New Project
Fig.3. Select chip STM32F407VG
Fig.4. Select basic component
Fig. 5. Include standart library CMSIS
#include "stm32f4xx.h"
#include "stm32f4xx_rcc.h"
#include "stm32f4xx_gpio.h"
int main(void)
{ RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE); GPIO_InitTypeDef GPIO_InitDef;
GPIO_InitDef.GPIO_Pin = GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14; GPIO_InitDef.GPIO_OType = GPIO_OType_PP; GPIO_InitDef.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitDef.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_InitDef.GPIO_Speed = GPIO_Speed_100MHz; //Initialize pins GPIO_Init(GPIOB, &GPIO_InitDef);
volatile int i; while (1)
{ // Toggle leds GPIO_ToggleBits(GPIOB, GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14); // Waste some tome for (i = 0; i < 500000; i++); }}