generated from Embedded_Projects/LPCXpresso55S69_Template
53 lines
1.2 KiB
C
53 lines
1.2 KiB
C
/* SDK drivers */
|
|
#include "fsl_spi.h"
|
|
|
|
/* Private */
|
|
#include "app_lspi_flash.h"
|
|
|
|
#define APP_LSPI_FLASH_FREQ (10 * 1000 * 1000)
|
|
|
|
static int app_lspi_flash_identify(void) {
|
|
uint8_t tx_buf[4] = {0x9F, 0x00, 0x00, 0x00};
|
|
uint8_t rx_buf[4];
|
|
|
|
spi_transfer_t xfer = {
|
|
.txData = tx_buf,
|
|
.rxData = rx_buf,
|
|
.dataSize = 4,
|
|
.configFlags = kSPI_FrameAssert,
|
|
};
|
|
|
|
if (SPI_MasterTransferBlocking(SPI8, &xfer) != kStatus_Success) {
|
|
return -1;
|
|
}
|
|
|
|
/* TODO: Check for Winbond Mfg. ID for now. */
|
|
if (rx_buf[1] != 0xEF) {
|
|
return -2;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
int app_lspi_flash_init(void) {
|
|
/* Force re-compute the PLL frequency based on the configuration */
|
|
CLOCK_GetPLL0OutClockRate(true);
|
|
|
|
CLOCK_AttachClk(kMAIN_CLK_to_HSLSPI);
|
|
|
|
spi_master_config_t lspi_config;
|
|
SPI_MasterGetDefaultConfig(&lspi_config);
|
|
|
|
lspi_config.baudRate_Bps = APP_LSPI_FLASH_FREQ;
|
|
lspi_config.sselNum = kSPI_Ssel1;
|
|
|
|
if (SPI_MasterInit(SPI8, &lspi_config, CLOCK_GetCoreSysClkFreq()) != kStatus_Success) {
|
|
return -1;
|
|
}
|
|
|
|
if (app_lspi_flash_identify() != 0) {
|
|
return -2;
|
|
}
|
|
|
|
return 0;
|
|
} |