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 24
24
#include "cmsis.h"
25
25
26
26
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
+
27
65
int32_t flash_init (flash_t * obj )
28
66
{
29
67
return 0 ;
@@ -57,7 +95,8 @@ int32_t flash_erase_sector(flash_t *obj, uint32_t address)
57
95
/* MBED HAL erases 1 sector at a time */
58
96
/* Fill EraseInit structure*/
59
97
EraseInitStruct .TypeErase = FLASH_TYPEERASE_PAGES ;
60
- EraseInitStruct .Page = (address & 0xFFFFF ) / 2048 ; // page size = 2048
98
+ EraseInitStruct .Banks = GetBank (address );
99
+ EraseInitStruct .Page = GetPage (address );
61
100
EraseInitStruct .NbPages = 1 ;
62
101
63
102
/* 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