@@ -85,6 +85,7 @@ int32_t flash_erase_sector(flash_t *obj, uint32_t address)
85
85
86
86
n = GetSecNum (address ); // Get Sector Number
87
87
88
+ core_util_critical_section_enter ();
88
89
IAP .cmd = 50 ;// Prepare Sector for Erase
89
90
IAP .par [0 ] = n ;// Start Sector
90
91
IAP .par [1 ] = n ;// End Sector
@@ -98,6 +99,7 @@ int32_t flash_erase_sector(flash_t *obj, uint32_t address)
98
99
IAP .par [1 ] = n ;// End Sector
99
100
IAP .par [2 ] = CCLK ;// CCLK in kHz
100
101
IAP_Call (& IAP .cmd , & IAP .stat );// Call IAP Command
102
+ core_util_critical_section_exit ();
101
103
if (IAP .stat ) {
102
104
return (1 ); // Command Failed
103
105
}
@@ -106,18 +108,16 @@ int32_t flash_erase_sector(flash_t *obj, uint32_t address)
106
108
107
109
}
108
110
109
- /* IAP Call */
110
- typedef void (* IAP_Entry ) (unsigned long * cmd , unsigned long * stat );
111
- #define IAP_Call ((IAP_Entry) 0x1FFF1FF1)
112
-
113
111
int32_t flash_program_page (flash_t * obj , uint32_t address ,
114
112
const uint8_t * data , uint32_t size )
115
113
{
116
114
unsigned long n ;
117
- uint8_t * alignedData = 0 ;
115
+ // always malloc outside critical section
116
+ uint8_t * alignedData = malloc (size );
118
117
119
118
n = GetSecNum (address ); // Get Sector Number
120
119
120
+ core_util_critical_section_enter ();
121
121
IAP .cmd = 50 ;// Prepare Sector for Write
122
122
IAP .par [0 ] = n ;// Start Sector
123
123
IAP .par [1 ] = n ;// End Sector
@@ -132,14 +132,14 @@ int32_t flash_program_page(flash_t *obj, uint32_t address,
132
132
if ((unsigned long )data %4 == 0 ) { // Word boundary
133
133
IAP .par [1 ] = (unsigned long )data ;// Source RAM Address
134
134
} else {
135
- alignedData = malloc (size );
136
135
memcpy (alignedData ,data ,size );
137
136
IAP .par [1 ] = (unsigned long )alignedData ; // Source RAM Address
138
137
}
139
138
140
139
IAP .par [2 ] = 1024 ; // Fixed Page Size
141
140
IAP .par [3 ] = CCLK ;// CCLK in kHz
142
141
IAP_Call (& IAP .cmd , & IAP .stat );// Call IAP Command
142
+ core_util_critical_section_exit ();
143
143
144
144
if (alignedData != 0 ) { // We allocated our own memory
145
145
free (alignedData );
0 commit comments