I like the way artificial intelligence works, but I like the way it works. I like the way it works, and I like the way it works. I like the way it works, and I like the way it works
To review first, before the two development under Linux stm32 (a) | using GCC – arm – none – eabi tool chain compilation and development under Linux stm32 (2) | use openocd downloading and debugging, We showed you how to create an empty bare metal project (just startup files and main files), compile the project to generate elf files, convert them to bin or HEX format, download them using OpenOCd, and finally write a prototype Makefile. And successfully lit up an LED~ but this LED we are through the pointer direct operation register address to complete, next, we on this basis, the introduction of STM32 header file, which contains the macro definition of the register, that is, the use of registers for development ~
1. Create a register project
Start with the bare metal project created in the previous section00-template-reg
Make a copy and rename it01-led-reg
:
Leave it emptystm32f10x.h
The file is deleted, copied from the firmware library, and then used in the header filecore_cm3.h
andsystem_stm32f10x.h
Some of the definitions in “, contain these two header files, so copy these two files as well:
Next, write the main.c file:
#include "stm32f10x.h"
int main(a)
{
/* Start GPIOB clock */
//*(unsigned int*)(0x40021000+0x18) |= 1<<3;
RCC->APB2ENR |= 1<<3;
/* Configure PB0 as push-pull output */
//*(unsigned int*)(0x40010c00+0x00) |= 1<<(4*0);
GPIOB->CRL |= 1< < (4*0);
/* PB0 output low level, light green LED */
//*(unsigned int*)(0x40010c00+0x0c) &= ~(1<<0);
GPIOB->ODR &= ~(1<<0);
while(1);
}
void SystemInit(void)
{}Copy the code
At this point, the register project is created, then start compiling ~
2. Compile & download register projects
The focus of the compiler register project is on the C header and C source files, and the startup files are compiled and linked as before. Header files don’t compile, but be careful
- If the header file and the source file are not in the same folder when compiling the source file containing the header file, this parameter is required
-I
The (uppercase I) argument declares the header file path; - Header files often do some selective compilation by determining whether the user has a macro definition that can be used
-D
Parameter macro definition;
Next modify the makefile to compile the project we created:
- Using the command
make
Compile to generate elf files; - Using the command
make bin
Convert elf files into bin files. - Using the command
make hex
Convert elf files to HEX files; - Using the command
make clean
All files generated by compilation can be erased.
A: under Linux development stm32 (2) | use openocd download and debug the next: