MCUXpresso SDK API Reference Manual  Rev 2.16.000
NXP Semiconductors
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
EMC: External Memory Controller Driver

Overview

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 100 MHz. From software control, three main function blocks are related:

  1. Basic controller a. Timing control with programmable delay elements. b. Module enable.
  2. Dynamic memory controller
  3. Static memory controller

When using EMC, first call the EMC_Init() function to do module basic initialize. Note that this function enables the module clock, configures the module system level clock/delay, and enables the module. It is the initialization of the basic controller. To initialize the external dynamic memory. The EMC_DynamicMemInit() function should be called before you can access any dynamic memory. The EMC_DynamicMemInit() function is provided to initialize the Static memory controller and it should be called when you want to access any exterenal static memory. The function EMC_Deinit() deinitializes the EMC module.
EMC Provides many basic operation 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 does 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 and 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

Data Structures

struct  _emc_dynamic_timing_config
 EMC dynamic timing/delay configure structure. More...
 
struct  _emc_dynamic_chip_config
 EMC dynamic memory controller independent chip configuration structure. More...
 
struct  _emc_static_chip_config
 EMC static memory controller independent chip configuration structure. More...
 
struct  _emc_basic_config
 EMC module basic configuration structure. More...
 

Macros

#define EMC_STATIC_MEMDEV_NUM   (4U)
 Define the chip numbers for dynamic and static memory devices. More...
 
#define EMC_SDRAM_NOP_DELAY_US   (100U)
 EDMA_SDRAM NOP command wait us.
 
#define EMC_SDRAM_PRECHARGE_DELAY_US   (100U)
 EDMA_SDRAM precharge command wait us.
 
#define EMC_SDRAM_AUTO_REFRESH_DELAY_US   (50U)
 EDMA_SDRAM auto refresh wait us.
 

Typedefs

typedef enum _emc_static_memwidth emc_static_memwidth_t
 Define EMC memory width for static memory device.
 
typedef enum
_emc_static_special_config 
emc_static_special_config_t
 Define EMC static configuration.
 
typedef enum _emc_dynamic_device emc_dynamic_device_t
 EMC dynamic memory device. More...
 
typedef enum _emc_dynamic_read emc_dynamic_read_t
 EMC dynamic read strategy. More...
 
typedef enum _emc_endian_mode emc_endian_mode_t
 EMC endian mode. More...
 
typedef enum _emc_fbclk_src emc_fbclk_src_t
 EMC Feedback clock input source select. More...
 
typedef struct
_emc_dynamic_timing_config 
emc_dynamic_timing_config_t
 EMC dynamic timing/delay configure structure. More...
 
typedef struct
_emc_dynamic_chip_config 
emc_dynamic_chip_config_t
 EMC dynamic memory controller independent chip configuration structure. More...
 
typedef struct
_emc_static_chip_config 
emc_static_chip_config_t
 EMC static memory controller independent chip configuration structure.
 
typedef struct _emc_basic_config emc_basic_config_t
 EMC module basic configuration structure. More...
 

Enumerations

enum  _emc_static_memwidth {
  kEMC_8BitWidth = 0x0U,
  kEMC_16BitWidth,
  kEMC_32BitWidth
}
 Define EMC memory width for static memory device. More...
 
enum  _emc_static_special_config {
  kEMC_AsynchronosPageEnable = 0x0008U,
  kEMC_ActiveHighChipSelect = 0x0040U,
  kEMC_ByteLaneStateAllLow = 0x0080U,
  kEMC_ExtWaitEnable = 0x0100U,
  kEMC_BufferEnable = 0x80000U
}
 Define EMC static configuration. More...
 
enum  _emc_dynamic_device {
  kEMC_Sdram = 0x0U,
  kEMC_Lpsdram
}
 EMC dynamic memory device. More...
 
enum  _emc_dynamic_read {
  kEMC_NoDelay = 0x0U,
  kEMC_Cmddelay,
  kEMC_CmdDelayPulseOneclk,
  kEMC_CmddelayPulsetwoclk
}
 EMC dynamic read strategy. More...
 
enum  _emc_endian_mode {
  kEMC_LittleEndian = 0x0U,
  kEMC_BigEndian
}
 EMC endian mode. More...
 
enum  _emc_fbclk_src {
  kEMC_IntloopbackEmcclk = 0U,
  kEMC_EMCFbclkInput
}
 EMC Feedback clock input source select. More...
 

Driver version

#define FSL_EMC_DRIVER_VERSION   (MAKE_VERSION(2, 0, 4))
 EMC driver version. More...
 

EMC Initialize and de-initialize opeartion

void EMC_Init (EMC_Type *base, emc_basic_config_t *config)
 Initializes the basic for EMC. More...
 
void EMC_DynamicMemInit (EMC_Type *base, emc_dynamic_timing_config_t *timing, emc_dynamic_chip_config_t *config, uint32_t totalChips)
 Initializes the dynamic memory controller. More...
 
void EMC_StaticMemInit (EMC_Type *base, uint32_t *extWait_Ns, emc_static_chip_config_t *config, uint32_t totalChips)
 Initializes the static memory controller. More...
 
void EMC_Deinit (EMC_Type *base)
 Deinitializes the EMC module and gates the clock. More...
 

EMC Basic Operation

static void EMC_Enable (EMC_Type *base, bool enable)
 Enables/disables the EMC module. More...
 
static void EMC_EnableDynamicMemControl (EMC_Type *base, bool enable)
 Enables/disables the EMC Dynaimc memory controller. More...
 
static void EMC_MirrorChipAddr (EMC_Type *base, bool enable)
 Enables/disables the EMC address mirror. More...
 
static void EMC_EnterSelfRefreshCommand (EMC_Type *base, bool enable)
 Enter the self-refresh mode for dynamic memory controller. More...
 
static bool EMC_IsInSelfrefreshMode (EMC_Type *base)
 Get the operating mode of the EMC. More...
 
static void EMC_EnterLowPowerMode (EMC_Type *base, bool enable)
 Enter/exit the low-power mode. More...
 

Data Structure Documentation

struct _emc_dynamic_timing_config

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...
 

Field Documentation

uint32_t _emc_dynamic_timing_config::refreshPeriod_Nanosec
uint32_t _emc_dynamic_timing_config::tRp_Ns
uint32_t _emc_dynamic_timing_config::tRas_Ns
uint32_t _emc_dynamic_timing_config::tSrex_Ns
uint32_t _emc_dynamic_timing_config::tApr_Ns
uint32_t _emc_dynamic_timing_config::tDal_Ns
uint32_t _emc_dynamic_timing_config::tWr_Ns
uint32_t _emc_dynamic_timing_config::tRc_Ns
uint32_t _emc_dynamic_timing_config::tRfc_Ns
uint32_t _emc_dynamic_timing_config::tXsr_Ns
uint32_t _emc_dynamic_timing_config::tRrd_Ns
uint8_t _emc_dynamic_timing_config::tMrd_Nclk
struct _emc_dynamic_chip_config

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.

Data Fields

uint8_t chipIndex
 Chip Index, range from 0 ~ EMC_DYNAMIC_MEMDEV_NUM - 1. More...
 
emc_dynamic_device_t dynamicDevice
 All chips shall use the same device setting. More...
 
uint8_t rAS_Nclk
 Active to read/write delay tRCD. More...
 
uint16_t sdramModeReg
 Sdram mode register setting. More...
 
uint16_t sdramExtModeReg
 Used for low-power sdram device. More...
 
uint8_t devAddrMap
 dynamic device address mapping, choose the address mapping for your specific device. More...
 

Field Documentation

uint8_t _emc_dynamic_chip_config::chipIndex
emc_dynamic_device_t _emc_dynamic_chip_config::dynamicDevice

mixed use are not supported.

uint8_t _emc_dynamic_chip_config::rAS_Nclk
uint16_t _emc_dynamic_chip_config::sdramModeReg
uint16_t _emc_dynamic_chip_config::sdramExtModeReg

The extended mode register.

uint8_t _emc_dynamic_chip_config::devAddrMap
struct _emc_static_chip_config

Data Fields

emc_static_memwidth_t memWidth
 Memory width. More...
 
uint32_t specailConfig
 Static configuration,a logical OR of "emc_static_special_config_t". More...
 
uint32_t tWaitWriteEn_Ns
 The delay form chip select to write enable in unit of nanosecond. More...
 
uint32_t tWaitOutEn_Ns
 The delay from chip selcet to output enable in unit of nanosecond. More...
 
uint32_t tWaitReadNoPage_Ns
 In No-page mode, the delay from chip select to read access in unit of nanosecond. More...
 
uint32_t tWaitReadPage_Ns
 In page mode, the read after the first read wait states in unit of nanosecond. More...
 
uint32_t tWaitWrite_Ns
 The delay from chip select to write access in unit of nanosecond. More...
 
uint32_t tWaitTurn_Ns
 The Bus turn-around time in unit of nanosecond. More...
 

Field Documentation

emc_static_memwidth_t _emc_static_chip_config::memWidth
uint32_t _emc_static_chip_config::specailConfig
uint32_t _emc_static_chip_config::tWaitWriteEn_Ns
uint32_t _emc_static_chip_config::tWaitOutEn_Ns
uint32_t _emc_static_chip_config::tWaitReadNoPage_Ns
uint32_t _emc_static_chip_config::tWaitReadPage_Ns
uint32_t _emc_static_chip_config::tWaitWrite_Ns
uint32_t _emc_static_chip_config::tWaitTurn_Ns
struct _emc_basic_config

Defines the static memory controller configure structure and uses the EMC_Init() function to make necessary initializations.

Data Fields

emc_endian_mode_t endian
 Endian mode . More...
 
emc_fbclk_src_t fbClkSrc
 The feedback clock source. More...
 
uint8_t emcClkDiv
 EMC_CLK = AHB_CLK / (emc_clkDiv + 1). More...
 

Field Documentation

emc_endian_mode_t _emc_basic_config::endian
emc_fbclk_src_t _emc_basic_config::fbClkSrc
uint8_t _emc_basic_config::emcClkDiv

Macro Definition Documentation

#define FSL_EMC_DRIVER_VERSION   (MAKE_VERSION(2, 0, 4))
#define EMC_STATIC_MEMDEV_NUM   (4U)

Typedef Documentation

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.

Defines the static memory controller configure structure and uses the EMC_Init() function to make necessary initializations.

Enumeration Type Documentation

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.

Function Documentation

void EMC_Init ( EMC_Type *  base,
emc_basic_config_t config 
)

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
baseEMC peripheral base address.
configThe EMC basic configuration.
void EMC_DynamicMemInit ( EMC_Type *  base,
emc_dynamic_timing_config_t timing,
emc_dynamic_chip_config_t config,
uint32_t  totalChips 
)

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
baseEMC peripheral base address.
timingThe 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.
configThe 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".
totalChipsThe 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
baseEMC peripheral base address.
extWait_NsThe extended wait timeout or the read/write transfer time. This is common for all static memory chips and set with NULL if not required.
configThe 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".
totalChipsThe 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
baseEMC peripheral base address.
static void EMC_Enable ( EMC_Type *  base,
bool  enable 
)
inlinestatic
Parameters
baseEMC peripheral base address.
enableTrue enable EMC module, false disable.
static void EMC_EnableDynamicMemControl ( EMC_Type *  base,
bool  enable 
)
inlinestatic
Parameters
baseEMC peripheral base address.
enableTrue 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
baseEMC peripheral base address.
enableTrue 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
baseEMC peripheral base address.
enableTrue 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
baseEMC 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
baseEMC peripheral base address.
enableTrue Enter the low-power mode, false exit low-power mode and return to normal mode.