MSP432E4 DriverLib API Guide
1.11.00.03
|
Functions | |
int32_t | FlashErase (uint32_t ui32Address) |
int32_t | FlashProgram (uint32_t *pui32Data, uint32_t ui32Address, uint32_t ui32Count) |
tFlashProtection | FlashProtectGet (uint32_t ui32Address) |
int32_t | FlashProtectSet (uint32_t ui32Address, tFlashProtection eProtect) |
int32_t | FlashProtectSave (void) |
int32_t | FlashUserGet (uint32_t *pui32User0, uint32_t *pui32User1) |
int32_t | FlashUserSet (uint32_t ui32User0, uint32_t ui32User1) |
int32_t | FlashAllUserRegisterGet (uint32_t *pui32User0, uint32_t *pui32User1, uint32_t *pui32User2, uint32_t *pui32User3) |
int32_t | FlashAllUserRegisterSet (uint32_t ui32User0, uint32_t ui32User1, uint32_t ui32User2, uint32_t ui32User3) |
int32_t | FlashUserSave (void) |
int32_t | FlashAllUserRegisterSave (void) |
void | FlashIntRegister (void(*pfnHandler)(void)) |
void | FlashIntUnregister (void) |
void | FlashIntEnable (uint32_t ui32IntFlags) |
void | FlashIntDisable (uint32_t ui32IntFlags) |
uint32_t | FlashIntStatus (bool bMasked) |
void | FlashIntClear (uint32_t ui32IntFlags) |
The flash API provides a set of functions for dealing with the on-chip flash. Functions are provided to program and erase the flash, configure the flash protection, and handle the flash interrupt.
The flash is organized as a set of blocks that can be individually erased. See the device data sheet to determine the size of the flash blocks on an MCU. Erasing a block causes the entire contents of the block to be reset to all ones. The blocks can be marked as read-only or execute-only, providing differing levels of code protection. Read-only blocks cannot be erased or programmed, protecting the contents of those blocks from being modified. Execute-only blocks cannot be erased or programmed, and can only be read by the processor instruction fetch mechanism, protecting the contents of those blocks from being read by either the processor or by debuggers. Refer to the device data sheet to determine the size of flash blocks that can be configured as read-only or execute-only.
The flash can be programmed on a word-by-word basis. Programming causes 1 bits to become 0 bits (where appropriate); because of this, a word can be repeatedly programmed so long as each programming operation only requires changing 1 bits to 0 bits.
The timing for the flash is automatically handled by the flash controller. On some devices, flash timing depends on the PLL frequency that is specified. For these devices, the SysCtlClockFreqSet() function properly configures the flash timing.
The flash controller has the ability to generate an interrupt when an invalid access is attempted (such as reading from execute-only flash). This capability can be used to validate the operation of a program as the interrupt ensures that invalid accesses are not silently ignored, hiding potential bugs. The flash protection can be applied without being permanently enabled, which allows the program to be debugged before the flash protection is permanently applied to the device (which is a non-reversible operation on some devices). An interrupt can also be generated when an erase or programming operation has completed.
Depending upon the member of the MSP432E4 family used, the amount of available flash is 8 KB, 16 KB, 32 KB, 64 KB, 96 KB, 128 KB, 256 KB, 512 KB, or 1 MB.
The flash API is broken into three groups of functions: those that deal with programming the flash, those that deal with flash protection, and those that deal with interrupt handling.
Flash programming is managed with FlashErase(), FlashProgram(), FlashUsecGet(), and FlashUsecSet().
Flash protection is managed with FlashProtectGet(), FlashProtectSet(), and FlashProtectSave().
Interrupt handling is managed with FlashIntRegister(), FlashIntUnregister(), FlashIntEnable(), FlashIntDisable(), FlashIntGetStatus(), and FlashIntClear().
The following example shows how to use the flash API to erase a block of the flash and program a few words on a TM4C123x device.
int32_t FlashErase | ( | uint32_t | ui32Address | ) |
Erases a block of flash.
ui32Address | is the start address of the flash block to be erased. |
This function erases a block of the on-chip flash. After erasing, the block is filled with 0xFF bytes. Read-only and execute-only blocks cannot be erased.
The flash block size is 16-KB.
This function does not return until the block has been erased.
References ASSERT, FLASH_ERASE_SIZE, FLASH_FCMISC, FLASH_FCMISC_AMISC, FLASH_FCMISC_ERMISC, FLASH_FCMISC_VOLTMISC, FLASH_FCRIS, FLASH_FCRIS_ARIS, FLASH_FCRIS_ERRIS, FLASH_FCRIS_VOLTRIS, FLASH_FMA, FLASH_FMC, FLASH_FMC_ERASE, FLASH_FMC_WRKEY, and HWREG.
int32_t FlashProgram | ( | uint32_t * | pui32Data, |
uint32_t | ui32Address, | ||
uint32_t | ui32Count | ||
) |
Programs flash.
pui32Data | is a pointer to the data to be programmed. |
ui32Address | is the starting address in flash to be programmed. Must be a multiple of four. |
ui32Count | is the number of bytes to be programmed. Must be a multiple of four. |
This function programs a sequence of words into the on-chip flash. Because the flash is programmed one word at a time, the starting address and byte count must both be multiples of four. It is up to the caller to verify the programmed contents, if such verification is required.
This function does not return until the data has been programmed.
References ASSERT, FLASH_FCMISC, FLASH_FCMISC_AMISC, FLASH_FCMISC_INVDMISC, FLASH_FCMISC_PROGMISC, FLASH_FCMISC_VOLTMISC, FLASH_FCRIS, FLASH_FCRIS_ARIS, FLASH_FCRIS_INVDRIS, FLASH_FCRIS_PROGRIS, FLASH_FCRIS_VOLTRIS, FLASH_FMA, FLASH_FMC2, FLASH_FMC2_WRBUF, FLASH_FMC2_WRKEY, FLASH_FWBN, FLASH_FWBVAL, and HWREG.
tFlashProtection FlashProtectGet | ( | uint32_t | ui32Address | ) |
Gets the protection setting for a block of flash.
ui32Address | is the start address of the flash block to be queried. |
This function gets the current protection for the specified block of flash. A block can be read/write, read-only, or execute-only. Read/write blocks can be read, executed, erased, and programmed. Read-only blocks can be read and executed. Execute-only blocks can only be executed; processor and debugger data reads are not allowed.
References ASSERT, FLASH_PROTECT_SIZE, and HWREG.
int32_t FlashProtectSet | ( | uint32_t | ui32Address, |
tFlashProtection | eProtect | ||
) |
Sets the protection setting for a block of flash.
ui32Address | is the start address of the flash block to be protected. |
eProtect | is the protection to be applied to the block. Can be one of FlashReadWrite, FlashReadOnly, or FlashExecuteOnly. |
This function sets the protection for the specified block of flash. Blocks that are read/write can be made read-only or execute-only. Blocks that are read-only can be made execute-only. Blocks that are execute-only cannot have their protection modified. Attempts to make the block protection less stringent (that is, read-only to read/write) result in a failure (and are prevented by the hardware).
Changes to the flash protection are maintained only until the next reset. This protocol allows the application to be executed in the desired flash protection environment to check for inappropriate flash access (via the flash interrupt). To make the flash protection permanent, use the FlashProtectSave() function.
References ASSERT, FLASH_PROTECT_SIZE, FlashExecuteOnly, FlashReadOnly, FlashReadWrite, and HWREG.
int32_t FlashProtectSave | ( | void | ) |
Saves the flash protection settings.
This function makes the currently programmed flash protection settings permanent. This operation is non-reversible; a chip reset or power cycle does not change the flash protection.
This function does not return until the protection has been saved.
References FLASH_FMA, FLASH_FMC, FLASH_FMC_COMT, FLASH_FMC_WRKEY, and HWREG.
int32_t FlashUserGet | ( | uint32_t * | pui32User0, |
uint32_t * | pui32User1 | ||
) |
Gets the user registers.
pui32User0 | is a pointer to the location to store USER Register 0. |
pui32User1 | is a pointer to the location to store USER Register 1. |
This function reads the contents of user registers 0 and 1, and stores them in the specified locations.
References ASSERT, FLASH_USERREG0, FLASH_USERREG1, and HWREG.
int32_t FlashUserSet | ( | uint32_t | ui32User0, |
uint32_t | ui32User1 | ||
) |
Sets the user registers.
ui32User0 | is the value to store in USER Register 0. |
ui32User1 | is the value to store in USER Register 1. |
This function sets the contents of the user registers 0 and 1 to the specified values.
References FLASH_USERREG0, FLASH_USERREG1, and HWREG.
int32_t FlashAllUserRegisterGet | ( | uint32_t * | pui32User0, |
uint32_t * | pui32User1, | ||
uint32_t * | pui32User2, | ||
uint32_t * | pui32User3 | ||
) |
Gets all the user registers.
pui32User0 | is a pointer to the location to store USER Register 0. |
pui32User1 | is a pointer to the location to store USER Register 1. |
pui32User2 | is a pointer to the location to store USER Register 2. |
pui32User3 | is a pointer to the location to store USER Register 3. |
This function reads the contents of user registers 0, 1, 2 and 3, and stores them in the specified locations.
References ASSERT, FLASH_USERREG0, FLASH_USERREG1, FLASH_USERREG2, FLASH_USERREG3, and HWREG.
int32_t FlashAllUserRegisterSet | ( | uint32_t | ui32User0, |
uint32_t | ui32User1, | ||
uint32_t | ui32User2, | ||
uint32_t | ui32User3 | ||
) |
Sets the user registers 0 to 3
ui32User0 | is the value to store in USER Register 0. |
ui32User1 | is the value to store in USER Register 1. |
ui32User2 | is the value to store in USER Register 2. |
ui32User3 | is the value to store in USER Register 3. |
This function sets the contents of the user registers 0, 1, 2 and 3 to the specified values.
References FLASH_USERREG0, FLASH_USERREG1, FLASH_USERREG2, FLASH_USERREG3, and HWREG.
int32_t FlashUserSave | ( | void | ) |
Saves the user registers 0 and 1.
This function makes the currently programmed user register 0 and 1 settings permanent. This operation is non-reversible; a chip reset or power cycle does not change the flash protection.
This function does not return until the protection has been saved.
References FLASH_FMA, FLASH_FMC, FLASH_FMC_COMT, FLASH_FMC_WRKEY, and HWREG.
int32_t FlashAllUserRegisterSave | ( | void | ) |
Saves the user registers.
This function makes the currently programmed user register 0, 1, 2 and 3 settings permanent. This operation is non-reversible; a chip reset or power cycle does not change the flash protection.
This function does not return until the protection has been saved.
References FLASH_FMA, FLASH_FMC, FLASH_FMC_COMT, FLASH_FMC_WRKEY, and HWREG.
void FlashIntRegister | ( | void(*)(void) | pfnHandler | ) |
Registers an interrupt handler for the flash interrupt.
pfnHandler | is a pointer to the function to be called when the flash interrupt occurs. |
This function sets the handler to be called when the flash interrupt occurs. The flash controller can generate an interrupt when an invalid flash access occurs, such as trying to program or erase a read-only block, or trying to read from an execute-only block. It can also generate an interrupt when a program or erase operation has completed. The interrupt is automatically enabled when the handler is registered.
References INT_FLASH, IntEnable(), and IntRegister().
void FlashIntUnregister | ( | void | ) |
Unregisters the interrupt handler for the flash interrupt.
This function clears the handler to be called when the flash interrupt occurs. This function also masks off the interrupt in the interrupt controller so that the interrupt handler is no longer called.
References INT_FLASH, IntDisable(), and IntUnregister().
void FlashIntEnable | ( | uint32_t | ui32IntFlags | ) |
Enables individual flash controller interrupt sources.
ui32IntFlags | is a bit mask of the interrupt sources to be enabled. The ui32IntFlags parameter can be the logical OR of any of the following values: |
This function enables the indicated flash controller interrupt sources. Only the sources that are enabled can be reflected to the processor interrupt; disabled sources have no effect on the processor.
References FLASH_FCIM, and HWREG.
void FlashIntDisable | ( | uint32_t | ui32IntFlags | ) |
Disables individual flash controller interrupt sources.
ui32IntFlags | is a bit mask of the interrupt sources to be disabled. The ui32IntFlags parameter can be the logical OR of any of the following values: |
This function disables the indicated flash controller interrupt sources. Only the sources that are enabled can be reflected to the processor interrupt; disabled sources have no effect on the processor.
References FLASH_FCIM, and HWREG.
uint32_t FlashIntStatus | ( | bool | bMasked | ) |
Gets the current interrupt status.
bMasked | is false if the raw interrupt status is required and true if the masked interrupt status is required. |
This function returns the interrupt status for the flash controller. Either the raw interrupt status or the status of interrupts that are allowed to reflect to the processor can be returned.
References FLASH_FCMISC, FLASH_FCRIS, and HWREG.
void FlashIntClear | ( | uint32_t | ui32IntFlags | ) |
Clears flash controller interrupt sources.
ui32IntFlags | is the bit mask of the interrupt sources to be cleared. |
The specified flash controller interrupt sources are cleared, so that they no longer assert. The ui32IntFlags parameter can be the logical OR of any of the following values:
This function must be called in the interrupt handler to keep the interrupt from being triggered again immediately upon exit.
References FLASH_FCMISC, and HWREG.