cancel
Showing results for 
Search instead for 
Did you mean: 

STM32CubeMX 4.22 SystemClock_Config Bug

Subrat Sahu
Associate II
Posted on September 07, 2017 at 21:43

I am using STM32CubeMX 4.22.0

I am using STM32F103C8T6 chip with Keil v5 under Windows 10.

I configured only RCC to 

HSE  for Crystal\Ceramic Resonator and in Clock Configuration input frequency to 8 MHz and HCLK to 72MHz .I generated the code for keil, but at the function 'SystemClock_Config()' the chip  falls into Error_Handler().

following code was generated:

void SystemClock_Config(void)

{

RCC_OscInitTypeDef RCC_OscInitStruct;

RCC_ClkInitTypeDef RCC_ClkInitStruct;

/**Initializes the CPU, AHB and APB busses clocks

*/

RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;

RCC_OscInitStruct.HSEState = RCC_HSE_ON;

RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;

RCC_OscInitStruct.HSIState = RCC_HSI_ON;

RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;

RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;

RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9;

if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)

{

_Error_Handler(__FILE__, __LINE__);

}

I debug step by step. At the point  'Error_Handler'  the program goes in to infinite loop of function 'Error_Handler(char * file, int line) ' I can not understand what is the problem.  I also attached the full project at the attachment.

#stm32cubemx-4.22-systemclock_config-bug*
10 REPLIES 10
Posted on September 08, 2017 at 10:06

And does your external clock actually start and function? 

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on September 08, 2017 at 18:41

Thanks for Reply,

I have not tested the code on real hardware. I have debugged the code in Keil Simulator(Debugger). the program has been going in to infinite loop of 'Error_Handler' during the SystemClock_Config() .

Posted on September 08, 2017 at 19:23

Hello!

Your code is working fine in my cheap ebay board with f103c8t6

Try to increase the timeout  of ''HSE clock ready'' like this

0690X00000608ANQAY.png

If you put eg 5000 and you have the same error..  the oscillator is problematic(crystal  capacitors resistors)

Actually the 100ms are very enough to start the HSE!

Posted on September 08, 2017 at 22:24

Very very thanks for your replay,

I tried HSE Startup timeout Values to 100, 200 and 500; But same error occurred. May be this error has 

occurred due to software debugging.

  As you suggested, I shall try this code (with adding a  led blink)  on my 

 board with STM32F103c8t6 (Blue Pill). 

Posted on September 09, 2017 at 02:02

The simulator probably isn't going to work well referencing external hardware.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on September 09, 2017 at 03:10

Hello!

The simulator , for sure is not going to work. it is tested .

In my pevious post i missed the word 'not' inside 'I have not tested the code on real hardware'

Posted on September 09, 2017 at 10:30

Thank you for your valuable suggestions.

The code is working fine in my blue pill board; but not in keil simulator,  I tested. Thank you for your valuable suggestions.

It is sure that there is no meaning of  software debugging in keill. Is there any simulator available for stm microcontroller ? 

Posted on September 09, 2017 at 10:35

Thanks for your reply.

I tested this code in external hardware,  It is running fine. 

Posted on September 09, 2017 at 11:34

hi!

If you don't want flashing and regflashing your MCU, you have the option to run the program from RAM for debuging

The Keil's simulator is a very good simulator for ARM MCUs (code without involving peripherals only)  but for peripherals.. not  How can simulate an incomming byte from UART or an EXTI event or in your case the HSE_RDY flag?