@@ -64,7 +64,8 @@ void flash_nrf5x_event_cb (uint32_t event)
6464
6565// When soft device is enabled, flash ops are async
6666// Eventual success is reported via callback, which we await
67- static uint32_t wait_for_async_flash_op_completion (uint32_t initial_result ) {
67+ static uint32_t wait_for_async_flash_op_completion (uint32_t initial_result )
68+ {
6869 // If initial result not NRF_SUCCESS, no need to await callback
6970 // We will pass the initial result (failure) straight through
7071 int32_t result = initial_result ;
@@ -76,18 +77,21 @@ static uint32_t wait_for_async_flash_op_completion(uint32_t initial_result) {
7677 xSemaphoreTake (_sem , portMAX_DELAY );
7778
7879 // If completed successfully
79- if (_flash_op_result == NRF_EVT_FLASH_OPERATION_SUCCESS )
80- result = NRF_SUCCESS ;
80+ if (_flash_op_result == NRF_EVT_FLASH_OPERATION_SUCCESS ) {
81+ result = NRF_SUCCESS ;
82+ }
8183
8284 // If general failure.
8385 // The comment on NRF_EVT_FLASH_OPERATION_ERROR describes it as a timeout,
8486 // so we're using a similar error when translating from NRF_SOC_EVTS type to the global NRF52 error defines
85- else if (_flash_op_result == NRF_EVT_FLASH_OPERATION_ERROR )
86- result = NRF_ERROR_TIMEOUT ;
87+ else if (_flash_op_result == NRF_EVT_FLASH_OPERATION_ERROR ) {
88+ result = NRF_ERROR_TIMEOUT ;
89+ }
8790
8891 // If this assert triggers, we need to implement a new NRF_SOC_EVTS value
89- else
90- assert (false);
92+ else {
93+ assert (false);
94+ }
9195 }
9296
9397 return result ;
@@ -147,8 +151,7 @@ bool flash_nrf5x_erase(uint32_t addr)
147151static bool fal_erase (uint32_t addr )
148152{
149153 // Init semaphore for first call
150- if ( _sem == NULL )
151- {
154+ if ( _sem == NULL ) {
152155 _sem = xSemaphoreCreateBinary ();
153156 VERIFY (_sem );
154157 }
@@ -164,9 +167,15 @@ static bool fal_erase (uint32_t addr)
164167 for (uint8_t attempt = 0 ; attempt < MAX_RETRY ; ++ attempt ) {
165168 err = sd_flash_page_erase (addr / FLASH_NRF52_PAGE_SIZE );
166169
167- if (sd_en ) err = wait_for_async_flash_op_completion (err ); // Only async if soft device enabled
168- if (err == NRF_SUCCESS ) break ;
169- if (err == NRF_ERROR_BUSY ) delay (1 );
170+ if (sd_en ) {
171+ err = wait_for_async_flash_op_completion (err ); // Only async if soft device enabled
172+ }
173+ if (err == NRF_SUCCESS ) {
174+ break ;
175+ }
176+ if (err == NRF_ERROR_BUSY ) {
177+ delay (1 );
178+ }
170179 }
171180 VERIFY_STATUS (err , false); // Return false if all retries fail
172181
@@ -190,9 +199,15 @@ static uint32_t fal_program (uint32_t dst, void const * src, uint32_t len)
190199 for (uint8_t attempt = 0 ; attempt < MAX_RETRY ; ++ attempt ) {
191200 err = sd_flash_write ((uint32_t * ) dst , (uint32_t const * ) src , len /4 );
192201
193- if (sd_en ) err = wait_for_async_flash_op_completion (err ); // Only async if soft device enabled
194- if (err == NRF_SUCCESS ) break ;
195- if (err == NRF_ERROR_BUSY ) delay (1 );
202+ if (sd_en ) {
203+ err = wait_for_async_flash_op_completion (err ); // Only async if soft device enabled
204+ }
205+ if (err == NRF_SUCCESS ) {
206+ break ;
207+ }
208+ if (err == NRF_ERROR_BUSY ) {
209+ delay (1 );
210+ }
196211 }
197212 VERIFY_STATUS (err , 0 ); // Return 0 if all retries fail
198213
@@ -202,9 +217,15 @@ static uint32_t fal_program (uint32_t dst, void const * src, uint32_t len)
202217 for (uint8_t attempt = 0 ; attempt < MAX_RETRY ; ++ attempt ) {
203218 err = sd_flash_write ((uint32_t * ) dst , (uint32_t const * ) src , len /8 );
204219
205- if (sd_en ) err = wait_for_async_flash_op_completion (err ); // Only async if soft device enabled
206- if (err == NRF_SUCCESS ) break ;
207- if (err == NRF_ERROR_BUSY ) delay (1 );
220+ if (sd_en ) {
221+ err = wait_for_async_flash_op_completion (err ); // Only async if soft device enabled
222+ }
223+ if (err == NRF_SUCCESS ) {
224+ break ;
225+ }
226+ if (err == NRF_ERROR_BUSY ) {
227+ delay (1 );
228+ }
208229 }
209230 VERIFY_STATUS (err , 0 ); // Return 0 if all retries fail
210231
@@ -213,9 +234,15 @@ static uint32_t fal_program (uint32_t dst, void const * src, uint32_t len)
213234 for (uint8_t attempt = 0 ; attempt < MAX_RETRY ; ++ attempt ) {
214235 err = sd_flash_write ((uint32_t * ) (dst + len /2 ), (uint32_t const * ) (src + len /2 ), len /8 );
215236
216- if (sd_en ) err = wait_for_async_flash_op_completion (err ); // Only async if soft device enabled
217- if (err == NRF_SUCCESS ) break ;
218- if (err == NRF_ERROR_BUSY ) delay (1 );
237+ if (sd_en ) {
238+ err = wait_for_async_flash_op_completion (err ); // Only async if soft device enabled
239+ }
240+ if (err == NRF_SUCCESS ) {
241+ break ;
242+ }
243+ if (err == NRF_ERROR_BUSY ) {
244+ delay (1 );
245+ }
219246 }
220247 VERIFY_STATUS (err , 0 ); // Return 0 if all retries fail
221248#endif
0 commit comments