2021-11-30 09:30 PM
Hi everyone. It's my first time posting here. I'm learning how to program STM32, especifically an STM32F303RE Nucleo Board using HAL libraries.
These are my resources to learn:
I'm trying to configure HSI oscilator using HAL drivers this is a part of my code (still incomplete):
void SystemClock_Config(){
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
RCC_OscInitStruct.HSEState = RCC_HSE_OFF;
RCC_OscInitStruct.HSEPrediValue = RCC_HSE_PREDIV_DIV1;
RCC_OscInitStruct.LSEState = RCC_LSE_OFF;
RCC_OscInitStruct.LSIState = RCC_HSI_OFF;
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
RCC_OscInitStruct.LSIStae = RCC_LSI_OFF;
RCC_PLLInitTypeDef.RCC_OscInitTypeDef = ???
}
As you can see, I pretend use HSI (its on), so, HSEState are OFF also LSE = OFF and so one. I compared my code with the generated with CubeMX:
void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
/** Initializes the RCC Oscillators according to the specified parameters
* in the RCC_OscInitTypeDef structure.
*/
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9;
RCC_OscInitStruct.PLL.PREDIV = RCC_PREDIV_DIV1;
As you can see, in this code CubeMX doesn't specify that HSE, LSI, are off. Only apears HSI = ON.
So my doubt is:
Can I skip to initialize these structure members for configure the osc?
Do they have a predefined value?
I hope you can help me. Ty
2021-12-01 02:15 AM
After the MCU resets, very little hardware is operational. Since you can assign other functions to the HSE and LSE pins, it is closed at startup.
simply everything is turned off except mandatory hardware like ram rom. If you don't install the hardware at boot, it will remain closed.
2021-12-01 02:24 AM
>> Can I skip to initialize these structure members for configure the osc?
Yes, as example, HSEState field will only be taken in account when calling the HAL_RCC_OscConfig if OscillatorType field is OR'ed with RCC_OSCILLATORTYPE_HSE.
Same for other like LSE,LSI, etc...
>> Do they have a predefined value?
As default they are 0 since RCC_OscInitStruct is declared with ={0};
2021-12-01 06:22 AM
The only thing this piece of code does is try to turn off the HSI (since HSIState = 0 = RCC_HSI_OFF):
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
RCC_OscInitStruct.HSEState = RCC_HSE_OFF;
RCC_OscInitStruct.HSEPrediValue = RCC_HSE_PREDIV_DIV1;
RCC_OscInitStruct.LSEState = RCC_LSE_OFF;
RCC_OscInitStruct.LSIState = RCC_HSI_OFF;
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
RCC_OscInitStruct.LSIStae = RCC_LSI_OFF;
There are also two typos here:
> RCC_OscInitStruct.LSIState = RCC_HSI_OFF;
> RCC_OscInitStruct.LSIStae = RCC_LSI_OFF;
2021-12-01 06:57 PM
Ok, now I understand. Ty so much guys !!!. :D