Contiki 3.x
flash.h
Go to the documentation of this file.
1 /** @file hal/micro/cortexm3/flash.h
2  * @brief Header for flash for APIs
3  *
4  * <!--(C) COPYRIGHT 2010 STMicroelectronics. All rights reserved. -->
5  */
6 
7 /**
8  * \addtogroup stm32w-cpu
9  * @{
10  */
11 
12 /**
13  * @defgroup flash Definition and description of public flash manipulation routines.
14  *
15  * @note
16  * During an erase or a write the flash is not available,
17  * which means code will not be executable from flash. These routines still
18  * execute from flash, though, since the bus architecture can support doing so.
19  * <b>Additonally, this also means all interrupts will be disabled.</b>
20  *
21  * <b>Hardware documentation indicates 40us for a write and 21ms for an erase.</b>
22  *
23  * See flash.h for source code.
24  *@{
25  */
26 
27 #ifndef FLASH_H_
28 #define FLASH_H_
29 
30 #include "memmap.h"
31 
32 
33 /** @brief Tells the calling code if a Flash Erase operation is active.
34  *
35  * This state is import to know because Flash Erasing is ATOMIC for 21ms
36  * and could disrupt interrupt latency. But if an ISR can know that it wasn't
37  * serviced immediately due to Flash Erasing, then the ISR has the opportunity
38  * to correct in whatever manner it needs to.
39  *
40  * @return A boolean flag: TRUE if Flash Erase is active, FALSE otherwise.
41  */
42 boolean halFlashEraseIsActive(void);
43 
44 #ifndef DOXYGEN_SHOULD_SKIP_THIS
45 
46 //[[ The following eraseType definitions must match the FIB erase types! ]]
47 /**
48  * @brief Assign numerical value to the type of erasure requested.
49  */
50 #define MFB_MASS_ERASE 0x01
51 #define MFB_PAGE_ERASE 0x02
52 #define CIB_ERASE 0x03
53 
54 /** @brief Erases a section of flash back to all 0xFFFF.
55  *
56  * @param eraseType Choose one of the three types of erasures to perform.
57  * - MFB_MASS_ERASE (0x01) Erase the entire main flash block.
58  * - MFB_PAGE_ERASE (0x02) Erase one hardware page in the main flash block
59  * chosen by the \c address parameter.
60  * - CIB_ERASE (0x03) Erase the entire customer information block.
61  *
62  * @param address This parameter is only effectual when a MFB_PAGE_ERASE is
63  * being performed. The hardware page encapsulating the address given in this
64  * parameter will be erased. A hardware page size depends on the chip
65  *
66  * @return An ::StStatus value indicating the success or failure of the
67  * command:
68  * - ST_ERR_FATAL if the \c eraseType is not valid
69  * - ST_ERR_FLASH_ERASE_FAIL if erasing failed due to write protection
70  * - ST_ERR_FLASH_VERIFY_FAILED if erase verification failed
71  * - ST_SUCCESS if erasure completed and verified properly
72  */
73 StStatus halInternalFlashErase(uint8_t eraseType, uint32_t address);
74 
75 /** @brief Writes a block of words to flash. A page is erased
76  * to 0xFFFF at every address. Only two writes can be performed to the same
77  * address between erasures and this is enforced by the flash interface
78  * controller. If the value already in the address being written to is 0xFFFF,
79  * any value can be written. If the value is not 0xFFFF and not 0x0000, only
80  * 0x0000 can be written. If the value is 0x0000, nothing can be written.
81  *
82  * \b NOTE: This function can NOT write the option bytes and will throw an
83  * error if that is attempted.
84  *
85  * @param address The starting address of where the programming will occur.
86  * This parameter MUST be half-word aligned since all programming operations
87  * are half-words. Also, the address parameter is NOT a pointer. This
88  * routines will cast the address to a pointer for the actual hardware access.
89  *
90  * @param data A pointer to a buffer containing the 16bit (half-words) to
91  * be written.
92  *
93  * @param length The number of 16bit (half-words) contained in the data buffer
94  * to be written to flash.
95  *
96  * @return An ::StStatus value indicating the success or failure of the
97  * command:
98  * - ST_ERR_FLASH_PROG_FAIL if the address is not half-word aligned, the
99  * address is inside the option bytes, write protection is enabled, or the
100  * address is being written to more than twice between erasures.
101  * - ST_ERR_FLASH_VERIFY_FAILED if write verification failed
102  * - ST_SUCCESS if writing completed and verified properly
103  */
104 StStatus halInternalFlashWrite(uint32_t address, uint16_t * data, uint32_t length);
105 
106 /** @brief Writes an option byte to the customer information block. Only
107  * two writes can be performed to the same address between erasures and this
108  * is enforced by the flash interface controller.
109  *
110  * @param byte The option byte number, 0 though 7, to be programmed.
111  *
112  * @param data The 8 bit value to be programmed into the option byte. The
113  * hardware is responsible for calculating the compliment and programming
114  * the full 16bit option byte space.
115  *
116  * @return An ::StStatus value indicating the success or failure of the
117  * command:
118  * - ST_ERR_FLASH_PROG_FAIL if the byte chosen is greater than 7, write
119  * protection is enabled, or the byte is being written to more than twice
120  * between erasures.
121  * - ST_ERR_FLASH_VERIFY_FAILED if write verification failed
122  * - ST_SUCCESS if writing completed and verified properly
123  */
124 StStatus halInternalCibOptionByteWrite(uint8_t byte, uint8_t data);
125 
126 #endif //DOXYGEN_SHOULD_SKIP_THIS
127 
128 #endif //FLASH_H_
129 
130 /** @} END addtogroup */
131 /** @} */
132 
StStatus halInternalFlashWrite(uint32_t address, uint16_t *data, uint32_t length)
Writes a block of words to flash.
Definition: flash.c:294
StStatus halInternalCibOptionByteWrite(uint8_t byte, uint8_t data)
Writes an option byte to the customer information block.
Definition: flash.c:355
boolean halFlashEraseIsActive(void)
Tells the calling code if a Flash Erase operation is active.
Definition: flash.c:41
STM32W108 series memory map definitions used by the full hal.
StStatus halInternalFlashErase(uint8_t eraseType, uint32_t address)
Erases a section of flash back to all 0xFFFF.
Definition: flash.c:231