STM32跑72MHz比36MHz快不了一倍. STM32跑72MHz可能比LM3S跑50MHz还要慢(浮点数运算)
测试环境 软件:keil ARM3.11 第二级优化 LM3S硬件: EasyARM8962开发板 测量LED3闪烁周期 STM硬件:EK-STM32F开发板 测量LD2闪烁周期
LM3S程序:
#include "hw_memmap.h" #include "hw_types.h" #include "gpio.h" #include "sysctl.h"
#define PINS GPIO_PIN_6 //8962开发板LED3
#define N (1024)
//int a[N],b[N],c[N]; //LED3输出周期76.4ms float a[N],b[N],c[N]; //LED3输出周期401.4ms
void test(int t) { int i; int count;
for(count=0;count<50;count++) { t += count; for(i=0;i<N;i++) { a = t*i; } for(i=0;i<N;i++) { b = t+i; } for(i=0;i<N;i++) { c = a * b / (i+1); } }
}//void test(int t)
/********************************************************************************************************* ** Function name: main ** Descriptions: 主函数 ** input parameters: 无 ** output parameters: 无 ** Returned value: 无 *********************************************************************************************************/ int main(void) { SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_6MHZ);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
GPIOPadConfigSet(GPIO_PORTB_BASE, PINS, GPIO_STRENGTH_4MA, GPIO_PIN_TYPE_STD);
GPIODirModeSet(GPIO_PORTB_BASE, PINS, GPIO_DIR_MODE_OUT); while(1) { GPIOPinWrite(GPIO_PORTB_BASE, PINS, PINS); test(100); GPIOPinWrite(GPIO_PORTB_BASE, PINS, ~PINS); test(200); } } /********************************************************************************************************* END FILE *********************************************************************************************************/
STM32程序:
/* Includes ------------------------------------------------------------------*/ #include "stm32f10x_lib.h"
/* Private typedef -----------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/ /* Private macro -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ /* Private function prototypes -----------------------------------------------*/ /* Private functions ---------------------------------------------------------*/
#define N (1024)
GPIO_InitTypeDef GPIO_InitStructure; ErrorStatus HSEStartUpStatus;
//int a[N],b[N],c[N]; //EK-STM32F开发板LD2输出周期73.0ms float a[N],b[N],c[N]; //EK-STM32F开发板LD2输出周期420.2ms
void test(int t) { int i; int count;
for(count=0;count<50;count++) { t += count; for(i=0;i<N;i++) { a = t*i; } for(i=0;i<N;i++) { b = t+i; } for(i=0;i<N;i++) { c = a * b / (i+1); } }
}//void test(int t)
/******************************************************************************* * Function Name : RCC_Configuration * Description : Configures the different system clocks. * Input : None * Output : None * Return : None *******************************************************************************/ void RCC_Configuration(void) { /* RCC system reset(for debug purpose) */ RCC_DeInit();
/* Enable HSE */ RCC_HSEConfig(RCC_HSE_ON);
/* Wait till HSE is ready */ HSEStartUpStatus = RCC_WaitForHSEStartUp();
if(HSEStartUpStatus == SUCCESS) { /* HCLK = SYSCLK */ RCC_HCLKConfig(RCC_SYSCLK_Div1); /* PCLK2 = HCLK */ RCC_PCLK2Config(RCC_HCLK_Div1);
/* PCLK1 = HCLK/2 */ RCC_PCLK1Config(RCC_HCLK_Div2);
/* Flash 2 wait state */ FLASH_SetLatency(FLASH_Latency_2); /* Enable Prefetch Buffer */ FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
/* PLLCLK = 8MHz * 9 = 72 MHz */ RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9);
/* Enable PLL */ RCC_PLLCmd(ENABLE);
/* Wait till PLL is ready */ while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET) { }
/* Select PLL as system clock source */ RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
/* Wait till PLL is used as system clock source */ while(RCC_GetSYSCLKSource() != 0x08) { } } }
/******************************************************************************* * Function Name : NVIC_Configuration * Description : Configures Vector Table base location. * Input : None * Output : None * Return : None *******************************************************************************/ void NVIC_Configuration(void) { #ifdef VECT_TAB_RAM /* Set the Vector Table base location at 0x20000000 */ NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0); #else /* VECT_TAB_FLASH */ /* Set the Vector Table base location at 0x08000000 */ NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0); #endif }
/******************************************************************************* * Function Name : main * Description : Main program. * Input : None * Output : None * Return : None *******************************************************************************/ int main(void) {
#ifdef DEBUG debug(); #endif
/* Configure the system clocks */ RCC_Configuration(); /* NVIC Configuration */ NVIC_Configuration();
// Enable GPIOC clock RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7 ; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; GPIO_Init(GPIOC, &GPIO_InitStructure);
/* Infinite loop */ while (1) {
GPIO_WriteBit(GPIOC,GPIO_Pin_7,Bit_SET); test(100); GPIO_WriteBit(GPIOC,GPIO_Pin_7,Bit_RESET); test(200); } }
#ifdef DEBUG /******************************************************************************* * Function Name : assert_failed * Description : Reports the name of the source file and the source line number * where the assert error has occurred. * Input : - file: pointer to the source file name * - line: assert error line source number * Output : None * Return : None *******************************************************************************/ void assert_failed(u8* file, u32 line) { /* User can add his own implementation to report the file name and line number, ex: printf("Wrong parameters value: file %s on line %d
", file, line) */
/* Infinite loop */ while (1) {
} } #endif
/******************* (C) COPYRIGHT 2007 STMicroelectronics *****END OF FILE****/
|