annotate Small_CPU/Src/RTE_FlashAccess.c @ 865:cb386cccc7c5

When opening the logbook, or scrolling inside a logbook page, show 'Page' instead of 'Back' to make it clear that this is the way to page through the logbook pages. from mikeller
author heinrichsweikamp
date Mon, 22 Jul 2024 16:39:48 +0200
parents 91a8f9893e68
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3 * @file RTE_FLashAccess.c based on BonexFlashAccess.c based on firmwareEraseProgram.v
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
4 * @author heinrichs weikamp gmbh
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
5 * @version V0.0.1
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
6 * @date 20-July-2016
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
7 * @version V0.0.1
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
8 * @since 20-July-2016
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
9 * @brief erase and program the STM32F4xx internal FLASH memory for compasss calib etc.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
10 * based on firmwareEraseProgram.c from OSTC4
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
11 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
12 @verbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
13 ==============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
14 ##### How to use #####
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
15 ==============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
16
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
17 4 x 32 Byte with first block can not be 0xFFFFFFFF
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
18
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
19
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
20
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
21 @endverbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
22 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
23 * @attention
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
24 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
25 * <h2><center>&copy; COPYRIGHT(c) 2015 heinrichs weikamp</center></h2>
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
26 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
27 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
28 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
29
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
30 /* Includes ------------------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
31 #include "RTE_FlashAccess.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
32 #include "stdio.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
33
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
34 /** @addtogroup BONEXINFOSYSTEM
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
35 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
36 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
37
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
38 /* Exported variables --------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
39
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
40 /* Private types -------------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
41 /* taken from
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
42 * C:\Users\hw\STM32Cube\Repository\STM32Cube_FW_F3_V1.2.0\Projects\STM32F3-Discovery\Examples\FLASH\FLASH_EraseProgram
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
43 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
44
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
45 #define FLASH_SECTOR_SIZE_128KB (0x00020000)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
46 #define FLASH_USER_START_ADDR (ADDR_FLASH_SECTOR_7) /* Start @ of user Flash area */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
47 #define FLASH_USER_END_ADDR (ADDR_FLASH_SECTOR_7 + FLASH_SECTOR_SIZE_128KB) /* End @ of user Flash area */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
48
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
49 /* Base address of the Flash pages */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
50
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
51 #define ADDR_FLASH_SECTOR_0 ((uint32_t)0x08000000) /* Base @ of Sector 0, 16 Kbytes */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
52 #define ADDR_FLASH_SECTOR_1 ((uint32_t)0x08004000) /* Base @ of Sector 1, 16 Kbytes */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
53 #define ADDR_FLASH_SECTOR_2 ((uint32_t)0x08008000) /* Base @ of Sector 2, 16 Kbytes */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
54 #define ADDR_FLASH_SECTOR_3 ((uint32_t)0x0800C000) /* Base @ of Sector 3, 16 Kbytes */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
55 #define ADDR_FLASH_SECTOR_4 ((uint32_t)0x08010000) /* Base @ of Sector 4, 64 Kbytes */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
56 #define ADDR_FLASH_SECTOR_5 ((uint32_t)0x08020000) /* Base @ of Sector 5, 128 Kbytes */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
57 #define ADDR_FLASH_SECTOR_6 ((uint32_t)0x08040000) /* Base @ of Sector 6, 128 Kbytes */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
58 #define ADDR_FLASH_SECTOR_7 ((uint32_t)0x08060000) /* Base @ of Sector 7, 128 Kbytes */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
59
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
60
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
61
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
62
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
63 /* Private variables ---------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
64
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
65 //static FLASH_EraseInitTypeDef EraseInitStruct; //Variable used for Erase procedure
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
66
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
67 uint32_t Address = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
68 uint32_t PageError = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
69 __IO uint32_t data32 = 0 , MemoryProgramStatus = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
70
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
71 /* Private function prototypes -----------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
72 //uint8_t BFA_eraseSectors(uint32_t SectorAddress, uint32_t NbSectors);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
73 //uint8_t BFA_eraseSectorsAll(void);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
74 uint8_t BFA_FindLastDataBlockAndSetAddress(void);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
75
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
76 /* Exported functions --------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
77
571
91a8f9893e68 Reactivate compass parameter stored in NVM:
Ideenmodellierer
parents: 38
diff changeset
78 uint8_t BFA_readLastDataBlock(tfull32 *dataArray4)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
79 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
80 uint8_t answer;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
81
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
82 answer = BFA_FindLastDataBlockAndSetAddress();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
83 if(answer != BFA_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
84 return answer;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
85
571
91a8f9893e68 Reactivate compass parameter stored in NVM:
Ideenmodellierer
parents: 38
diff changeset
86 dataArray4[0].Full32 = *(__IO uint32_t*)(Address + 0);
91a8f9893e68 Reactivate compass parameter stored in NVM:
Ideenmodellierer
parents: 38
diff changeset
87 dataArray4[1].Full32 = *(__IO uint32_t*)(Address + 4);
91a8f9893e68 Reactivate compass parameter stored in NVM:
Ideenmodellierer
parents: 38
diff changeset
88 dataArray4[2].Full32 = *(__IO uint32_t*)(Address + 8);
91a8f9893e68 Reactivate compass parameter stored in NVM:
Ideenmodellierer
parents: 38
diff changeset
89 dataArray4[3].Full32 = *(__IO uint32_t*)(Address + 12);
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
90 return BFA_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
91 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
92
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
93
571
91a8f9893e68 Reactivate compass parameter stored in NVM:
Ideenmodellierer
parents: 38
diff changeset
94 uint8_t BFA_writeDataBlock(const tfull32 *dataArray4)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
95 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
96 uint8_t answer;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
97 uint32_t dataTest[4];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
98 uint32_t StartAddress;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
99
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
100 answer = BFA_FindLastDataBlockAndSetAddress();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
101 Address = Address + 16;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
102
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
103 if((answer == BFA_EMPTY) || (Address >= FLASH_USER_END_ADDR) || (Address < FLASH_USER_START_ADDR))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
104 Address = FLASH_USER_START_ADDR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
105
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
106 dataTest[0] = *(__IO uint32_t*)(Address + 0);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
107 dataTest[1] = *(__IO uint32_t*)(Address + 4);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
108 dataTest[2] = *(__IO uint32_t*)(Address + 8);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
109 dataTest[3] = *(__IO uint32_t*)(Address + 12);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
110
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
111 for(int i=0;i<4;i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
112 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
113 if(dataTest[i] != 0xFFFFFFFF)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
114 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
115 return 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
116 // answer = BFA_eraseSectorsAll();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
117 // break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
118 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
119 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
120 answer = BFA_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
121 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
122
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
123 // can I write?
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
124 if(answer != BFA_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
125 return answer;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
126
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
127 StartAddress = Address;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
128 HAL_FLASH_Unlock();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
129 for(int i=0;i<4;i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
130 {
571
91a8f9893e68 Reactivate compass parameter stored in NVM:
Ideenmodellierer
parents: 38
diff changeset
131 answer = HAL_FLASH_Program(TYPEPROGRAM_WORD, Address, dataArray4[i].Full32);
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
132 Address = Address + 4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
133 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
134 HAL_FLASH_Lock();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
135 Address = StartAddress; // back to start of this data set (for reading etc.)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
136 return answer;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
137 }
571
91a8f9893e68 Reactivate compass parameter stored in NVM:
Ideenmodellierer
parents: 38
diff changeset
138 uint16_t BFA_calc_Block_Checksum(const tfull32 *dataArray4)
91a8f9893e68 Reactivate compass parameter stored in NVM:
Ideenmodellierer
parents: 38
diff changeset
139 {
91a8f9893e68 Reactivate compass parameter stored in NVM:
Ideenmodellierer
parents: 38
diff changeset
140 uint16_t checksum = 0;
91a8f9893e68 Reactivate compass parameter stored in NVM:
Ideenmodellierer
parents: 38
diff changeset
141 uint8_t loop = 0;
91a8f9893e68 Reactivate compass parameter stored in NVM:
Ideenmodellierer
parents: 38
diff changeset
142 uint16_t* p_data = (uint16_t*)dataArray4;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
143
571
91a8f9893e68 Reactivate compass parameter stored in NVM:
Ideenmodellierer
parents: 38
diff changeset
144 for (loop = 0; loop < 6; loop++) // calc checksum across first 6 words */
91a8f9893e68 Reactivate compass parameter stored in NVM:
Ideenmodellierer
parents: 38
diff changeset
145 {
91a8f9893e68 Reactivate compass parameter stored in NVM:
Ideenmodellierer
parents: 38
diff changeset
146 checksum += *p_data;
91a8f9893e68 Reactivate compass parameter stored in NVM:
Ideenmodellierer
parents: 38
diff changeset
147 }
91a8f9893e68 Reactivate compass parameter stored in NVM:
Ideenmodellierer
parents: 38
diff changeset
148 return checksum;
91a8f9893e68 Reactivate compass parameter stored in NVM:
Ideenmodellierer
parents: 38
diff changeset
149 }
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
150
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
151 /* Private functions ---------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
152 /*
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
153 uint8_t BFA_eraseSectorsAll(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
154 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
155 return BFA_eraseSectors(FLASH_USER_START_ADDR, (FLASH_USER_END_ADDR - FLASH_USER_START_ADDR)/FLASH_SECTOR_SIZE_128KB);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
156 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
157
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
158
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
159 uint8_t BFA_eraseSectors(uint32_t SectorAddress, uint32_t NbSectors)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
160 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
161 if((NbSectors > 1) || (SectorAddress != FLASH_USER_START_ADDR))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
162 return 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
163
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
164 uint8_t answer;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
165 uint32_t PageError = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
166
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
167 HAL_FLASH_Unlock();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
168
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
169 EraseInitStruct.TypeErase = FLASH_TYPEERASE_SECTORS;//ERASE_SECTORS;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
170 EraseInitStruct.Sector = SectorAddress;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
171 EraseInitStruct.NbSectors = NbSectors;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
172
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
173 answer = HAL_FLASHEx_Erase(&EraseInitStruct, &PageError);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
174
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
175 HAL_FLASH_Lock();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
176 return answer;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
177 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
178 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
179
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
180 uint8_t BFA_FindLastDataBlockAndSetAddress(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
181 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
182 uint32_t StartAddress;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
183
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
184 // first part from here to the end
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
185 // there it should be, most likely at Address itself
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
186 if(Address == 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
187 Address = FLASH_USER_END_ADDR - 16;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
188 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
189 Address &= 0xFFFFFFF0; // align with 16Byte
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
190
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
191 StartAddress = Address;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
192 while (Address >= FLASH_USER_START_ADDR)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
193 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
194 data32 = *(__IO uint32_t*)Address;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
195 if(data32 != 0xFFFFFFFF)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
196 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
197 return BFA_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
198 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
199 Address = Address - 16;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
200 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
201
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
202 // second part from the end to here
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
203 if(StartAddress == FLASH_USER_END_ADDR - 16)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
204 return BFA_EMPTY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
205
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
206 Address = FLASH_USER_END_ADDR - 16;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
207 while (Address > StartAddress)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
208 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
209 data32 = *(__IO uint32_t*)Address;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
210 if(data32 != 0xFFFFFFFF)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
211 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
212 return BFA_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
213 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
214 Address = Address - 16;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
215 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
216
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
217 // empty flash
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
218 return BFA_EMPTY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
219 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
220 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
221 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
222 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
223
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
224 /************************ (C) COPYRIGHT heinrichs weikamp *****END OF FILE****/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
225
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
226