首先是JTAG 和SWD的问题,假如用习惯ST cubemx HAL库的小伙伴是不用管这个的,可以直接引脚复用配置。JTAG :TDI TDO CLK DAT RST SWD: CLK DAT RST原则上可以省掉
HC32F460默认是JTAG 模式 如果你使用SWD模式 然后需要使用 PB3 和PA15引脚的话,需要操作操作寄存器
/* unlock */
M4_PORT->PWPR = 0xA501u;
bM4_PORT_PSPCR_SPFE2=0; //LED1 TDI
bM4_PORT_PSPCR_SPFE3=0; //LED2 TDO
bM4_PORT_PSPCR_SPFE4=0; //PWM Time43_WL RST
/* lock */
M4_PORT->PWPR = 0xA500u;//禁用JTAG的 TDI TDO RST 释放IO
2 SPI 使用SDK 里面的NSS引脚复用,做SPI主机 做硬件flash读取是没问题的,当接外部从机传感器时,传感器示波器测试是有数据的,可是DR就是读不上来。
所以我干脆自己把NSS的复用屏蔽了,自己初始化为GPIO 然后读写的时候拉高拉低
stc_spi_init_t stcSpiInit;
stc_port_init_t stcPortInit;
MEM_ZERO_STRUCT(stcPortInit);
MEM_ZERO_STRUCT(stcSpiInit);
/* Configuration peripheral clock */
PWC_Fcg1PeriphClockCmd(SPI_UNIT_CLOCK, Enable);
stcPortInit.enPinMode = Pin_Mode_In;
stcPortInit.enExInt = Disable;
stcPortInit.enPullUp = Enable;
PORT_Init(SPI_MISO_PORT, SPI_MISO_PIN, &stcPortInit);
stcPortInit.enPinMode = Pin_Mode_Out;
stcPortInit.enExInt = Disable;
stcPortInit.enPullUp = Disable;
PORT_Init(SPI_NSS_PORT, SPI_NSS_PIN, &stcPortInit);
/* Configuration SPI pin */
PORT_SetFunc(SPI_SCK_PORT, SPI_SCK_PIN, SPI_SCK_FUNC, Disable);
// PORT_SetFunc(SPI_NSS_PORT, SPI_NSS_PIN, SPI_NSS_FUNC, Disable);
PORT_SetFunc(SPI_MOSI_PORT, SPI_MOSI_PIN, SPI_MOSI_FUNC, Disable);
PORT_SetFunc(SPI_MISO_PORT, SPI_MISO_PIN, SPI_MISO_FUNC, Disable);
/* Configuration SPI structure */
stcSpiInit.enClkDiv = SpiClkDiv8;
stcSpiInit.enFrameNumber = SpiFrameNumber1;
stcSpiInit.enDataLength = SpiDataLengthBit8;
stcSpiInit.enFirstBitPosition = SpiFirstBitPositionMSB;
stcSpiInit.enSckPolarity = SpiSckIdleLevelLow;
stcSpiInit.enSckPhase = SpiSckOddSampleEvenChange;
stcSpiInit.enReadBufferObject = SpiReadReceiverBuffer;
stcSpiInit.enWorkMode = SpiWorkMode4Line;
stcSpiInit.enTransMode = SpiTransFullDuplex;
stcSpiInit.enCommAutoSuspendEn = Disable;
stcSpiInit.enModeFaultErrorDetectEn = Disable;
stcSpiInit.enParitySelfDetectEn = Disable;
stcSpiInit.enParityEn = Disable;
stcSpiInit.enParity = SpiParityEven;
#ifdef SPI_MASTER_MODE
stcSpiInit.enMasterSlaveMode = SpiModeMaster;
stcSpiInit.stcDelayConfig.enSsSetupDelayOption = SpiSsSetupDelayCustomValue;
stcSpiInit.stcDelayConfig.enSsSetupDelayTime = SpiSsSetupDelaySck1;
stcSpiInit.stcDelayConfig.enSsHoldDelayOption = SpiSsHoldDelayCustomValue;
stcSpiInit.stcDelayConfig.enSsHoldDelayTime = SpiSsHoldDelaySck1;
stcSpiInit.stcDelayConfig.enSsIntervalTimeOption = SpiSsIntervalCustomValue;
stcSpiInit.stcDelayConfig.enSsIntervalTime = SpiSsIntervalSck6PlusPck2;
stcSpiInit.stcSsConfig.enSsValidBit = SpiSsValidChannel0;
stcSpiInit.stcSsConfig.enSs0Polarity = SpiSsLowValid;
#endif
#ifdef SPI_SLAVE_MODE
stcSpiInit.enMasterSlaveMode = SpiModeSlave;
stcSpiInit.stcSsConfig.enSsValidBit = SpiSsValidChannel0;
stcSpiInit.stcSsConfig.enSs0Polarity = SpiSsLowValid;
#endif
SPI_Init(SPI_UNIT, &stcSpiInit);
SPI_Cmd(SPI_UNIT, Enable);
目前暂时只做了一些简单的外设测试,更多问题后续记录。
————————————————
原文链接:https://blog.csdn.net/u014803614/article/details/112233785
|