[National Technology N32WB031_STB development board review] GPIO flip performance test
[Copy link]
N32WB03x GPIO flip performance test
Preface
In some cases, GPIO is needed to simulate some peripherals, although this will take up more MCU. In order to find out the upper limit of the MCU's GPIO flip speed, it is still necessary to test it.
Official GPIO flip project
In this directory, there is an official GPIO flip top speed project
N32WB03x_V1.3.0\5-Software Development Kit\N32WB03x_SDK_V1.3\projects\n32wb03x_EVAL\peripheral\GPIO\IOToggle_MaxFrequency
Open this project with Keil and you can see the main.c program
int main(void)
{
/* -1- Enable GPIOx Clock (to be able to program the configuration registers) */
RCC_EnableAPB2PeriphClk(GPIOx_CLK, ENABLE);
/* -2- Configure GPIOx_PIN in output push-pull mode */
GPIO_InitStruct(&GPIO_InitStructure);
GPIO_InitStructure.Pin = GPIOx_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_SPEED_HIGH;
GPIO_InitPeripheral(GPIOx, &GPIO_InitStructure);
/* -3- Toggle GPIOx_PIN in an infinite loop */
while (1)
{
GPIOA->POD = 1;
GPIOA->POD = 0;
GPIOA->POD = 1;
GPIOA->POD = 0;
GPIOA->POD = 1;
GPIOA->POD = 0;
GPIOA->POD = 1;
GPIOA->POD = 0;
GPIOA->POD = 1;
GPIOA->POD = 0;
GPIOA->POD = 1;
GPIOA->POD = 0;
GPIOA->POD = 1;
GPIOA->POD = 0;
GPIOA->POD = 1;
GPIOA->POD = 0;
GPIOA->POD = 1;
GPIOA->POD = 0;
GPIOA->POD = 1;
GPIOA->POD = 0;
}
}
After compiling and burning, use an oscilloscope to test and the flip speed is around 8Mhz. To further test the upper limit, try to put the function into RAM for execution.
What is the difference between MCU programs in Flash and RAM?
Since the resources of MCU are relatively small, the Flash of common products also supports XIP, that is, the MCU can directly fetch instructions from the Flash and execute them directly. Therefore, unlike PC, the program must be loaded into RAM before it can be run. At the same time, because the speed of many MCUs is much higher than the speed of Flash, in order to improve the execution efficiency, engineers generally use three methods (if there are other methods, please help to add them).
- Add ICache, add instruction buffer between the core and Flash, and speed up execution.
- Use part of SRAM as zero buffer and automatically load most of Flash into zero buffer when MCU starts (data synchronization between buffer and Flash is done by hardware without user intervention).
- Load some functions from Flash to RAM when the MCU starts up, and execute these functions in RAM.
How to specify some functions to load into RAM in Keil
- Click the Options for Target.. icon, and then select the Linker tab in the pop-up tab
- Uncheck the Use Memory Layout from Target Dialog in the upper left corner, then click the edit button next to the sct file below (see picture), then click OK to close the tab
- Modify the .sct file, customize a section (here we use RAMCODE), and put it in the RW_IRAM1 segment
- Put #pragma arm section code = "RAMCODE" before the main function and #pragma arm section after the main function.
The final content of .sct is as follows
; *************************************************************
; *** Scatter-Loading Description File generated by uVision ***
; *************************************************************
LR_IROM1 0x01000000 0x00040000 { ; load region size_region
ER_IROM1 0x01000000 0x00040000 { ; load address = execution address
*.o (RESET, +First)
*(InRoot$Sections)
.ANY (+RO)
.ANY (+XO)
}
RW_IRAM1 0x20000000 0x0000C000 { ; RW data
*.o(RAMCODE)
.ANY (+RW +ZI)
}
}
The final content of the main function after modification is as follows
#pragma arm section code = "RAMCODE"
int main(void)
{
/* -1- Enable GPIOx Clock (to be able to program the configuration registers) */
RCC_EnableAPB2PeriphClk(GPIOx_CLK, ENABLE);
/* -2- Configure GPIOx_PIN in output push-pull mode */
GPIO_InitStruct(&GPIO_InitStructure);
GPIO_InitStructure.Pin = GPIOx_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_SPEED_HIGH;
GPIO_InitPeripheral(GPIOx, &GPIO_InitStructure);
/* -3- Toggle GPIOx_PIN in an infinite loop */
while (1)
{
GPIOA->POD = 1;
GPIOA->POD = 0;
GPIOA->POD = 1;
GPIOA->POD = 0;
GPIOA->POD = 1;
GPIOA->POD = 0;
GPIOA->POD = 1;
GPIOA->POD = 0;
GPIOA->POD = 1;
GPIOA->POD = 0;
GPIOA->POD = 1;
GPIOA->POD = 0;
GPIOA->POD = 1;
GPIOA->POD = 0;
GPIOA->POD = 1;
GPIOA->POD = 0;
GPIOA->POD = 1;
GPIOA->POD = 0;
GPIOA->POD = 1;
GPIOA->POD = 0;
}
}
#pragma arm section
After compiling and burning, you can see that the speed increases to 9.25MHz, which should be the maximum flip speed of the GPIO of this MCU. See the screenshot for details.
|