The MCUXpresso SDK provides a peripheral driver for the External Memory Controller block of MCUXpresso SDK devices.
The EMC driver is provides support for synchronous static memory devices such as RAM, rom and flash, in addition to dynamic memories such as single data rate SDRAM with an SDRAM clock of up to 100Mhz. From software control, three mainly function blocks are related:
- Baisc controller a.Timing control with programmable delay elements. b.Module enable.
- Dynamic memory controller
- Static memory controller
When using EMC, call EMC_Init() function firstly to do module basic initialize. Note that this function enables the module clock, configure the module system level clock/delay and enable the module. It is the initialization of the Basic controller. To initialize the external dynamic memory. The EMC_DynamicMemInit() function shall be called before you can access any dynamic memory. The EMC_DynamicMemInit() function is provided to initialize the Static memory controller and it shall be called when you want to access any exterenal static memory. The function EMC_Deinit() deinitializes the EMC module.
EMC Provides many basic opeartion APIs for application to do flexible control. The function EMC_Enable() is provided to enable/disable the EMC module. The function EMC_EnableDynamicMemControl() is provided to enable/disble the EMC dynamic memory controller. The function EMC_SendDynamicMemCommand() is provided to send the NOP/PRECHARGE/MODE/SELF-REFRESH commands. Call EMC_EnterLowPowerMode() to enter or exit the low-power mode. There is a calibration function EMC_DelayCalibrate() which do calibaration of the EMC programmable delays by providing a real-time representation of the values of those deays.
Typical use case
This example shows how to use the EMC to initialize the external 64M 16-bit bus width SDRAM chip (4 banks nd 9 columns). The SDRAM is on the CS0.
First, initialize the EMC Controller. Refer to the driver examples codes located at <SDK_ROOT>/boards/<BOARD>/driver_examples/emc For the APP_DelayCal(): The system configure provided the command and feedback clock delay calibration for EMC EMCDYCTRL and EMCCAL. Application may require the change for these two system configure register. please use the recommded work flow to choose the best delay.
Refer to the driver examples codes located at <SDK_ROOT>/boards/<BOARD>/driver_examples/emc
|
enum | emc_static_memwidth_t {
kEMC_8BitWidth = 0x0U,
kEMC_16BitWidth,
kEMC_32BitWidth
} |
| Define EMC memory width for static memory device. More...
|
|
enum | emc_static_special_config_t {
kEMC_AsynchronosPageEnable = 0x0008U,
kEMC_ActiveHighChipSelect = 0x0040U,
kEMC_ByteLaneStateAllLow = 0x0080U,
kEMC_ExtWaitEnable = 0x0100U,
kEMC_BufferEnable = 0x80000U
} |
| Define EMC static configuration. More...
|
|
enum | emc_dynamic_device_t {
kEMC_Sdram = 0x0U,
kEMC_Lpsdram
} |
| EMC dynamic memory device. More...
|
|
enum | emc_dynamic_read_t {
kEMC_NoDelay = 0x0U,
kEMC_Cmddelay,
kEMC_CmdDelayPulseOneclk,
kEMC_CmddelayPulsetwoclk
} |
| EMC dynamic read strategy. More...
|
|
enum | emc_endian_mode_t {
kEMC_LittleEndian = 0x0U,
kEMC_BigEndian
} |
| EMC endian mode. More...
|
|
enum | emc_fbclk_src_t {
kEMC_IntloopbackEmcclk = 0U,
kEMC_EMCFbclkInput
} |
| EMC Feedback clock input source select. More...
|
|
struct emc_dynamic_timing_config_t |
Data Fields |
uint32_t | refreshPeriod_Nanosec |
| The refresh period in unit of nanosecond. More...
|
|
uint32_t | tRp_Ns |
| Precharge command period in unit of nanosecond. More...
|
|
uint32_t | tRas_Ns |
| Active to precharge command period in unit of nanosecond. More...
|
|
uint32_t | tSrex_Ns |
| Self-refresh exit time in unit of nanosecond. More...
|
|
uint32_t | tApr_Ns |
| Last data out to active command time in unit of nanosecond. More...
|
|
uint32_t | tDal_Ns |
| Data-in to active command in unit of nanosecond. More...
|
|
uint32_t | tWr_Ns |
| Write recovery time in unit of nanosecond. More...
|
|
uint32_t | tRc_Ns |
| Active to active command period in unit of nanosecond. More...
|
|
uint32_t | tRfc_Ns |
| Auto-refresh period and auto-refresh to active command period in unit of nanosecond. More...
|
|
uint32_t | tXsr_Ns |
| Exit self-refresh to active command time in unit of nanosecond. More...
|
|
uint32_t | tRrd_Ns |
| Active bank A to active bank B latency in unit of nanosecond. More...
|
|
uint8_t | tMrd_Nclk |
| Load mode register to active command time in unit of EMCCLK cycles. More...
|
|
uint32_t emc_dynamic_timing_config_t::refreshPeriod_Nanosec |
uint32_t emc_dynamic_timing_config_t::tRp_Ns |
uint32_t emc_dynamic_timing_config_t::tRas_Ns |
uint32_t emc_dynamic_timing_config_t::tSrex_Ns |
uint32_t emc_dynamic_timing_config_t::tApr_Ns |
uint32_t emc_dynamic_timing_config_t::tDal_Ns |
uint32_t emc_dynamic_timing_config_t::tWr_Ns |
uint32_t emc_dynamic_timing_config_t::tRc_Ns |
uint32_t emc_dynamic_timing_config_t::tRfc_Ns |
uint32_t emc_dynamic_timing_config_t::tXsr_Ns |
uint32_t emc_dynamic_timing_config_t::tRrd_Ns |
uint8_t emc_dynamic_timing_config_t::tMrd_Nclk |
struct emc_dynamic_chip_config_t |
Please take refer to the address mapping table in the RM in EMC chapter when you set the "devAddrMap". Choose the right Bit 14 Bit12 ~ Bit 7 group in the table according to the bus width/banks/row/colum length for you device. Set devAddrMap with the value make up with the seven bits (bit14 bit12 ~ bit 7) and inset the bit 13 with 0. for example, if the bit 14 and bit12 ~ bit7 is 1000001 is choosen according to the 32bit high-performance bus width with 2 banks, 11 row lwngth, 8 column length. Set devAddrMap with 0x81.
uint8_t emc_dynamic_chip_config_t::chipIndex |
mixed use are not supported.
uint8_t emc_dynamic_chip_config_t::rAS_Nclk |
uint16_t emc_dynamic_chip_config_t::sdramModeReg |
uint16_t emc_dynamic_chip_config_t::sdramExtModeReg |
The extended mode register.
uint8_t emc_dynamic_chip_config_t::devAddrMap |
struct emc_static_chip_config_t |
uint32_t emc_static_chip_config_t::specailConfig |
uint32_t emc_static_chip_config_t::tWaitWriteEn_Ns |
uint32_t emc_static_chip_config_t::tWaitOutEn_Ns |
uint32_t emc_static_chip_config_t::tWaitReadNoPage_Ns |
uint32_t emc_static_chip_config_t::tWaitReadPage_Ns |
uint32_t emc_static_chip_config_t::tWaitWrite_Ns |
uint32_t emc_static_chip_config_t::tWaitTurn_Ns |
struct emc_basic_config_t |
Defines the static memory controller configure structure and uses the EMC_Init() function to make necessary initializations.
uint8_t emc_basic_config_t::emcClkDiv |
#define EMC_STATIC_MEMDEV_NUM (4U) |
Enumerator |
---|
kEMC_8BitWidth |
8 bit memory width.
|
kEMC_16BitWidth |
16 bit memory width.
|
kEMC_32BitWidth |
32 bit memory width.
|
Enumerator |
---|
kEMC_AsynchronosPageEnable |
Enable the asynchronous page mode.
page length four.
|
kEMC_ActiveHighChipSelect |
Chip select active high.
|
kEMC_ByteLaneStateAllLow |
Reads/writes the respective valuie bits in BLS3:0 are low.
|
kEMC_ExtWaitEnable |
Extended wait enable.
|
kEMC_BufferEnable |
Buffer enable.
|
Enumerator |
---|
kEMC_Sdram |
Dynamic memory device: SDRAM.
|
kEMC_Lpsdram |
Dynamic memory device: Low-power SDRAM.
|
Enumerator |
---|
kEMC_NoDelay |
No delay.
|
kEMC_Cmddelay |
Command delayed strategy, using EMCCLKDELAY.
|
kEMC_CmdDelayPulseOneclk |
Command delayed strategy pluse one clock cycle using EMCCLKDELAY.
|
kEMC_CmddelayPulsetwoclk |
Command delayed strategy pulse two clock cycle using EMCCLKDELAY.
|
Enumerator |
---|
kEMC_LittleEndian |
Little endian mode.
|
kEMC_BigEndian |
Big endian mode.
|
Enumerator |
---|
kEMC_IntloopbackEmcclk |
Use the internal loop back from EMC_CLK output.
|
kEMC_EMCFbclkInput |
Use the external EMC_FBCLK input.
|
This function ungates the EMC clock, initializes the emc system configure and enable the EMC module. This function must be called in the first step to initialize the external memory.
- Parameters
-
base | EMC peripheral base address. |
config | The EMC basic configuration. |
This function initializes the dynamic memory controller in external memory controller. This function must be called after EMC_Init and before accessing the external dynamic memory.
- Parameters
-
base | EMC peripheral base address. |
timing | The timing and latency for dynamica memory controller setting. It shall be used for all dynamica memory chips, threfore the worst timing value for all used chips must be given. |
configure | The EMC dynamic memory controller chip independent configuration pointer. This configuration pointer is actually pointer to a configration array. the array number depends on the "totalChips". |
totalChips | The total dynamic memory chip numbers been used or the length of the "emc_dynamic_chip_config_t" type memory. |
void EMC_StaticMemInit |
( |
EMC_Type * |
base, |
|
|
uint32_t * |
extWait_Ns, |
|
|
emc_static_chip_config_t * |
config, |
|
|
uint32_t |
totalChips |
|
) |
| |
This function initializes the static memory controller in external memory controller. This function must be called after EMC_Init and before accessing the external static memory.
- Parameters
-
base | EMC peripheral base address. |
extWait_Ns | The extended wait timeout or the read/write transfer time. This is common for all static memory chips and set with NULL if not required. |
configure | The EMC static memory controller chip independent configuration pointer. This configuration pointer is actually pointer to a configration array. the array number depends on the "totalChips". |
totalChips | The total static memory chip numbers been used or the length of the "emc_static_chip_config_t" type memory. |
void EMC_Deinit |
( |
EMC_Type * |
base | ) |
|
This function gates the EMC controller clock. As a result, the EMC module doesn't work after calling this function.
- Parameters
-
base | EMC peripheral base address. |
static void EMC_Enable |
( |
EMC_Type * |
base, |
|
|
bool |
enable |
|
) |
| |
|
inlinestatic |
- Parameters
-
base | EMC peripheral base address. |
enable | True enable EMC module, false disable. |
static void EMC_EnableDynamicMemControl |
( |
EMC_Type * |
base, |
|
|
bool |
enable |
|
) |
| |
|
inlinestatic |
- Parameters
-
base | EMC peripheral base address. |
enable | True enable EMC dynamic memory controller, false disable. |
static void EMC_MirrorChipAddr |
( |
EMC_Type * |
base, |
|
|
bool |
enable |
|
) |
| |
|
inlinestatic |
Enable the address mirror the EMC_CS1is mirrored to both EMC_CS0 and EMC_DYCS0 memory areas. Disable the address mirror enables EMC_cS0 and EMC_DYCS0 memory to be accessed.
- Parameters
-
base | EMC peripheral base address. |
enable | True enable the address mirror, false disable the address mirror. |
static void EMC_EnterSelfRefreshCommand |
( |
EMC_Type * |
base, |
|
|
bool |
enable |
|
) |
| |
|
inlinestatic |
This function provided self-refresh mode enter or exit for application.
- Parameters
-
base | EMC peripheral base address. |
enable | True enter the self-refresh mode, false to exit self-refresh and enter the normal mode. |
static bool EMC_IsInSelfrefreshMode |
( |
EMC_Type * |
base | ) |
|
|
inlinestatic |
This function can be used to get the operating mode of the EMC.
- Parameters
-
base | EMC peripheral base address. |
- Returns
- The EMC in self-refresh mode if true, else in normal mode.
static void EMC_EnterLowPowerMode |
( |
EMC_Type * |
base, |
|
|
bool |
enable |
|
) |
| |
|
inlinestatic |
- Parameters
-
base | EMC peripheral base address. |
enable | True Enter the low-power mode, false exit low-power mode and return to normal mode. |