提交 | 用户 | age
|
5dd1b7
|
1 |
#ifndef __STM32F0xx_LL_FLASH_EX_H |
Q |
2 |
#define __STM32F0xx_LL_FLASH_EX_H |
|
3 |
|
|
4 |
#include "stm32f0xx.h" |
|
5 |
|
|
6 |
|
|
7 |
#define FLASH_FLAG_BSY FLASH_SR_BSY /*!< FLASH Busy flag */ |
|
8 |
#define FLASH_FLAG_PGERR FLASH_SR_PGERR /*!< FLASH Programming error flag */ |
|
9 |
#define FLASH_FLAG_WRPERR FLASH_SR_WRPERR /*!< FLASH Write protected error flag */ |
|
10 |
#define FLASH_FLAG_EOP FLASH_SR_EOP /*!< FLASH End of Operation flag */ |
|
11 |
|
|
12 |
#define LL_FLASH_TYPEERASE_PAGES FLASH_CR_PER /*!< FLASH_CR_PER */ |
|
13 |
#define LL_FLASH_TYPEERASE_MASSERASE FLASH_CR_MER /*!< MASSERASE */ |
|
14 |
|
|
15 |
|
|
16 |
#if defined(STM32F030x6) || defined(STM32F030x8) || defined(STM32F031x6) || defined(STM32F038xx) \ |
|
17 |
|| defined(STM32F051x8) || defined(STM32F042x6) || defined(STM32F048xx) || defined(STM32F058xx) || defined(STM32F070x6) |
|
18 |
#define FLASH_PAGE_SIZE 0x400U |
|
19 |
#endif /* STM32F030x6 || STM32F030x8 || STM32F031x6 || STM32F051x8 || STM32F042x6 || STM32F048xx || STM32F058xx || STM32F070x6 */ |
|
20 |
|
|
21 |
#if defined(STM32F071xB) || defined(STM32F072xB) || defined(STM32F078xx) || defined(STM32F070xB) \ |
|
22 |
|| defined(STM32F091xC) || defined(STM32F098xx) || defined(STM32F030xC) |
|
23 |
#define FLASH_PAGE_SIZE 0x800U |
|
24 |
#endif /* STM32F071xB || STM32F072xB || STM32F078xx || STM32F091xC || STM32F098xx || STM32F030xC */ |
|
25 |
|
|
26 |
typedef enum { |
|
27 |
ProgaraType_DATA64, |
|
28 |
ProgaraType_DATA32, |
|
29 |
ProgaraType_DATA16 |
|
30 |
}ProgaramDataType; |
|
31 |
|
|
32 |
typedef enum {\ |
|
33 |
FLASH_Lock=1U,Flash_Unlock=!FLASH_Lock\ |
|
34 |
}FlashStates; |
|
35 |
|
|
36 |
/* Set the OBL_Launch bit to launch the option byte loading */ |
|
37 |
__STATIC_INLINE void LL_FLASH_SET_OBL_Launch(FLASH_TypeDef *FLASHx) |
|
38 |
{ |
|
39 |
SET_BIT(FLASHx->CR, FLASH_CR_OBL_LAUNCH); |
|
40 |
} |
|
41 |
__STATIC_INLINE void LL_FLASH_Lock(FLASH_TypeDef *FLASHx) |
|
42 |
{ |
|
43 |
SET_BIT(FLASHx->CR, FLASH_CR_LOCK); |
|
44 |
} |
|
45 |
|
|
46 |
|
|
47 |
/* @brief Set flash erase type. |
|
48 |
* @param FLASH_TYPEERASE specifies the FLASH flags to clear. |
|
49 |
* This parameter can be any combination of the following values: |
|
50 |
* @arg @ref FLASH_TYPEERASE_PAGES PAGES Erase |
|
51 |
* @arg @ref FLASH_TYPEERASE_MASSERASE FLASH Write protected error flag |
|
52 |
* @retval none*/ |
|
53 |
|
|
54 |
__STATIC_INLINE void LL_FLASH_SetTypeErase(FLASH_TypeDef *FLASHx,uint32_t FLASH_TYPEERASE) |
|
55 |
{ |
|
56 |
SET_BIT(FLASHx->CR, FLASH_TYPEERASE); |
|
57 |
} |
|
58 |
/* @brief Set flash erase ADDR. |
|
59 |
* This parameter can be any combination of the following values: |
|
60 |
* @arg @ref EraseADDR uint32_t value |
|
61 |
* @retval none*/ |
|
62 |
|
|
63 |
__STATIC_INLINE void LL_FLASH_SetEraseADDR(FLASH_TypeDef *FLASHx,uint32_t EraseADDR) |
|
64 |
{ |
|
65 |
WRITE_REG(FLASHx->AR, EraseADDR); |
|
66 |
} |
|
67 |
/* @brief Set flash erase ADDR. |
|
68 |
* This parameter can be any combination of the following values: |
|
69 |
* @arg @ref EraseADDR uint32_t value |
|
70 |
* @retval none*/ |
|
71 |
|
|
72 |
__STATIC_INLINE void LL_FLASH_StartErase(FLASH_TypeDef *FLASHx) |
|
73 |
{ |
|
74 |
SET_BIT(FLASHx->CR, FLASH_CR_STRT); |
|
75 |
} |
|
76 |
|
|
77 |
/* @brief Clear the specified FLASH flag. |
|
78 |
* @param __FLAG__ specifies the FLASH flags to clear. |
|
79 |
* This parameter can be any combination of the following values: |
|
80 |
* @arg @ref FLASH_FLAG_EOP FLASH End of Operation flag |
|
81 |
* @arg @ref FLASH_FLAG_WRPERR FLASH Write protected error flag |
|
82 |
* @arg @ref FLASH_FLAG_PGERR FLASH Programming error flag |
|
83 |
* @retval none*/ |
|
84 |
|
|
85 |
__STATIC_INLINE void LL_FLASH_ClearFlag(FLASH_TypeDef *FLASHx,uint32_t STATE_FLAG) |
|
86 |
{ |
|
87 |
WRITE_REG(FLASHx->SR, STATE_FLAG); |
|
88 |
} |
|
89 |
|
|
90 |
/*get bit flash bsy*/ |
|
91 |
__STATIC_INLINE uint32_t LL_FLASH_IsActiveFlag_BSY(FLASH_TypeDef *FLASHx) |
|
92 |
{ |
|
93 |
return (READ_BIT(FLASHx->SR, FLASH_SR_BSY) == (FLASH_SR_BSY)); |
|
94 |
} |
|
95 |
/*get end of operation bilt*/ |
|
96 |
__STATIC_INLINE uint32_t LL_FLASH_IsActiveFlag_EOP(FLASH_TypeDef *FLASHx) |
|
97 |
{ |
|
98 |
return (READ_BIT(FLASHx->SR, FLASH_SR_EOP) == (FLASH_SR_EOP)); |
|
99 |
} |
|
100 |
/*clear end of operation bilt*/ |
|
101 |
__STATIC_INLINE void LL_FLASH_ClearFlag_EOP(FLASH_TypeDef *FLASHx) |
|
102 |
{ |
|
103 |
SET_BIT(FLASHx->SR, FLASH_SR_EOP);//EOP bit Set clear |
|
104 |
} |
|
105 |
/* @brief Set flash erase type. |
|
106 |
* @param FLASH_TYPEERASE specifies the FLASH flags to clear. |
|
107 |
* This parameter can be any combination of the following values: |
|
108 |
* @arg @ref FLASH_TYPEERASE_PAGES PAGES Erase |
|
109 |
* @arg @ref FLASH_TYPEERASE_MASSERASE FLASH Write protected error flag |
|
110 |
* @retval none*/ |
|
111 |
__STATIC_INLINE void LL_FLASH_DisenableErase(FLASH_TypeDef *FLASHx,uint32_t FLASH_TYPEERASE) |
|
112 |
{ |
|
113 |
CLEAR_BIT(FLASHx->CR, FLASH_TYPEERASE); |
|
114 |
} |
|
115 |
|
|
116 |
/*EnableProgram*/ |
|
117 |
__STATIC_INLINE void LL_FLASH_EnableProgram(FLASH_TypeDef *FLASHx) |
|
118 |
{ |
|
119 |
SET_BIT(FLASHx->CR,FLASH_CR_PG); |
|
120 |
} |
|
121 |
/*DisenableProgram*/ |
|
122 |
__STATIC_INLINE void LL_FLASH_DisenableProgram(FLASH_TypeDef *FLASHx) |
|
123 |
{ |
|
124 |
CLEAR_BIT(FLASHx->CR,FLASH_CR_PG); |
|
125 |
} |
|
126 |
/*read flash's states of lock or unlock*/ |
|
127 |
__STATIC_INLINE FlashStates LL_FLASH_LockState(FLASH_TypeDef *FLASHx) |
|
128 |
{ |
|
129 |
return (FlashStates)(READ_BIT(FLASHx->CR,FLASH_CR_LOCK)); |
|
130 |
} |
|
131 |
/*set key for flash*/ |
|
132 |
__STATIC_INLINE void LL_FLASh_SetKey(FLASH_TypeDef *FLASHx,uint32_t key) |
|
133 |
{ |
|
134 |
WRITE_REG(FLASH->KEYR,key); |
|
135 |
} |
|
136 |
|
|
137 |
ErrorStatus LL_Flash_Unlock(void); |
|
138 |
ErrorStatus LL_Flash_PageErase(void * page_addr,uint16_t NbPages); |
|
139 |
ErrorStatus LL_FLASH_Program(ProgaramDataType ProgramType,uint32_t flash_addr,uint64_t data); |
|
140 |
#endif /* __STM32F0xx_LL_FLASH_EX_H */ |