We decide to use the STM32F4-Discovery for this tutorial.
For create a new project we decide to use CUBE and the predefined SetUp that STM has already done for the STM32F4-Discovery.
By the CUBE is possible configure all the clock source and the internal MCU clock in graphics mode.
Follow the steps shown below.
For a future application we decide to select the USB device and the VirtualCom, see below.
For see if, our clock configuration is correct, we decide to enable the RCC_MCO_2, see the PC9 below.
Now select the: Clock Configuration page
and check that your configuration, is the same as shown below.
NOTE:
We selected the MCO2 with SYSCLK input and the output is divided by 4.
In this way we reach 42MHz on the MCO2 pin (PC9).
We choose 42Mhz because our oscilloscope has 100MHz bandwidth. In this way we have a good resolution on our oscilloscope.
Now is a time to choose what C compiler you want to use and the working directory.
For do this follow the steps below.
Select: Project and Settings... (see below).
Now, from the page that appear, select a Project Location, a Project Name, and the compiler that you want to use (Toolchain/IDE).
Next, select: Code Generator
and do the same configuration that you see below.
Now, select: Project and Generate Report
After this, you will have a pdf file that contain all the configuration of your project, MCU name, Pins allocation, etc.
Now it is time to generate the code, select: Project and Generate Code
After this, you will have a complete project ready to use.
After the actions explained before, you have in your working directory something like below.
P1.ioc is the CUBE configuration
P1_Configuration.pdf contain all the configuration of your project, MCU name, Pin allocation, etc.
MDK-ARM contain the KEIL files configuration (this because we decide to use KEIL).
For compile the program, enter in the directory: MDK-ARM
and double click on: P1.uvprojx
ATTENTION:
Before to compile is necessary do some configurations that are shown below, follow the steps from 1 to 10.
Now compile your program and you must see:
0 Error(s), 0 Warning(s)
See below.
It is time to download your program on STM32F4-Discovery, see below.
Now if you connect an oscilloscope to PC9 (MCO2) you must see 42MHz, this means that your SYSCLK is configure to 168Mhz, see below the MCO2 configuration .
Now it is time to flash a LED, for do this follow the steps below.Open the main.c and insert the lines of code shown below.Compile and download again, your program on STM32F4-Discovery. At this point you must see Blue LED blinking.
The docs regarding F4 HAL librry functions is here:UM1725 User Manual Description of STM32F4xx HAL driversIn the above manual you can find:HAL_GPIO_TogglePin
HAL_Delay