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