CC26xx Driver Library
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
flash.h
Go to the documentation of this file.
1 /******************************************************************************
2 * Filename: flash.h
3 * Revised: 2015-01-05 16:57:31 +0100 (ma, 05 jan 2015)
4 * Revision: 42287
5 *
6 * Description: Defines and prototypes for the Flash driver.
7 *
8 * Copyright (c) 2015, Texas Instruments Incorporated
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions are met:
13 *
14 * 1) Redistributions of source code must retain the above copyright notice,
15 * this list of conditions and the following disclaimer.
16 *
17 * 2) Redistributions in binary form must reproduce the above copyright notice,
18 * this list of conditions and the following disclaimer in the documentation
19 * and/or other materials provided with the distribution.
20 *
21 * 3) Neither the name of the ORGANIZATION nor the names of its contributors may
22 * be used to endorse or promote products derived from this software without
23 * specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
29 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 * POSSIBILITY OF SUCH DAMAGE.
36 *
37 ******************************************************************************/
38 
39 //*****************************************************************************
40 //
43 //
44 //*****************************************************************************
45 
46 #ifndef __FLASH_H__
47 #define __FLASH_H__
48 
49 //*****************************************************************************
50 //
51 // If building with a C++ compiler, make all of the definitions in this header
52 // have a C binding.
53 //
54 //*****************************************************************************
55 #ifdef __cplusplus
56 extern "C"
57 {
58 #endif
59 
60 #include <stdbool.h>
61 #include <stdint.h>
62 #include <inc/hw_types.h>
63 #include <inc/hw_flash.h>
64 #include <inc/hw_memmap.h>
65 #include <inc/hw_ints.h>
66 #include <inc/hw_aon_sysctl.h>
67 #include <inc/hw_fcfg1.h>
68 #include <driverlib/interrupt.h>
69 #include <driverlib/debug.h>
70 
71 //*****************************************************************************
72 //
73 // Support for DriverLib in ROM:
74 // This section renames all functions that are not "static inline", so that
75 // calling these functions will default to implementation in flash. At the end
76 // of this file a second renaming will change the defaults to implementation in
77 // ROM for available functions.
78 //
79 // To force use of the implementation in flash, e.g. for debugging:
80 // - Globally: Define DRIVERLIB_NOROM at project level
81 // - Per function: Use prefix "NOROM_" when calling the function
82 //
83 // Do not define DRIVERLIB_GENERATE_ROM!
84 //
85 //*****************************************************************************
86 #ifndef DRIVERLIB_GENERATE_ROM
87  #define FlashPowerModeSet NOROM_FlashPowerModeSet
88  #define FlashPowerModeGet NOROM_FlashPowerModeGet
89  #define FlashProtectionSet NOROM_FlashProtectionSet
90  #define FlashProtectionGet NOROM_FlashProtectionGet
91  #define FlashProtectionSave NOROM_FlashProtectionSave
92  #define FlashSectorErase NOROM_FlashSectorErase
93  #define FlashProgram NOROM_FlashProgram
94  #define FlashProgramNowait NOROM_FlashProgramNowait
95  #define FlashEfuseReadRow NOROM_FlashEfuseReadRow
96  #define FlashDisableSectorsForWrite NOROM_FlashDisableSectorsForWrite
97 #endif
98 
99 //*****************************************************************************
100 //
101 // Values that can be returned from the API functions
102 //
103 //*****************************************************************************
104 #define FAPI_STATUS_SUCCESS 0x00000000 // Function completed successfully
105 #define FAPI_STATUS_FSM_BUSY 0x00000001 // FSM is Busy
106 #define FAPI_STATUS_FSM_READY 0x00000002 // FSM is Ready
107 #define FAPI_STATUS_INCORRECT_DATABUFFER_LENGTH \
108  0x00000003 // Incorrect parameter value
109 #define FAPI_STATUS_FSM_ERROR 0x00000004 // Operation failed
110 
111 //*****************************************************************************
112 //
113 // Values passed to FlashIntEnable(), FlashIntDisable() and FlashIntClear() and
114 // returned from FlashIntStatus().
115 //
116 //*****************************************************************************
117 #define FLASH_INT_FSM_DONE 0x00400000 // FSM Done Interrupt Mask
118 #define FLASH_INT_RV 0x00010000 // Read Verify error Interrupt Mask
119 
120 //*****************************************************************************
121 //
122 // Values passed to FlashSetPowerMode() and returned from FlashGetPowerMode().
123 //
124 //*****************************************************************************
125 #define FLASH_PWR_ACTIVE_MODE 0x00000000
126 #define FLASH_PWR_OFF_MODE 0x00000001
127 #define FLASH_PWR_DEEP_STDBY_MODE \
128  0x00000002
129 
130 //*****************************************************************************
131 //
132 // Values passed to FlashSetProtection() and returned from FlashGetProtection().
133 //
134 //*****************************************************************************
135 #define FLASH_NO_PROTECT 0x00000000 // Sector not protected
136 #define FLASH_WRITE_PROTECT 0x00000001 // Sector erase and program
137  // protected
138 
139 //*****************************************************************************
140 //
141 // Define used by the flash programming and erase functions
142 //
143 //*****************************************************************************
144 #define ADDR_OFFSET (0x1F800000 - FLASHMEM_BASE)
145 
146 //*****************************************************************************
147 //
148 // Define used for access to factory configuration area.
149 //
150 //*****************************************************************************
151 #define FCFG1_OFFSET 0x1000
152 
153 //*****************************************************************************
154 //
155 // Define for the clock frequencey input to the flash module in number of MHz
156 //
157 //*****************************************************************************
158 #define FLASH_MODULE_CLK_FREQ 48
159 
160 //*****************************************************************************
161 //
163 //
164 //*****************************************************************************
165 typedef enum
166 {
167  FAPI_PROGRAM_DATA = 0x0002,
168  FAPI_ERASE_SECTOR = 0x0006,
169  FAPI_ERASE_BANK = 0x0008,
171  FAPI_CLEAR_STATUS = 0x0010,
173  FAPI_ERASE_RESUME = 0x0016,
174  FAPI_CLEAR_MORE = 0x0018,
176  FAPI_ERASE_OTP = 0x0030
178 
179 //*****************************************************************************
180 //
181 // Defines for values written to the FLASH_O_FSM_WR_ENA register
182 //
183 //*****************************************************************************
184 #define FSM_REG_WRT_ENABLE 5
185 #define FSM_REG_WRT_DISABLE 2
186 
187 //*****************************************************************************
188 //
189 // Defines for the bank power mode field the FLASH_O_FBFALLBACK register
190 //
191 //*****************************************************************************
192 #define FBFALLBACK_SLEEP 0
193 #define FBFALLBACK_DEEP_STDBY 1
194 #define FBFALLBACK_ACTIVE 3
195 
196 //*****************************************************************************
197 //
198 // Defines for the bank grace periode and pump grace periode
199 //
200 //*****************************************************************************
201 #define FLASH_BAGP 0x14
202 #define FLASH_PAGP 0x14
203 
204 //*****************************************************************************
205 //
206 // Defines used by the FlashProgramPattern() function
207 //
208 //*****************************************************************************
209 #define PATTERN_BITS 0x20 // No of bits in data pattern to program
210 
211 //*****************************************************************************
212 //
213 // Defines for the FW flag bits in the FLASH_O_FWFLAG register
214 //
215 //*****************************************************************************
216 #define FW_WRT_TRIMMED 0x00000001
217 
218 //*****************************************************************************
219 //
220 // Defines used by the flash programming functions
221 //
222 //*****************************************************************************
223 typedef volatile uint8_t tFwpWriteByte;
224 #define FWPWRITE_BYTE_ADDRESS ((tFwpWriteByte *)((FLASH_BASE + FLASH_O_FWPWRITE0)))
225 
226 //*****************************************************************************
227 //
228 // Define for efuse instruction
229 //
230 //*****************************************************************************
231 #define DUMPWORD_INSTR 0x04
232 
233 //*****************************************************************************
234 //
235 // Define for FSM command execution
236 //
237 //*****************************************************************************
238 #define FLASH_CMD_EXEC 0x15
239 
240 //*****************************************************************************
241 //
242 // Defines for accesses to the customer configuration area in flash top sector
243 //
244 //*****************************************************************************
245 #define CCFG_OFFSET_SECURITY 0x00000FD8
246 #define CCFG_OFFSET_SECT_PROT 0x00000FF0
247 #define CCFG_SIZE_SECURITY 0x00000014
248 #define CCFG_SIZE_SECT_PROT 0x00000004
249 
250 //*****************************************************************************
251 //
257 //
258 //*****************************************************************************
259 __STATIC_INLINE uint32_t
261 {
262  uint32_t ui32SectorSizeInKbyte;
263 
264  ui32SectorSizeInKbyte = (HWREG(FLASH_BASE + FLASH_O_FCFG_B0_SSIZE0) &
267 
268  //
269  // Return flash sector size in number of bytes.
270  //
271  return(ui32SectorSizeInKbyte * 1024);
272 }
273 
274 //*****************************************************************************
275 //
281 //
282 //*****************************************************************************
283 __STATIC_INLINE uint32_t
285 {
286  uint32_t ui32NoOfSectors;
287 
288  //
289  // Get number of flash sectors
290  //
291  ui32NoOfSectors = (HWREG(FLASH_BASE + FLASH_O_FLASH_SIZE) &
294 
295  //
296  // Return flash size in number of bytes
297  //
298  return(ui32NoOfSectors * FlashSectorSizeGet());
299 }
300 
301 //*****************************************************************************
302 //
340 //
341 //*****************************************************************************
342 extern void FlashPowerModeSet(uint32_t ui32PowerMode,
343  uint32_t ui32BankGracePeriode,
344  uint32_t ui32PumpGracePeriode);
345 
346 //*****************************************************************************
347 //
357 //
358 //*****************************************************************************
359 extern uint32_t FlashPowerModeGet(void);
360 
361 //*****************************************************************************
362 //
378 //
379 //*****************************************************************************
380 extern void FlashProtectionSet(uint32_t ui32SectorAddress,
381  uint32_t ui32ProtectMode);
382 
383 //*****************************************************************************
384 //
394 //
395 //*****************************************************************************
396 extern uint32_t FlashProtectionGet(uint32_t ui32SectorAddress);
397 
398 //*****************************************************************************
399 //
415 //
416 //*****************************************************************************
417 extern uint32_t FlashProtectionSave(uint32_t ui32SectorAddress);
418 
419 //*****************************************************************************
420 //
434 //
435 //*****************************************************************************
436 __STATIC_INLINE uint32_t
438 {
440  {
441  return(FAPI_STATUS_FSM_ERROR);
442  }
443  else
444  {
445  return(FAPI_STATUS_SUCCESS);
446  }
447 }
448 
449 //*****************************************************************************
450 //
464 //
465 //*****************************************************************************
466 __STATIC_INLINE uint32_t
468 {
470  {
471  return(FAPI_STATUS_FSM_BUSY);
472  }
473  else
474  {
475  return(FAPI_STATUS_FSM_READY);
476  }
477 }
478 
479 //*****************************************************************************
480 //
495 //
496 //*****************************************************************************
497 __STATIC_INLINE void
498 FlashIntRegister(void (*pfnHandler)(void))
499 {
500  //
501  // Register the interrupt handler.
502  //
503  IntRegister(INT_FLASH, pfnHandler);
504 
505  //
506  // Enable the flash interrupt.
507  //
508  IntEnable(INT_FLASH);
509 }
510 
511 //*****************************************************************************
512 //
524 //
525 //*****************************************************************************
526 __STATIC_INLINE void
528 {
529  //
530  // Disable the interrupts.
531  //
532  IntDisable(INT_FLASH);
533 
534  //
535  // Unregister the interrupt handler.
536  //
537  IntUnregister(INT_FLASH);
538 }
539 
540 //*****************************************************************************
541 //
552 //
553 //*****************************************************************************
554 __STATIC_INLINE void
555 FlashIntEnable(uint32_t ui32IntFlags)
556 {
558  HWREG(FLASH_BASE + FLASH_O_FSM_ST_MACHINE) |= ui32IntFlags;
560 }
561 
562 //*****************************************************************************
563 //
574 //
575 //*****************************************************************************
576 __STATIC_INLINE void
577 FlashIntDisable(uint32_t ui32IntFlags)
578 {
580  HWREG(FLASH_BASE + FLASH_O_FSM_ST_MACHINE) &= ~ui32IntFlags;
582 }
583 
584 //*****************************************************************************
585 //
592 //
593 //*****************************************************************************
594 __STATIC_INLINE uint32_t
596 {
597  uint32_t ui32IntFlags;
598 
599  ui32IntFlags = 0;
600 
601  //
602  // Check if FSM_DONE interrupt status is set.
603  //
605  {
606  ui32IntFlags = FLASH_INT_FSM_DONE;
607  }
608 
609  //
610  // Check if RVF_INT interrupt status is set.
611  //
613  {
614  ui32IntFlags |= FLASH_INT_RV;
615  }
616 
617  return(ui32IntFlags);
618 }
619 
620 //*****************************************************************************
621 //
643 //
644 //*****************************************************************************
645 __STATIC_INLINE void
646 FlashIntClear(uint32_t ui32IntFlags)
647 {
648  uint32_t ui32TempVal;
649 
650  ui32TempVal = 0;
651 
652  if(ui32IntFlags & FLASH_INT_FSM_DONE)
653  {
654  ui32TempVal = FLASH_FEDACSTAT_FSM_DONE;
655  }
656 
657  if(ui32IntFlags & FLASH_INT_RV)
658  {
659  ui32TempVal |= FLASH_FEDACSTAT_RVF_INT;
660  }
661 
662  //
663  // Clear the flash interrupt source.
664  //
665  HWREG(FLASH_BASE + FLASH_O_FEDACSTAT) = ui32TempVal;
666 }
667 
668 //*****************************************************************************
669 //
691 //
692 //*****************************************************************************
693 extern uint32_t FlashSectorErase(uint32_t ui32SectorAddress);
694 
695 
696 //*****************************************************************************
697 //
725 //
726 //*****************************************************************************
727 extern uint32_t FlashProgram(uint8_t *pui8DataBuffer,
728  uint32_t ui32Address, uint32_t ui32Count);
729 
730 //*****************************************************************************
731 //
744 //
745 //*****************************************************************************
746 extern bool FlashEfuseReadRow(uint32_t *pui32EfuseData,
747  uint32_t ui32RowAddress);
748 
749 //*****************************************************************************
750 //
762 //
763 //*****************************************************************************
764 extern void FlashDisableSectorsForWrite(void);
765 
766 
767 //*****************************************************************************
768 //
769 // Support for DriverLib in ROM:
770 // Redirect to implementation in ROM when available.
771 //
772 //*****************************************************************************
773 #ifndef DRIVERLIB_NOROM
774  #include <driverlib/rom.h>
775  #ifdef ROM_FlashPowerModeSet
776  #undef FlashPowerModeSet
777  #define FlashPowerModeSet ROM_FlashPowerModeSet
778  #endif
779  #ifdef ROM_FlashPowerModeGet
780  #undef FlashPowerModeGet
781  #define FlashPowerModeGet ROM_FlashPowerModeGet
782  #endif
783  #ifdef ROM_FlashProtectionSet
784  #undef FlashProtectionSet
785  #define FlashProtectionSet ROM_FlashProtectionSet
786  #endif
787  #ifdef ROM_FlashProtectionGet
788  #undef FlashProtectionGet
789  #define FlashProtectionGet ROM_FlashProtectionGet
790  #endif
791  #ifdef ROM_FlashProtectionSave
792  #undef FlashProtectionSave
793  #define FlashProtectionSave ROM_FlashProtectionSave
794  #endif
795  #ifdef ROM_FlashSectorErase
796  #undef FlashSectorErase
797  #define FlashSectorErase ROM_FlashSectorErase
798  #endif
799  #ifdef ROM_FlashProgram
800  #undef FlashProgram
801  #define FlashProgram ROM_FlashProgram
802  #endif
803  #ifdef ROM_FlashProgramNowait
804  #undef FlashProgramNowait
805  #define FlashProgramNowait ROM_FlashProgramNowait
806  #endif
807  #ifdef ROM_FlashEfuseReadRow
808  #undef FlashEfuseReadRow
809  #define FlashEfuseReadRow ROM_FlashEfuseReadRow
810  #endif
811  #ifdef ROM_FlashDisableSectorsForWrite
812  #undef FlashDisableSectorsForWrite
813  #define FlashDisableSectorsForWrite ROM_FlashDisableSectorsForWrite
814  #endif
815 #endif
816 
817 //*****************************************************************************
818 //
819 // Mark the end of the C bindings section for C++ compilers.
820 //
821 //*****************************************************************************
822 #ifdef __cplusplus
823 }
824 #endif
825 
826 #endif // __FLASH_H__
827 
828 //*****************************************************************************
829 //
832 //
833 //*****************************************************************************
Program data.
Definition: flash.h:167
__STATIC_INLINE uint32_t FlashSectorSizeGet(void)
Get size of a flash sector in number of bytes.
Definition: flash.h:260
Erase resume.
Definition: flash.h:173
__STATIC_INLINE uint32_t FlashCheckFsmForReady(void)
Checks if the Flash state machine is ready.
Definition: flash.h:467
uint32_t FlashProtectionGet(uint32_t ui32SectorAddress)
Get sector protection.
Definition: flash.c:267
void FlashPowerModeSet(uint32_t ui32PowerMode, uint32_t ui32BankGracePeriode, uint32_t ui32PumpGracePeriode)
Set power mode.
Definition: flash.c:103
Erase sector.
Definition: flash.h:168
void FlashDisableSectorsForWrite(void)
Disables all sectors for erase and programming on the active bank.
Definition: flash.c:520
__STATIC_INLINE void FlashIntUnregister(void)
Unregisters the interrupt handler for the flash interrupt.
Definition: flash.h:527
__STATIC_INLINE uint32_t FlashCheckFsmForError(void)
Checks if the Flash state machine has detected an error.
Definition: flash.h:437
#define FLASH_INT_FSM_DONE
Definition: flash.h:117
#define FSM_REG_WRT_DISABLE
Definition: flash.h:185
uint32_t FlashPowerModeGet(void)
Get current configured power mode.
Definition: flash.c:194
__STATIC_INLINE uint32_t FlashSizeGet(void)
Get the size of the flash.
Definition: flash.h:284
#define FAPI_STATUS_SUCCESS
Definition: flash.h:104
Program sector.
Definition: flash.h:175
uint32_t FlashSectorErase(uint32_t ui32SectorAddress)
Erase a flash sector.
Definition: flash.c:364
Erase OTP.
Definition: flash.h:176
Clear status.
Definition: flash.h:171
#define FSM_REG_WRT_ENABLE
Definition: flash.h:184
#define FAPI_STATUS_FSM_ERROR
Definition: flash.h:109
__STATIC_INLINE void FlashIntClear(uint32_t ui32IntFlags)
Clears flash controller interrupt source.
Definition: flash.h:646
#define FAPI_STATUS_FSM_READY
Definition: flash.h:106
bool FlashEfuseReadRow(uint32_t *pui32EfuseData, uint32_t ui32RowAddress)
Reads efuse data from specified row.
Definition: flash.c:435
Erase bank.
Definition: flash.h:169
__STATIC_INLINE void FlashIntEnable(uint32_t ui32IntFlags)
Enables flash controller interrupt sources.
Definition: flash.h:555
tFlashStateCommandsType
Defined values for Flash State Machine commands.
Definition: flash.h:165
Validate sector.
Definition: flash.h:170
void IntUnregister(uint32_t ui32Interrupt)
Unregisters the function to be called when an interrupt occurs.
Definition: interrupt.c:205
__STATIC_INLINE uint32_t FlashIntStatus(void)
Gets the current interrupt status.
Definition: flash.h:595
uint32_t FlashProtectionSave(uint32_t ui32SectorAddress)
Save sector protection to make it permanent.
Definition: flash.c:310
#define FLASH_INT_RV
Definition: flash.h:118
Clear more.
Definition: flash.h:174
Program resume.
Definition: flash.h:172
__STATIC_INLINE void FlashIntRegister(void(*pfnHandler)(void))
Registers an interrupt handler for the flash interrupt.
Definition: flash.h:498
void FlashProtectionSet(uint32_t ui32SectorAddress, uint32_t ui32ProtectMode)
Set sector protection.
Definition: flash.c:227
__STATIC_INLINE void FlashIntDisable(uint32_t ui32IntFlags)
Disables individual flash controller interrupt sources.
Definition: flash.h:577
volatile uint8_t tFwpWriteByte
Definition: flash.h:223
#define FAPI_STATUS_FSM_BUSY
Definition: flash.h:105
uint32_t FlashProgram(uint8_t *pui8DataBuffer, uint32_t ui32Address, uint32_t ui32Count)
Programs unprotected main bank flash sectors.
Definition: flash.c:401
void IntDisable(uint32_t ui32Interrupt)
Disables an interrupt.
Definition: interrupt.c:383
void IntRegister(uint32_t ui32Interrupt, void(*pfnHandler)(void))
Registers a function to be called when an interrupt occurs.
Definition: interrupt.c:157
void IntEnable(uint32_t ui32Interrupt)
Enables an interrupt.
Definition: interrupt.c:323