*This content has been reposted with the approval of the original author.
PrefaceLast time I shared “The APM32F1 development environment configuration based on VScode”, and then I made persistent efforts to the development of APM32F4, the development process is documented here.
1 Environment setup and VSCode environment configurationThe environment setup in this section can be found in chapters 2 and 4 of "APM32F1 development environment configuration based on VScode", but it should be noted here that OpenOCD compiled by xpack does not support APM32F4, here I also prepared an OpenOCD package that supports APM32F4 (openocd-v0.12.0-rc2 - 2022-11-22-1713.zip (9.96 MB)), based on the latest OpenOCD source code (this is its official website Open On-Chip Debugger, https://openocd.org/ ) to add APM32 series MCUs (If you are interested in the following, we will post a separate discussion).
Here you need to take care to change the path of OpenOCD of Embedded IDE plug-in to the new one.
2 Boot file and Connection script writing2.1 Boot fileUnder GCC environment, the chip boot file is generally used to complete chip kernel, interrupt vector number declaration, and some data segment initialization operations, and finally calls the corresponding system clock initialization function ("SystemInit" function) in the Reset_Handler function, and then executes the 'main' function.
Under GCC environment, the chip's boot files are generally used to complete the chip's kernel, declare the interrupt vector number, and initialize some data segments, and finally call the corresponding system clock initialization function ("SystemInit" function) in the Reset_Handler function, and then execute the "main" function.
We create a new file 'startup_ apm32f40x.S', the code is similar to the F1 code we mentioned, you can refer to it (the main modification is the declaration of the interrupt function), here we need to note that F4 is the M4 kernel, so we need to change the kernel declaration inside the boot file to M4:
.syntax unified
.cpu cortex-m4
.fpu softvfp
.thumb
Summary:
1. Change the kernel declaration
2. Change the interrupt declaration to be consistent with the APM32F4 header file "apm32f4xx.h".
For the specific code, you can see the source code in the attached file, so I won't mention the whole thing here.
2.2 Link script fileThe link script files are generally the main storage space information of the chip and some program segment storage location information, which is relatively simple to write out after understanding its writing specification.
Here we create a new file “APM32F4XxxE_ FLASH.ld", the content of which is similar to the previous F1 file. However, it is worth noting that F4 has a separate RAM for kernel use only, with a size of 64KB, which needs to be declared separately here.
The memory allocation of APM32F407xE is as follows
/* Specify the memory areas */
MEMORY
{
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K
CCMRAM (xrw) : ORIGIN = 0x10000000, LENGTH = 64K
FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 512K
}
For the specific code, you can see the source code in the attached file, so I won't mention the whole thing here.
3 Project creation and compilation simulationThis section is relatively simple, you can refer to the corresponding section of the F1 environmental setup, but you need to pay attention to change the configuration of the boot file and link script file, as well as OpenOCD (when using CMSIS-DAP emulators such as Geehy-Link) as follows:
After configuring the appropriate macro definitions, and the inclusion of header files, etc., we can compile and download the simulation.
Welcome to discuss the interesting things you encountered in developing with VSCode in the comment section~
Comments
Please log in or sign up to comment.