flash

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers <title>main.cpp Source File</title>

main.cpp

00001 #include "stm32f4xx_flash.h"
00002 #include "mbed.h"
00003 
00004 //address (write & read)
00005 #define ADDR_FLASH_SECTOR_0     ((uint32_t)0x08000000) /* Base @ of Sector 0, 16 Kbytes */
00006 #define ADDR_FLASH_SECTOR_1     ((uint32_t)0x08004000) /* Base @ of Sector 1, 16 Kbytes */
00007 #define ADDR_FLASH_SECTOR_2     ((uint32_t)0x08008000) /* Base @ of Sector 2, 16 Kbytes */
00008 #define ADDR_FLASH_SECTOR_3     ((uint32_t)0x0800C000) /* Base @ of Sector 3, 16 Kbytes */
00009 #define ADDR_FLASH_SECTOR_4     ((uint32_t)0x08010000) /* Base @ of Sector 4, 64 Kbytes */
00010 #define ADDR_FLASH_SECTOR_5     ((uint32_t)0x08020000) /* Base @ of Sector 5, 128 Kbytes */
00011 #define ADDR_FLASH_SECTOR_6     ((uint32_t)0x08040000) /* Base @ of Sector 6, 128 Kbytes */
00012 #define ADDR_FLASH_SECTOR_7     ((uint32_t)0x08060000) /* Base @ of Sector 7, 128 Kbytes */
00013 
00014 // sector (erase sector) binary_SNB<<3
00015 #define FLASH_Latency_0                ((uint8_t)0x0000)  /*!< FLASH Zero Latency cycle      */
00016 #define FLASH_Latency_1                ((uint8_t)0x0001)  /*!< FLASH One Latency cycle       */
00017 #define FLASH_Latency_2                ((uint8_t)0x0002)  /*!< FLASH Two Latency cycles      */
00018 #define FLASH_Latency_3                ((uint8_t)0x0003)  /*!< FLASH Three Latency cycles    */
00019 #define FLASH_Latency_4                ((uint8_t)0x0004)  /*!< FLASH Four Latency cycles     */
00020 #define FLASH_Latency_5                ((uint8_t)0x0005)  /*!< FLASH Five Latency cycles     */
00021 #define FLASH_Latency_6                ((uint8_t)0x0006)  /*!< FLASH Six Latency cycles      */
00022 #define FLASH_Latency_7                ((uint8_t)0x0007)  /*!< FLASH Seven Latency cycles    */
00023                              
00024 Serial pc(USBTX,USBRX);
00025 
00026 int main(){
00027     FLASH_Unlock();
00028     FLASH_ClearFlag( FLASH_FLAG_EOP |  FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR | FLASH_FLAG_PGSERR);
00029     FLASH_EraseSector(0x0002<<3, VoltageRange_3); // erase whole sector 
00030     FLASH_ProgramWord(0x08008000,0xFFFF);           // write at address, 쓸때도 4byte씩 씀
00031     FLASH_Lock();
00032     int a=*(int*)(0x08008000);                // 32 bit int로 읽음 _ 4byte씩 
00033     pc.printf("%d\n",a);
00034     a=*(int*)(0x08008001);
00035     pc.printf("%d\n",a);
00036     a=*(int*)(0x08008002);
00037     pc.printf("%d\n",a);
00038     a=*(int*)(0x08008003);
00039     pc.printf("%d\n",a);
00040     a=*(int*)(0x08040004);
00041     pc.printf("%d\n",a);
00042     while(1){
00043 //        int a=*(int*)(0x08040000);                // read value at address
00044 //        pc.printf("%d\n",a);
00045         }
00046 }
00047