File tree Expand file tree Collapse file tree 1 file changed +40
-1
lines changed
targets/TARGET_STM/TARGET_STM32G0 Expand file tree Collapse file tree 1 file changed +40
-1
lines changed Original file line number Diff line number Diff line change 2424#include "cmsis.h"
2525
2626
27+ uint32_t GetBank (uint32_t Addr )
28+ {
29+ #if defined(FLASH_DBANK_SUPPORT )
30+ if (Addr < (FLASH_BASE + FLASH_BANK_SIZE ))
31+ {
32+ return FLASH_BANK_1 ;
33+ }
34+ else
35+ {
36+ return FLASH_BANK_2 ;
37+ }
38+ #else
39+ return FLASH_BANK_1 ;
40+ #endif
41+ }
42+
43+ uint32_t GetPage (uint32_t Addr )
44+ {
45+ uint32_t page = 0 ;
46+
47+ #if defined(FLASH_DBANK_SUPPORT )
48+ if (Addr < (FLASH_BASE + FLASH_BANK_SIZE ))
49+ {
50+ /* Bank 1 */
51+ page = (Addr - FLASH_BASE ) / FLASH_PAGE_SIZE ;
52+ }
53+ else
54+ {
55+ /* Bank 2 */
56+ page = (Addr - (FLASH_BASE + FLASH_BANK_SIZE )) / FLASH_PAGE_SIZE ;
57+ }
58+ #else
59+ page = (Addr - FLASH_BASE ) / FLASH_PAGE_SIZE ;
60+ #endif
61+
62+ return page ;
63+ }
64+
2765int32_t flash_init (flash_t * obj )
2866{
2967 return 0 ;
@@ -57,7 +95,8 @@ int32_t flash_erase_sector(flash_t *obj, uint32_t address)
5795 /* MBED HAL erases 1 sector at a time */
5896 /* Fill EraseInit structure*/
5997 EraseInitStruct .TypeErase = FLASH_TYPEERASE_PAGES ;
60- EraseInitStruct .Page = (address & 0xFFFFF ) / 2048 ; // page size = 2048
98+ EraseInitStruct .Banks = GetBank (address );
99+ EraseInitStruct .Page = GetPage (address );
61100 EraseInitStruct .NbPages = 1 ;
62101
63102 /* Note: If an erase operation in Flash memory also concerns data in the data or instruction cache,
You can’t perform that action at this time.
0 commit comments