cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F051 - Flash not working with an external clock

Abi Nair
Associate
Posted on March 26, 2018 at 15:16

I have been trying to erase and store data in the flash without any success. As long as I am using the HSI clock to drive the SYSCLK, the flash works just fine. However, if I start using the external oscillator to drive the SYSCLK, any flash operation would freeze the MCU.

I am using an 8 MHz external oscillator. Initialization code that I use is provided below:

RCC_HSEConfig(RCC_HSE_ON);

RCC_PLLConfig(RCC_PLLSource_PREDIV1, RCC_PLLMul_6); // set the PLL Clock to 48 Mhz

RCC_PLLCmd(ENABLE);

RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK); // PLL selected as system clock source

RCC_HSI14Cmd(ENABLE);

RCC_HCLKConfig(RCC_SYSCLK_Div2); // HCLK selected as 24 MHz

RCC_PCLKConfig(RCC_HCLK_Div1); // PCLK selected as 24 MHz

RCC_ADCCLKConfig(RCC_ADCCLK_PCLK_Div2);

RCC_USARTCLKConfig(RCC_USART1CLK_SYSCLK);

RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);

RCC_LSICmd(ENABLE);

EDIT: Sorry. I am using an external 8 MHz oscillator (crystal), not an external clock. 

#flash-storage #external-clock #stmf051
4 REPLIES 4
Posted on March 26, 2018 at 16:01

Flash would have issues with wait-states at higher speed, and also issues if the power supply is marginal.

For an external 'source', ie TCXO, then you should use HSE BYPASS mode.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on March 28, 2018 at 01:28

None of your code waits for anything to spin up properly

Check you have the flash set suitably

    /* Enable Prefetch Buffer and set Flash Latency */

    FLASH->ACR = FLASH_ACR_PRFTBE | FLASH_ACR_LATENCY;
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on March 28, 2018 at 14:57

Thank you for your help. Flash latency is zero and I have not enabled the prefetch buffer as HCLK is 24 MHz. Should I implement a delay to initialize the clocks?

Posted on March 28, 2018 at 16:23

Try using some of the demo/example codes to see if they fail, and make a determination if it is a software issue or something specific about your board implementation.

Would suggest you clock the PLL at 24 MHz if that's how fast you want to run chip. You should follow directions in manuals with respect to waiting for resources to start properly, like ST's examples do.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..