Skip to main content
pr_it
Associate III
Jul 27, 2020 1:19 PM UTC
Question

Why does my all-defaults, CubeMX-generated STM32F407G-DISC1 SystemClock_Config() fail at HAL_RCC_OscConfig() ?

I generate pinmux and init code for my STM32F407G-DISC1 board with STM32CubeMX 5.6.1, and copy it into my Eclipse CDT project that uses the HAL/LL drivers to that came with STM32CubeF4 Firmware Package V1.25.0. It builds ok; I download the binary to the board with OpenOCD/GDB. I can step through the code.

For some reason, the call to 'HAL_RCC_OscConfig()' in 'SystemClock_Config()' hits my error handler (line 57 below) :

int main(int argc, char* argv[])
{
 puts( "starting" );
 
 /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
 HAL_Init();
 
 /* Configure the system clock */
 SystemClock_Config();
 
 /* Initialize all configured peripherals */
 MX_GPIO_Init();
 
 while (1)
 {
 // LED ON
 HAL_GPIO_WritePin(GPIOE, GPIO_PIN_5, GPIO_PIN_SET);
 HAL_Delay(100);
 // LED OFF
 HAL_GPIO_WritePin(GPIOE, GPIO_PIN_5, GPIO_PIN_RESET);
 HAL_Delay(100);
 }
 
 // we shouldn't ever reach this point: return error
 return -1;
}
 
void Error_Handler(void)
{
 asm( "bkpt 255" );
}
 
/**
 * @brief System Clock Configuration
 * @retval None
 */
void SystemClock_Config(void)
{
 RCC_OscInitTypeDef RCC_OscInitStruct = {0};
 RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
 RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
 
 /** Configure the main internal regulator output voltage
 */
 __HAL_RCC_PWR_CLK_ENABLE();
 __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
 /** Initializes the CPU, AHB and APB busses clocks
 */
 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
 RCC_OscInitStruct.HSEState = RCC_HSE_ON;
 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
 RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
 RCC_OscInitStruct.PLL.PLLM = 8;
 RCC_OscInitStruct.PLL.PLLN = 336;
 RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
 RCC_OscInitStruct.PLL.PLLQ = 7;
 if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
 {
 Error_Handler();
 }

When I created the project, a prompt asked if I want to "initialize all peripherals with their Default mode ?" -- I said yes. Could someone explain what I'm doing wrong ?

This topic has been closed for replies.

3 replies

TDK
Jul 27, 2020 3:52 PM UTC

The mco output from stlink is probably connected by default. Try HSE bypass mode.

Seems like both MCO and HSE are connected per the user manual.

"If you feel a post has answered your question, please click ""Accept as Solution""."
pr_it
pr_itAuthor
Associate III
Jul 30, 2020 12:39 PM UTC

I tried the following, which also fails:

RCC_OscInitStruct.HSEState = RCC_HSE_BYPASS;

Is it what you meant ?

YPear.1
Associate II
May 6, 2021 4:42 PM UTC

Was this resolved?