1 /******************************************************************************
2 * Filename: flash.h
3 * Revised: 2020-06-07 13:30:55 +0200 (Sun, 07 Jun 2020)
4 * Revision: 57689
5 *
6 * Description: Defines and prototypes for the Flash driver.
7 *
8 * Copyright (c) 2015 - 2020, 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 //
41 //! \addtogroup system_control_group
42 //! @{
43 //! \addtogroup flash_api
44 //! @{
45 //
46 //*****************************************************************************
47
48 #ifndef __FLASH_H__
49 #define __FLASH_H__
50
51 //*****************************************************************************
52 //
53 // If building with a C++ compiler, make all of the definitions in this header
54 // have a C binding.
55 //
56 //*****************************************************************************
57 #ifdef __cplusplus
58 extern "C"
59 {
60 #endif
61
62 #include <stdbool.h>
63 #include <stdint.h>
64 #include "../inc/hw_types.h"
65 #include "../inc/hw_flash.h"
66 #include "../inc/hw_memmap.h"
67 #include "../inc/hw_ints.h"
68 #include "../inc/hw_aon_pmctl.h"
69 #include "../inc/hw_fcfg1.h"
70 #include "interrupt.h"
71 #include "debug.h"
72
73 //*****************************************************************************
74 //
75 // Support for DriverLib in ROM:
76 // This section renames all functions that are not "static inline", so that
77 // calling these functions will default to implementation in flash. At the end
78 // of this file a second renaming will change the defaults to implementation in
79 // ROM for available functions.
80 //
81 // To force use of the implementation in flash, e.g. for debugging:
82 // - Globally: Define DRIVERLIB_NOROM at project level
83 // - Per function: Use prefix "NOROM_" when calling the function
84 //
85 //*****************************************************************************
86 #if !defined(DOXYGEN)
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 FlashEfuseReadRow NOROM_FlashEfuseReadRow
95 #define FlashDisableSectorsForWrite NOROM_FlashDisableSectorsForWrite
96 #endif
97
98 //*****************************************************************************
99 //
100 // Values that can be returned from the API functions
101 //
102 //*****************************************************************************
103 #define FAPI_STATUS_SUCCESS 0x00000000 // Function completed successfully
104 #define FAPI_STATUS_FSM_BUSY 0x00000001 // FSM is Busy
105 #define FAPI_STATUS_FSM_READY 0x00000002 // FSM is Ready
106 #define FAPI_STATUS_INCORRECT_DATABUFFER_LENGTH \
107 0x00000003 // Incorrect parameter value
108 #define FAPI_STATUS_FSM_ERROR 0x00000004 // Operation failed
109
110 //*****************************************************************************
111 //
112 // Values passed to FlashIntEnable(), FlashIntDisable() and FlashIntClear() and
113 // returned from FlashIntStatus().
114 //
115 //*****************************************************************************
116 #define FLASH_INT_FSM_DONE 0x00400000 // FSM Done Interrupt Mask
117 #define FLASH_INT_RV 0x00010000 // Read Verify error Interrupt Mask
118
119 //*****************************************************************************
120 //
121 // Values passed to FlashSetPowerMode() and returned from FlashGetPowerMode().
122 //
123 //*****************************************************************************
124 #define FLASH_PWR_ACTIVE_MODE 0x00000000
125 #define FLASH_PWR_OFF_MODE 0x00000001
126 #define FLASH_PWR_DEEP_STDBY_MODE \
127 0x00000002 // Deprecated. Will force same
128 // power mode as for FLASH_PWR_OFF_MODE
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 frequency input to the flash module in number of MHz
156 //
157 //*****************************************************************************
158 #define FLASH_MODULE_CLK_FREQ 48
159
160 //*****************************************************************************
161 //
162 //! \brief Defined values for Flash State Machine commands
163 //
164 //*****************************************************************************
165 typedef enum
166 {
167 FAPI_PROGRAM_DATA = 0x0002, //!< Program data.
168 FAPI_ERASE_SECTOR = 0x0006, //!< Erase sector.
169 FAPI_ERASE_BANK = 0x0008, //!< Erase bank.
170 FAPI_VALIDATE_SECTOR = 0x000E, //!< Validate sector.
171 FAPI_CLEAR_STATUS = 0x0010, //!< Clear status.
172 FAPI_PROGRAM_RESUME = 0x0014, //!< Program resume.
173 FAPI_ERASE_RESUME = 0x0016, //!< Erase resume.
174 FAPI_CLEAR_MORE = 0x0018, //!< Clear more.
175 FAPI_PROGRAM_SECTOR = 0x0020, //!< Program sector.
176 FAPI_ERASE_OTP = 0x0030 //!< Erase OTP.
177 } tFlashStateCommandsType;
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 period and pump grace period
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 #define FW_PWRMODE_DEPRECATED 0x00000002
218
219 //*****************************************************************************
220 //
221 // Defines used by the flash programming functions
222 //
223 //*****************************************************************************
224 typedef volatile uint8_t tFwpWriteByte;
225 #define FWPWRITE_BYTE_ADDRESS ((tFwpWriteByte *)((FLASH_BASE + FLASH_O_FWPWRITE0)))
226
227 //*****************************************************************************
228 //
229 // Define for efuse instruction
230 //
231 //*****************************************************************************
232 #define DUMPWORD_INSTR 0x04
233
234 //*****************************************************************************
235 //
236 // Define for FSM command execution
237 //
238 //*****************************************************************************
239 #define FLASH_CMD_EXEC 0x15
240
241 //*****************************************************************************
242 //
243 //! \brief Get size of a flash sector in number of bytes.
244 //!
245 //! This function will return the size of a flash sector in number of bytes.
246 //!
247 //! \return Returns size of a flash sector in number of bytes.
248 //
249 //*****************************************************************************
250 __STATIC_INLINE uint32_t
FlashSectorSizeGet(void)251 FlashSectorSizeGet(void)
252 {
253 uint32_t ui32SectorSizeInKbyte;
254
255 ui32SectorSizeInKbyte = (HWREG(FLASH_BASE + FLASH_O_FCFG_B0_SSIZE0) &
256 FLASH_FCFG_B0_SSIZE0_B0_SECT_SIZE_M) >>
257 FLASH_FCFG_B0_SSIZE0_B0_SECT_SIZE_S;
258
259 // Return flash sector size in number of bytes.
260 return(ui32SectorSizeInKbyte * 1024);
261 }
262
263 //*****************************************************************************
264 //
265 //! \brief Get the size of the flash.
266 //!
267 //! This function returns the size of the flash main bank in number of bytes.
268 //!
269 //! \return Returns the flash size in number of bytes.
270 //
271 //*****************************************************************************
272 __STATIC_INLINE uint32_t
FlashSizeGet(void)273 FlashSizeGet(void)
274 {
275 uint32_t ui32NoOfSectors;
276
277 // Get number of flash sectors
278 ui32NoOfSectors = (HWREG(FLASH_BASE + FLASH_O_FLASH_SIZE) &
279 FLASH_FLASH_SIZE_SECTORS_M) >>
280 FLASH_FLASH_SIZE_SECTORS_S;
281
282 // Return flash size in number of bytes
283 return(ui32NoOfSectors * FlashSectorSizeGet());
284 }
285
286 //*****************************************************************************
287 //
288 //! \brief Set power mode.
289 //!
290 //! This function will set the specified power mode.
291 //!
292 //! Any access to the bank causes a reload of the specified bank grace period
293 //! input value into the bank down counter. After the last access to the
294 //! flash bank, the down counter delays from 0 to 255 prescaled HCLK clock
295 //! cycles before putting the bank into one of the fallback power modes as
296 //! determined by \c ui32PowerMode. This value must be greater than 1 when the
297 //! fallback mode is not \ref FLASH_PWR_ACTIVE_MODE.
298 //!
299 //! Note: The prescaled clock used for the down counter is a clock divided by
300 //! 16 from input HCLK. The \c ui32BankGracePeriod parameter is ignored if
301 //! \c ui32PowerMode is equal to \ref FLASH_PWR_ACTIVE_MODE.
302 //! Any access to flash memory causes the pump grace period down counter to
303 //! reload with value of \c ui32PumpGracePeriod. After the bank has gone to sleep,
304 //! the down counter delays this number of prescaled HCLK clock cycles before
305 //! entering one of the charge pump fallback power modes as determined by
306 //! \c ui32PowerMode. The prescaled clock used for the pump grace period down
307 //! counter is a clock divided by 16 from input HCLK. This parameter is ignored
308 //! if \c ui32PowerMode is equal to \ref FLASH_PWR_ACTIVE_MODE.
309 //!
310 //! Note: The \ref FLASH_PWR_DEEP_STDBY_MODE power mode is deprecated and
311 //! shall not be used. When used this mode will force the same power mode as
312 //! for \ref FLASH_PWR_OFF_MODE.
313 //!
314 //! Changing the power mode of the flash module must be a part within a
315 //! device power mode transition requiring configuration of multiple modules.
316 //! Refer to documents describing the device power modes.
317 //!
318 //! \param ui32PowerMode is the wanted power mode.
319 //! The defined flash power modes are:
320 //! - \ref FLASH_PWR_ACTIVE_MODE
321 //! - \ref FLASH_PWR_OFF_MODE
322 //! - \ref FLASH_PWR_DEEP_STDBY_MODE (Not to be used. This mode is deprecated.)
323 //! \param ui32BankGracePeriod is the starting count value for the bank grace
324 //! period down counter.
325 //! \param ui32PumpGracePeriod is the starting count value for the pump grace
326 //! period down counter.
327 //!
328 //! \return None
329 //
330 //*****************************************************************************
331 extern void FlashPowerModeSet(uint32_t ui32PowerMode,
332 uint32_t ui32BankGracePeriod,
333 uint32_t ui32PumpGracePeriod);
334
335 //*****************************************************************************
336 //
337 //! \brief Get current configured power mode.
338 //!
339 //! This function will return the current configured power mode.
340 //!
341 //! \return Returns the current configured power mode.
342 //! The defined power modes are:
343 //! - \ref FLASH_PWR_ACTIVE_MODE
344 //! - \ref FLASH_PWR_OFF_MODE
345 //! - \ref FLASH_PWR_DEEP_STDBY_MODE (Not to be used. This mode is deprecated.)
346 //
347 //*****************************************************************************
348 extern uint32_t FlashPowerModeGet(void);
349
350 //*****************************************************************************
351 //
352 //! \brief Set sector protection.
353 //!
354 //! This function will set the specified protection on specified flash bank
355 //! sector. A sector can either have no protection or have write protection
356 //! which guards for both program and erase of that sector.
357 //! Sector protection can only be changed from \ref FLASH_NO_PROTECT to
358 //! \ref FLASH_WRITE_PROTECT! After write protecting a sector this sector can
359 //! only be set back to unprotected by a device reset.
360 //!
361 //! \param ui32SectorAddress is the start address of the sector to protect.
362 //! \param ui32ProtectMode is the enumerated sector protection mode.
363 //! - \ref FLASH_NO_PROTECT
364 //! - \ref FLASH_WRITE_PROTECT
365 //!
366 //! \return None
367 //
368 //*****************************************************************************
369 extern void FlashProtectionSet(uint32_t ui32SectorAddress,
370 uint32_t ui32ProtectMode);
371
372 //*****************************************************************************
373 //
374 //! \brief Get sector protection.
375 //!
376 //! This return the protection mode for the specified flash bank sector.
377 //!
378 //! \param ui32SectorAddress is the start address of the desired sector.
379 //!
380 //! \return Returns the sector protection:
381 //! - \ref FLASH_NO_PROTECT
382 //! - \ref FLASH_WRITE_PROTECT
383 //
384 //*****************************************************************************
385 extern uint32_t FlashProtectionGet(uint32_t ui32SectorAddress);
386
387 //*****************************************************************************
388 //
389 //! \brief Save sector protection to make it permanent.
390 //!
391 //! This function will save the current protection mode for the specified
392 //! flash bank sector.
393 //!
394 //! This function must only be executed from ROM or SRAM.
395 //!
396 //! \note A write protected sector will become permanent write
397 //! protected!! A device reset will not change the write protection!
398 //!
399 //! \param ui32SectorAddress is the start address of the sector to be protected.
400 //!
401 //! \return Returns the status of the sector protection:
402 //! - \ref FAPI_STATUS_SUCCESS : Success.
403 //! - \ref FAPI_STATUS_FSM_ERROR : An erase error is encountered.
404 //
405 //*****************************************************************************
406 extern uint32_t FlashProtectionSave(uint32_t ui32SectorAddress);
407
408 //*****************************************************************************
409 //
410 //! \brief Checks if the Flash state machine has detected an error.
411 //!
412 //! This function returns the status of the Flash State Machine indicating if
413 //! an error is detected or not. Primary use is to check if an Erase or
414 //! Program operation has failed.
415 //!
416 //! \note Please note that code can not execute in flash while any part of the flash
417 //! is being programmed or erased. This function must be called from ROM or
418 //! SRAM while any part of the flash is being programmed or erased.
419 //!
420 //! \return Returns status of Flash state machine:
421 //! - \ref FAPI_STATUS_FSM_ERROR
422 //! - \ref FAPI_STATUS_SUCCESS
423 //
424 //*****************************************************************************
425 __STATIC_INLINE uint32_t
FlashCheckFsmForError(void)426 FlashCheckFsmForError(void)
427 {
428 if(HWREG(FLASH_BASE + FLASH_O_FMSTAT) & FLASH_FMSTAT_CSTAT)
429 {
430 return(FAPI_STATUS_FSM_ERROR);
431 }
432 else
433 {
434 return(FAPI_STATUS_SUCCESS);
435 }
436 }
437
438 //*****************************************************************************
439 //
440 //! \brief Checks if the Flash state machine is ready.
441 //!
442 //! This function returns the status of the Flash State Machine indicating if
443 //! it is ready to accept a new command or not. Primary use is to check if an
444 //! Erase or Program operation has finished.
445 //!
446 //! \note Please note that code can not execute in flash while any part of the flash
447 //! is being programmed or erased. This function must be called from ROM or
448 //! SRAMh while any part of the flash is being programmed or erased.
449 //!
450 //! \return Returns readiness status of Flash state machine:
451 //! - \ref FAPI_STATUS_FSM_READY
452 //! - \ref FAPI_STATUS_FSM_BUSY
453 //
454 //*****************************************************************************
455 __STATIC_INLINE uint32_t
FlashCheckFsmForReady(void)456 FlashCheckFsmForReady(void)
457 {
458 if(HWREG(FLASH_BASE + FLASH_O_STAT) & FLASH_STAT_BUSY)
459 {
460 return(FAPI_STATUS_FSM_BUSY);
461 }
462 else
463 {
464 return(FAPI_STATUS_FSM_READY);
465 }
466 }
467
468 //*****************************************************************************
469 //
470 //! \brief Registers an interrupt handler for the flash interrupt in the dynamic interrupt table.
471 //!
472 //! \note Only use this function if you want to use the dynamic vector table (in SRAM)!
473 //!
474 //! This function registers a function as the interrupt handler for a specific
475 //! interrupt and enables the corresponding interrupt in the interrupt controller.
476 //!
477 //! Specific FLASH interrupts must be enabled via \ref FlashIntEnable(). It is the
478 //! interrupt handler's responsibility to clear the interrupt source.
479 //!
480 //! \param pfnHandler is a pointer to the function to be called when the flash
481 //! interrupt occurs.
482 //!
483 //! \return None
484 //!
485 //! \sa \ref IntRegister() for important information about registering interrupt
486 //! handlers.
487 //
488 //*****************************************************************************
489 __STATIC_INLINE void
FlashIntRegister(void (* pfnHandler)(void))490 FlashIntRegister(void (*pfnHandler)(void))
491 {
492 // Register the interrupt handler.
493 IntRegister(INT_FLASH, pfnHandler);
494
495 // Enable the flash interrupt.
496 IntEnable(INT_FLASH);
497 }
498
499 //*****************************************************************************
500 //
501 //! \brief Unregisters the interrupt handler for the flash interrupt in the dynamic interrupt table.
502 //!
503 //! This function does the actual unregistering of the interrupt handler. It
504 //! clears the handler to be called when a FLASH interrupt occurs. This
505 //! function also masks off the interrupt in the interrupt controller so that
506 //! the interrupt handler no longer is called.
507 //!
508 //! \return None
509 //!
510 //! \sa \ref IntRegister() for important information about registering interrupt
511 //! handlers.
512 //
513 //*****************************************************************************
514 __STATIC_INLINE void
FlashIntUnregister(void)515 FlashIntUnregister(void)
516 {
517 // Disable the interrupts.
518 IntDisable(INT_FLASH);
519
520 // Unregister the interrupt handler.
521 IntUnregister(INT_FLASH);
522 }
523
524 //*****************************************************************************
525 //
526 //! \brief Enables flash controller interrupt sources.
527 //!
528 //! This function enables the flash controller interrupt sources.
529 //!
530 //! \param ui32IntFlags is the bit mask of the interrupt sources to be enabled.
531 //! The parameter is the bitwise OR of any of the following:
532 //! - \ref FLASH_INT_FSM_DONE : FSM Done interrupt.
533 //! - \ref FLASH_INT_RV : Read verify error interrupt.
534 //!
535 //! \return None
536 //
537 //*****************************************************************************
538 __STATIC_INLINE void
FlashIntEnable(uint32_t ui32IntFlags)539 FlashIntEnable(uint32_t ui32IntFlags)
540 {
541 HWREG(FLASH_BASE + FLASH_O_FSM_WR_ENA) = FSM_REG_WRT_ENABLE;
542 HWREG(FLASH_BASE + FLASH_O_FSM_ST_MACHINE) |= ui32IntFlags;
543 HWREG(FLASH_BASE + FLASH_O_FSM_WR_ENA) = FSM_REG_WRT_DISABLE;
544 }
545
546 //*****************************************************************************
547 //
548 //! \brief Disables individual flash controller interrupt sources.
549 //!
550 //! This function disables the flash controller interrupt sources.
551 //!
552 //! \param ui32IntFlags is the bit mask of the interrupt sources to be disabled.
553 //! The parameter is the bitwise OR of any of the following:
554 //! - \ref FLASH_INT_FSM_DONE : FSM Done interrupt.
555 //! - \ref FLASH_INT_RV : Read verify error interrupt.
556 //!
557 //! \return None
558 //
559 //*****************************************************************************
560 __STATIC_INLINE void
FlashIntDisable(uint32_t ui32IntFlags)561 FlashIntDisable(uint32_t ui32IntFlags)
562 {
563 HWREG(FLASH_BASE + FLASH_O_FSM_WR_ENA) = FSM_REG_WRT_ENABLE;
564 HWREG(FLASH_BASE + FLASH_O_FSM_ST_MACHINE) &= ~ui32IntFlags;
565 HWREG(FLASH_BASE + FLASH_O_FSM_WR_ENA) = FSM_REG_WRT_DISABLE;
566 }
567
568 //*****************************************************************************
569 //
570 //! \brief Gets the current interrupt status.
571 //!
572 //! This function returns the interrupt status for the Flash.
573 //!
574 //! \return Returns the current interrupt status as values described in
575 //! \ref FlashIntEnable().
576 //
577 //*****************************************************************************
578 __STATIC_INLINE uint32_t
FlashIntStatus(void)579 FlashIntStatus(void)
580 {
581 uint32_t ui32IntFlags;
582
583 ui32IntFlags = 0;
584
585 // Check if FSM_DONE interrupt status is set.
586 if(HWREG(FLASH_BASE + FLASH_O_FEDACSTAT) & FLASH_FEDACSTAT_FSM_DONE)
587 {
588 ui32IntFlags = FLASH_INT_FSM_DONE;
589 }
590
591 // Check if RVF_INT interrupt status is set.
592 if(HWREG(FLASH_BASE + FLASH_O_FEDACSTAT) & FLASH_FEDACSTAT_RVF_INT)
593 {
594 ui32IntFlags |= FLASH_INT_RV;
595 }
596
597 return(ui32IntFlags);
598 }
599
600 //*****************************************************************************
601 //
602 //! \brief Clears flash controller interrupt source.
603 //!
604 //! The flash controller interrupt source is cleared, so that it no longer
605 //! asserts. This must be done in the interrupt handler to keep it from being
606 //! called again immediately upon exit.
607 //!
608 //! \note Due to write buffers and synchronizers in the system it may take several
609 //! clock cycles from a register write clearing an event in a module and until the
610 //! event is actually cleared in the NVIC of the system CPU. It is recommended to
611 //! clear the event source early in the interrupt service routine (ISR) to allow
612 //! the event clear to propagate to the NVIC before returning from the ISR.
613 //! At the same time, an early event clear allows new events of the same type to be
614 //! pended instead of ignored if the event is cleared later in the ISR.
615 //! It is the responsibility of the programmer to make sure that enough time has passed
616 //! before returning from the ISR to avoid false re-triggering of the cleared event.
617 //! A simple, although not necessarily optimal, way of clearing an event before
618 //! returning from the ISR is:
619 //! -# Write to clear event (interrupt source). (buffered write)
620 //! -# Dummy read from the event source module. (making sure the write has propagated)
621 //! -# Wait two system CPU clock cycles (user code or two NOPs). (allowing cleared event to propagate through any synchronizers)
622 //!
623 //! \param ui32IntFlags is the bit mask of the interrupt sources to be cleared.
624 //! Can be any of:
625 //! - \ref FLASH_INT_FSM_DONE
626 //! - \ref FLASH_INT_RV
627 //!
628 //! \return None
629 //
630 //*****************************************************************************
631 __STATIC_INLINE void
FlashIntClear(uint32_t ui32IntFlags)632 FlashIntClear(uint32_t ui32IntFlags)
633 {
634 uint32_t ui32TempVal;
635
636 ui32TempVal = 0;
637
638 if(ui32IntFlags & FLASH_INT_FSM_DONE)
639 {
640 ui32TempVal = FLASH_FEDACSTAT_FSM_DONE;
641 }
642
643 if(ui32IntFlags & FLASH_INT_RV)
644 {
645 ui32TempVal |= FLASH_FEDACSTAT_RVF_INT;
646 }
647
648 // Clear the flash interrupt source.
649 HWREG(FLASH_BASE + FLASH_O_FEDACSTAT) = ui32TempVal;
650 }
651
652 //*****************************************************************************
653 //
654 //! \brief Erase a flash sector.
655 //!
656 //! This function will erase the specified flash sector. The function will
657 //! not return until the flash sector has been erased or an error condition
658 //! occurred. If flash top sector is erased the function will program the
659 //! the device security data bytes with default values. The device security
660 //! data located in the customer configuration area of the flash top sector,
661 //! must have valid values at all times. These values affect the configuration
662 //! of the device during boot.
663 //!
664 //! \warning Please note that code can not execute in flash while any part of the flash
665 //! is being programmed or erased. The application must disable interrupts that have
666 //! interrupt routines in flash. This function calls a ROM function which handles the
667 //! actual program operation.
668 //!
669 //! \param ui32SectorAddress is the starting address in flash of the sector to be
670 //! erased.
671 //!
672 //! \return Returns the status of the sector erase:
673 //! - \ref FAPI_STATUS_SUCCESS : Success.
674 //! - \ref FAPI_STATUS_INCORRECT_DATABUFFER_LENGTH : Invalid argument.
675 //! - \ref FAPI_STATUS_FSM_ERROR : A programming error is encountered.
676 //
677 //*****************************************************************************
678 extern uint32_t FlashSectorErase(uint32_t ui32SectorAddress);
679
680
681 //*****************************************************************************
682 //
683 //! \brief Programs unprotected flash sectors in the main bank.
684 //!
685 //! This function programs a sequence of bytes into the on-chip flash.
686 //! Programming each location consists of the result of an AND operation
687 //! of the new data and the existing data; in other words bits that contain
688 //! 1 can remain 1 or be changed to 0, but bits that are 0 cannot be changed
689 //! to 1. Therefore, a byte can be programmed multiple times as long as these
690 //! rules are followed; if a program operation attempts to change a 0 bit to
691 //! a 1 bit, that bit will not have its value changed.
692 //!
693 //! This function does not return until the data has been programmed or a
694 //! programming error occurs.
695 //!
696 //! \note It is recommended to disable cache and line buffer before programming the
697 //! flash. Cache and line buffer are not automatically updated if a flash program
698 //! causes a mismatch between new flash content and old content in cache and
699 //! line buffer. Remember to enable cache and line buffer when the program
700 //! operation completes. See \ref VIMSModeSafeSet(), \ref VIMSLineBufDisable(),
701 //! and \ref VIMSLineBufEnable() for more information.
702 //!
703 //! \warning Please note that code can not execute in flash while any part of the flash
704 //! is being programmed or erased. The application must disable interrupts that have
705 //! interrupt routines in flash. This function calls a ROM function which handles the
706 //! actual program operation.
707 //!
708 //! The \c pui8DataBuffer pointer can not point to flash.
709 //!
710 //! \param pui8DataBuffer is a pointer to the data to be programmed.
711 //! \param ui32Address is the starting address in flash to be programmed.
712 //! \param ui32Count is the number of bytes to be programmed.
713 //!
714 //! \return Returns status of the flash programming:
715 //! - \ref FAPI_STATUS_SUCCESS : Success.
716 //! - \ref FAPI_STATUS_INCORRECT_DATABUFFER_LENGTH : Too many bytes were requested.
717 //! - \ref FAPI_STATUS_FSM_ERROR : A programming error is encountered.
718 //
719 //*****************************************************************************
720 extern uint32_t FlashProgram(uint8_t *pui8DataBuffer,
721 uint32_t ui32Address, uint32_t ui32Count);
722
723 //*****************************************************************************
724 //
725 //! \brief Reads efuse data from specified row.
726 //!
727 //! This function will read one efuse row.
728 //! It is assumed that any previous efuse operation has finished.
729 //!
730 //! \param pui32EfuseData is pointer to variable to be updated with efuse data.
731 //! \param ui32RowAddress is the efuse row number to be read. First row is row
732 //! number 0.
733 //!
734 //! \return Returns the status of the efuse read operation.
735 //! - \c false : OK status.
736 //! - \c true : Error status
737 //
738 //*****************************************************************************
739 extern bool FlashEfuseReadRow(uint32_t *pui32EfuseData,
740 uint32_t ui32RowAddress);
741
742 //*****************************************************************************
743 //
744 //! \brief Disables all sectors for erase and programming on the active bank.
745 //!
746 //! This function disables all sectors for erase and programming on the active
747 //! bank and enables the Idle Reading Power reduction mode if no low power
748 //! mode is configured. Furthermore, an additional level of protection from
749 //! erase is enabled.
750 //!
751 //! \note Please note that code can not execute in flash while any part of the flash
752 //! is being programmed or erased.
753 //!
754 //! \return None
755 //
756 //*****************************************************************************
757 extern void FlashDisableSectorsForWrite(void);
758
759
760 //*****************************************************************************
761 //
762 // Support for DriverLib in ROM:
763 // Redirect to implementation in ROM when available.
764 //
765 //*****************************************************************************
766 #if !defined(DRIVERLIB_NOROM) && !defined(DOXYGEN)
767 #include "../driverlib/rom.h"
768 #ifdef ROM_FlashPowerModeSet
769 #undef FlashPowerModeSet
770 #define FlashPowerModeSet ROM_FlashPowerModeSet
771 #endif
772 #ifdef ROM_FlashPowerModeGet
773 #undef FlashPowerModeGet
774 #define FlashPowerModeGet ROM_FlashPowerModeGet
775 #endif
776 #ifdef ROM_FlashProtectionSet
777 #undef FlashProtectionSet
778 #define FlashProtectionSet ROM_FlashProtectionSet
779 #endif
780 #ifdef ROM_FlashProtectionGet
781 #undef FlashProtectionGet
782 #define FlashProtectionGet ROM_FlashProtectionGet
783 #endif
784 #ifdef ROM_FlashProtectionSave
785 #undef FlashProtectionSave
786 #define FlashProtectionSave ROM_FlashProtectionSave
787 #endif
788 #ifdef ROM_FlashSectorErase
789 #undef FlashSectorErase
790 #define FlashSectorErase ROM_FlashSectorErase
791 #endif
792 #ifdef ROM_FlashProgram
793 #undef FlashProgram
794 #define FlashProgram ROM_FlashProgram
795 #endif
796 #ifdef ROM_FlashEfuseReadRow
797 #undef FlashEfuseReadRow
798 #define FlashEfuseReadRow ROM_FlashEfuseReadRow
799 #endif
800 #ifdef ROM_FlashDisableSectorsForWrite
801 #undef FlashDisableSectorsForWrite
802 #define FlashDisableSectorsForWrite ROM_FlashDisableSectorsForWrite
803 #endif
804 #endif
805
806 //*****************************************************************************
807 //
808 // Mark the end of the C bindings section for C++ compilers.
809 //
810 //*****************************************************************************
811 #ifdef __cplusplus
812 }
813 #endif
814
815 #endif // __FLASH_H__
816
817 //*****************************************************************************
818 //
819 //! Close the Doxygen group.
820 //! @}
821 //! @}
822 //
823 //*****************************************************************************
824