AnsweredAssumed Answered

Random CAN Clock

Question asked by David Pekin on Dec 29, 2017
Latest reply on Jan 2, 2018 by David Pekin

Hello, I'm trying to bring up CAN on the STM32F303RE.  After banging my head against the wall, and with much help from the forum, I'm getting closer.  What I notice is that the CAN clock is not repeatable from power up to power up.  I've copied the Config_System_Clock() function from the Can Networking example from the STM32373C_Eval.  It is shown below.  The line with the HSEPredivValue does not compile since this platform doesn't define it.  I suspect my random CAN bus timing is because the System Clock is not configured properly.  

 

Has anyone experienced this?  Does anyone have a known good clock configuration that will repeatably drive the CAN bus at a known rate?  (I'd also like to know how to change the clock to vary the bus rate.)

 

Thanks and happy new year!

 


/**
* @brief System Clock Configuration
* The system Clock is configured as follow :
* System Clock source = PLL (HSI)
* SYSCLK(Hz) = 64000000
* HCLK(Hz) = 64000000
* AHB Prescaler = 1
* APB1 Prescaler = 2
* APB2 Prescaler = 1
* HSI Frequency(Hz) = 8000000
* PREDIV = RCC_PREDIV_DIV2 (2)
* PLLMUL = RCC_PLL_MUL16 (16)
* Flash Latency(WS) = 2
* @param None
* @retval None
*/

static void SystemClock_Config(void)
{
RCC_ClkInitTypeDef RCC_ClkInitStruct;
RCC_OscInitTypeDef RCC_OscInitStruct;

/* Enable HSE Oscillator and activate PLL with HSE as source */
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
// RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;     This line does not compile on STM32f303 platform
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();
}

/* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2
clocks dividers */
RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2);
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2)!= HAL_OK)
{
Error_Handler();
}
}

Outcomes