Presentation is loading. Please wait.

Presentation is loading. Please wait.

WU-YANG Technology Co., Ltd. SIOC 實驗 5 : Embedded Flash 實驗 郭明聰 / 陳慶瀚 MIAT 實驗室.

Similar presentations


Presentation on theme: "WU-YANG Technology Co., Ltd. SIOC 實驗 5 : Embedded Flash 實驗 郭明聰 / 陳慶瀚 MIAT 實驗室."— Presentation transcript:

1 WU-YANG Technology Co., Ltd. SIOC 實驗 5 : Embedded Flash 實驗 郭明聰 / 陳慶瀚 MIAT 實驗室

2 2 實驗目的  瞭解 STM32 內部 Flash 記憶體與處理器界面的架 構;實驗存取 Flash 的資料,並透過 VCP 傳送到 超級終端機觀察結果

3 Flash 界面架構 3 SIOC 為 64KB

4 FLITF  Features Read interface with prefetch buffer (2x64-bit words) Option byte Loader Flash Program / Erase operation Read / Write protection 4

5 Memory Mapping 5

6 6 0x800 3000 DFU 程式區塊, User 不可使用 0x800 8000 0x800 C000

7 Embedded Flash Memory 7

8 8 Flash memory interface registers

9 Flash memory interface register 9 Bit 9 OPTWRE: Option bytes write enable When set, the option bytes can be programmed. This bit is set on writing the correct key sequence to the FLASH_OPTKEYR register. This bit can be reset by software Bit 8 Reserved, must be kept cleared. Bit 7 LOCK: Lock Write to 1 only. When it is set, it indicates that the FPEC and FLASH_CR are locked. This bit is reset by hardware after detecting the unlock sequence. In the event of unsuccessful unlock operation, this bit remains set until the next reset. Bit 6 STRT: Start This bit triggers an ERASE operation when set. This bit is set only by software and reset when the BSY bit is reset. Bit 5 OPTER: Option byte erase Option byte erase chosen. Bit 4 OPTPG: Option byte programming Option byte programming chosen. Bit 3 Reserved, must be kept cleared. Bit 2 MER: Mass erase Erase of all user pages chosen. Bit 1 PER: Page erase Page Erase chosen. Bit 0 PG: Programming Flash programming chosen.

10 FLASH library function 10

11 FLASH library function(conti.) 11

12 Main Flash memory programming 12

13 Flash memory Page Erase 13

14 Flash memory Mass Erase 14

15 Option byte programming 15

16 Option byte Erase 16

17 WU-YANG Technology Co., Ltd. 實驗 實驗 1 : flash memory 資料存取 實驗 2 :非揮發性資料寫入 實驗 3 : flash 資料寫入鎖定

18 WU-YANG Technology Co., Ltd. 實驗 1 : flash memory 資料存取

19 程式架構 19 Programming Bootup STM32F10x NVIC Configure int main(void) { u32 *temp; Set_System(); /*pause*/ getchar(); printf("start \r\n"); FLASHStatus = FLASH_COMPLETE; MemoryProgramStatus = PASSED; Data = 0x15041925; /* NVIC configuration */ NVIC_Configuration(); ….... Flash memory R/W operation FLASH Unlock FLASH ClearFlag FLASH ErasePage FLASH ProgramWord

20 程式架構 (conti.) 20 /* Unlock the Flash Program Erase controller */ FLASH_Unlock(); /* Define the number of page to be erased */ NbrOfPage = (EndAddr - StartAddr) / FLASH_PAGE_SIZE; /* Clear All pending flags */ FLASH_ClearFlag(FLASH_FLAG_BSY | FLASH_FLAG_EOP | FLASH_FLAG_PGERR | FLASH_FLAG_WRPRTERR); /* Erase the FLASH pages */ for(EraseCounter = 0; (EraseCounter < NbrOfPage) && (FLASHStatus == FLASH_COMPLETE); EraseCounter++) { FLASHStatus = FLASH_ErasePage(StartAddr + (FLASH_PAGE_SIZE * EraseCounter)); } /* FLASH Word program of data 0x15041979 at addresses defined by StartAddr and EndAddr*/ Address = StartAddr; while((Address < EndAddr) && (FLASHStatus == FLASH_COMPLETE)) { FLASHStatus = FLASH_ProgramWord(Address, Data); temp=(u32 *)Address; printf("0x%x data is 0x%x \r\n",Address,*temp); Address = Address + 4; } Flash memory R/W operation FLASH Unlock FLASH ClearFlag FLASH ErasePage FLASH ProgramWord

21 預設定義說明  #define StartAddr ((u32)0x08008000) 定義 Flash 使用起始點 使用起始點必需大於 0x8003000 + Code Size  #define EndAddr ((u32)0x0800C000) 定義 Flash 使用結束點 使用起始點必需小於 0x8040000  Data = 0x15041975; 寫入資料 32Bit  #define FLASH_PAGE_SIZE ((u16)0x400) 每一個 Page 有 1KByte 21 附註 : 0x8000000~0x8003000 為 DFU 程式區塊,使用此區塊將造成無法燒錄程 式 Code Size 可由產生的 HEX 檔得知

22 Intel HEX Format 22

23 HEX Example 23  資料填入起始位置為 0x08003000  每一行有 0x10(16) 個 Bytes  最後一筆資料為 04000005080030EDD2  資料結束點為 0x08005C10  (0x08005C10 -0x08000000)/0x400 = 23  需以 0x400 為單位,所以可存的 flash 位置起點為 0x08006000 :020000040800F2 :10300000100E002001310008913E0008DD3D00084F ……… :105C00001A4497292829106908011B3C020406CC74 :0C5C10002D0102030404850607080900AA :04000005080030EDD2 :00000001FF

24 程式執行結果 24

25 Flash 存取控制流程 25

26 改變 Putty Lines of scrollback 數值 26

27 實驗 1 注意事項  #define StartAddr ((u32)0x08020000) /* 定義 Flash 使用起始點 */ 使用起始點必需大於 0x8003000 + Code Size  0x8000000~0x8003000 為 DFU 程式區塊,使用此區塊將 造成無法燒錄程式  Code Size 可由產生的 HEX 檔得知  u32 Address = 0x08020000; 定義 Address 初始值 初始值必需與 Flash 使用起始點相同

28 WU-YANG Technology Co., Ltd. 實驗 2 :非揮發性資料寫入 觀察 Flash 寫入後電源關閉 ( 拔除 USB 連 線 ) ,再重新接電後觀察寫入資料是否 仍存在

29 29 實驗 2 程式說明 /* Erase the FLASH pages */ for(EraseCounter = 0; (EraseCounter < NbrOfPage) && (FLASHStatus == FLASH_COMPLETE); EraseCounter++) { FLASHStatus = FLASH_ErasePage(StartAddr + (FLASH_PAGE_SIZE * EraseCounter)); } /* FLASH Word program of data 0x15041979 at addresses defined by StartAddr and EndAddr*/ Address = StartAddr; while((Address < EndAddr) && (FLASHStatus == FLASH_COMPLETE)) { FLASHStatus = FLASH_ProgramWord(Address, Data); temp=(u32 *)Address; printf("0x%x data is 0x%x \r\n",Address,*temp); Address = Address + 4; } Flash memory R/W operation FLASH ErasePage FLASH ProgramWord

30 WU-YANG Technology Co., Ltd. 實驗 3 : flash 資料寫入鎖定

31 實驗 3 說明  注意 :  請使用預設 0x08006000 之後的位置,避免覆蓋 DFU 與 使用者程式碼區塊  更改寫入位置測試寫入鎖定時需同時更改 FLASH_EnableWriteProtection 鎖定之 Page  練習 : 打開 #define WriteProtection_Enable 測試是否可寫入 打開 #define WriteProtection_Disable 測試是否可寫入 修改存取位置測試是否正常 修改寫入資料測試是否正常

32 32 /* Uncomment this line to Enable Write Protection */ //#define WriteProtection_Enable /* Uncomment this line to Disable Write Protection */ #define WriteProtection_Disable #ifdef WriteProtection_Disable printf("WriteProtection_Disable \r\n"); if (ProtectedPages == 0x00) {/* Pages are write protected */ /* Disable the write protection */ FLASHStatus = FLASH_EraseOptionBytes(); /* Generate System Reset to load the new option byte values */ NVIC_GenerateSystemReset(); } #else #ifdef WriteProtection_Enable printf("WriteProtection_Enable \r\n"); if (ProtectedPages != 0x00) {/* Pages not write protected */ /* Disable the write protection */ FLASHStatus = FLASH_EraseOptionBytes(); /* Enable the pages write protection */ //FLASHStatus = FLASH_EnableWriteProtection(FLASH_WRProt_Pages12to13 |FLASH_WRProt_Pages14to15); // 0x00006000 / 0x800 =12 0x0000 8000 / 0x800=16 /* Generate System Reset to load the new option byte values */ NVIC_GenerateSystemReset(); } #endif 實驗 3 說明

33 WU-YANG Technology Co., Ltd. Q & AQ & A


Download ppt "WU-YANG Technology Co., Ltd. SIOC 實驗 5 : Embedded Flash 實驗 郭明聰 / 陳慶瀚 MIAT 實驗室."

Similar presentations


Ads by Google