cancel
Showing results for 
Search instead for 
Did you mean: 

Oscillator configuration error on SW 1.3

leogarberoglio
Associate III
Posted on August 08, 2015 at 15:20

Hi, I've been working with SW 1.2 and integrated cube MX on my custom board. It has a stm32f411re with a TI audio codec.

I could make a project on cubemx, on it I configure the occillator to HSE 12MHz crystal. I've import that project on SW and everithing works ok. Now I want to work without cubemx. So I've started a new workspace, create a new project, select my uC and add hal library as shared external library. At this point I have just a startup function and a main function. Then I copy theSystemClock_Config from generated cubemx and paste on this new project.

void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct;
RCC_ClkInitTypeDef RCC_ClkInitStruct;
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct;
__PWR_CLK_ENABLE();
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE2);
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 = 7;
RCC_OscInitStruct.PLL.PLLN = 196;
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4;
RCC_OscInitStruct.PLL.PLLQ = 4;
HAL_RCC_OscConfig(&RCC_OscInitStruct);
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK|RCC_CLOCKTYPE_PCLK1;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2);
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_I2S;
PeriphClkInitStruct.PLLI2S.PLLI2SN = 271;
PeriphClkInitStruct.PLLI2S.PLLI2SM = 12;
PeriphClkInitStruct.PLLI2S.PLLI2SR = 2;
HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct);
HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);
HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
}

I compile and run this code but I have the problem that the resulting frequency is 50% more than expected... I have I2C configured to 100KHz and measure 150KHz on SCL. I have 44khz I2S and I measure 66KHz on WS... same code on cubemx generated project run ok.... any ideas? thank!
2 REPLIES 2
leogarberoglio
Associate III
leogarberoglio
Associate III
Posted on August 08, 2015 at 15:57

answer my self, onstm32f4xx_hal_conf.h I have:

/* ########################## HSE/HSI Values adaptation ##################### */
/**
* @brief Adjust the value of External High Speed oscillator (HSE) used in your application.
* This value is used by the RCC HAL module to compute the system frequency
* (when HSE is used as system clock source, directly or through the PLL). 
*/
#if !defined (HSE_VALUE) 
#define HSE_VALUE ((uint32_t)8000000) /*!< Value of the External oscillator in Hz */
#endif /* HSE_VALUE */

changing that for my 12000000 make it working ok. On cubemx generated project it include this file with value configured on Oscillator configuration page...