EE445M RTOS
Taken at the University of Texas Spring 2015
Flash_api

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 FlashUserSave (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)
 

Variables

static const uint32_t g_pui32FMPPERegs []
 
static const uint32_t g_pui32FMPRERegs []
 

Detailed Description

Function Documentation

int32_t FlashErase ( uint32_t  ui32Address)

Erases a block of flash.

Parameters
ui32Addressis 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 device-class dependent. All TM4C123x devices use 1-KB blocks but TM4C129x devices use 16-KB blocks. Please consult the device datasheet to determine the block size in use.

This function does not return until the block has been erased.

Returns
Returns 0 on success, or -1 if an invalid block address was specified or the block is write-protected.

Definition at line 130 of file flash.c.

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.

131 {
132  //
133  // Check the arguments.
134  //
135  ASSERT(!(ui32Address & (FLASH_ERASE_SIZE - 1)));
136 
137  //
138  // Clear the flash access and error interrupts.
139  //
142 
143  //
144  // Erase the block.
145  //
146  HWREG(FLASH_FMA) = ui32Address;
148 
149  //
150  // Wait until the block has been erased.
151  //
153  {
154  }
155 
156  //
157  // Return an error if an access violation or erase error occurred.
158  //
161  {
162  return(-1);
163  }
164 
165  //
166  // Success.
167  //
168  return(0);
169 }
#define FLASH_FCMISC_VOLTMISC
Definition: hw_flash.h:207
#define HWREG(x)
Definition: hw_types.h:48
#define ASSERT(expr)
Definition: debug.h:67
#define FLASH_FCRIS_ERRIS
Definition: hw_flash.h:173
#define FLASH_FCRIS_ARIS
Definition: hw_flash.h:181
#define FLASH_FCRIS
Definition: hw_flash.h:51
#define FLASH_FCRIS_VOLTRIS
Definition: hw_flash.h:177
#define FLASH_FMA
Definition: hw_flash.h:48
#define FLASH_FCMISC_ERMISC
Definition: hw_flash.h:203
#define FLASH_FCMISC_AMISC
Definition: hw_flash.h:213
#define FLASH_FMC_WRKEY
Definition: hw_flash.h:160
#define FLASH_FMC_ERASE
Definition: hw_flash.h:163
#define FLASH_FMC
Definition: hw_flash.h:50
#define FLASH_FCMISC
Definition: hw_flash.h:54
#define FLASH_ERASE_SIZE
Definition: hw_flash.h:623
void FlashIntClear ( uint32_t  ui32IntFlags)

Clears flash controller interrupt sources.

Parameters
ui32IntFlagsis 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:

  • FLASH_INT_ACCESS occurs when a program or erase action was attempted on a block of flash that is marked as read-only or execute-only.
  • FLASH_INT_PROGRAM occurs when a programming or erase cycle completes.
  • FLASH_INT_EEPROM occurs when an EEPROM interrupt occurs. The source of the EEPROM interrupt can be determined by reading the EEDONE register.
  • FLASH_INT_VOLTAGE_ERR occurs when the voltage was out of spec during the flash operation and the operation was terminated.
  • FLASH_INT_DATA_ERR occurs when an operation attempts to program a bit that contains a 0 to a 1.
  • FLASH_INT_ERASE_ERR occurs when an erase operation fails.
  • FLASH_INT_PROGRAM_ERR occurs when a program operation fails.

This function must be called in the interrupt handler to keep the interrupt from being triggered again immediately upon exit.

Note
Because there is a write buffer in the Cortex-M processor, it may take several clock cycles before the interrupt source is actually cleared. Therefore, it is recommended that the interrupt source be cleared early in the interrupt handler (as opposed to the very last action) to avoid returning from the interrupt handler before the interrupt source is actually cleared. Failure to do so may result in the interrupt handler being immediately reentered (because the interrupt controller still sees the interrupt source asserted).
Returns
None.

Definition at line 838 of file flash.c.

References FLASH_FCMISC, and HWREG.

839 {
840  //
841  // Clear the flash interrupt.
842  //
843  HWREG(FLASH_FCMISC) = ui32IntFlags;
844 }
#define HWREG(x)
Definition: hw_types.h:48
#define FLASH_FCMISC
Definition: hw_flash.h:54
void FlashIntDisable ( uint32_t  ui32IntFlags)

Disables individual flash controller interrupt sources.

Parameters
ui32IntFlagsis a bit mask of the interrupt sources to be disabled. The ui32IntFlags parameter can be the logical OR of any of the following values:
  • FLASH_INT_ACCESS occurs when a program or erase action was attempted on a block of flash that is marked as read-only or execute-only.
  • FLASH_INT_PROGRAM occurs when a programming or erase cycle completes.
  • FLASH_INT_EEPROM occurs when an EEPROM interrupt occurs. The source of the EEPROM interrupt can be determined by reading the EEDONE register.
  • FLASH_INT_VOLTAGE_ERR occurs when the voltage was out of spec during the flash operation and the operation was terminated.
  • FLASH_INT_DATA_ERR occurs when an operation attempts to program a bit that contains a 0 to a 1.
  • FLASH_INT_ERASE_ERR occurs when an erase operation fails.
  • FLASH_INT_PROGRAM_ERR occurs when a program operation fails.

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.

Returns
None.

Definition at line 757 of file flash.c.

References FLASH_FCIM, and HWREG.

758 {
759  //
760  // Disable the specified interrupts.
761  //
762  HWREG(FLASH_FCIM) &= ~(ui32IntFlags);
763 }
#define HWREG(x)
Definition: hw_types.h:48
#define FLASH_FCIM
Definition: hw_flash.h:53
void FlashIntEnable ( uint32_t  ui32IntFlags)

Enables individual flash controller interrupt sources.

Parameters
ui32IntFlagsis a bit mask of the interrupt sources to be enabled. The ui32IntFlags parameter can be the logical OR of any of the following values:
  • FLASH_INT_ACCESS occurs when a program or erase action was attempted on a block of flash that is marked as read-only or execute-only.
  • FLASH_INT_PROGRAM occurs when a programming or erase cycle completes.
  • FLASH_INT_EEPROM occurs when an EEPROM interrupt occurs. The source of the EEPROM interrupt can be determined by reading the EEDONE register.
  • FLASH_INT_VOLTAGE_ERR occurs when the voltage was out of spec during the flash operation and the operation was terminated.
  • FLASH_INT_DATA_ERR occurs when an operation attempts to program a bit that contains a 0 to a 1.
  • FLASH_INT_ERASE_ERR occurs when an erase operation fails.
  • FLASH_INT_PROGRAM_ERR occurs when a program operation fails.

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.

Returns
None.

Definition at line 721 of file flash.c.

References FLASH_FCIM, and HWREG.

722 {
723  //
724  // Enable the specified interrupts.
725  //
726  HWREG(FLASH_FCIM) |= ui32IntFlags;
727 }
#define HWREG(x)
Definition: hw_types.h:48
#define FLASH_FCIM
Definition: hw_flash.h:53
void FlashIntRegister ( void(*)(void)  pfnHandler)

Registers an interrupt handler for the flash interrupt.

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

See also
IntRegister() for important information about registering interrupt handlers.
Returns
None.

Definition at line 652 of file flash.c.

References INT_FLASH_TM4C123, IntEnable(), and IntRegister().

653 {
654  //
655  // Register the interrupt handler, returning an error if an error occurs.
656  //
657  IntRegister(INT_FLASH_TM4C123, pfnHandler);
658 
659  //
660  // Enable the flash interrupt.
661  //
663 }
#define INT_FLASH_TM4C123
Definition: hw_ints.h:93
void IntRegister(uint32_t ui32Interrupt, void(*pfnHandler)(void))
Definition: interrupt.c:309
void IntEnable(uint32_t ui32Interrupt)
Definition: interrupt.c:610

Here is the call graph for this function:

uint32_t FlashIntStatus ( bool  bMasked)

Gets the current interrupt status.

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

Returns
The current interrupt status, enumerated as a bit field of FLASH_INT_ACCESS, FLASH_INT_PROGRAM, FLASH_INT_EEPROM, FLASH_INT_VOLTAGE_ERR, FLASH_INT_DATA_ERR, FLASH_INT_ERASE_ERR, and FLASH_INT_PROGRAM_ERR.

Definition at line 783 of file flash.c.

References FLASH_FCMISC, FLASH_FCRIS, and HWREG.

784 {
785  //
786  // Return either the interrupt status or the raw interrupt status as
787  // requested.
788  //
789  if(bMasked)
790  {
791  return(HWREG(FLASH_FCMISC));
792  }
793  else
794  {
795  return(HWREG(FLASH_FCRIS));
796  }
797 }
#define HWREG(x)
Definition: hw_types.h:48
#define FLASH_FCRIS
Definition: hw_flash.h:51
#define FLASH_FCMISC
Definition: hw_flash.h:54
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.

See also
IntRegister() for important information about registering interrupt handlers.
Returns
None.

Definition at line 680 of file flash.c.

References INT_FLASH_TM4C123, IntDisable(), and IntUnregister().

681 {
682  //
683  // Disable the interrupt.
684  //
686 
687  //
688  // Unregister the interrupt handler.
689  //
691 }
#define INT_FLASH_TM4C123
Definition: hw_ints.h:93
void IntUnregister(uint32_t ui32Interrupt)
Definition: interrupt.c:381
void IntDisable(uint32_t ui32Interrupt)
Definition: interrupt.c:684

Here is the call graph for this function:

int32_t FlashProgram ( uint32_t *  pui32Data,
uint32_t  ui32Address,
uint32_t  ui32Count 
)

Programs flash.

Parameters
pui32Datais a pointer to the data to be programmed.
ui32Addressis the starting address in flash to be programmed. Must be a multiple of four.
ui32Countis 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.

Returns
Returns 0 on success, or -1 if a programming error is encountered.

Definition at line 192 of file flash.c.

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.

193 {
194  //
195  // Check the arguments.
196  //
197  ASSERT(!(ui32Address & 3));
198  ASSERT(!(ui32Count & 3));
199 
200  //
201  // Clear the flash access and error interrupts.
202  //
205 
206  //
207  // Loop over the words to be programmed.
208  //
209  while(ui32Count)
210  {
211  //
212  // Set the address of this block of words.
213  //
214  HWREG(FLASH_FMA) = ui32Address & ~(0x7f);
215 
216  //
217  // Loop over the words in this 32-word block.
218  //
219  while(((ui32Address & 0x7c) || (HWREG(FLASH_FWBVAL) == 0)) &&
220  (ui32Count != 0))
221  {
222  //
223  // Write this word into the write buffer.
224  //
225  HWREG(FLASH_FWBN + (ui32Address & 0x7c)) = *pui32Data++;
226  ui32Address += 4;
227  ui32Count -= 4;
228  }
229 
230  //
231  // Program the contents of the write buffer into flash.
232  //
234 
235  //
236  // Wait until the write buffer has been programmed.
237  //
239  {
240  }
241  }
242 
243  //
244  // Return an error if an access violation occurred.
245  //
248  {
249  return(-1);
250  }
251 
252  //
253  // Success.
254  //
255  return(0);
256 }
#define FLASH_FCMISC_INVDMISC
Definition: hw_flash.h:205
#define FLASH_FCMISC_VOLTMISC
Definition: hw_flash.h:207
#define FLASH_FCRIS_PROGRIS
Definition: hw_flash.h:171
#define HWREG(x)
Definition: hw_types.h:48
#define FLASH_FCMISC_PROGMISC
Definition: hw_flash.h:201
#define ASSERT(expr)
Definition: debug.h:67
#define FLASH_FWBVAL
Definition: hw_flash.h:57
#define FLASH_FCRIS_ARIS
Definition: hw_flash.h:181
#define FLASH_FWBN
Definition: hw_flash.h:59
#define FLASH_FCRIS
Definition: hw_flash.h:51
#define FLASH_FCRIS_VOLTRIS
Definition: hw_flash.h:177
#define FLASH_FMC2_WRBUF
Definition: hw_flash.h:222
#define FLASH_FMA
Definition: hw_flash.h:48
#define FLASH_FCRIS_INVDRIS
Definition: hw_flash.h:175
#define FLASH_FCMISC_AMISC
Definition: hw_flash.h:213
#define FLASH_FMC2
Definition: hw_flash.h:56
#define FLASH_FMC2_WRKEY
Definition: hw_flash.h:221
#define FLASH_FCMISC
Definition: hw_flash.h:54
tFlashProtection FlashProtectGet ( uint32_t  ui32Address)

Gets the protection setting for a block of flash.

Parameters
ui32Addressis the start address of the flash block to be queried.

This function gets the current protection for the specified block of flash. Refer to the device data sheet to determine the granularity for each protection option. 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.

Returns
Returns the protection setting for this block. See FlashProtectSet() for possible values.

Definition at line 276 of file flash.c.

References ASSERT, FLASH_PROTECT_SIZE, FlashExecuteOnly, FlashReadOnly, FlashReadWrite, g_pui32FMPPERegs, g_pui32FMPRERegs, and HWREG.

277 {
278  uint32_t ui32FMPRE, ui32FMPPE;
279  uint32_t ui32Bank;
280 
281  //
282  // Check the argument.
283  //
284  ASSERT(!(ui32Address & (FLASH_PROTECT_SIZE - 1)));
285 
286  //
287  // Calculate the Flash Bank from Base Address, and mask off the Bank
288  // from ui32Address for subsequent reference.
289  //
290  ui32Bank = (((ui32Address / FLASH_PROTECT_SIZE) / 32) % 4);
291  ui32Address &= ((FLASH_PROTECT_SIZE * 32) - 1);
292 
293  //
294  // Read the appropriate flash protection registers for the specified
295  // flash bank.
296  //
297  ui32FMPRE = HWREG(g_pui32FMPRERegs[ui32Bank]);
298  ui32FMPPE = HWREG(g_pui32FMPPERegs[ui32Bank]);
299 
300  //
301  // Check the appropriate protection bits for the block of memory that
302  // is specified by the address.
303  //
304  switch((((ui32FMPRE >> (ui32Address / FLASH_PROTECT_SIZE)) & 0x1) << 1) |
305  ((ui32FMPPE >> (ui32Address / FLASH_PROTECT_SIZE)) & 0x1))
306  {
307  //
308  // This block is marked as execute only (that is, it can not be erased
309  // or programmed, and the only reads allowed are via the instruction
310  // fetch interface).
311  //
312  case 0:
313  case 1:
314  {
315  return(FlashExecuteOnly);
316  }
317 
318  //
319  // This block is marked as read only (that is, it can not be erased or
320  // programmed).
321  //
322  case 2:
323  {
324  return(FlashReadOnly);
325  }
326 
327  //
328  // This block is read/write; it can be read, erased, and programmed.
329  //
330  case 3:
331  default:
332  {
333  return(FlashReadWrite);
334  }
335  }
336 }
#define HWREG(x)
Definition: hw_types.h:48
#define FLASH_PROTECT_SIZE
Definition: hw_flash.h:622
#define ASSERT(expr)
Definition: debug.h:67
static const uint32_t g_pui32FMPRERegs[]
Definition: flash.c:89
static const uint32_t g_pui32FMPPERegs[]
Definition: flash.c:63
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.

Returns
Returns 0 on success, or -1 if a hardware error is encountered.

Definition at line 491 of file flash.c.

References FLASH_FMA, FLASH_FMC, FLASH_FMC_COMT, FLASH_FMC_WRKEY, and HWREG.

492 {
493  uint32_t ui32Temp;
494 
495  //
496  // Save the entire bank of 8 flash protection registers.
497  //
498  for(ui32Temp = 0; ui32Temp < 8; ui32Temp++)
499  {
500  //
501  // Tell the flash controller to write the flash protection register.
502  //
503  HWREG(FLASH_FMA) = ui32Temp;
505 
506  //
507  // Wait until the write has completed.
508  //
509  while(HWREG(FLASH_FMC) & FLASH_FMC_COMT)
510  {
511  }
512  }
513 
514  //
515  // Success.
516  //
517  return(0);
518 }
#define HWREG(x)
Definition: hw_types.h:48
#define FLASH_FMA
Definition: hw_flash.h:48
#define FLASH_FMC_WRKEY
Definition: hw_flash.h:160
#define FLASH_FMC
Definition: hw_flash.h:50
#define FLASH_FMC_COMT
Definition: hw_flash.h:161
int32_t FlashProtectSet ( uint32_t  ui32Address,
tFlashProtection  eProtect 
)

Sets the protection setting for a block of flash.

Parameters
ui32Addressis the start address of the flash block to be protected.
eProtectis 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. Refer to the device data sheet to determine the granularity for each protection option. 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.

Returns
Returns 0 on success, or -1 if an invalid address or an invalid protection was specified.

Definition at line 365 of file flash.c.

References ASSERT, FLASH_PROTECT_SIZE, FlashExecuteOnly, FlashReadOnly, FlashReadWrite, g_pui32FMPPERegs, g_pui32FMPRERegs, and HWREG.

366 {
367  uint32_t ui32ProtectRE, ui32ProtectPE;
368  uint32_t ui32Bank;
369 
370  //
371  // Check the argument.
372  //
373  ASSERT(!(ui32Address & (FLASH_PROTECT_SIZE - 1)));
374  ASSERT((eProtect == FlashReadWrite) || (eProtect == FlashReadOnly) ||
375  (eProtect == FlashExecuteOnly));
376 
377  //
378  // Convert the address into a block number.
379  //
380  ui32Address /= FLASH_PROTECT_SIZE;
381 
382  //
383  // ui32Address contains a "raw" block number. Derive the Flash Bank from
384  // the "raw" block number, and convert ui32Address to a "relative"
385  // block number.
386  //
387  ui32Bank = ((ui32Address / 32) % 4);
388  ui32Address %= 32;
389 
390  //
391  // Get the current protection for the specified flash bank.
392  //
393  ui32ProtectRE = HWREG(g_pui32FMPRERegs[ui32Bank]);
394  ui32ProtectPE = HWREG(g_pui32FMPPERegs[ui32Bank]);
395 
396  //
397  // Set the protection based on the requested protection.
398  //
399  switch(eProtect)
400  {
401  //
402  // Make this block execute only.
403  //
404  case FlashExecuteOnly:
405  {
406  //
407  // Turn off the read and program bits for this block.
408  //
409  ui32ProtectRE &= ~(0x1 << ui32Address);
410  ui32ProtectPE &= ~(0x1 << ui32Address);
411 
412  //
413  // We're done handling this protection.
414  //
415  break;
416  }
417 
418  //
419  // Make this block read only.
420  //
421  case FlashReadOnly:
422  {
423  //
424  // The block can not be made read only if it is execute only.
425  //
426  if(((ui32ProtectRE >> ui32Address) & 0x1) != 0x1)
427  {
428  return(-1);
429  }
430 
431  //
432  // Make this block read only.
433  //
434  ui32ProtectPE &= ~(0x1 << ui32Address);
435 
436  //
437  // We're done handling this protection.
438  //
439  break;
440  }
441 
442  //
443  // Make this block read/write.
444  //
445  case FlashReadWrite:
446  default:
447  {
448  //
449  // The block can not be made read/write if it is not already
450  // read/write.
451  //
452  if((((ui32ProtectRE >> ui32Address) & 0x1) != 0x1) ||
453  (((ui32ProtectPE >> ui32Address) & 0x1) != 0x1))
454  {
455  return(-1);
456  }
457 
458  //
459  // The block is already read/write, so there is nothing to do.
460  //
461  return(0);
462  }
463  }
464 
465  //
466  // Set the new protection for the specified flash bank.
467  //
468  HWREG(g_pui32FMPRERegs[ui32Bank]) = ui32ProtectRE;
469  HWREG(g_pui32FMPPERegs[ui32Bank]) = ui32ProtectPE;
470 
471  //
472  // Success.
473  //
474  return(0);
475 }
#define HWREG(x)
Definition: hw_types.h:48
#define FLASH_PROTECT_SIZE
Definition: hw_flash.h:622
#define ASSERT(expr)
Definition: debug.h:67
static const uint32_t g_pui32FMPRERegs[]
Definition: flash.c:89
static const uint32_t g_pui32FMPPERegs[]
Definition: flash.c:63
int32_t FlashUserGet ( uint32_t *  pui32User0,
uint32_t *  pui32User1 
)

Gets the user registers.

Parameters
pui32User0is a pointer to the location to store USER Register 0.
pui32User1is 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.

Returns
Returns 0 on success, or -1 if a hardware error is encountered.

Definition at line 534 of file flash.c.

References ASSERT, FLASH_USERREG0, FLASH_USERREG1, and HWREG.

535 {
536  //
537  // Verify that the pointers are valid.
538  //
539  ASSERT(pui32User0 != 0);
540  ASSERT(pui32User1 != 0);
541 
542  //
543  // Get and store the current value of the user registers.
544  //
545  *pui32User0 = HWREG(FLASH_USERREG0);
546  *pui32User1 = HWREG(FLASH_USERREG1);
547 
548  //
549  // Success.
550  //
551  return(0);
552 }
#define HWREG(x)
Definition: hw_types.h:48
#define ASSERT(expr)
Definition: debug.h:67
#define FLASH_USERREG0
Definition: hw_flash.h:70
#define FLASH_USERREG1
Definition: hw_flash.h:71
int32_t FlashUserSave ( void  )

Saves the user registers.

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.

Returns
Returns 0 on success, or -1 if a hardware error is encountered.

Definition at line 596 of file flash.c.

References FLASH_FMA, FLASH_FMC, FLASH_FMC_COMT, FLASH_FMC_WRKEY, and HWREG.

597 {
598  //
599  // Setting the MSB of FMA will trigger a permanent save of a USER
600  // register. Bit 0 will indicate User 0 (0) or User 1 (1).
601  //
602  HWREG(FLASH_FMA) = 0x80000000;
604 
605  //
606  // Wait until the write has completed.
607  //
608  while(HWREG(FLASH_FMC) & FLASH_FMC_COMT)
609  {
610  }
611 
612  //
613  // Tell the flash controller to write the USER1 Register.
614  //
615  HWREG(FLASH_FMA) = 0x80000001;
617 
618  //
619  // Wait until the write has completed.
620  //
621  while(HWREG(FLASH_FMC) & FLASH_FMC_COMT)
622  {
623  }
624 
625  //
626  // Success.
627  //
628  return(0);
629 }
#define HWREG(x)
Definition: hw_types.h:48
#define FLASH_FMA
Definition: hw_flash.h:48
#define FLASH_FMC_WRKEY
Definition: hw_flash.h:160
#define FLASH_FMC
Definition: hw_flash.h:50
#define FLASH_FMC_COMT
Definition: hw_flash.h:161
int32_t FlashUserSet ( uint32_t  ui32User0,
uint32_t  ui32User1 
)

Sets the user registers.

Parameters
ui32User0is the value to store in USER Register 0.
ui32User1is the value to store in USER Register 1.

This function sets the contents of the user registers 0 and 1 to the specified values.

Returns
Returns 0 on success, or -1 if a hardware error is encountered.

Definition at line 568 of file flash.c.

References FLASH_USERREG0, FLASH_USERREG1, and HWREG.

569 {
570  //
571  // Save the new values into the user registers.
572  //
573  HWREG(FLASH_USERREG0) = ui32User0;
574  HWREG(FLASH_USERREG1) = ui32User1;
575 
576  //
577  // Success.
578  //
579  return(0);
580 }
#define HWREG(x)
Definition: hw_types.h:48
#define FLASH_USERREG0
Definition: hw_flash.h:70
#define FLASH_USERREG1
Definition: hw_flash.h:71

Variable Documentation

const uint32_t g_pui32FMPPERegs[]
static
Initial value:
=
{
}
#define FLASH_FMPPE9
Definition: hw_flash.h:124
#define FLASH_FMPPE3
Definition: hw_flash.h:112
#define FLASH_FMPPE11
Definition: hw_flash.h:128
#define FLASH_FMPPE0
Definition: hw_flash.h:106
#define FLASH_FMPPE10
Definition: hw_flash.h:126
#define FLASH_FMPPE5
Definition: hw_flash.h:116
#define FLASH_FMPPE6
Definition: hw_flash.h:118
#define FLASH_FMPPE14
Definition: hw_flash.h:134
#define FLASH_FMPPE1
Definition: hw_flash.h:108
#define FLASH_FMPPE4
Definition: hw_flash.h:114
#define FLASH_FMPPE12
Definition: hw_flash.h:130
#define FLASH_FMPPE2
Definition: hw_flash.h:110
#define FLASH_FMPPE15
Definition: hw_flash.h:136
#define FLASH_FMPPE7
Definition: hw_flash.h:120
#define FLASH_FMPPE8
Definition: hw_flash.h:122
#define FLASH_FMPPE13
Definition: hw_flash.h:132

Definition at line 63 of file flash.c.

Referenced by FlashProtectGet(), and FlashProtectSet().

const uint32_t g_pui32FMPRERegs[]
static
Initial value:
=
{
}
#define FLASH_FMPRE8
Definition: hw_flash.h:90
#define FLASH_FMPRE1
Definition: hw_flash.h:76
#define FLASH_FMPRE4
Definition: hw_flash.h:82
#define FLASH_FMPRE9
Definition: hw_flash.h:92
#define FLASH_FMPRE13
Definition: hw_flash.h:100
#define FLASH_FMPRE5
Definition: hw_flash.h:84
#define FLASH_FMPRE3
Definition: hw_flash.h:80
#define FLASH_FMPRE12
Definition: hw_flash.h:98
#define FLASH_FMPRE2
Definition: hw_flash.h:78
#define FLASH_FMPRE7
Definition: hw_flash.h:88
#define FLASH_FMPRE14
Definition: hw_flash.h:102
#define FLASH_FMPRE15
Definition: hw_flash.h:104
#define FLASH_FMPRE0
Definition: hw_flash.h:74
#define FLASH_FMPRE11
Definition: hw_flash.h:96
#define FLASH_FMPRE6
Definition: hw_flash.h:86
#define FLASH_FMPRE10
Definition: hw_flash.h:94

Definition at line 89 of file flash.c.

Referenced by FlashProtectGet(), and FlashProtectSet().