嗨圣。
我在 dts 文件中设置时钟如下。
&rcc {
st, hsi-cal;
圣,西卡尔;
st,cal-sec = <60>;
圣,clksrc = <
CLK_MPU_PLL1P
CLK_AXI_PLL2P
CLK_MCU_PLL3P
CLK_PLL12_HSE
CLK_PLL3_HSE
CLK_PLL4_HSE
CLK_RTC_LSE
CLK_MCO1_DISABLED
CLK_MCO2_DISABLED
>;
st,clkdiv = <
1 /*微处理器*/
0 /*轴线*/
0 /*
单片机*/
1 /*APB1*/
1 /*APB2*/
1 /*APB3*/
1 /*APB4*/
2 /*APB5*/
23 /*实时时钟*/
0 /*MCO1*/
0 /*MCO2*/
>;
st, pkcs = <
CLK_CKPER_HSI
CLK_QSPI_ACLK
CLK_ETH_DISABLED
CLK_SDMMC12_PLL4P
CLK_STGEN_HSE
CLK_USBPHY_HSE
CLK_SPI2S1_CKPER
CLK_SPI2S23_PLL3Q
CLK_SPI45_PLL4Q
CLK_SPI6_DISABLED
CLK_I2C46_HSI
CLK_SDMMC3_DISABLED
CLK_USB_USBPHY
CLK_ADC_PLL4R
CLK_CEC_DISABLED
CLK_I2C12_HSI
CLK_I2C35_禁用
CLK_UART1_HSI
CLK_UART24_HSI
CLK_UART35_HSI
CLK_UART6_HSI
CLK_UART78_HSI
CLK_SPDIF_DISABLED
CLK_SAI1_DISABLED
CLK_SAI2_DISABLED
CLK_SAI3_DISABLED
CLK_SAI4_DISABLED
CLK_RNG1_LSI
CLK_RNG2_LSI
CLK_LP
tiM1_PCLK1
CLK_LPTIM23_PCLK3
CLK_LPTIM45_LSE
>;
/* VCO = 1066.0 MHz => P = 266 (AXI), Q = 533 (GPU), R = 533 (DDR) */
pll2: st,pll@1 {
compatible = "st,
STM32mp1-pll";
注册 = <1>;
cfg = < 2 65 1 1 0 PQR(1,0,1) >;
压裂 = <0x1400>;
};
/* VCO = 600.0 MHz => P = 200,Q = 40,R = 60 */
pll3: st,pll@2 {
compatible = "st,stm32mp1-pll";
注册 = <2>;
cfg = < 3 99 2 14 9 PQR(1,1,1) >;
/*
frac = <0x1a04>;
*/
};
/* VCO = 792.0 MHz => P = 99,Q = 66,R = 72 */
pll4: st,pll@3 {
compatible = "st,stm32mp1-pll";
注册 = <3>;
cfg = < 5 197 7 11 10 PQR(1,1,1) >;
};
};
下面是M4 Core Side的SPI设置部分。
静态无效 MX_SPI5_Init(无效)
{
LL_SPI_InitTypeDef SPI_InitStruct = {0};
LL_GPIO_InitTypeDef GPIO_InitStruct = {0};
RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
如果(IS_ENGINEERING_BOOT_MODE())
{
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_SPI45;
PeriphClkInit.Spi45ClockSelection = RCC_SPI45CLKSOURCE_PLL4;
如果(HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit)!= HAL_OK)
{
错误处理程序();
}
}
别的
{
如果(!LL_RCC_PLL4_IsReady())
{
LL_RCC_PLL4_Enable();
}
LL_RCC_PLL4Q_Enable();
}
//外设时钟使能
LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_SPI5);
LL_AHB4_GRP1_EnableClock(LL_AHB4_GRP1_PERIPH_GPIOK);
LL_AHB4_GRP1_EnableClock(LL_AHB4_GRP1_PERIPH_GPIOJ);
/* SPI5 GPIO 配置
PK0 ------> SPI5_SCK
PJ10 ------> SPI5_MOSI
*/
GPIO_InitStruct.Pin = LL_GPIO_PIN_0;
GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_MEDIUM;
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
GPIO_InitStruct.Alternate = LL_GPIO_AF_5;
LL_GPIO_Init(GPIOK, &GPIO_InitStruct);`
GPIO_InitStruct.Pin = LL_GPIO_PIN_10;
GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_MEDIUM;
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
GPIO_InitStruct.Alternate = LL_GPIO_AF_5;
LL_GPIO_Init(GPIOJ, &GPIO_InitStruct);
SPI_InitStruct.TransferDirection = LL_SPI_SIMPLEX_TX;
SPI_InitStruct.Mode = LL_SPI_MODE_MASTER;
SPI_InitStruct.DataWidth = LL_SPI_DATAWIDTH_16BIT;
SPI_InitStruct.ClockPolarity = LL_SPI_POLARITY_LOW;
SPI_InitStruct.ClockPhase = LL_SPI_PHASE_1EDGE;
SPI_InitStruct.NSS = LL_SPI_NSS_SOFT;
SPI_InitStruct.BaudRate = LL_SPI_BAUDRATEPRESCALER_DIV2;
SPI_InitStruct.BitOrder = LL_SPI_MSB_FIRST;
SPI_InitStruct.CRCCalculation = LL_SPI_CRCCALCULATION_DISABLE;
SPI_InitStruct.CRCPoly = 0x0;
LL_SPI_Init(SPI5, &SPI_InitStruct);
LL_SPI_SetStandard(SPI5, LL_SPI_PROTOCOL_MOTOROLA);
}
下面是M4 Core Side使用SPI传输数据的部分。
uint16_t uData = 0xFF0F;
LL_SPI_SetTransferSize(SPI5, 1);
LL_SPI_Enable(SPI5);
LL_SPI_StartMasterTransfer(SPI5);
LL_SPI_TransmitData16(SPI5, uData);
而 (LL_SPI_IsActiveFlag_EOT(SPI5) == 0);
LL_SPI_ClearFlag_EOT(SPI5);
LL_SPI_ClearFlag_TXTF(SPI5);
LL_SPI_SuspendMasterTransfer(SPI5);
LL_SPI_Disable(SPI5);
SPI5 使用 PLL4Q。
PLL4Q = 66Mhz -> 66/2 -> 33Mhz
SPI5的时钟应该工作在33Mhz,但用实际示波器检查的结果是2.6Mhz左右。
当我在工程模式下用示波器检查时,它大约是 33Mhz,但在生产模式 (Linux) 下是 2.6Mhz。
我的时钟或 SPI5 设置有误吗?
下面是开发环境。
电路板:使用 stm32mp151c 芯片的定制电路板。
操作系统:生态系统 2.1.0 (202-11-12)
集成开发环境:STM32CubeIDE
调试器:STLINK-V3SET
请告诉我一个解决方案。
0