STM32 runın at 16 mhz
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2013-12-14 12:32 AM
I wrote 1 sn delay code for stm32 and ı used 168 mhz system clock.My delay cycle ıs 16000 for each ms and ıt work led blınk 1 sn.It dıdn't work when ıt was 168000 shouldn't it have worked at 168000 cycle.my code ıs
**** File : main.c**** Abstract : main function.**** Functions : main**** Environment : Atollic TrueSTUDIO(R)** STMicroelectronics STM32F4xx Standard Peripherals Library**** Distribution: The file is distributed “as is,�? without any warranty** of any kind.**** (c)Copyright Atollic AB.** You may use this file as-is or modify it according to the needs of your** project. This file may only be built (assembled or compiled and linked)** using the Atollic TrueSTUDIO(R) product. The use of this file together** with other tools than Atollic TrueSTUDIO(R) is not permitted.********************************************************************************//* Includes */#include ''stm32f4xx.h''/* Private macro *//* Private variables *//* Private function prototypes *//* Private functions *//****===========================================================================**** Abstract: main program****===========================================================================*/void delay_ms(int delay1){ delay1 = delay1*16000; while (--delay1) { }}int main(void){ GPIO_InitTypeDef GPIO_InitStruct; RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE); GPIO_InitStruct.GPIO_Pin = GPIO_Pin_15 | GPIO_Pin_14 | GPIO_Pin_13 | GPIO_Pin_12; // we want to configure all LED GPIO pins GPIO_InitStruct.GPIO_Mode = GPIO_Mode_OUT; // we want the pins to be an output GPIO_InitStruct.GPIO_Speed = GPIO_Speed_100MHz; // this sets the GPIO modules clock speed GPIO_InitStruct.GPIO_OType = GPIO_OType_PP; // this sets the pin type to push / pull (as opposed to open drain) GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL; // this sets the pullup / pulldown resistors to be inactive GPIO_Init(GPIOD, &GPIO_InitStruct); // this passes the configuration to the Init function which takes care of the low level stuff /* Infinite loop */ while (1) { // if(1 == GPIO_ReadInputDataBit( GPIOA,GPIO_Pin_0)) // { // while(1 == GPIO_ReadInputDataBit( GPIOA,GPIO_Pin_0)); GPIO_SetBits ( GPIOD, GPIO_Pin_14) ; delay_ms(1000); GPIO_ResetBits (GPIOD, GPIO_Pin_14) ; delay_ms(1000); // } }}/* * Callback used by stm32f4_discovery_audio_codec.c. * Refer to stm32f4_discovery_audio_codec.h for more info. */void EVAL_AUDIO_TransferComplete_CallBack(uint32_t pBuffer, uint32_t Size){ /* TODO, implement your code here */ return;}/* * Callback used by stm324xg_eval_audio_codec.c. * Refer to stm324xg_eval_audio_codec.h for more info. */uint16_t EVAL_AUDIO_GetSampleCallBack(void){ /* TODO, implement your code here */ return -1;}- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2013-12-14 4:16 AM
If you are concerned about the processor speed, use the MCOx pins and output internal clocks, and measure them on a scope.
Observe that the processor in fact starts for a 16 MHz HSI clock, and has to be switched to something else, typically via SystemInit() in system_stm32f4xx.cFinally look at the assembler code generated by the compiler, and the optimization level selected. Unless you're writing code in assembler you probably have little control of cycle level performance.Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2013-12-15 12:11 AM
void delay_s
(int delay2)
{ delay2 = delay2*1680
00;
while (delay2--) { }} Delay(1000);it waits more than 10 second ı dıdn't understant why it waits more.ısn't ıt te same thing its like my main fuction has a diffrent clock speed from systemclock and it is like 8mhz or smtn like that- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2013-12-15 6:00 AM
The processor doesn't natively run C code, so assuming it's going to take a single cycle per loop iteration probably isn't going to hold water. To understand where the 10 cycles go you'll want to review the code output by the compiler.
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2013-12-15 4:16 PM
''The processor doesn't natively run C code, so assuming it's going to take a single cycle per loop iteration probably (sic?) isn't going to hold water''
I'd say it is certainly not going to hold water!In fact, any assumption - unless fully qualified by compiler, version, and complete settings - about a direct correspondence from 'C' source lines to machine code is unlikely to hold water.http://www.8052.com/forum/read/162556
A complex system designed from scratch never works and cannot be patched up to make it work.
