MCUXpresso SDK API Reference Manual  Rev. 0
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 100Mhz. From software control, three mainly function blocks are related:

  1. Baisc controller a.Timing control with programmable delay elements. b.Module enable.
  2. Dynamic memory controller
  3. 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

Data Structures

struct  emc_dynamic_timing_config_t
 EMC dynamic timing/delay configure structure. More...
 
struct  emc_dynamic_chip_config_t
 EMC dynamic memory controller independent chip configuration structure. More...
 
struct  emc_static_chip_config_t
 EMC static memory controller independent chip configuration structure. More...
 
struct  emc_basic_config_t
 EMC module basic configuration structure. More...
 

Macros

#define EMC_STATIC_MEMDEV_NUM   (4U)
 Define the chip numbers for dynamic and static memory devices. More...
 

Enumerations

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

Driver version

#define FSL_EMC_DRIVER_VERSION   (MAKE_VERSION(2, 0, 0))
 EMC driver version 2.0.0. 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_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...
 

Field Documentation

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.

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_t::chipIndex
emc_dynamic_device_t emc_dynamic_chip_config_t::dynamicDevice

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

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_t::memWidth
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.

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_t::endian
emc_fbclk_src_t emc_basic_config_t::fbClkSrc
uint8_t emc_basic_config_t::emcClkDiv

Macro Definition Documentation

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

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