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
+ core_util_critical_section_exit ();
67
+
68
+ HAL_FLASH_Lock ();
90
69
91
70
return status ;
92
71
}
@@ -99,10 +78,11 @@ 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
85
+ core_util_critical_section_enter ();
106
86
/* Note: If an erase operation in Flash memory also concerns data in the data or instruction cache,
107
87
you have to make sure that these data are rewritten before they are accessed during code
108
88
execution. If this cannot be done safely, it is recommended to flush the caches by setting the
@@ -126,7 +106,9 @@ int32_t flash_program_page(flash_t *obj, uint32_t address, const uint8_t *data,
126
106
}
127
107
}
128
108
129
- flash_lock ();
109
+ core_util_critical_section_exit ();
110
+
111
+ HAL_FLASH_Lock ();
130
112
131
113
return status ;
132
114
}
0 commit comments