MSC
[EM_Library]

Flash controller (MSC) peripheral API. More...

Collaboration diagram for MSC:

Defines

#define MSC_PROGRAM_TIMEOUT   10000000ul
 The timeout used while waiting for the flash to become ready after a write. This number indicates the number of iterations to perform before issuing a timeout.

Enumerations

enum  MSC_Status_TypeDef {
  mscReturnOk = 0,
  mscReturnInvalidAddr = -1,
  mscReturnLocked = -2,
  mscReturnTimeOut = -3,
  mscReturnUnaligned = -4
}

Functions

void MSC_Init (void)
 Enables the flash controller for writing.
void MSC_Deinit (void)
 Disables the flash controller for writing.
__STATIC_INLINE void MSC_IntClear (uint32_t flags)
 Clear one or more pending MSC interrupts.
__STATIC_INLINE void MSC_IntDisable (uint32_t flags)
 Disable one or more MSC interrupts.
__STATIC_INLINE void MSC_IntEnable (uint32_t flags)
 Enable one or more MSC interrupts.
__STATIC_INLINE uint32_t MSC_IntGet (void)
 Get pending MSC interrupt flags.
__STATIC_INLINE uint32_t MSC_IntGetEnabled (void)
 Get enabled and pending MSC interrupt flags. Useful for handling more interrupt sources in the same interrupt handler.
__STATIC_INLINE void MSC_IntSet (uint32_t flags)
 Set one or more pending MSC interrupts from SW.
MSC_Status_TypeDef MSC_WriteWord (uint32_t *address, void const *data, uint32_t numBytes)
 Writes data to flash memory. This function is interrupt safe, but slower than MSC_WriteWordFast(), which writes to flash with interrupts disabled. Write data must be aligned to words and contain a number of bytes that is divisable by four.
MSC_Status_TypeDef MSC_WriteWordFast (uint32_t *address, void const *data, uint32_t numBytes)
 Writes data to flash memory. This function is faster than MSC_WriteWord(), but it disables interrupts. Write data must be aligned to words and contain a number of bytes that is divisable by four.
MSC_Status_TypeDef MSC_ErasePage (uint32_t *startAddress)
 Erases a page in flash memory.

Detailed Description

Flash controller (MSC) peripheral API.

Flash controller (MSC) Peripheral API.


Define Documentation

#define MSC_PROGRAM_TIMEOUT   10000000ul

The timeout used while waiting for the flash to become ready after a write. This number indicates the number of iterations to perform before issuing a timeout.

Note:
This timeout is set very large (in the order of 100x longer than necessary). This is to avoid any corner cases.

Definition at line 72 of file em_msc.h.

Referenced by MSC_ErasePage().


Enumeration Type Documentation

Return codes for writing/erasing the flash

Enumerator:
mscReturnOk 

Flash write/erase successful.

mscReturnInvalidAddr 

Invalid address. Write to an address that is not flash.

mscReturnLocked 

Flash address is locked.

mscReturnTimeOut 

Timeout while writing to flash.

mscReturnUnaligned 

Unaligned access to flash.

Definition at line 79 of file em_msc.h.


Function Documentation

void MSC_Deinit ( void   ) 

Disables the flash controller for writing.

Definition at line 171 of file em_msc.c.

MSC_Status_TypeDef MSC_ErasePage ( uint32_t *  startAddress  ) 

Erases a page in flash memory.

Note:
It is recommended to run this code from RAM. On the Gecko family, it is required to run this function from RAM.

For IAR, Rowley, SimplicityStudio, Atollic and armgcc 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.

Parameters:
[in] startAddress Pointer to the flash page to erase. Must be aligned to beginning of page boundary.
Returns:
Returns the status of erase operation, MSC_Status_TypeDef
 *   mscReturnOk - Operation completed successfully.
 *   mscReturnInvalidAddr - Operation tried to erase a non-flash area.
 *   mscReturnLocked - Operation tried to erase a locked area of the flash.
 *   mscReturnTimeOut - Operation timed out waiting for flash operation
 *       to complete.
 * 

Definition at line 592 of file em_msc.c.

References MSC_PROGRAM_TIMEOUT, mscReturnInvalidAddr, mscReturnLocked, mscReturnOk, and mscReturnTimeOut.

void MSC_Init ( void   ) 

Enables the flash controller for writing.

Note:
IMPORTANT: This function must be called before flash operations when AUXHFRCO clock has been changed from default 14MHz band.
This function calls SystemCoreClockGet in order to set the global variable SystemCoreClock which is used in subseqent calls of MSC_WriteWord to make sure the frequency is sufficiently high for flash operations. If the clock frequency is changed then software is responsible for calling MSC_Init or SystemCoreClockGet in order to set the SystemCoreClock variable to the correct value.

Definition at line 119 of file em_msc.c.

References CMU_ClockFreqGet(), and cmuClock_AUX.

Here is the call graph for this function:

__STATIC_INLINE void MSC_IntClear ( uint32_t  flags  ) 

Clear one or more pending MSC interrupts.

Parameters:
[in] flags Pending MSC intterupt source to clear. Use a bitwise logic OR combination of valid interrupt flags for the MSC module (MSC_IF_nnn).

Definition at line 120 of file em_msc.h.

__STATIC_INLINE void MSC_IntDisable ( uint32_t  flags  ) 

Disable one or more MSC interrupts.

Parameters:
[in] flags MSC interrupt sources to disable. Use a bitwise logic OR combination of valid interrupt flags for the MSC module (MSC_IF_nnn).

Definition at line 133 of file em_msc.h.

__STATIC_INLINE void MSC_IntEnable ( uint32_t  flags  ) 

Enable one or more MSC interrupts.

Note:
Depending on the use, a pending interrupt may already be set prior to enabling the interrupt. Consider using MSC_IntClear() prior to enabling if such a pending interrupt should be ignored.
Parameters:
[in] flags MSC interrupt sources to enable. Use a bitwise logic OR combination of valid interrupt flags for the MSC module (MSC_IF_nnn).

Definition at line 152 of file em_msc.h.

__STATIC_INLINE uint32_t MSC_IntGet ( void   ) 

Get pending MSC interrupt flags.

Note:
The event bits are not cleared by the use of this function.
Returns:
MSC interrupt sources pending. A bitwise logic OR combination of valid interrupt flags for the MSC module (MSC_IF_nnn).

Definition at line 169 of file em_msc.h.

__STATIC_INLINE uint32_t MSC_IntGetEnabled ( void   ) 

Get enabled and pending MSC interrupt flags. Useful for handling more interrupt sources in the same interrupt handler.

Note:
Interrupt flags are not cleared by the use of this function.
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

Definition at line 189 of file em_msc.h.

__STATIC_INLINE void MSC_IntSet ( uint32_t  flags  ) 

Set one or more pending MSC interrupts from SW.

Parameters:
[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).

Definition at line 206 of file em_msc.h.

MSC_Status_TypeDef MSC_WriteWord ( uint32_t *  address,
void const *  data,
uint32_t  numBytes 
)

Writes data to flash memory. This function is interrupt safe, but slower than MSC_WriteWordFast(), which writes to flash with interrupts disabled. Write data must be aligned to words and contain a number of bytes that is divisable by four.

Note:
It is recommended to erase the flash page before performing a write.

It is recommended to run this code from RAM. On the Gecko family, it is required to run this function from RAM.

For IAR, Rowley, SimplicityStudio, Atollic and armgcc 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.

This function requires a ystem core clock at 1MHz or higher.

Parameters:
[in] address Pointer to the flash word to write to. Must be aligned to words.
[in] data Data to write to flash.
[in] numBytes Number of bytes to write from flash. NB: Must be divisable by four.
Returns:
Returns the status of the write operation
 *   flashReturnOk - Operation completed successfully.
 *   flashReturnInvalidAddr - Operation tried to erase a non-flash area.
 *   flashReturnLocked - Operation tried to erase a locked area of the flash.
 *   flashReturnTimeOut - Operation timed out waiting for flash operation
 *       to complete. Or the MSC timed out waiting for the software to write
 *       the next word into the DWORD register.
 * 

Definition at line 693 of file em_msc.c.

MSC_Status_TypeDef MSC_WriteWordFast ( uint32_t *  address,
void const *  data,
uint32_t  numBytes 
)

Writes data to flash memory. This function is faster than MSC_WriteWord(), but it disables interrupts. Write data must be aligned to words and contain a number of bytes that is divisable by four.

Note:
It is recommended to erase the flash page before performing a write.

It is recommended to run this code from RAM. On the Gecko family, it is required to run this function from RAM.

For IAR, Rowley, SimplicityStudio, Atollic and armgcc 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.

Parameters:
[in] address Pointer to the flash word to write to. Must be aligned to words.
[in] data Data to write to flash.
[in] numBytes Number of bytes to write from flash. NB: Must be divisable by four.
Returns:
Returns the status of the write operation
 *   flashReturnOk - Operation completed successfully.
 *   flashReturnInvalidAddr - Operation tried to erase a non-flash area.
 *   flashReturnLocked - Operation tried to erase a locked area of the flash.
 *   flashReturnTimeOut - Operation timed out waiting for flash operation
 *       to complete. Or the MSC timed out waiting for the software to write
 *       the next word into the DWORD register.
 * 

Definition at line 752 of file em_msc.c.