2022-02-01 02:32 PM
I created a new project from BLE_HeartRate.ioc (v1.13.1) using STM32CubeIDE (v6.4.0). The code executes on the P-NUCLEO-WB55 as well as on my target HW. I then added peripherals from my application: ADC1, I2C3, SAI1 etc. I was unable to communicate via i2C3 with my LED driver. Write timeouts occur. I have an older version of the application code generated using v6.3.0 that works over i2c. It appears that the peripheral clocks are not getting enabled in the code generated by v6.4.0.
// v.6.3.0 Code
/**
* @brief Peripherals Common Clock Configuration
* @retval None
*/
void PeriphCommonClock_Config(void)
{
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
/** Initializes the peripherals clock
*/
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_SMPS|RCC_PERIPHCLK_RFWAKEUP
|RCC_PERIPHCLK_RTC|RCC_PERIPHCLK_USART1
|RCC_PERIPHCLK_SAI1|RCC_PERIPHCLK_I2C3
|RCC_PERIPHCLK_RNG|RCC_PERIPHCLK_ADC;
PeriphClkInitStruct.PLLSAI1.PLLN = 24;
PeriphClkInitStruct.PLLSAI1.PLLP = RCC_PLLP_DIV2;
PeriphClkInitStruct.PLLSAI1.PLLQ = RCC_PLLQ_DIV2;
PeriphClkInitStruct.PLLSAI1.PLLR = RCC_PLLR_DIV2;
PeriphClkInitStruct.PLLSAI1.PLLSAI1ClockOut = RCC_PLLSAI1_SAI1CLK|RCC_PLLSAI1_ADCCLK;
PeriphClkInitStruct.Usart1ClockSelection = RCC_USART1CLKSOURCE_PCLK2;
PeriphClkInitStruct.I2c3ClockSelection = RCC_I2C3CLKSOURCE_PCLK1;
PeriphClkInitStruct.Sai1ClockSelection = RCC_SAI1CLKSOURCE_PLLSAI1;
PeriphClkInitStruct.RngClockSelection = RCC_RNGCLKSOURCE_LSI;
PeriphClkInitStruct.AdcClockSelection = RCC_ADCCLKSOURCE_PLLSAI1;
PeriphClkInitStruct.RTCClockSelection = RCC_RTCCLKSOURCE_HSE_DIV32;
PeriphClkInitStruct.RFWakeUpClockSelection = RCC_RFWKPCLKSOURCE_LSE;
PeriphClkInitStruct.SmpsClockSelection = RCC_SMPSCLKSOURCE_HSE;
PeriphClkInitStruct.SmpsDivSelection = RCC_SMPSCLKDIV_RANGE1;
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN Smps */
/* USER CODE END Smps */
}
// v.6.4.0 Code
/**
* @brief Peripherals Common Clock Configuration
* @retval None
*/
void PeriphCommonClock_Config(void)
{
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
/** Initializes the peripherals clock
*/
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_SMPS|RCC_PERIPHCLK_RFWAKEUP
|RCC_PERIPHCLK_SAI1|RCC_PERIPHCLK_ADC;
PeriphClkInitStruct.PLLSAI1.PLLN = 24;
PeriphClkInitStruct.PLLSAI1.PLLP = RCC_PLLP_DIV2;
PeriphClkInitStruct.PLLSAI1.PLLQ = RCC_PLLQ_DIV2;
PeriphClkInitStruct.PLLSAI1.PLLR = RCC_PLLR_DIV2;
PeriphClkInitStruct.PLLSAI1.PLLSAI1ClockOut = RCC_PLLSAI1_SAI1CLK|RCC_PLLSAI1_ADCCLK;
PeriphClkInitStruct.Sai1ClockSelection = RCC_SAI1CLKSOURCE_PLLSAI1;
PeriphClkInitStruct.AdcClockSelection = RCC_ADCCLKSOURCE_PLLSAI1;
PeriphClkInitStruct.RFWakeUpClockSelection = RCC_RFWKPCLKSOURCE_LSE;
PeriphClkInitStruct.SmpsClockSelection = RCC_SMPSCLKSOURCE_HSE;
PeriphClkInitStruct.SmpsDivSelection = RCC_SMPSCLKDIV_RANGE1;
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN Smps */
/* USER CODE END Smps */
}
The .ioc files are attached.
Solved! Go to Solution.
2022-02-03 01:55 AM
Hello @HCohe.1 ,
It turns out that only peripherals using PLL2, PLL3, PLLSAI1, PLLSAI2 as a source clock are configured in PeriphCommonClock_Config() and only when they are used by more than one peripheral. Otherwise the clock init will be generated in HAL_IPNAME_MspInit or in MX_IPINSTANCE_Init.
This is a new implementation for WB in CubeMX6.4.0, the reason for this change is to do the split between RCC peripheral initialization and the system clock config.
For I2C for example, the peripheral clock is PCLK1 so it is configured in HAL_I2C_MspInit in stm32wbxx_hal_msp.c file.
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_I2C3;
PeriphClkInitStruct.I2c3ClockSelection = RCC_I2C3CLKSOURCE_PCLK1;
However, ADC and SAI1 are using PLLSAI1, so the clock config is done in PeriphCommonClock_Config() in main.c file.
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_SMPS|RCC_PERIPHCLK_RFWAKEUP| RCC_PERIPHCLK_SAI1|RCC_PERIPHCLK_ADC;
The clock config is generated correctly in your project and it is not the source of the issue. If it is possible, please send us your project to investigate more the issue.
Thanks,
Sara.
2022-02-02 12:37 AM
Hello @HCohe.1 ,
Thanks for your feedback,
You are right, Some peripherals clock are not configured in PeriphCommonClock_Config (RTC, I2C, SPI, USART, RNG etc). This issue is now reported to the dev team.
I will keep you posted with the updates.
If your issue is solved, please close this post by clicking the "Select as Best" button. This will help other members of the community find this response more quickly :)
Thanks for your contribution and do not hesitate to raise any issue/ feedback.
Sara.
2022-02-03 01:55 AM
Hello @HCohe.1 ,
It turns out that only peripherals using PLL2, PLL3, PLLSAI1, PLLSAI2 as a source clock are configured in PeriphCommonClock_Config() and only when they are used by more than one peripheral. Otherwise the clock init will be generated in HAL_IPNAME_MspInit or in MX_IPINSTANCE_Init.
This is a new implementation for WB in CubeMX6.4.0, the reason for this change is to do the split between RCC peripheral initialization and the system clock config.
For I2C for example, the peripheral clock is PCLK1 so it is configured in HAL_I2C_MspInit in stm32wbxx_hal_msp.c file.
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_I2C3;
PeriphClkInitStruct.I2c3ClockSelection = RCC_I2C3CLKSOURCE_PCLK1;
However, ADC and SAI1 are using PLLSAI1, so the clock config is done in PeriphCommonClock_Config() in main.c file.
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_SMPS|RCC_PERIPHCLK_RFWAKEUP| RCC_PERIPHCLK_SAI1|RCC_PERIPHCLK_ADC;
The clock config is generated correctly in your project and it is not the source of the issue. If it is possible, please send us your project to investigate more the issue.
Thanks,
Sara.