Skip to content

Commit 5da83a2

Browse files
LMESTM0xc0170
authored andcommitted
STM32WB: Add FLASH HW Semaphore
Because FLASH is a shared resource between the 2 STM32WB cores, SW needs to acquire HW Semaphore before using the resource.
1 parent 92ef812 commit 5da83a2

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

targets/TARGET_STM/TARGET_STM32WB/flash_api.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
#include "mbed_assert.h"
2424
#include "cmsis.h"
2525

26+
/* Family specific include for WB with HW semaphores */
27+
#include "hw.h"
28+
#include "hw_conf.h"
29+
2630
/**
2731
* @brief Gets the page of a given address
2832
* @param Addr: Address of the FLASH Memory
@@ -71,6 +75,11 @@ int32_t flash_erase_sector(flash_t *obj, uint32_t address)
7175
return -1;
7276
}
7377

78+
#if defined(CFG_HW_FLASH_SEMID)
79+
/* In case RNG is a shared ressource, get the HW semaphore first */
80+
while( LL_HSEM_1StepLock( HSEM, CFG_HW_FLASH_SEMID ) );
81+
#endif
82+
7483
/* Unlock the Flash to enable the flash control register access */
7584
if (HAL_FLASH_Unlock() != HAL_OK) {
7685
return -1;
@@ -99,6 +108,10 @@ int32_t flash_erase_sector(flash_t *obj, uint32_t address)
99108
to protect the FLASH memory against possible unwanted operation) */
100109
HAL_FLASH_Lock();
101110

111+
#if defined(CFG_HW_FLASH_SEMID)
112+
LL_HSEM_ReleaseLock( HSEM, CFG_HW_FLASH_SEMID, 0 );
113+
#endif
114+
102115
return status;
103116
}
104117

@@ -126,6 +139,11 @@ int32_t flash_program_page(flash_t *obj, uint32_t address, const uint8_t *data,
126139
return -1;
127140
}
128141

142+
#if defined(CFG_HW_FLASH_SEMID)
143+
/* In case RNG is a shared ressource, get the HW semaphore first */
144+
while( LL_HSEM_1StepLock( HSEM, CFG_HW_FLASH_SEMID ) );
145+
#endif
146+
129147
/* Unlock the Flash to enable the flash control register access */
130148
if (HAL_FLASH_Unlock() != HAL_OK) {
131149
return -1;
@@ -163,6 +181,10 @@ int32_t flash_program_page(flash_t *obj, uint32_t address, const uint8_t *data,
163181
to protect the FLASH memory against possible unwanted operation) */
164182
HAL_FLASH_Lock();
165183

184+
#if defined(CFG_HW_FLASH_SEMID)
185+
LL_HSEM_ReleaseLock( HSEM, CFG_HW_FLASH_SEMID, 0 );
186+
#endif
187+
166188
return status;
167189
}
168190

0 commit comments

Comments
 (0)