2018-04-26 10:04 AM
Hello All,
I am using STM32L486RGT, CubeMX 4.25 STM32L4 lib 1.11.
At the STM32 I have a 16MHz crystall connected.
Now I run into problems setting up the clocktree. It works under certain combinations but not under the ones I want.
I want to use the 16MHz crystal, HSE, PLL, USB and CPU running at 64MHz.
not working: 16MHz Crystal, PLLSource:HSE, PLLM:1, PLLN:8, PLLR:2, Sysclock:64MHz, PLLSAI1N:12, PLLSAI1Q:4, USB:PLLSAI1Q:48MHz
working: switching the PLL source to HSI
I tried also with Nucleo Board STM32L452 and found the combination does initially does not work.
I put an 16MHz crystal to the board.
working: 16MHz Crystal, PLLSource:HSE, PLLM:1, PLLN:8, PLLR:2, Sysclock:64MHz
not working: as above, plus USB, PLLSAI1N:2, PLLSAI1Q:4, USB:PLLSAI1Q:48MHz
On all examples: AHBPrescalers are 1 so all peripheral/core/sysclock clocks are 64MHz
Here is the example SysClock Init from the generated not working sample:
the failing function is:
<<
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
>>
Can anyone confirm those problems?
Regards, Adib.
--
/**
* @brief System Clock Configuration * @retval None */void SystemClock_Config(void){RCC_OscInitTypeDef RCC_OscInitStruct;
RCC_ClkInitTypeDef RCC_ClkInitStruct; RCC_PeriphCLKInitTypeDef PeriphClkInit;/**Initializes the CPU, AHB and APB busses clocks
*/ RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI; RCC_OscInitStruct.HSEState = RCC_HSE_ON; RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; RCC_OscInitStruct.PLL.PLLN = 8; 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) { _Error_Handler(__FILE__, __LINE__); }/**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_PLLCLK; 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_3) != HAL_OK)
{ _Error_Handler(__FILE__, __LINE__); }PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USART1|RCC_PERIPHCLK_USART3
|RCC_PERIPHCLK_LPUART1|RCC_PERIPHCLK_I2C1 |RCC_PERIPHCLK_USB|RCC_PERIPHCLK_ADC; PeriphClkInit.Usart1ClockSelection = RCC_USART1CLKSOURCE_PCLK2; PeriphClkInit.Usart3ClockSelection = RCC_USART3CLKSOURCE_PCLK1; PeriphClkInit.Lpuart1ClockSelection = RCC_LPUART1CLKSOURCE_PCLK1; PeriphClkInit.I2c1ClockSelection = RCC_I2C1CLKSOURCE_PCLK1; PeriphClkInit.AdcClockSelection = RCC_ADCCLKSOURCE_SYSCLK; PeriphClkInit.UsbClockSelection = RCC_USBCLKSOURCE_PLLSAI1; PeriphClkInit.PLLSAI1.PLLSAI1Source = RCC_PLLSOURCE_HSE; PeriphClkInit.PLLSAI1.PLLSAI1M = 1; PeriphClkInit.PLLSAI1.PLLSAI1N = 12; PeriphClkInit.PLLSAI1.PLLSAI1P = RCC_PLLP_DIV7; PeriphClkInit.PLLSAI1.PLLSAI1Q = RCC_PLLQ_DIV4; PeriphClkInit.PLLSAI1.PLLSAI1R = RCC_PLLR_DIV8; PeriphClkInit.PLLSAI1.PLLSAI1ClockOut = RCC_PLLSAI1_48M2CLK; if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK) { _Error_Handler(__FILE__, __LINE__); }/**Configure the main internal regulator output voltage
*/ if (HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1) != HAL_OK) { _Error_Handler(__FILE__, __LINE__); }/**Configure the Systick interrupt time
*/ HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);/**Configure the Systick
*/ HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);/* SysTick_IRQn interrupt configuration */
HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);}2018-05-29 07:32 AM
maybe you need a different clock frequency, what is the exact issue ?
CubeMx 4.22.1
shows everything you want;
PLLM 1 x8 /2 = 64mhz /1 Hclk =64MHz
USB clock source is PLLSAI1Q
which is x12 /4
2018-05-29 08:24 AM
the IOC file is in the original posts section. sam2_goware.ioc.
My board is based on STM32L486RGT7. Crystal frequency is 16MHz. USB is connected.
For test purposes I ususaly use the Nucleo-L476RG board (but that has different crystal).
The problem is not board specific: the code stucks in SystemClock_Config() and runs into the Error handler.
Adib.
--
2018-05-29 09:27 AM
it gets stuck here ?
void SystemClock_Config(void)
{RCC_OscInitTypeDef RCC_OscInitStruct;
RCC_ClkInitTypeDef RCC_ClkInitStruct; RCC_PeriphCLKInitTypeDef PeriphClkInit;/**Initializes the CPU, AHB and APB busses clocks
*/ RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI; RCC_OscInitStruct.HSEState = RCC_HSE_ON; RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; RCC_OscInitStruct.PLL.PLLN = 8; 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) { _Error_Handler(__FILE__, __LINE__); }where did you set PLLM as /1 ?
where did you set AHB Prescaler as /1 ?
why is RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI; ? HSE ?
did you enable the CSS ? should you ?
Clive ?
2018-05-29 09:37 AM
Does the code show a PLLM setting, or not?
Make sure to clear the auto/local declaration on the stack.
Follow the error path backward to understand where in the source it is triggered.
2018-05-29 09:39 AM
Not describing PLLM parameter?
Consider RCC_OscInitTypeDef RCC_OscInitStruct = {0}; so that initial values are clearly defined and not subject to noise from stack.
It probably throws an error and then gets stuck in the Error_Handler(), going to have to work backward, through code to determine cause. You have the source, you have a debugger, shouldn't take too long to pinpoint the cause/reason for the error.
2018-05-29 10:08 AM
can you to single step inside HAL_RCC_OscConfig,
which line causes the problem ?
2018-05-29 10:11 AM
2018-05-29 12:28 PM
void SystemClock_Config(void)
{RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};/**Initializes the CPU, AHB and APB buses 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 = 1; RCC_OscInitStruct.PLL.PLLN = 12; RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV7; RCC_OscInitStruct.PLL.PLLQ = RCC_PLLQ_DIV2; RCC_OscInitStruct.PLL.PLLR = RCC_PLLR_DIV4; if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) { _Error_Handler(__FILE__, __LINE__); }...
Check obvious things like HSE ticking, and PLL parameters not exceeded