1 /******************************************************************************
2 * Filename: flash.h
3 *
4 * Description: Defines and prototypes for the Flash driver.
5 *
6 * Copyright (c) 2015 - 2022, Texas Instruments Incorporated
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are met:
11 *
12 * 1) Redistributions of source code must retain the above copyright notice,
13 * this list of conditions and the following disclaimer.
14 *
15 * 2) Redistributions in binary form must reproduce the above copyright notice,
16 * this list of conditions and the following disclaimer in the documentation
17 * and/or other materials provided with the distribution.
18 *
19 * 3) Neither the name of the ORGANIZATION nor the names of its contributors may
20 * be used to endorse or promote products derived from this software without
21 * specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
27 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 * POSSIBILITY OF SUCH DAMAGE.
34 *
35 ******************************************************************************/
36
37 //*****************************************************************************
38 //
39 //! \addtogroup system_control_group
40 //! @{
41 //! \addtogroup flash_api
42 //! @{
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_pmctl.h"
67 #include "../inc/hw_fcfg1.h"
68 #include "interrupt.h"
69 #include "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 //*****************************************************************************
84 #if !defined(DOXYGEN)
85 #define FlashPowerModeSet NOROM_FlashPowerModeSet
86 #define FlashPowerModeGet NOROM_FlashPowerModeGet
87 #define FlashProtectionSet NOROM_FlashProtectionSet
88 #define FlashProtectionGet NOROM_FlashProtectionGet
89 #define FlashProtectionSave NOROM_FlashProtectionSave
90 #define FlashSectorErase NOROM_FlashSectorErase
91 #define FlashProgram NOROM_FlashProgram
92 #define FlashEfuseReadRow NOROM_FlashEfuseReadRow
93 #define FlashDisableSectorsForWrite NOROM_FlashDisableSectorsForWrite
94 #endif
95
96 //*****************************************************************************
97 //
98 // Values that can be returned from the API functions
99 //
100 //*****************************************************************************
101 #define FAPI_STATUS_SUCCESS 0x00000000 // Function completed successfully
102 #define FAPI_STATUS_FSM_BUSY 0x00000001 // FSM is Busy
103 #define FAPI_STATUS_FSM_READY 0x00000002 // FSM is Ready
104 #define FAPI_STATUS_INCORRECT_DATABUFFER_LENGTH \
105 0x00000003 // Incorrect parameter value
106 #define FAPI_STATUS_FSM_ERROR 0x00000004 // Operation failed
107
108 //*****************************************************************************
109 //
110 // Values passed to FlashIntEnable(), FlashIntDisable() and FlashIntClear() and
111 // returned from FlashIntStatus().
112 //
113 //*****************************************************************************
114 #define FLASH_INT_FSM_DONE 0x00400000 // FSM Done Interrupt Mask
115 #define FLASH_INT_RV 0x00010000 // Read Verify error Interrupt Mask
116
117 //*****************************************************************************
118 //
119 // Values passed to FlashSetPowerMode() and returned from FlashGetPowerMode().
120 //
121 //*****************************************************************************
122 #define FLASH_PWR_ACTIVE_MODE 0x00000000
123 #define FLASH_PWR_OFF_MODE 0x00000001
124 #define FLASH_PWR_DEEP_STDBY_MODE \
125 0x00000002 // Deprecated. Will force same
126 // power mode as for FLASH_PWR_OFF_MODE
127
128 //*****************************************************************************
129 //
130 // Values passed to FlashSetProtection() and returned from FlashGetProtection().
131 //
132 //*****************************************************************************
133 #define FLASH_NO_PROTECT 0x00000000 // Sector not protected
134 #define FLASH_WRITE_PROTECT 0x00000001 // Sector erase and program
135 // protected
136
137 //*****************************************************************************
138 //
139 // Define used by the flash programming and erase functions
140 //
141 //*****************************************************************************
142 #define ADDR_OFFSET (0x1F800000 - FLASHMEM_BASE)
143
144 //*****************************************************************************
145 //
146 // Define used for access to factory configuration area.
147 //
148 //*****************************************************************************
149 #define FCFG1_OFFSET 0x1000
150
151 //*****************************************************************************
152 //
153 // Define for the clock frequency input to the flash module in number of MHz
154 //
155 //*****************************************************************************
156 #define FLASH_MODULE_CLK_FREQ 48
157
158 //*****************************************************************************
159 //
160 //! \brief Defined values for Flash State Machine commands
161 //
162 //*****************************************************************************
163 typedef enum
164 {
165 FAPI_PROGRAM_DATA = 0x0002, //!< Program data.
166 FAPI_ERASE_SECTOR = 0x0006, //!< Erase sector.
167 FAPI_ERASE_BANK = 0x0008, //!< Erase bank.
168 FAPI_VALIDATE_SECTOR = 0x000E, //!< Validate sector.
169 FAPI_CLEAR_STATUS = 0x0010, //!< Clear status.
170 FAPI_PROGRAM_RESUME = 0x0014, //!< Program resume.
171 FAPI_ERASE_RESUME = 0x0016, //!< Erase resume.
172 FAPI_CLEAR_MORE = 0x0018, //!< Clear more.
173 FAPI_PROGRAM_SECTOR = 0x0020, //!< Program sector.
174 FAPI_ERASE_OTP = 0x0030 //!< Erase OTP.
175 } tFlashStateCommandsType;
176
177 //*****************************************************************************
178 //
179 // Defines for values written to the FLASH_O_FSM_WR_ENA register
180 //
181 //*****************************************************************************
182 #define FSM_REG_WRT_ENABLE 5
183 #define FSM_REG_WRT_DISABLE 2
184
185 //*****************************************************************************
186 //
187 // Defines for the bank power mode field the FLASH_O_FBFALLBACK register
188 //
189 //*****************************************************************************
190 #define FBFALLBACK_SLEEP 0
191 #define FBFALLBACK_DEEP_STDBY 1
192 #define FBFALLBACK_ACTIVE 3
193
194 //*****************************************************************************
195 //
196 // Defines for the bank grace period and pump grace period
197 //
198 //*****************************************************************************
199 #define FLASH_BAGP 0x14
200 #define FLASH_PAGP 0x14
201
202 //*****************************************************************************
203 //
204 // Defines used by the FlashProgramPattern() function
205 //
206 //*****************************************************************************
207 #define PATTERN_BITS 0x20 // No of bits in data pattern to program
208
209 //*****************************************************************************
210 //
211 // Defines for the FW flag bits in the FLASH_O_FWFLAG register
212 //
213 //*****************************************************************************
214 #define FW_WRT_TRIMMED 0x00000001
215 #define FW_PWRMODE_DEPRECATED 0x00000002
216
217 //*****************************************************************************
218 //
219 // Defines used by the flash programming functions
220 //
221 //*****************************************************************************
222 typedef volatile uint8_t tFwpWriteByte;
223 #define FWPWRITE_BYTE_ADDRESS ((tFwpWriteByte *)((FLASH_BASE + FLASH_O_FWPWRITE0)))
224
225 //*****************************************************************************
226 //
227 // Define for efuse instruction
228 //
229 //*****************************************************************************
230 #define DUMPWORD_INSTR 0x04
231
232 //*****************************************************************************
233 //
234 // Define for FSM command execution
235 //
236 //*****************************************************************************
237 #define FLASH_CMD_EXEC 0x15
238
239 //*****************************************************************************
240 //
241 //! \brief Get size of a flash sector in number of bytes.
242 //!
243 //! This function will return the size of a flash sector in number of bytes.
244 //!
245 //! \return Returns size of a flash sector in number of bytes.
246 //
247 //*****************************************************************************
248 __STATIC_INLINE uint32_t
FlashSectorSizeGet(void)249 FlashSectorSizeGet(void)
250 {
251 uint32_t ui32SectorSizeInKbyte;
252
253 ui32SectorSizeInKbyte = (HWREG(FLASH_BASE + FLASH_O_FCFG_B0_SSIZE0) &
254 FLASH_FCFG_B0_SSIZE0_B0_SECT_SIZE_M) >>
255 FLASH_FCFG_B0_SSIZE0_B0_SECT_SIZE_S;
256
257 // Return flash sector size in number of bytes.
258 return(ui32SectorSizeInKbyte * 1024);
259 }
260
261 //*****************************************************************************
262 //
263 //! \brief Get the size of the flash.
264 //!
265 //! This function returns the size of the flash main bank in number of bytes.
266 //!
267 //! \return Returns the flash size in number of bytes.
268 //
269 //*****************************************************************************
270 __STATIC_INLINE uint32_t
FlashSizeGet(void)271 FlashSizeGet(void)
272 {
273 uint32_t ui32NoOfSectors;
274
275 // Get number of flash sectors
276 ui32NoOfSectors = (HWREG(FLASH_BASE + FLASH_O_FLASH_SIZE) &
277 FLASH_FLASH_SIZE_SECTORS_M) >>
278 FLASH_FLASH_SIZE_SECTORS_S;
279
280 // Return flash size in number of bytes
281 return(ui32NoOfSectors * FlashSectorSizeGet());
282 }
283
284 //*****************************************************************************
285 //
286 //! \brief Set power mode.
287 //!
288 //! This function will set the specified power mode.
289 //!
290 //! Any access to the bank causes a reload of the specified bank grace period
291 //! input value into the bank down counter. After the last access to the
292 //! flash bank, the down counter delays from 0 to 255 prescaled HCLK clock
293 //! cycles before putting the bank into one of the fallback power modes as
294 //! determined by \c ui32PowerMode. This value must be greater than 1 when the
295 //! fallback mode is not \ref FLASH_PWR_ACTIVE_MODE.
296 //!
297 //! Note: The prescaled clock used for the down counter is a clock divided by
298 //! 16 from input HCLK. The \c ui32BankGracePeriod parameter is ignored if
299 //! \c ui32PowerMode is equal to \ref FLASH_PWR_ACTIVE_MODE.
300 //! Any access to flash memory causes the pump grace period down counter to
301 //! reload with value of \c ui32PumpGracePeriod. After the bank has gone to sleep,
302 //! the down counter delays this number of prescaled HCLK clock cycles before
303 //! entering one of the charge pump fallback power modes as determined by
304 //! \c ui32PowerMode. The prescaled clock used for the pump grace period down
305 //! counter is a clock divided by 16 from input HCLK. This parameter is ignored
306 //! if \c ui32PowerMode is equal to \ref FLASH_PWR_ACTIVE_MODE.
307 //!
308 //! Note: The \ref FLASH_PWR_DEEP_STDBY_MODE power mode is deprecated and
309 //! shall not be used. When used this mode will force the same power mode as
310 //! for \ref FLASH_PWR_OFF_MODE.
311 //! This function should not be called at any time before powering off Vims.
312 //!
313 //! Changing the power mode of the flash module must be a part within a
314 //! device power mode transition requiring configuration of multiple modules.
315 //! Refer to documents describing the device power modes.
316 //!
317 //! \param ui32PowerMode is the wanted power mode.
318 //! The defined flash power modes are:
319 //! - \ref FLASH_PWR_ACTIVE_MODE
320 //! - \ref FLASH_PWR_OFF_MODE
321 //! - \ref FLASH_PWR_DEEP_STDBY_MODE (Not to be used. This mode is deprecated.)
322 //! \param ui32BankGracePeriod is the starting count value for the bank grace
323 //! period down counter.
324 //! \param ui32PumpGracePeriod is the starting count value for the pump grace
325 //! period down counter.
326 //!
327 //! \return None
328 //
329 //*****************************************************************************
330 extern void FlashPowerModeSet(uint32_t ui32PowerMode,
331 uint32_t ui32BankGracePeriod,
332 uint32_t ui32PumpGracePeriod);
333
334 //*****************************************************************************
335 //
336 //! \brief Get current configured power mode.
337 //!
338 //! This function will return the current configured power mode.
339 //!
340 //! \return Returns the current configured power mode.
341 //! The defined power modes are:
342 //! - \ref FLASH_PWR_ACTIVE_MODE
343 //! - \ref FLASH_PWR_OFF_MODE
344 //! - \ref FLASH_PWR_DEEP_STDBY_MODE (Not to be used. This mode is deprecated.)
345 //
346 //*****************************************************************************
347 extern uint32_t FlashPowerModeGet(void);
348
349 //*****************************************************************************
350 //
351 //! \brief Set sector protection.
352 //!
353 //! This function will set the specified protection on specified flash bank
354 //! sector. A sector can either have no protection or have write protection
355 //! which guards for both program and erase of that sector.
356 //! Sector protection can only be changed from \ref FLASH_NO_PROTECT to
357 //! \ref FLASH_WRITE_PROTECT! After write protecting a sector this sector can
358 //! only be set back to unprotected by a device reset.
359 //!
360 //! \param ui32SectorAddress is the start address of the sector to protect.
361 //! \param ui32ProtectMode is the enumerated sector protection mode.
362 //! - \ref FLASH_NO_PROTECT
363 //! - \ref FLASH_WRITE_PROTECT
364 //!
365 //! \return None
366 //
367 //*****************************************************************************
368 extern void FlashProtectionSet(uint32_t ui32SectorAddress,
369 uint32_t ui32ProtectMode);
370
371 //*****************************************************************************
372 //
373 //! \brief Get sector protection.
374 //!
375 //! This return the protection mode for the specified flash bank sector.
376 //!
377 //! \param ui32SectorAddress is the start address of the desired sector.
378 //!
379 //! \return Returns the sector protection:
380 //! - \ref FLASH_NO_PROTECT
381 //! - \ref FLASH_WRITE_PROTECT
382 //
383 //*****************************************************************************
384 extern uint32_t FlashProtectionGet(uint32_t ui32SectorAddress);
385
386 //*****************************************************************************
387 //
388 //! \brief Save sector protection to make it permanent.
389 //!
390 //! This function will save the current protection mode for the specified
391 //! flash bank sector.
392 //!
393 //! This function must only be executed from ROM or SRAM.
394 //!
395 //! \note A write protected sector will become permanent write
396 //! protected!! A device reset will not change the write protection!
397 //!
398 //! \param ui32SectorAddress is the start address of the sector to be protected.
399 //!
400 //! \return Returns the status of the sector protection:
401 //! - \ref FAPI_STATUS_SUCCESS : Success.
402 //! - \ref FAPI_STATUS_FSM_ERROR : An erase error is encountered.
403 //
404 //*****************************************************************************
405 extern uint32_t FlashProtectionSave(uint32_t ui32SectorAddress);
406
407 //*****************************************************************************
408 //
409 //! \brief Checks if the Flash state machine has detected an error.
410 //!
411 //! This function returns the status of the Flash State Machine indicating if
412 //! an error is detected or not. Primary use is to check if an Erase or
413 //! Program operation has failed.
414 //!
415 //! \note Please note that code can not execute in flash while any part of the flash
416 //! is being programmed or erased. This function must be called from ROM or
417 //! SRAM while any part of the flash is being programmed or erased.
418 //!
419 //! \return Returns status of Flash state machine:
420 //! - \ref FAPI_STATUS_FSM_ERROR
421 //! - \ref FAPI_STATUS_SUCCESS
422 //
423 //*****************************************************************************
424 __STATIC_INLINE uint32_t
FlashCheckFsmForError(void)425 FlashCheckFsmForError(void)
426 {
427 if(HWREG(FLASH_BASE + FLASH_O_FMSTAT) & FLASH_FMSTAT_CSTAT)
428 {
429 return(FAPI_STATUS_FSM_ERROR);
430 }
431 else
432 {
433 return(FAPI_STATUS_SUCCESS);
434 }
435 }
436
437 //*****************************************************************************
438 //
439 //! \brief Checks if the Flash state machine is ready.
440 //!
441 //! This function returns the status of the Flash State Machine indicating if
442 //! it is ready to accept a new command or not. Primary use is to check if an
443 //! Erase or Program operation has finished.
444 //!
445 //! \note Please note that code can not execute in flash while any part of the flash
446 //! is being programmed or erased. This function must be called from ROM or
447 //! SRAMh while any part of the flash is being programmed or erased.
448 //!
449 //! \return Returns readiness status of Flash state machine:
450 //! - \ref FAPI_STATUS_FSM_READY
451 //! - \ref FAPI_STATUS_FSM_BUSY
452 //
453 //*****************************************************************************
454 __STATIC_INLINE uint32_t
FlashCheckFsmForReady(void)455 FlashCheckFsmForReady(void)
456 {
457 if(HWREG(FLASH_BASE + FLASH_O_STAT) & FLASH_STAT_BUSY_M)
458 {
459 return(FAPI_STATUS_FSM_BUSY);
460 }
461 else
462 {
463 return(FAPI_STATUS_FSM_READY);
464 }
465 }
466
467 //*****************************************************************************
468 //
469 //! \brief Registers an interrupt handler for the flash interrupt in the dynamic interrupt table.
470 //!
471 //! \note Only use this function if you want to use the dynamic vector table (in SRAM)!
472 //!
473 //! This function registers a function as the interrupt handler for a specific
474 //! interrupt and enables the corresponding interrupt in the interrupt controller.
475 //!
476 //! Specific FLASH interrupts must be enabled via \ref FlashIntEnable(). It is the
477 //! interrupt handler's responsibility to clear the interrupt source.
478 //!
479 //! \param pfnHandler is a pointer to the function to be called when the flash
480 //! interrupt occurs.
481 //!
482 //! \return None
483 //!
484 //! \sa \ref IntRegister() for important information about registering interrupt
485 //! handlers.
486 //
487 //*****************************************************************************
488 __STATIC_INLINE void
FlashIntRegister(void (* pfnHandler)(void))489 FlashIntRegister(void (*pfnHandler)(void))
490 {
491 // Register the interrupt handler.
492 IntRegister(INT_FLASH, pfnHandler);
493
494 // Enable the flash interrupt.
495 IntEnable(INT_FLASH);
496 }
497
498 //*****************************************************************************
499 //
500 //! \brief Unregisters the interrupt handler for the flash interrupt in the dynamic interrupt table.
501 //!
502 //! This function does the actual unregistering of the interrupt handler. It
503 //! clears the handler to be called when a FLASH interrupt occurs. This
504 //! function also masks off the interrupt in the interrupt controller so that
505 //! the interrupt handler no longer is called.
506 //!
507 //! \return None
508 //!
509 //! \sa \ref IntRegister() for important information about registering interrupt
510 //! handlers.
511 //
512 //*****************************************************************************
513 __STATIC_INLINE void
FlashIntUnregister(void)514 FlashIntUnregister(void)
515 {
516 // Disable the interrupts.
517 IntDisable(INT_FLASH);
518
519 // Unregister the interrupt handler.
520 IntUnregister(INT_FLASH);
521 }
522
523 //*****************************************************************************
524 //
525 //! \brief Enables flash controller interrupt sources.
526 //!
527 //! This function enables the flash controller interrupt sources.
528 //!
529 //! \param ui32IntFlags is the bit mask of the interrupt sources to be enabled.
530 //! The parameter is the bitwise OR of any of the following:
531 //! - \ref FLASH_INT_FSM_DONE : FSM Done interrupt.
532 //! - \ref FLASH_INT_RV : Read verify error interrupt.
533 //!
534 //! \return None
535 //
536 //*****************************************************************************
537 __STATIC_INLINE void
FlashIntEnable(uint32_t ui32IntFlags)538 FlashIntEnable(uint32_t ui32IntFlags)
539 {
540 HWREG(FLASH_BASE + FLASH_O_FSM_WR_ENA) = FSM_REG_WRT_ENABLE;
541 HWREG(FLASH_BASE + FLASH_O_FSM_ST_MACHINE) |= ui32IntFlags;
542 HWREG(FLASH_BASE + FLASH_O_FSM_WR_ENA) = FSM_REG_WRT_DISABLE;
543 }
544
545 //*****************************************************************************
546 //
547 //! \brief Disables individual flash controller interrupt sources.
548 //!
549 //! This function disables the flash controller interrupt sources.
550 //!
551 //! \param ui32IntFlags is the bit mask of the interrupt sources to be disabled.
552 //! The parameter is the bitwise OR of any of the following:
553 //! - \ref FLASH_INT_FSM_DONE : FSM Done interrupt.
554 //! - \ref FLASH_INT_RV : Read verify error interrupt.
555 //!
556 //! \return None
557 //
558 //*****************************************************************************
559 __STATIC_INLINE void
FlashIntDisable(uint32_t ui32IntFlags)560 FlashIntDisable(uint32_t ui32IntFlags)
561 {
562 HWREG(FLASH_BASE + FLASH_O_FSM_WR_ENA) = FSM_REG_WRT_ENABLE;
563 HWREG(FLASH_BASE + FLASH_O_FSM_ST_MACHINE) &= ~ui32IntFlags;
564 HWREG(FLASH_BASE + FLASH_O_FSM_WR_ENA) = FSM_REG_WRT_DISABLE;
565 }
566
567 //*****************************************************************************
568 //
569 //! \brief Gets the current interrupt status.
570 //!
571 //! This function returns the interrupt status for the Flash.
572 //!
573 //! \return Returns the current interrupt status as values described in
574 //! \ref FlashIntEnable().
575 //
576 //*****************************************************************************
577 __STATIC_INLINE uint32_t
FlashIntStatus(void)578 FlashIntStatus(void)
579 {
580 uint32_t ui32IntFlags;
581
582 ui32IntFlags = 0;
583
584 // Check if FSM_DONE interrupt status is set.
585 if(HWREG(FLASH_BASE + FLASH_O_FEDACSTAT) & FLASH_FEDACSTAT_FSM_DONE)
586 {
587 ui32IntFlags = FLASH_INT_FSM_DONE;
588 }
589
590 // Check if RVF_INT interrupt status is set.
591 if(HWREG(FLASH_BASE + FLASH_O_FEDACSTAT) & FLASH_FEDACSTAT_RVF_INT)
592 {
593 ui32IntFlags |= FLASH_INT_RV;
594 }
595
596 return(ui32IntFlags);
597 }
598
599 //*****************************************************************************
600 //
601 //! \brief Clears flash controller interrupt source.
602 //!
603 //! The flash controller interrupt source is cleared, so that it no longer
604 //! asserts. This must be done in the interrupt handler to keep it from being
605 //! called again immediately upon exit.
606 //!
607 //! \note Due to write buffers and synchronizers in the system it may take several
608 //! clock cycles from a register write clearing an event in a module and until the
609 //! event is actually cleared in the NVIC of the system CPU. It is recommended to
610 //! clear the event source early in the interrupt service routine (ISR) to allow
611 //! the event clear to propagate to the NVIC before returning from the ISR.
612 //! At the same time, an early event clear allows new events of the same type to be
613 //! pended instead of ignored if the event is cleared later in the ISR.
614 //! It is the responsibility of the programmer to make sure that enough time has passed
615 //! before returning from the ISR to avoid false re-triggering of the cleared event.
616 //! A simple, although not necessarily optimal, way of clearing an event before
617 //! returning from the ISR is:
618 //! -# Write to clear event (interrupt source). (buffered write)
619 //! -# Dummy read from the event source module. (making sure the write has propagated)
620 //! -# Wait two system CPU clock cycles (user code or two NOPs). (allowing cleared event to propagate through any synchronizers)
621 //!
622 //! \param ui32IntFlags is the bit mask of the interrupt sources to be cleared.
623 //! Can be any of:
624 //! - \ref FLASH_INT_FSM_DONE
625 //! - \ref FLASH_INT_RV
626 //!
627 //! \return None
628 //
629 //*****************************************************************************
630 __STATIC_INLINE void
FlashIntClear(uint32_t ui32IntFlags)631 FlashIntClear(uint32_t ui32IntFlags)
632 {
633 uint32_t ui32TempVal;
634
635 ui32TempVal = 0;
636
637 if(ui32IntFlags & FLASH_INT_FSM_DONE)
638 {
639 ui32TempVal = FLASH_FEDACSTAT_FSM_DONE;
640 }
641
642 if(ui32IntFlags & FLASH_INT_RV)
643 {
644 ui32TempVal |= FLASH_FEDACSTAT_RVF_INT;
645 }
646
647 // Clear the flash interrupt source.
648 HWREG(FLASH_BASE + FLASH_O_FEDACSTAT) = ui32TempVal;
649 }
650
651 //*****************************************************************************
652 //
653 //! \brief Erase a flash sector.
654 //!
655 //! This function will erase the specified flash sector. The function will
656 //! not return until the flash sector has been erased or an error condition
657 //! occurred. If flash top sector is erased the function will program the
658 //! the device security data bytes with default values. The device security
659 //! data located in the customer configuration area of the flash top sector,
660 //! must have valid values at all times. These values affect the configuration
661 //! of the device during boot.
662 //!
663 //! \warning Please note that code can not execute in flash while any part of the flash
664 //! is being programmed or erased. The application must disable interrupts that have
665 //! interrupt routines in flash. This function calls a ROM function which handles the
666 //! actual program operation.
667 //!
668 //! \param ui32SectorAddress is the starting address in flash of the sector to be
669 //! erased.
670 //!
671 //! \return Returns the status of the sector erase:
672 //! - \ref FAPI_STATUS_SUCCESS : Success.
673 //! - \ref FAPI_STATUS_INCORRECT_DATABUFFER_LENGTH : Invalid argument.
674 //! - \ref FAPI_STATUS_FSM_ERROR : A programming error is encountered.
675 //
676 //*****************************************************************************
677 extern uint32_t FlashSectorErase(uint32_t ui32SectorAddress);
678
679
680 //*****************************************************************************
681 //
682 //! \brief Programs unprotected flash sectors in the main bank.
683 //!
684 //! This function programs a sequence of bytes into the on-chip flash.
685 //! Programming each location consists of the result of an AND operation
686 //! of the new data and the existing data; in other words bits that contain
687 //! 1 can remain 1 or be changed to 0, but bits that are 0 cannot be changed
688 //! to 1. Therefore, a byte can be programmed multiple times as long as these
689 //! rules are followed; if a program operation attempts to change a 0 bit to
690 //! a 1 bit, that bit will not have its value changed.
691 //!
692 //! This function does not return until the data has been programmed or a
693 //! programming error occurs.
694 //!
695 //! \note It is recommended to disable cache and line buffer before programming the
696 //! flash. Cache and line buffer are not automatically updated if a flash program
697 //! causes a mismatch between new flash content and old content in cache and
698 //! line buffer. Remember to enable cache and line buffer when the program
699 //! operation completes. See \ref VIMSModeSafeSet(), \ref VIMSLineBufDisable(),
700 //! and \ref VIMSLineBufEnable() for more information.
701 //!
702 //! \warning Please note that code can not execute in flash while any part of the flash
703 //! is being programmed or erased. The application must disable interrupts that have
704 //! interrupt routines in flash. This function calls a ROM function which handles the
705 //! actual program operation.
706 //!
707 //! The \c pui8DataBuffer pointer can not point to flash.
708 //!
709 //! \param pui8DataBuffer is a pointer to the data to be programmed.
710 //! \param ui32Address is the starting address in flash to be programmed.
711 //! \param ui32Count is the number of bytes to be programmed.
712 //!
713 //! \return Returns status of the flash programming:
714 //! - \ref FAPI_STATUS_SUCCESS : Success.
715 //! - \ref FAPI_STATUS_INCORRECT_DATABUFFER_LENGTH : Too many bytes were requested.
716 //! - \ref FAPI_STATUS_FSM_ERROR : A programming error is encountered.
717 //
718 //*****************************************************************************
719 extern uint32_t FlashProgram(uint8_t *pui8DataBuffer,
720 uint32_t ui32Address, uint32_t ui32Count);
721
722 //*****************************************************************************
723 //
724 //! \brief Reads efuse data from specified row.
725 //!
726 //! This function will read one efuse row.
727 //! It is assumed that any previous efuse operation has finished.
728 //!
729 //! \param pui32EfuseData is pointer to variable to be updated with efuse data.
730 //! \param ui32RowAddress is the efuse row number to be read. First row is row
731 //! number 0.
732 //!
733 //! \return Returns the status of the efuse read operation.
734 //! - \c false : OK status.
735 //! - \c true : Error status
736 //
737 //*****************************************************************************
738 extern bool FlashEfuseReadRow(uint32_t *pui32EfuseData,
739 uint32_t ui32RowAddress);
740
741 //*****************************************************************************
742 //
743 //! \brief Disables all sectors for erase and programming on the active bank.
744 //!
745 //! This function disables all sectors for erase and programming on the active
746 //! bank and enables the Idle Reading Power reduction mode if no low power
747 //! mode is configured. Furthermore, an additional level of protection from
748 //! erase is enabled.
749 //!
750 //! \note Please note that code can not execute in flash while any part of the flash
751 //! is being programmed or erased.
752 //!
753 //! \return None
754 //
755 //*****************************************************************************
756 extern void FlashDisableSectorsForWrite(void);
757
758
759 //*****************************************************************************
760 //
761 // Support for DriverLib in ROM:
762 // Redirect to implementation in ROM when available.
763 //
764 //*****************************************************************************
765 #if !defined(DRIVERLIB_NOROM) && !defined(DOXYGEN)
766 #include "../driverlib/rom.h"
767 #ifdef ROM_FlashPowerModeSet
768 #undef FlashPowerModeSet
769 #define FlashPowerModeSet ROM_FlashPowerModeSet
770 #endif
771 #ifdef ROM_FlashPowerModeGet
772 #undef FlashPowerModeGet
773 #define FlashPowerModeGet ROM_FlashPowerModeGet
774 #endif
775 #ifdef ROM_FlashProtectionSet
776 #undef FlashProtectionSet
777 #define FlashProtectionSet ROM_FlashProtectionSet
778 #endif
779 #ifdef ROM_FlashProtectionGet
780 #undef FlashProtectionGet
781 #define FlashProtectionGet ROM_FlashProtectionGet
782 #endif
783 #ifdef ROM_FlashProtectionSave
784 #undef FlashProtectionSave
785 #define FlashProtectionSave ROM_FlashProtectionSave
786 #endif
787 #ifdef ROM_FlashSectorErase
788 #undef FlashSectorErase
789 #define FlashSectorErase ROM_FlashSectorErase
790 #endif
791 #ifdef ROM_FlashProgram
792 #undef FlashProgram
793 #define FlashProgram ROM_FlashProgram
794 #endif
795 #ifdef ROM_FlashEfuseReadRow
796 #undef FlashEfuseReadRow
797 #define FlashEfuseReadRow ROM_FlashEfuseReadRow
798 #endif
799 #ifdef ROM_FlashDisableSectorsForWrite
800 #undef FlashDisableSectorsForWrite
801 #define FlashDisableSectorsForWrite ROM_FlashDisableSectorsForWrite
802 #endif
803 #endif
804
805 //*****************************************************************************
806 //
807 // Mark the end of the C bindings section for C++ compilers.
808 //
809 //*****************************************************************************
810 #ifdef __cplusplus
811 }
812 #endif
813
814 #endif // __FLASH_H__
815
816 //*****************************************************************************
817 //
818 //! Close the Doxygen group.
819 //! @}
820 //! @}
821 //
822 //*****************************************************************************
823