Skip to main content
falseReality
Associate
February 13, 2019
Question

STM32(f303cbt) chip never reaches while loop in default cubeMX generated code.

I designed my own PCB and created a project with STM32CubeMX for Truestudio with the chip taht I used on my board (stm32f303cbt). This is the first time I made my own PCB and my last project was done with an AVR chipset.

When I debug the chip with the code generated by cubeMX, it never reaches the while loop.

The main function looks like this:

int main(void)
{
 
 HAL_Init();
 
 SystemClock_Config();
 
 int i = 0;
 while (1)
 {
	 i++;
	 if(i>100) {
		 i=0;
	 }
 }
}

After executing the `SystemClock_Config();` function, I can't pause or step through the code anymore with the debugger. I can step into the SystemClock_Config(); function, but after the last line it looks like the chip is busy with this line until the end of time.

I might be missing crucial info since I don't know where I should be looking to solve this error. Here are some extra screenshots of the cubeMX configuration.

0690X000006DahpQAC.png0690X000006DahuQAC.png

This topic has been closed for replies.

3 replies

Tesla DeLorean
Guru
February 13, 2019

So perhaps show the code that's actually failing and not the level above it.

​

Flash wait states? Clocks or PLL not starting? Errors returned, helpful infinite loops? ​

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
falseReality
Associate
February 13, 2019

Here is a video of what happens when I debug and try to step towards the while loop:

https://www.youtube.com/watch?v=YUmL_YaZdeo

Here is a copy of the SystemClock_Config(); as well:

/**
 * @brief System Clock Configuration
 * @retval None
 */
void SystemClock_Config(void)
{
 RCC_OscInitTypeDef RCC_OscInitStruct = {0};
 RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
 
 /**Initializes the CPU, AHB and APB busses clocks 
 */
 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
 RCC_OscInitStruct.HSIState = RCC_HSI_ON;
 RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
 if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
 {
 Error_Handler();
 }
 /**Initializes the CPU, AHB and APB busses clocks 
 */
 RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
 |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;
 RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
 RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
 RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
 
 if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
 {
 Error_Handler();
 }
}

Something I noticed is that the Error_Handler functions are never called. Neither do I find any errors that are linked to this problem in the console.

falseReality
Associate
February 13, 2019

> Flash wait states? Clocks or PLL not starting?

I don't know how to read/change these values and states. Aren't the default values ok for normal operations?