2015-03-20 11:41 AM
Hello,
I'm looking for some help about the main frequency. Maybe I do not understand correctly the documentation. My test program is just a blinking LED on PORTA PIN 0.RCC->APB2ENR |= RCC_APB2ENR_IOPAEN;
IO_ACCESS* IO_PORTA = NEW_IO_ACCESS(&GPIOA->CRL,&GPIOA->CRH,&GPIOA->IDR,&GPIOA->ODR); IO_PORTA->PinAsOutput(0,0); while (1) { for (unsigned int long i = 0; i<8000000; i++); IO_PORTA->PinToggle(0); } With defaut values clock registers, this code use the HSI and run at 8MHz according the doc. Not I want want use HSE and PLL to run at 32MHz. So here my code:LASH->ACR |= FLASH_ACR_LATENCY_1;
RCC->CR |= RCC_CR_HSEON; while (!(RCC->CR & RCC_CR_HSERDY)); RCC->CFGR |= RCC_CFGR_PLLSRC_HSE; RCC->CFGR |= RCC_CFGR_PLLMULL4; RCC->CR |= RCC_CR_PLLON; while (!(RCC->CR & RCC_CR_PLLRDY)); RCC->CFGR |= RCC_CFGR_SW_PLL; while (!(RCC->CFGR & RCC_CFGR_SWS_PLL)); RCC->APB2ENR |= RCC_APB2ENR_IOPAEN;IO_ACCESS* IO_PORTA = NEW_IO_ACCESS(&GPIOA->CRL,&GPIOA->CRH,&GPIOA->IDR,&GPIOA->ODR); IO_PORTA->PinAsOutput(0,0); while (1) { for (unsigned int long i = 0; i<8000000; i++); IO_PORTA->PinToggle(0); } I'm expect that my LED blinks 4x faster. But not. I tried some other comfiguration with HSI also other PLL, etc... But whatever I did, my LED always blink at the same speed. Is someone able to say me where is my mistake? Thanks,2015-03-20 01:10 PM
Blindly ORing on to registers seems to be prone to issues, and you probably want volatile loop iterators to stop the compiler removing the code.
2015-03-20 01:34 PM
Hello Clive,
can you say me more about what you think with blindy ORing? I use the file stm32f10x.h. I check every #define number with the datasheet. And it's exactly what I should have. Compiler doesn't remove the for loop, if I change my max, I can speed down and speed up. So my problem is elsewhere. I'm continuing to test2015-03-20 01:36 PM
Since you are changing to 32Mhz and are above 24MHz where do you set the flash wait state to 1? Try 16MHz as a quick test to see if your LED speeds up. Above 24MHz you need wait states. Below 24MHz you can leave the prefetch buffer turned off.
How do you set up PCLK1 (APB) and PCLK2 (AHB)? PCLK2 (usually HCLK/1) should be twice the frequency of PCLK1 (usually set to HCLK/2).2015-03-20 01:46 PM
can you say me more about what you think with blindy ORing?
Your use of OR assumes things about the initial condition of the registers. If the accumulation of bits means something else to the chip it's going to do that, not what you expect. If the CMSIS code here has already called SystemInit() the registers may not be in reset condition. It's always safer not to assume, but rather mask the register bits you wish to keep vs the ones you don't.2015-03-20 02:13 PM
FLASH->ACR |= FLASH_ACR_LATENCY_1;
I tired a lot of other frequency with HSI, HSE. nothing give me something right.
About PCLK, I assume defaut value register of RCC and FLASH after POR. So the div is always 1. My crystal is 8MHz. So do not need to change them. I will check again. Maybe the default value are not what it is written in the datasheet. I will force them.
Hello Clive,
Ok I get it. You right. maybe the defaut value are not what I assume. I will force them.
2015-03-21 07:24 AM
Hello Clive, Jack,
my problem is solved. thanks for your help. That's was well the ''blindy'' ORing. I thought I worked with defaut value register after POR according to the documentation. But I included the file stm32f10x.h thinking it's was just all the #define and structure userfriendly register access. But somewhere it call the function SystemInit(void) and mess with my register access. I just deleted all these part, and now it's ok. Thanks again.