官方demo没有开优化,编译后烧录超级慢,开了O3优化后快不少。
#include "main.h"
#include "Board.h"
#include "stdio.h"
#include "apm32f4xx_gpio.h"
#include "apm32f4xx_misc.h"
#include "apm32f4xx_usart.h"
extern void DSPTestDemo(void);
uint32_t delay_init(void)
{
uint32_t c;
/* Enable TRC */
CoreDebug->DEMCR &= ~0x01000000;
CoreDebug->DEMCR |= 0x01000000;
/* Enable counter */
DWT->CTRL &= ~0x00000001;
DWT->CTRL |= 0x00000001;
/* Reset counter */
DWT->CYCCNT = 0;
/* Check if DWT has started */
c = DWT->CYCCNT;
/* 2 dummys */
__ASM volatile ("NOP");
__ASM volatile ("NOP");
/* Return difference, if result is zero, DWT has not started */
return (DWT->CYCCNT - c);
}
void delay_ms(uint32_t ms)
{
uint32_t start = DWT->CYCCNT;
/* Go to number of cycles for system */
ms *= (SystemCoreClock / 1000);
/* Delay till end */
while ((DWT->CYCCNT - start) < ms);
}
int main(void)
{
uint8_t keyType;
/* Set system interrupt priority grouping */
NVIC_ConfigPriorityGroup(NVIC_PRIORITY_GROUP_2);
/* Init delay function */
Delay_Init();
/* Init LED */
APM_MINI_LEDInit(LED2);
APM_MINI_LEDInit(LED3);
/* Init USART1 */
USART1_Init(115200);
/* Init KEY */
APM_MINI_PBInit(BUTTON_KEY2, BUTTON_MODE_GPIO);
APM_MINI_PBInit(BUTTON_KEY1, BUTTON_MODE_GPIO);
delay_init();
/* Wait board and module power on */
delay_ms(200);
uint32_t t1 = DWT->CYCCNT;
DSPTestDemo();
uint32_t t2 = DWT->CYCCNT;
printf("time=%fus\n",(t2-t1)*1000000.0/SystemCoreClock);
APM_MINI_LEDOn(LED3);
while(1)
{
delay_ms(10);
}
}
没有开启FPU情况下2048点FFT耗时约16.2ms,网友stm32f407的测试对比
尝试加入宏定义开启FPU,但是编译报错了。。
__FPU_PRESENT = 1,__FPU_USED = 1