Intel® Quark™ Microcontroller Software Interface  1.4.0
Intel® Quark™ Microcontroller BSP
Flash

Flash controller. More...

Data Structures

struct  qm_flash_config_t
 Flash configuration structure. More...
 

Enumerations

enum  qm_flash_region_t { QM_FLASH_REGION_OTP = 0, QM_FLASH_REGION_SYS, QM_FLASH_REGION_DATA, QM_FLASH_REGION_NUM }
 Flash region enum. More...
 
enum  qm_flash_disable_t { QM_FLASH_WRITE_ENABLE = 0, QM_FLASH_WRITE_DISABLE }
 Flash write disable / enable enum. More...
 

Functions

int qm_flash_set_config (const qm_flash_t flash, const qm_flash_config_t *const cfg)
 Configure a Flash controller. More...
 
int qm_flash_word_write (const qm_flash_t flash, const qm_flash_region_t region, uint32_t f_addr, const uint32_t data)
 Write 4 bytes of data to Flash. More...
 
int qm_flash_page_update (const qm_flash_t flash, const qm_flash_region_t reg, uint32_t f_addr, uint32_t *const page_buf, const uint32_t *const data, uint32_t len)
 Write multiple of 4 bytes of data to Flash. More...
 
int qm_flash_page_write (const qm_flash_t flash, const qm_flash_region_t region, uint32_t page_num, const uint32_t *data, uint32_t len)
 Write a flash page. More...
 
int qm_flash_page_erase (const qm_flash_t flash, const qm_flash_region_t region, uint32_t page_num)
 Erase one page of Flash. More...
 
int qm_flash_mass_erase (const qm_flash_t flash, const uint8_t include_rom)
 Perform mass erase. More...
 
int qm_flash_save_context (const qm_flash_t flash, qm_flash_context_t *const ctx)
 Save flash context. More...
 
int qm_flash_restore_context (const qm_flash_t flash, const qm_flash_context_t *const ctx)
 Restore flash context. More...
 

Detailed Description

Flash controller.

Enumeration Type Documentation

Flash write disable / enable enum.

Enumerator
QM_FLASH_WRITE_ENABLE 

Flash write enable.

QM_FLASH_WRITE_DISABLE 

Flash write disable.

Definition at line 33 of file qm_flash.h.

Flash region enum.

Enumerator
QM_FLASH_REGION_OTP 

Flash OTP region.

QM_FLASH_REGION_SYS 

Flash System region.

QM_FLASH_REGION_DATA 

Flash Data region (Quark D2000 only).

QM_FLASH_REGION_NUM 

Total number of flash regions.

Definition at line 21 of file qm_flash.h.

Function Documentation

int qm_flash_mass_erase ( const qm_flash_t  flash,
const uint8_t  include_rom 
)

Perform mass erase.

Perform mass erase on the specified flash controller. The mass erase may include the ROM region, if present and unlocked. Note: it is not possible to mass-erase the ROM portion separately.

Note
: Since this operation may take some time to complete, the caller is responsible for ensuring that the watchdog timer does not elapse in the meantime (e.g., by restarting it before calling this function).
Parameters
[in]flashFlash controller index.
[in]include_romIf set, it also erases the ROM region.
Returns
Standard errno return type for QMSI.
Return values
0on success.
Negativeerrno for possible error codes.

Definition at line 314 of file qm_flash.c.

References qm_flash_reg_t::ctrl, and qm_flash_reg_t::flash_stts.

int qm_flash_page_erase ( const qm_flash_t  flash,
const qm_flash_region_t  region,
uint32_t  page_num 
)

Erase one page of Flash.

Parameters
[in]flashFlash controller index.
[in]regionFlash region to address.
[in]page_numPage within the Flash controller to erase.
Returns
Standard errno return type for QMSI.
Return values
0on success.
Negativeerrno for possible error codes.

Definition at line 271 of file qm_flash.c.

References qm_flash_reg_t::flash_stts, qm_flash_reg_t::flash_wr_ctrl, QM_FLASH_REGION_DATA, QM_FLASH_REGION_NUM, QM_FLASH_REGION_OTP, QM_FLASH_REGION_SYS, and qm_flash_reg_t::rom_wr_ctrl.

int qm_flash_page_update ( const qm_flash_t  flash,
const qm_flash_region_t  reg,
uint32_t  f_addr,
uint32_t *const  page_buf,
const uint32_t *const  data,
uint32_t  len 
)

Write multiple of 4 bytes of data to Flash.

The page is erased, and then written to.

Note
: Since this operation may take some time to complete, the caller is responsible for ensuring that the watchdog timer does not elapse in the meantime (e.g., by restarting it before calling this function).
Parameters
[in]flashFlash controller index.
[in]regWhich Flash region to address.
[in]f_addrAddress within Flash physical address space.
[in]page_bufPage buffer to store page during update. Must be at least QM_FLASH_PAGE_SIZE words big and must not be NULL.
[in]dataData to write (array of words). This must not be NULL.
[in]lenLength of data to write (number of words).
Returns
Standard errno return type for QMSI.
Return values
0on success.
Negativeerrno for possible error codes.

Definition at line 168 of file qm_flash.c.

References qm_flash_reg_t::flash_stts, qm_flash_reg_t::flash_wr_ctrl, qm_flash_reg_t::flash_wr_data, QM_FLASH_REGION_DATA, QM_FLASH_REGION_NUM, QM_FLASH_REGION_OTP, QM_FLASH_REGION_SYS, qm_flash_reg_t::rom_wr_ctrl, and qm_flash_reg_t::rom_wr_data.

int qm_flash_page_write ( const qm_flash_t  flash,
const qm_flash_region_t  region,
uint32_t  page_num,
const uint32_t *  data,
uint32_t  len 
)

Write a flash page.

The page is erased, and then written to.

Note
: Since this operation may take some time to complete, the caller is responsible for ensuring that the watchdog timer does not elapse in the meantime (e.g., by restarting it before calling this function).
Parameters
[in]flashFlash controller index.
[in]regionWhich Flash region to address.
[in]page_numWhich page of flash to overwrite.
[in]dataData to write (array of words). This must not be NULL.
[in]lenLength of data to write (number of words).
Returns
Standard errno return type for QMSI.
Return values
0on success.
Negativeerrno for possible error codes.

Definition at line 100 of file qm_flash.c.

References qm_flash_reg_t::flash_stts, qm_flash_reg_t::flash_wr_ctrl, qm_flash_reg_t::flash_wr_data, QM_FLASH_REGION_DATA, QM_FLASH_REGION_NUM, QM_FLASH_REGION_OTP, QM_FLASH_REGION_SYS, qm_flash_reg_t::rom_wr_ctrl, and qm_flash_reg_t::rom_wr_data.

int qm_flash_restore_context ( const qm_flash_t  flash,
const qm_flash_context_t *const  ctx 
)

Restore flash context.

Restore the configuration of the specified flash controller. If the system clock frequency is lowered, the flash timings need to be restored. Otherwise, reading from flash will not be optimal (there will be 2 wait states instead of 0 wait states.)

Parameters
[in]flashFlash controller index.
[in]ctxFlash context structure. This must not be NULL.
Returns
Standard errno return type for QMSI.
Return values
0on success.
Negativeerrno for possible error codes.

Definition at line 350 of file qm_flash.c.

References qm_flash_reg_t::ctrl, qm_flash_context_t::ctrl, qm_flash_reg_t::tmg_ctrl, and qm_flash_context_t::tmg_ctrl.

int qm_flash_save_context ( const qm_flash_t  flash,
qm_flash_context_t *const  ctx 
)

Save flash context.

Save the configuration of the specified flash controller.

Parameters
[in]flashFlash controller index.
[out]ctxFlash context structure. This must not be NULL.
Returns
Standard errno return type for QMSI.
Return values
0on success.
Negativeerrno for possible error codes.

Definition at line 337 of file qm_flash.c.

References qm_flash_reg_t::ctrl, qm_flash_context_t::ctrl, qm_flash_reg_t::tmg_ctrl, and qm_flash_context_t::tmg_ctrl.

int qm_flash_set_config ( const qm_flash_t  flash,
const qm_flash_config_t *const  cfg 
)

Configure a Flash controller.

The configuration includes timing and behavioral settings.

Note
: when switching SoC to a higher frequency, flash controllers must be reconfigured to reflect settings associated with higher frequency BEFORE SoC frequency is changed. On the other hand, when switching SoC to a lower frequency, flash controller must be reconfigured only 6 NOP instructions AFTER the SoC frequency has been updated. Otherwise, flash timings will be violated.
Parameters
[in]flashFlash controller index.
[in]cfgFlash configuration. It must not be NULL.
Returns
Standard errno return type for QMSI.
Return values
0on success.
Negativeerrno for possible error codes.

Definition at line 22 of file qm_flash.c.

References qm_flash_reg_t::ctrl, QM_FLASH_WRITE_DISABLE, qm_flash_reg_t::tmg_ctrl, qm_flash_config_t::us_count, qm_flash_config_t::wait_states, and qm_flash_config_t::write_disable.

int qm_flash_word_write ( const qm_flash_t  flash,
const qm_flash_region_t  region,
uint32_t  f_addr,
const uint32_t  data 
)

Write 4 bytes of data to Flash.

Note
: this function performs a write operation only; page erase may be needed if the page is already programmed.
Parameters
[in]flashFlash controller index.
[in]regionFlash region to address.
[in]f_addrAddress within Flash physical address space.
[in]dataData word to write.
Returns
Standard errno return type for QMSI.
Return values
0on success.
Negativeerrno for possible error codes.

Definition at line 43 of file qm_flash.c.

References qm_flash_reg_t::flash_stts, qm_flash_reg_t::flash_wr_ctrl, qm_flash_reg_t::flash_wr_data, QM_FLASH_REGION_DATA, QM_FLASH_REGION_NUM, QM_FLASH_REGION_OTP, QM_FLASH_REGION_SYS, qm_flash_reg_t::rom_wr_ctrl, and qm_flash_reg_t::rom_wr_data.