I'm working in a STM32L476JGY based project using the board STEVAL-STLCS02V1.
The code generated by the Cube using the default clock configuration "forgets" initialize the M value of the PLL struct, see original code:
/** System Clock Configuration
/**Initializes the CPU, AHB and APB busses clocks
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_MSI;
RCC_OscInitStruct.MSIState = RCC_MSI_ON;
RCC_OscInitStruct.MSICalibrationValue = 0;
RCC_OscInitStruct.MSIClockRange = RCC_MSIRANGE_6;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_MSI;
RCC_OscInitStruct.PLL.PLLN = 40;
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV7;
RCC_OscInitStruct.PLL.PLLQ = RCC_PLLQ_DIV2;
RCC_OscInitStruct.PLL.PLLR = RCC_PLLR_DIV2;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
it's very strange that the call to HAL_RCC_OscConfig returns with a HAL_OK, but later, when the function tries to configure the PPLSAI1 it fails and the system is blocked on the _Error_Handler loop.
I fixed the problem initializing the M value on the PLL adding the following line:
RCC_OscInitStruct.PLL.PLLM = 1; // STM32CubeMX forgets that line.