Select one of the symbols to view example projects that use it.
 
Outline
Includes
#include "flash_if.h"
FLASH_If_Init()
FLASH_If_Erase(uint32_t)
FLASH_If_Write(volatile uint32_t *, uint32_t *, uint16_t)
Files
loading...
SourceVuSTM32 Libraries and SamplesLwIP_IAPSrc/flash_if.c
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/** ****************************************************************************** * @file LwIP/LwIP_IAP/Src/flash_if.c * @author MCD Application Team * @brief This file provides high level routines to manage internal Flash * programming (erase and write). ****************************************************************************** * @attention * * Copyright (c) 2017 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** *//* ... */ /* Includes ------------------------------------------------------------------*/ #include "flash_if.h" Includes /* Private typedef -----------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/ /* Private macro -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ /* Private function prototypes -----------------------------------------------*/ /* Private functions ---------------------------------------------------------*/ /** * @brief Unlocks Flash for write access * @param None * @retval None *//* ... */ void FLASH_If_Init(void) { HAL_FLASH_Unlock(); }{ ... } /** * @brief This function does an erase of all user flash area * @param StartSector: start of user flash area * @retval 0: user flash area successfully erased * 1: error occurred *//* ... */ int8_t FLASH_If_Erase(uint32_t StartSector) { uint32_t FlashAddress; FlashAddress = StartSector; /* Device voltage range supposed to be [2.7V to 3.6V], the operation will be done by word *//* ... */ if (FlashAddress <= (uint32_t) USER_FLASH_LAST_PAGE_ADDRESS) { FLASH_EraseInitTypeDef FLASH_EraseInitStruct; uint32_t sectornb = 0; FLASH_EraseInitStruct.TypeErase = FLASH_TYPEERASE_SECTORS; FLASH_EraseInitStruct.Sector = FLASH_SECTOR_5; FLASH_EraseInitStruct.NbSectors = 7; FLASH_EraseInitStruct.VoltageRange = FLASH_VOLTAGE_RANGE_3; if (HAL_FLASHEx_Erase(&FLASH_EraseInitStruct, &sectornb) != HAL_OK) return (1); }if (FlashAddress <= (uint32_t) USER_FLASH_LAST_PAGE_ADDRESS) { ... } else { return (1); }else { ... } return (0); }{ ... } /** * @brief This function writes a data buffer in flash (data are 32-bit aligned). * @note After writing data buffer, the flash content is checked. * @param FlashAddress: start address for writing data buffer * @param Data: pointer on data buffer * @param DataLength: length of data buffer (unit is 32-bit word) * @retval 0: Data successfully written to Flash memory * 1: Error occurred while writing data in Flash memory * 2: Written Data in flash memory is different from expected one *//* ... */ uint32_t FLASH_If_Write(__IO uint32_t* FlashAddress, uint32_t* Data ,uint16_t DataLength) { uint32_t i = 0; for (i = 0; (i < DataLength) && (*FlashAddress <= (USER_FLASH_END_ADDRESS-4)); i++) { /* Device voltage range supposed to be [2.7V to 3.6V], the operation will be done by word *//* ... */ if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, *FlashAddress, *(uint32_t*)(Data+i)) == HAL_OK) { /* Check the written value */ if (*(uint32_t*)*FlashAddress != *(uint32_t*)(Data+i)) { /* Flash content doesn't match SRAM content */ return(2); }if (*(uint32_t*)*FlashAddress != *(uint32_t*)(Data+i)) { ... } /* Increment FLASH destination address */ *FlashAddress += 4; }if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, *FlashAddress, *(uint32_t*)(Data+i)) == HAL_OK) { ... } else { /* Error occurred while writing data in Flash memory */ return (1); }else { ... } }for (i = 0; (i < DataLength) && (*FlashAddress <= (USER_FLASH_END_ADDRESS-4)); i++) { ... } return (0); }{ ... }
Details