21
21
#include "flash_data.h"
22
22
#include "platform/mbed_critical.h"
23
23
24
- // This file is automatically generated
25
-
26
-
27
24
static uint32_t GetSector (uint32_t Address );
28
25
static uint32_t GetSectorSize (uint32_t Sector );
29
26
@@ -37,30 +34,8 @@ int32_t flash_free(flash_t *obj)
37
34
return 0 ;
38
35
}
39
36
40
- static int32_t flash_unlock (void )
41
- {
42
- /* Allow Access to Flash control registers and user Falsh */
43
- if (HAL_FLASH_Unlock ()) {
44
- return -1 ;
45
- } else {
46
- return 0 ;
47
- }
48
- }
49
-
50
- static int32_t flash_lock (void )
51
- {
52
- /* Disable the Flash option control register access (recommended to protect
53
- the option Bytes against possible unwanted operations) */
54
- if (HAL_FLASH_Lock ()) {
55
- return -1 ;
56
- } else {
57
- return 0 ;
58
- }
59
- }
60
-
61
37
int32_t flash_erase_sector (flash_t * obj , uint32_t address )
62
38
{
63
- /*Variable used for Erase procedure*/
64
39
static FLASH_EraseInitTypeDef EraseInitStruct ;
65
40
uint32_t FirstSector ;
66
41
uint32_t SectorError = 0 ;
@@ -70,10 +45,12 @@ int32_t flash_erase_sector(flash_t *obj, uint32_t address)
70
45
return -1 ;
71
46
}
72
47
73
- if (flash_unlock () != HAL_OK ) {
48
+ if (HAL_FLASH_Unlock () != HAL_OK ) {
74
49
return -1 ;
75
50
}
76
51
52
+ core_util_critical_section_enter ();
53
+
77
54
/* Get the 1st sector to erase */
78
55
FirstSector = GetSector (address );
79
56
@@ -86,7 +63,9 @@ int32_t flash_erase_sector(flash_t *obj, uint32_t address)
86
63
status = -1 ;
87
64
}
88
65
89
- flash_lock ();
66
+ HAL_FLASH_Lock ();
67
+
68
+ core_util_critical_section_exit ();
90
69
91
70
return status ;
92
71
}
@@ -99,7 +78,7 @@ int32_t flash_program_page(flash_t *obj, uint32_t address, const uint8_t *data,
99
78
return -1 ;
100
79
}
101
80
102
- if (flash_unlock () != HAL_OK ) {
81
+ if (HAL_FLASH_Unlock () != HAL_OK ) {
103
82
return -1 ;
104
83
}
105
84
@@ -126,7 +105,7 @@ int32_t flash_program_page(flash_t *obj, uint32_t address, const uint8_t *data,
126
105
}
127
106
}
128
107
129
- flash_lock ();
108
+ HAL_FLASH_Lock ();
130
109
131
110
return status ;
132
111
}
0 commit comments