最近在用MDK5.26系统自带的NXP的底层驱动,使用的过程中发现有些不合适自己的使用,所以就做一些相应的修改!
1、引脚配置初始化部分,配置了SCK, MISO,MOSI,唯独漏了SSEL。虽然SSEL可以直接通过引脚编写控制,不过在代码里修改添加一下这条命令也不是太繁琐。就改一下,做个记录吧。
static int32_t SSPx_Initialize (ARM_SPI_SignalEvent_t cb_event, SSP_RESOURCES *ssp) {
if (ssp->info->state & SSP_INITIALIZED) { return ARM_DRIVER_OK; }
// Initialize SSP Run-Time Resources
ssp->info->cb_event = cb_event;
ssp->info->status.busy = 0U;
ssp->info->status.data_lost = 0U;
ssp->info->status.mode_fault = 0U;
// Clear transfer information
memset(ssp->xfer, 0, sizeof(SSP_TRANSFER_INFO));
#if defined (LPC175x_6x)
PIN_Configure (ssp->pin.sck->Portnum, ssp->pin.sck->Pinnum, ssp->pin.sck_func, PIN_PINMODE_PULLUP, PIN_PINMODE_NORMAL);
if (ssp->pin.miso != NULL) {
PIN_Configure (ssp->pin.miso->Portnum, ssp->pin.miso->Pinnum, ssp->pin.miso_func, PIN_PINMODE_PULLUP, PIN_PINMODE_NORMAL);
}
if (ssp->pin.mosi != NULL) {
PIN_Configure (ssp->pin.mosi->Portnum, ssp->pin.mosi->Pinnum, ssp->pin.mosi_func, PIN_PINMODE_PULLUP, PIN_PINMODE_NORMAL);
}
#elif defined (LPC177x_8x)
PIN_Configure (ssp->pin.sck->Portnum, ssp->pin.sck->Pinnum, ssp->pin.sck_func | IOCON_HYS_ENABLE | ((ssp->pin.sck_io_wa) ?
(IOCON_10ns_FILTER_DISABLE | IOCON_DIGITIAL_MODE) : IOCON_MODE_PULLUP));
if (ssp->pin.miso != NULL) {
PIN_Configure (ssp->pin.miso->Portnum, ssp->pin.miso->Pinnum, ssp->pin.miso_func | IOCON_HYS_ENABLE | ((ssp->pin.miso_io_wa) ?
(IOCON_10ns_FILTER_DISABLE | IOCON_DIGITIAL_MODE) : IOCON_MODE_PULLUP));
}
if (ssp->pin.mosi != NULL) {
PIN_Configure (ssp->pin.mosi->Portnum, ssp->pin.mosi->Pinnum, ssp->pin.mosi_func | IOCON_HYS_ENABLE | ((ssp->pin.mosi_io_wa) ?
(IOCON_10ns_FILTER_DISABLE | IOCON_DIGITIAL_MODE) : IOCON_MODE_PULLUP));
}
#endif
// Configure DMA if it will be used
if (ssp->dma.tx_en || ssp->dma.rx_en) { GPDMA_Initialize (); }
if (ssp->dma.tx_en) { GPDMA_PeripheralSelect (ssp->dma.tx_req, 0U); }
if (ssp->dma.rx_en) { GPDMA_PeripheralSelect (ssp->dma.rx_req, 0U); }
ssp->info->state = SSP_INITIALIZED; // SSP is initialized
return ARM_DRIVER_OK;
}
修改为
static int32_t SSPx_Initialize (ARM_SPI_SignalEvent_t cb_event, SSP_RESOURCES *ssp) {
if (ssp->info->state & SSP_INITIALIZED) { return ARM_DRIVER_OK; }
// Initialize SSP Run-Time Resources
ssp->info->cb_event = cb_event;
ssp->info->status.busy = 0U;
ssp->info->status.data_lost = 0U;
ssp->info->status.mode_fault = 0U;
// Clear transfer information
memset(ssp->xfer, 0, sizeof(SSP_TRANSFER_INFO));
#if defined (LPC175x_6x)
PIN_Configure (ssp->pin.sck->Portnum, ssp->pin.sck->Pinnum, ssp->pin.sck_func, PIN_PINMODE_PULLUP, PIN_PINMODE_NORMAL);
if (ssp->pin.ssel != NULL){
PIN_Configure (ssp->pin.ssel->Portnum, ssp->pin.ssel->Pinnum, ssp->pin.ssel_func, PIN_PINMODE_PULLUP, PIN_PINMODE_NORMAL);
}
if (ssp->pin.miso != NULL) {
PIN_Configure (ssp->pin.miso->Portnum, ssp->pin.miso->Pinnum, ssp->pin.miso_func, PIN_PINMODE_PULLUP, PIN_PINMODE_NORMAL);
}
if (ssp->pin.mosi != NULL) {
PIN_Configure (ssp->pin.mosi->Portnum, ssp->pin.mosi->Pinnum, ssp->pin.mosi_func, PIN_PINMODE_PULLUP, PIN_PINMODE_NORMAL);
}
#elif defined (LPC177x_8x)
PIN_Configure (ssp->pin.sck->Portnum, ssp->pin.sck->Pinnum, ssp->pin.sck_func | IOCON_HYS_ENABLE | ((ssp->pin.sck_io_wa) ?
(IOCON_10ns_FILTER_DISABLE | IOCON_DIGITIAL_MODE) : IOCON_MODE_PULLUP));
if (ssp->pin.miso != NULL) {
PIN_Configure (ssp->pin.miso->Portnum, ssp->pin.miso->Pinnum, ssp->pin.miso_func | IOCON_HYS_ENABLE | ((ssp->pin.miso_io_wa) ?
(IOCON_10ns_FILTER_DISABLE | IOCON_DIGITIAL_MODE) : IOCON_MODE_PULLUP));
}
if (ssp->pin.mosi != NULL) {
PIN_Configure (ssp->pin.mosi->Portnum, ssp->pin.mosi->Pinnum, ssp->pin.mosi_func | IOCON_HYS_ENABLE | ((ssp->pin.mosi_io_wa) ?
(IOCON_10ns_FILTER_DISABLE | IOCON_DIGITIAL_MODE) : IOCON_MODE_PULLUP));
}
if (ssp->pin.ssel != NULL) {
PIN_Configure (ssp->pin.ssel->Portnum, ssp->pin.ssel->Pinnum, ssp->pin.ssel_func | IOCON_HYS_ENABLE | ((ssp->pin.ssel_io_wa) ?
(IOCON_10ns_FILTER_DISABLE | IOCON_DIGITIAL_MODE) : IOCON_MODE_PULLUP));
}
#endif
// Configure DMA if it will be used
if (ssp->dma.tx_en || ssp->dma.rx_en) { GPDMA_Initialize (); }
if (ssp->dma.tx_en) { GPDMA_PeripheralSelect (ssp->dma.tx_req, 0U); }
if (ssp->dma.rx_en) { GPDMA_PeripheralSelect (ssp->dma.rx_req, 0U); }
ssp->info->state = SSP_INITIALIZED; // SSP is initialized
return ARM_DRIVER_OK;
}