flash

Dependencies:   mbed

main.cpp

Committer:
GiJeongKim
Date:
14 months ago
Revision:
0:d885866e7cbf

File content as of revision 0:d885866e7cbf:

#include "stm32f4xx_flash.h"
#include "mbed.h"

//address (write & read)
#define ADDR_FLASH_SECTOR_0     ((uint32_t)0x08000000) /* Base @ of Sector 0, 16 Kbytes */
#define ADDR_FLASH_SECTOR_1     ((uint32_t)0x08004000) /* Base @ of Sector 1, 16 Kbytes */
#define ADDR_FLASH_SECTOR_2     ((uint32_t)0x08008000) /* Base @ of Sector 2, 16 Kbytes */
#define ADDR_FLASH_SECTOR_3     ((uint32_t)0x0800C000) /* Base @ of Sector 3, 16 Kbytes */
#define ADDR_FLASH_SECTOR_4     ((uint32_t)0x08010000) /* Base @ of Sector 4, 64 Kbytes */
#define ADDR_FLASH_SECTOR_5     ((uint32_t)0x08020000) /* Base @ of Sector 5, 128 Kbytes */
#define ADDR_FLASH_SECTOR_6     ((uint32_t)0x08040000) /* Base @ of Sector 6, 128 Kbytes */
#define ADDR_FLASH_SECTOR_7     ((uint32_t)0x08060000) /* Base @ of Sector 7, 128 Kbytes */

// sector (erase sector) binary_SNB<<3
#define FLASH_Latency_0                ((uint8_t)0x0000)  /*!< FLASH Zero Latency cycle      */
#define FLASH_Latency_1                ((uint8_t)0x0001)  /*!< FLASH One Latency cycle       */
#define FLASH_Latency_2                ((uint8_t)0x0002)  /*!< FLASH Two Latency cycles      */
#define FLASH_Latency_3                ((uint8_t)0x0003)  /*!< FLASH Three Latency cycles    */
#define FLASH_Latency_4                ((uint8_t)0x0004)  /*!< FLASH Four Latency cycles     */
#define FLASH_Latency_5                ((uint8_t)0x0005)  /*!< FLASH Five Latency cycles     */
#define FLASH_Latency_6                ((uint8_t)0x0006)  /*!< FLASH Six Latency cycles      */
#define FLASH_Latency_7                ((uint8_t)0x0007)  /*!< FLASH Seven Latency cycles    */
                             
Serial pc(USBTX,USBRX);

int main(){
    FLASH_Unlock();
    FLASH_ClearFlag( FLASH_FLAG_EOP |  FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR | FLASH_FLAG_PGSERR);
    FLASH_EraseSector(0x0002<<3, VoltageRange_3); // erase whole sector 
    FLASH_ProgramWord(0x08008000,0xFFFF);           // write at address, 쓸때도 4byte씩 씀
    FLASH_Lock();
    int a=*(int*)(0x08008000);                // 32 bit int로 읽음 _ 4byte씩 
    pc.printf("%d\n",a);
    a=*(int*)(0x08008001);
    pc.printf("%d\n",a);
    a=*(int*)(0x08008002);
    pc.printf("%d\n",a);
    a=*(int*)(0x08008003);
    pc.printf("%d\n",a);
    a=*(int*)(0x08040004);
    pc.printf("%d\n",a);
    while(1){
//        int a=*(int*)(0x08040000);                // read value at address
//        pc.printf("%d\n",a);
        }
}