PER Firmware
Loading...
Searching...
No Matches
flash.h
Go to the documentation of this file.
1
12#ifndef _PHAL_FLASH_H_
13#define _PHAL_FLASH_H_
14
15#include "common/phal_F4_F7/phal_F4_F7.h"
16
17enum {
18 FLASH_OK = 0,
19 FLASH_FAIL,
20 FLASH_ADDR_NOT_CLEARED,
21 FLASH_TIMEOUT,
22};
23
24// Flash magic numbers obtained from family reference manual
25#define FLASH_KEY_1 0x45670123
26#define FLASH_KEY_2 0xCDEF89AB
27
28#define PHAL_FLASH_TIMEOUT 500000U
29
30/* Base address of the Flash sectors */
31#ifdef STM32F407xx
32#define ADDR_FLASH_SECTOR_0 ((uint32_t)0x08000000) /* Base @ of Sector 0, 16 Kbyte */
33#define ADDR_FLASH_SECTOR_1 ((uint32_t)0x08004000) /* Base @ of Sector 1, 16 Kbyte */
34#define ADDR_FLASH_SECTOR_2 ((uint32_t)0x08008000) /* Base @ of Sector 2, 16 Kbyte */
35#define ADDR_FLASH_SECTOR_3 ((uint32_t)0x0800C000) /* Base @ of Sector 3, 16 Kbyte */
36#define ADDR_FLASH_SECTOR_4 ((uint32_t)0x08010000) /* Base @ of Sector 4, 64 Kbyte */
37#define ADDR_FLASH_SECTOR_5 ((uint32_t)0x08020000) /* Base @ of Sector 5, 128 Kbyte */
38#define ADDR_FLASH_SECTOR_6 ((uint32_t)0x08040000) /* Base @ of Sector 6, 128 Kbyte */
39#define ADDR_FLASH_SECTOR_7 ((uint32_t)0x08060000) /* Base @ of Sector 7, 128 Kbyte */
40#define ADDR_FLASH_SECTOR_8 ((uint32_t)0x08080000) /* Base @ of Sector 8, 128 Kbyte */
41#define ADDR_FLASH_SECTOR_9 ((uint32_t)0x080A0000) /* Base @ of Sector 9, 128 Kbyte */
42#define ADDR_FLASH_SECTOR_10 ((uint32_t)0x080C0000) /* Base @ of Sector 10, 128 Kbyte */
43#define ADDR_FLASH_SECTOR_11 ((uint32_t)0x080E0000) /* Base @ of Sector 11, 128 Kbyte */
44
45#define USER_FLASH_END_ADDRESS ((uint32_t)0x080FFFFF) /* Last usable flash address */
46#define MAX_FLASH_SECTOR (12 - 1)
47#endif
48#ifdef STM32F732xx
49#define ADDR_FLASH_SECTOR_0 ((uint32_t)0x08000000) /* Base @ of Sector 0, 16 Kbyte */
50#define ADDR_FLASH_SECTOR_1 ((uint32_t)0x08004000) /* Base @ of Sector 1, 16 Kbyte */
51#define ADDR_FLASH_SECTOR_2 ((uint32_t)0x08008000) /* Base @ of Sector 2, 16 Kbyte */
52#define ADDR_FLASH_SECTOR_3 ((uint32_t)0x0800C000) /* Base @ of Sector 3, 16 Kbyte */
53#define ADDR_FLASH_SECTOR_4 ((uint32_t)0x08010000) /* Base @ of Sector 4, 64 Kbyte */
54#define ADDR_FLASH_SECTOR_5 ((uint32_t)0x08020000) /* Base @ of Sector 5, 128 Kbyte */
55#define ADDR_FLASH_SECTOR_6 ((uint32_t)0x08040000) /* Base @ of Sector 6, 128 Kbyte */
56#define ADDR_FLASH_SECTOR_7 ((uint32_t)0x08060000) /* Base @ of Sector 7, 128 Kbyte */
57
58#define USER_FLASH_END_ADDRESS ((uint32_t)0x0807FFFF) /* Last usable flash address */
59#define MAX_FLASH_SECTOR (8 - 1)
60#endif
61
62uint32_t PHAL_flashReadU32(uint32_t addr);
63
64uint8_t PHAL_flashWriteU32(uint32_t address, uint32_t value);
65uint8_t PHAL_flashWriteU32_Buffered(uint32_t Address, uint32_t* data, uint32_t count);
66
67uint8_t PHAL_flashWriteU64(uint32_t address, uint64_t data);
68uint8_t PHAL_flashErasePage(uint8_t page);
69uint8_t PHAL_flashErase(uint32_t* addr, uint32_t words);
70
71#endif