MSC - Memory System Controller#
Memory System Controller API.
Contains functions to control the MSC, primarily the Flash. Users can perform Flash memory write and erase operations, as well as optimization of the CPU instruction fetch interface for the application. Available instruction fetch features depends on the MCU or SoC family, but features such as instruction pre-fetch, cache, and configurable branch prediction are typically available.
Flash erase may add ms of delay to interrupt latency if executing from Flash. Flash write and erase operations are supported by sl_hal_msc_write_word(), sl_hal_msc_erase_page(), and sl_hal_msc_mass_erase(). Mass erase is supported for MCU and SoC families with larger Flash sizes.
sl_hal_msc_init() must be called prior to any Flash write or erase operation. The following steps are necessary to perform a page erase and write:
uint32_t *user_data_page = (uint32_t *) USERDATA_BASE;
uint32_t user_data = 0x05060708;
#if defined(_CMU_CLKEN1_MSC_MASK)
sl_clock_manager_enable_bus_clock(SL_BUS_CLOCK_MSC);
#endif
// Initialize MSC module.
sl_hal_msc_init();
// Erase user data page.
sl_hal_msc_erase_page(user_data_page);
// Write value to user data page.
sl_hal_msc_write_word(user_data_page, &user_data, sizeof(user_data));
Modules#
Enumerations#
Return codes for writing/erasing Flash.
Functions#
Enable MSC module.
Wait for a specified MSC status or timeout.
Writes data to flash memory.
Set MSC code execution configuration.
Erase the entire Flash in one operation.
Erases a page in flash memory.
Writes data to flash memory.
Writes data to flash memory using the DMA.
Get the status of the MSC register lock.
Set the MSC register lock to a locked state.
Set the MSC register lock to an unlocked state.
Write a value to the read control register (MSC_READCTRL).
Get the current value of the read control register (MSC_READCTRL).
Set the lockbit for a flash page in order to prevent page writes/erases to the corresponding page.
Get the value of the lockbit for a flash page.
Get the size of the user data region in flash.
Write a value to the mass erase and user data page lock word (MSC_MISCLOCKWORD).
Get the current value of the mass erase and user data page lock word (MSC_MISCLOCKWORD).
Enable one or more MSC interrupts.
Disable one or more MSC interrupts.
Set one or more pending MSC interrupts from SW.
Clear one or more pending MSC interrupts.
Get pending MSC interrupt flags.
Get enabled and pending MSC interrupt flags.
Macros#
Timeout used while waiting for Flash to become ready after a write.
SL_HAL_MSC_CODE_RAM is used to place functions in RAM.
Default MSC exec_config initialization.
Enumeration Documentation#
sl_hal_msc_status_t#
sl_hal_msc_status_t
Return codes for writing/erasing Flash.
| Enumerator | |
|---|---|
| SL_HAL_MSC_OK | Flash write/erase successful. |
| SL_HAL_MSC_INVALID_ADDR | Invalid address. Write to an address that is not Flash. |
| SL_HAL_MSC_LOCKED | Flash address is locked. |
| SL_HAL_MSC_TIMEOUT | Timeout while writing to Flash. |
| SL_HAL_MSC_UNALIGNED | Unaligned access to Flash. |
Function Documentation#
sl_hal_msc_init#
void sl_hal_msc_init (void )
Enable MSC module.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| void | N/A |
Puts MSC hardware in a known state.
sl_hal_msc_wait_status#
SL_HAL_MSC_CODE_RAM sl_hal_msc_status_t sl_hal_msc_wait_status (uint32_t mask, uint32_t value)
Wait for a specified MSC status or timeout.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| uint32_t | [in] | mask | MSC->STATUS register mask to apply when testing for specified status. |
| uint32_t | [in] | value | The value the MSC->STATUS test is waiting to see. |
Returns
Returns the status of a write or erase operation, sl_hal_msc_status_t SL_HAL_MSC_OK - Specified status criteria fulfilled. SL_HAL_MSC_INVALID_ADDR - Operation tried to write or erase a non-flash area. SL_HAL_MSC_LOCKED - MSC registers are locked or the operation tried to write or erase a locked area of the flash. SL_HAL_MSC_TIMEOUT - Operation timed out.
sl_hal_msc_write_burst#
SL_HAL_MSC_CODE_RAM sl_hal_msc_status_t sl_hal_msc_write_burst (uint32_t address, const uint32_t * data, uint32_t num_bytes)
Writes data to flash memory.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| uint32_t | [in] | address | Pointer to the flash word to write to. Must be aligned to words. |
| const uint32_t * | [in] | data | Data to write to flash. |
| uint32_t | [in] | num_bytes | Number of bytes to write to flash. NB: Must be divisable by four. |
It is assumed that start address is word aligned and that num_bytes is an integer multiple of four, and that the write operation does not cross a flash page boundary.
Returns
Returns the status of the write operation, sl_hal_msc_status_t SL_HAL_MSC_OK - Operation completed successfully. SL_HAL_MSC_INVALID_ADDR - Operation tried to write to a non-flash area. SL_HAL_MSC_LOCKED - MSC registers are locked or the operation tried to program a locked area of the flash. SL_HAL_MSC_TIMEOUT - Operation timed out.
sl_hal_msc_set_exec_config#
void sl_hal_msc_set_exec_config (const sl_hal_msc_exec_config_t * exec_config)
Set MSC code execution configuration.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| const sl_hal_msc_exec_config_t * | [in] | exec_config | Code execution configuration. |
sl_hal_msc_mass_erase#
SL_HAL_MSC_CODE_RAM sl_hal_msc_status_t sl_hal_msc_mass_erase (void )
Erase the entire Flash in one operation.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| void | N/A |
Returns
Returns the status of the operation.
Note
This command will erase the entire contents of the device. Use with care, both a debug session and all contents of the flash will be lost. The lock bit, MLW will prevent this operation from executing and might prevent a successful mass erase.
sl_hal_msc_erase_page#
SL_HAL_MSC_CODE_RAM sl_hal_msc_status_t sl_hal_msc_erase_page (uint32_t * start_address)
Erases a page in flash memory.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| uint32_t * | [in] | start_address | Pointer to the flash page to erase. Must be aligned to beginning of page boundary. |
Returns
Returns the status of erase operation, sl_hal_msc_status_t SL_HAL_MSC_OK - Operation completed successfully. SL_HAL_MSC_INVALID_ADDR - Operation tried to erase a non-flash area. SL_HAL_MSC_LOCKED - MSC registers are locked or the operation tried to erase a locked area of the flash. SL_HAL_MSC_TIMEOUT - Operation timed out.
sl_hal_msc_write_word#
SL_HAL_MSC_CODE_RAM sl_hal_msc_status_t sl_hal_msc_write_word (uint32_t * address, void const * data, uint32_t num_bytes)
Writes data to flash memory.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| uint32_t * | [in] | address | Pointer to the flash word to write to. Must be aligned to words. |
| void const * | [in] | data | Data to write to flash. |
| uint32_t | [in] | num_bytes | Number of bytes to write to flash. NB: Must be divisable by four. |
Write data must be aligned to words and contain a number of bytes that is divisible by four.
Returns
Returns the status of the write operation, sl_hal_msc_status_t SL_HAL_MSC_OK - Operation completed successfully. SL_HAL_MSC_INVALID_ADDR - Operation tried to write to a non-flash area. SL_HAL_MSC_LOCKED - MSC registers are locked or the operation tried to program a locked area of the flash. SL_HAL_MSC_TIMEOUT - Operation timed out.
Note
It is recommended to erase the flash page before performing a write. For IAR Embedded Workbench, Simplicity Studio and GCC this will be achieved automatically by using attributes in the function proctype. For Keil uVision you must define a section called "ram_code" and place this manually in your project's scatter file. The Flash memory is organized into 64-bit wide double-words. Each 64-bit double-word can be written only twice using burst write operation between erasing cycles. The user's application must store data in RAM to sustain burst write operation. EFR32XG21 RevC is not able to program every word twice before the next erase.
sl_hal_msc_write_word_dma#
sl_hal_msc_status_t sl_hal_msc_write_word_dma (uint32_t channel, uint32_t * address, const void * data, uint32_t num_bytes)
Writes data to flash memory using the DMA.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| uint32_t | [in] | channel | DMA channel to use. |
| uint32_t * | [in] | address | A pointer to the flash word to write to. Must be aligned to words. |
| const void * | [in] | data | Data to write to flash and be aligned to words. |
| uint32_t | [in] | num_bytes | A number of bytes to write from flash. NB: Must be divisible by four. |
Returns
Returns the status of the write operation. SL_HAL_MSC_OK - The operation completed successfully. SL_HAL_MSC_INVALID_ADDR -The operation tried to erase a non-flash area.
This function uses the LDMA to write data to the internal flash memory. This is the fastest way to write data to the flash and should be used when the application wants to achieve write speeds like they are reported in the datasheet. Note that copying data from flash to flash will be slower than copying from RAM to flash. So the source data must be in RAM in order to see the write speeds similar to the datasheet numbers.
Note
This function requires that the LDMA and LDMAXBAR clock is enabled user can use sl_clock_manager_enable_bus_clock() to enable the clock.
sl_hal_msc_is_locked#
bool sl_hal_msc_is_locked (void )
Get the status of the MSC register lock.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| void | N/A |
Returns
Boolean true if register lock is applied, false otherwise.
sl_hal_msc_lock#
void sl_hal_msc_lock (void )
Set the MSC register lock to a locked state.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| void | N/A |
sl_hal_msc_unlock#
void sl_hal_msc_unlock (void )
Set the MSC register lock to an unlocked state.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| void | N/A |
sl_hal_msc_set_readctrl#
void sl_hal_msc_set_readctrl (uint32_t value)
Write a value to the read control register (MSC_READCTRL).
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| uint32_t | [in] | value | The 32-bit value to write to the MSC_READCTRL register. |
sl_hal_msc_get_readctrl#
uint32_t sl_hal_msc_get_readctrl (void )
Get the current value of the read control register (MSC_READCTRL).
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| void | N/A |
Returns
The 32-bit value read from the MSC_READCTRL register.
sl_hal_msc_lock_page#
void sl_hal_msc_lock_page (uint32_t page_number)
Set the lockbit for a flash page in order to prevent page writes/erases to the corresponding page.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| uint32_t | [in] | page_number | The index of the page to apply the pagelock to. Must be in the range [0, (flash_size / page_size) - 1]. |
sl_hal_msc_page_is_locked#
bool sl_hal_msc_page_is_locked (uint32_t page_number)
Get the value of the lockbit for a flash page.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| uint32_t | [in] | page_number | The index of the page to get the lockbit value from. Must be in the range [0, (flash_size / page_size) - 1]. |
Returns
Boolean true if the page is locked, false otherwise.
sl_hal_msc_get_size_userdata#
uint32_t sl_hal_msc_get_size_userdata (void )
Get the size of the user data region in flash.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| void | N/A |
Returns
The size of the user data region divided by 256.
sl_hal_msc_set_misc_lock_word#
void sl_hal_msc_set_misc_lock_word (uint32_t value)
Write a value to the mass erase and user data page lock word (MSC_MISCLOCKWORD).
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| uint32_t | [in] | value | The 32-bit value to write to the MSC_MISCLOCKWORD register. |
sl_hal_msc_get_misc_lock_word#
uint32_t sl_hal_msc_get_misc_lock_word (void )
Get the current value of the mass erase and user data page lock word (MSC_MISCLOCKWORD).
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| void | N/A |
Returns
The 32-bit value read from the MSC_MISCLOCKWORD register.
sl_hal_msc_enable_interrupts#
void sl_hal_msc_enable_interrupts (uint32_t flags)
Enable one or more MSC interrupts.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| uint32_t | [in] | flags | MSC interrupt sources to enable. Use a bitwise logic OR combination of valid interrupt flags for the MSC module (MSC_IF_nnn). |
Note
Depending on the use, a pending interrupt may already be set prior to enabling the interrupt. To ignore a pending interrupt, consider using sl_hal_msc_clear_interrupts() prior to enabling the interrupt.
sl_hal_msc_disable_interrupts#
void sl_hal_msc_disable_interrupts (uint32_t flags)
Disable one or more MSC interrupts.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| uint32_t | [in] | flags | MSC interrupt sources to disable. Use a bitwise logic OR combination of valid interrupt flags for the MSC module (MSC_IF_nnn). |
sl_hal_msc_set_pending_interrupts#
void sl_hal_msc_set_pending_interrupts (uint32_t flags)
Set one or more pending MSC interrupts from SW.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| uint32_t | [in] | flags | MSC interrupt sources to set to pending. Use a bitwise logic OR combination of valid interrupt flags for the MSC module (MSC_IF_nnn). |
sl_hal_msc_clear_interrupts#
void sl_hal_msc_clear_interrupts (uint32_t flags)
Clear one or more pending MSC interrupts.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| uint32_t | [in] | flags | Pending MSC interrupt source to clear. Use a bitwise logic OR combination of valid interrupt flags for the MSC module (MSC_IF_nnn). |
sl_hal_msc_get_pending_interrupts#
uint32_t sl_hal_msc_get_pending_interrupts (void )
Get pending MSC interrupt flags.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| void | N/A |
Returns
MSC interrupt sources pending. A bitwise logic OR combination of valid interrupt flags for the MSC module (MSC_IF_nnn).
Note
The event bits are not cleared by the use of this function.
sl_hal_msc_get_enabled_pending_interrupts#
uint32_t sl_hal_msc_get_enabled_pending_interrupts (void )
Get enabled and pending MSC interrupt flags.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| void | N/A |
Returns
Pending and enabled MSC interrupt sources. The return value is the bitwise AND of
the enabled interrupt sources in MSC_IEN and
the pending interrupt flags MSC_IF
Note
Interrupt flags are not cleared by the use of this function.