Kim GiJeong
/
try15_flash_write_register
flash
main.cpp@0:d885866e7cbf, 2019-08-12 (annotated)
- Committer:
- GiJeongKim
- Date:
- Mon Aug 12 09:16:40 2019 +0000
- Revision:
- 0:d885866e7cbf
flash memory;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
GiJeongKim | 0:d885866e7cbf | 1 | #include "stm32f4xx_flash.h" |
GiJeongKim | 0:d885866e7cbf | 2 | #include "mbed.h" |
GiJeongKim | 0:d885866e7cbf | 3 | |
GiJeongKim | 0:d885866e7cbf | 4 | //address (write & read) |
GiJeongKim | 0:d885866e7cbf | 5 | #define ADDR_FLASH_SECTOR_0 ((uint32_t)0x08000000) /* Base @ of Sector 0, 16 Kbytes */ |
GiJeongKim | 0:d885866e7cbf | 6 | #define ADDR_FLASH_SECTOR_1 ((uint32_t)0x08004000) /* Base @ of Sector 1, 16 Kbytes */ |
GiJeongKim | 0:d885866e7cbf | 7 | #define ADDR_FLASH_SECTOR_2 ((uint32_t)0x08008000) /* Base @ of Sector 2, 16 Kbytes */ |
GiJeongKim | 0:d885866e7cbf | 8 | #define ADDR_FLASH_SECTOR_3 ((uint32_t)0x0800C000) /* Base @ of Sector 3, 16 Kbytes */ |
GiJeongKim | 0:d885866e7cbf | 9 | #define ADDR_FLASH_SECTOR_4 ((uint32_t)0x08010000) /* Base @ of Sector 4, 64 Kbytes */ |
GiJeongKim | 0:d885866e7cbf | 10 | #define ADDR_FLASH_SECTOR_5 ((uint32_t)0x08020000) /* Base @ of Sector 5, 128 Kbytes */ |
GiJeongKim | 0:d885866e7cbf | 11 | #define ADDR_FLASH_SECTOR_6 ((uint32_t)0x08040000) /* Base @ of Sector 6, 128 Kbytes */ |
GiJeongKim | 0:d885866e7cbf | 12 | #define ADDR_FLASH_SECTOR_7 ((uint32_t)0x08060000) /* Base @ of Sector 7, 128 Kbytes */ |
GiJeongKim | 0:d885866e7cbf | 13 | |
GiJeongKim | 0:d885866e7cbf | 14 | // sector (erase sector) binary_SNB<<3 |
GiJeongKim | 0:d885866e7cbf | 15 | #define FLASH_Latency_0 ((uint8_t)0x0000) /*!< FLASH Zero Latency cycle */ |
GiJeongKim | 0:d885866e7cbf | 16 | #define FLASH_Latency_1 ((uint8_t)0x0001) /*!< FLASH One Latency cycle */ |
GiJeongKim | 0:d885866e7cbf | 17 | #define FLASH_Latency_2 ((uint8_t)0x0002) /*!< FLASH Two Latency cycles */ |
GiJeongKim | 0:d885866e7cbf | 18 | #define FLASH_Latency_3 ((uint8_t)0x0003) /*!< FLASH Three Latency cycles */ |
GiJeongKim | 0:d885866e7cbf | 19 | #define FLASH_Latency_4 ((uint8_t)0x0004) /*!< FLASH Four Latency cycles */ |
GiJeongKim | 0:d885866e7cbf | 20 | #define FLASH_Latency_5 ((uint8_t)0x0005) /*!< FLASH Five Latency cycles */ |
GiJeongKim | 0:d885866e7cbf | 21 | #define FLASH_Latency_6 ((uint8_t)0x0006) /*!< FLASH Six Latency cycles */ |
GiJeongKim | 0:d885866e7cbf | 22 | #define FLASH_Latency_7 ((uint8_t)0x0007) /*!< FLASH Seven Latency cycles */ |
GiJeongKim | 0:d885866e7cbf | 23 | |
GiJeongKim | 0:d885866e7cbf | 24 | Serial pc(USBTX,USBRX); |
GiJeongKim | 0:d885866e7cbf | 25 | |
GiJeongKim | 0:d885866e7cbf | 26 | int main(){ |
GiJeongKim | 0:d885866e7cbf | 27 | FLASH_Unlock(); |
GiJeongKim | 0:d885866e7cbf | 28 | FLASH_ClearFlag( FLASH_FLAG_EOP | FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR | FLASH_FLAG_PGSERR); |
GiJeongKim | 0:d885866e7cbf | 29 | FLASH_EraseSector(0x0002<<3, VoltageRange_3); // erase whole sector |
GiJeongKim | 0:d885866e7cbf | 30 | FLASH_ProgramWord(0x08008000,0xFFFF); // write at address, 쓸때도 4byte씩 씀 |
GiJeongKim | 0:d885866e7cbf | 31 | FLASH_Lock(); |
GiJeongKim | 0:d885866e7cbf | 32 | int a=*(int*)(0x08008000); // 32 bit int로 읽음 _ 4byte씩 |
GiJeongKim | 0:d885866e7cbf | 33 | pc.printf("%d\n",a); |
GiJeongKim | 0:d885866e7cbf | 34 | a=*(int*)(0x08008001); |
GiJeongKim | 0:d885866e7cbf | 35 | pc.printf("%d\n",a); |
GiJeongKim | 0:d885866e7cbf | 36 | a=*(int*)(0x08008002); |
GiJeongKim | 0:d885866e7cbf | 37 | pc.printf("%d\n",a); |
GiJeongKim | 0:d885866e7cbf | 38 | a=*(int*)(0x08008003); |
GiJeongKim | 0:d885866e7cbf | 39 | pc.printf("%d\n",a); |
GiJeongKim | 0:d885866e7cbf | 40 | a=*(int*)(0x08040004); |
GiJeongKim | 0:d885866e7cbf | 41 | pc.printf("%d\n",a); |
GiJeongKim | 0:d885866e7cbf | 42 | while(1){ |
GiJeongKim | 0:d885866e7cbf | 43 | // int a=*(int*)(0x08040000); // read value at address |
GiJeongKim | 0:d885866e7cbf | 44 | // pc.printf("%d\n",a); |
GiJeongKim | 0:d885866e7cbf | 45 | } |
GiJeongKim | 0:d885866e7cbf | 46 | } |
GiJeongKim | 0:d885866e7cbf | 47 |