LPCOpen SPIFI FLASH Library (LPCSPIFILIB)
Documentation for the LPCSPIFILIB library
|
The LPCSPIFILIB Library provides functions to control the SPIFI controller and handle device family protocol for a number of different devices.
The LPCSPIFILIB Library does not do the following functions:
SPIFI pin muxing
Setting up pin muxing is unique per board and chip and needs to be performed outside the library. This should be setup prior to initializing the LPCSPIFILIB library.
Example SPIFI FLASH interface setup for the LPC18xx/43xx for QUAD FLASH using LPCOpen.
#include "board.h" /* SPIFI high speed pin mode setup */ STATIC const PINMUX_GRP_T spifipinmuxing[] = { {0x3, 3, (SCU_PINIO_FAST | SCU_MODE_FUNC3)}, /* SPIFI CLK */ {0x3, 4, (SCU_PINIO_FAST | SCU_MODE_FUNC3)}, /* SPIFI D3 */ {0x3, 5, (SCU_PINIO_FAST | SCU_MODE_FUNC3)}, /* SPIFI D2 */ {0x3, 6, (SCU_PINIO_FAST | SCU_MODE_FUNC3)}, /* SPIFI D1 */ {0x3, 7, (SCU_PINIO_FAST | SCU_MODE_FUNC3)}, /* SPIFI D0 */ {0x3, 8, (SCU_PINIO_FAST | SCU_MODE_FUNC3)} /* SPIFI CS/SSEL */ }; /* Setup SPIFI FLASH pin muxing (QUAD) */ Chip_SCU_SetPinMuxing(spifipinmuxing, sizeof(spifipinmuxing) / sizeof(PINMUX_GRP_T));
SPIFI clock setup prior to initializing the LPCSPIFILIB library
Setting up the SPIFI controller/FLASH interface clock varies per platform and chip. Some parts allow different clock sources and many different rates for the SPIFI controller. This should be setup prior to initializing the LPCSPIFILIB library.
Example SPIFI controller clock setup for the LPC18xx/43xx. The clock is setup to a low clock rate for initial part detection to allow use with slower parts.
/* SPIFI base clock will be based on the main PLL rate and a divider */ uint32_t spifiBaseClockRate = Chip_Clock_GetClockInputHz(CLKIN_MAINPLL); /* Setup SPIFI clock to run around 15Mhz. Use divider E for this, as it allows higher divider values up to 256 maximum) */ Chip_Clock_SetDivider(CLK_IDIV_E, CLKIN_MAINPLL, (1 + (spifiBaseClockRate / 15000000))); Chip_Clock_SetBaseClock(CLK_BASE_SPIFI, CLKIN_IDIVE, true, false);
SPIFI clock setup after initializing the LPCSPIFILIB library
After the device is detected and the device specific initialization is called, the SPIFI controller clock can be updated to the maximum clock rate that driver can use for the detected device.
/* Get maximum clock rate the detected device can support */ maxSpifiClock = spifiDevGetInfo(pSpifi, SPIFI_INFO_MAXCLOCK); /* Setup SPIFI clock to at the maximum interface rate the detected device can use. This should be done after device init. */ Chip_Clock_SetDivider(CLK_IDIV_E, CLKIN_MAINPLL, (1 + (spifiBaseClockRate / maxSpifiClock)));