|
36 | 36 |
|
37 | 37 | #if DEVICE_FLASH
|
38 | 38 |
|
39 |
| -// This is a flash algo binary blob. It is PIC (position independent code) that should be stored in RAM |
40 |
| -static uint32_t FLASH_ALGO[] = { |
41 |
| - 0xf3c04601, 0x28203007, 0x2204bf24, 0x1050eb02, 0x2810d205, 0x2203bf26, 0x1010eb02, 0xf4110880, |
42 |
| - 0xbf181f80, 0x0010f040, 0x48714770, 0x6001496f, 0x60014970, 0x68014870, 0x01f0f041, 0x486f6001, |
43 |
| - 0xf0106800, 0xd1080f20, 0xf245486d, 0x60015155, 0x60412106, 0x71fff640, 0x20006081, 0x49694770, |
44 |
| - 0xf4206808, 0x600a52f8, 0x48676008, 0xf0416801, 0x60014100, 0x47702000, 0xc18cf8df, 0x0000f8dc, |
45 |
| - 0x0004f040, 0x0000f8cc, 0x0000f8dc, 0x4000f440, 0x0000f8cc, 0x0000f8dc, 0x3080f440, 0x0000f8cc, |
46 |
| - 0x0004f1ac, 0xf4116801, 0xbf1c3f80, 0x21aaf64a, 0xd0044a53, 0x68036011, 0x3f80f413, 0xf8dcd1fa, |
47 |
| - 0xf0200000, 0xf8cc0004, 0xf8dc0000, 0xf4200000, 0xf8cc4000, 0x20000000, 0xf3c04770, 0x29203107, |
48 |
| - 0x2204bf24, 0x1151eb02, 0x2910d205, 0x2203bf26, 0x1111eb02, 0xf4100889, 0xbf181f80, 0x0110f041, |
49 |
| - 0x6802483d, 0x02f0f042, 0xf1006002, 0x22020c04, 0x2000f8cc, 0x2000f8dc, 0xea0323f8, 0x431101c1, |
50 |
| - 0x1000f8cc, 0x1000f8dc, 0x3180f441, 0x1000f8cc, 0xf4116801, 0xbf1c3f80, 0x21aaf64a, 0xd0044a30, |
51 |
| - 0x68036011, 0x3f80f413, 0xf8dcd1fa, 0xf0211000, 0xf8cc0102, 0x68011000, 0x0ff0f011, 0x2000bf04, |
52 |
| - 0x68014770, 0x01f0f041, 0x20016001, 0x4b224770, 0x1cc9b430, 0xc000f8d3, 0x0103f031, 0x0cf0f04c, |
53 |
| - 0xc000f8c3, 0x0404f103, 0x0c00f04f, 0xc000f8c4, 0xf240bf18, 0xd0252501, 0xc000f8d4, 0x0c05ea4c, |
54 |
| - 0xc000f8c4, 0xc000f8d2, 0xc000f8c0, 0xc000f8d3, 0x3f80f41c, 0xf8d4d1fa, 0xf02cc000, 0xf8c40c01, |
55 |
| - 0xf8d3c000, 0xf01cc000, 0xd0060ff0, 0xf0406818, 0x601800f0, 0x2001bc30, 0x1d004770, 0xf1021f09, |
56 |
| - 0xd1d90204, 0x2000bc30, 0x00004770, 0x45670123, 0x40023c04, 0xcdef89ab, 0x40023c0c, 0x40023c14, |
57 |
| - 0x40003000, 0x40023c00, 0x40023c10, 0x00000000 |
58 |
| -}; |
| 39 | +#if defined (STM32F429xx) || defined (STM32F439xx) |
| 40 | +#define FLASH_SIZE (uint32_t) 0x200000 |
| 41 | +#endif |
59 | 42 |
|
60 |
| -static const flash_algo_t flash_algo_config = { |
61 |
| - .init = 0x2b, |
62 |
| - .uninit = 0x5f, |
63 |
| - .erase_sector = 0xdb, |
64 |
| - .program_page = 0x16f, |
65 |
| - .static_base = 0x20c, |
66 |
| - .algo_blob = FLASH_ALGO |
67 |
| -}; |
| 43 | +static uint32_t GetSector(uint32_t Address); |
| 44 | +static uint32_t GetSectorSize(uint32_t Sector); |
68 | 45 |
|
69 |
| -static const sector_info_t sectors_info[] = { |
70 |
| - {0x8000000, 0x4000}, |
71 |
| - {0x8010000, 0x10000}, |
72 |
| - {0x8020000, 0x20000}, |
73 |
| - {0x8100000, 0x4000}, |
74 |
| - {0x8110000, 0x10000}, |
75 |
| - {0x8120000, 0x20000}, |
76 |
| -}; |
| 46 | +int32_t flash_init(flash_t *obj) |
| 47 | +{ |
| 48 | + /* Allow Access to Flash control registers and user Falsh */ |
| 49 | + if (HAL_FLASH_Unlock()) { |
| 50 | + return -1; |
| 51 | + } else { |
| 52 | + return 0; |
| 53 | + } |
| 54 | +} |
| 55 | +int32_t flash_free(flash_t *obj) |
| 56 | +{ |
| 57 | + /* Disable the Flash option control register access (recommended to protect |
| 58 | + the option Bytes against possible unwanted operations) */ |
| 59 | + if (HAL_FLASH_Lock()) { |
| 60 | + return -1; |
| 61 | + } else { |
| 62 | + return 0; |
| 63 | + } |
| 64 | +} |
| 65 | +int32_t flash_erase_sector(flash_t *obj, uint32_t address) |
| 66 | +{ |
| 67 | + /*Variable used for Erase procedure*/ |
| 68 | + static FLASH_EraseInitTypeDef EraseInitStruct; |
| 69 | + uint32_t FirstSector; |
| 70 | + uint32_t SectorError = 0; |
| 71 | + |
| 72 | + if ((address >= (FLASH_BASE + FLASH_SIZE)) || (address < FLASH_BASE)) { |
| 73 | + |
| 74 | + return -1; |
| 75 | + } |
| 76 | + |
| 77 | + /* Get the 1st sector to erase */ |
| 78 | + FirstSector = GetSector(address); |
77 | 79 |
|
78 |
| -static const flash_target_config_t flash_target_config = { |
79 |
| - .page_size = 0x400, |
80 |
| - .flash_start = 0x8000000, |
81 |
| - .flash_size = 0x200000, |
82 |
| - .sectors = sectors_info, |
83 |
| - .sector_info_count = sizeof(sectors_info) / sizeof(sector_info_t) |
84 |
| -}; |
| 80 | + /* Fill EraseInit structure*/ |
| 81 | + EraseInitStruct.TypeErase = FLASH_TYPEERASE_SECTORS; |
| 82 | + EraseInitStruct.VoltageRange = FLASH_VOLTAGE_RANGE_3; |
| 83 | + EraseInitStruct.Sector = FirstSector; |
| 84 | + EraseInitStruct.NbSectors = 1; |
| 85 | + if(HAL_FLASHEx_Erase(&EraseInitStruct, &SectorError) != HAL_OK){ |
| 86 | + return -1; |
| 87 | + } else { |
| 88 | + return 0; |
| 89 | + } |
| 90 | +} |
85 | 91 |
|
86 |
| -void flash_set_target_config(flash_t *obj) |
| 92 | +int32_t flash_program_page(flash_t *obj, uint32_t address, const uint8_t *data, uint32_t size) |
87 | 93 | {
|
88 | 94 |
|
89 | 95 | if ((address >= (FLASH_BASE + FLASH_SIZE)) || (address < FLASH_BASE)) {
|
|
0 commit comments