Wen-ting Lo
/
STM32F303RE_LPG
Basic
main.cpp@9:4731ae675a01, 2019-04-24 (annotated)
- Committer:
- lwtroach
- Date:
- Wed Apr 24 06:13:22 2019 +0000
- Branch:
- Flash_Exam
- Revision:
- 9:4731ae675a01
- Parent:
- 8:92f9f1fb11e2
When programming the data into flash, the size to API of IAP must be the correct size of data itself, or the algorithm will save the next data after it.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
lwtroach | 0:6bdfb6ccd136 | 1 | /* mbed Microcontroller Library |
lwtroach | 0:6bdfb6ccd136 | 2 | * Copyright (c) 2018 ARM Limited |
lwtroach | 0:6bdfb6ccd136 | 3 | * SPDX-License-Identifier: Apache-2.0 |
lwtroach | 0:6bdfb6ccd136 | 4 | */ |
lwtroach | 0:6bdfb6ccd136 | 5 | |
lwtroach | 0:6bdfb6ccd136 | 6 | #include "mbed.h" |
lwtroach | 0:6bdfb6ccd136 | 7 | #include "LPG_Config.h" |
lwtroach | 0:6bdfb6ccd136 | 8 | #include "stats_report.h" |
lwtroach | 7:e556528beeba | 9 | #include "LPG_FlashIAP.h" |
lwtroach | 2:e90526c0bcbe | 10 | #include "LPG_ATCmd_Processing.h" |
lwtroach | 5:b9d12dfdc674 | 11 | #include "LPG_LTEPin_Controller.h" |
lwtroach | 0:6bdfb6ccd136 | 12 | |
lwtroach | 2:e90526c0bcbe | 13 | DigitalOut Led_1(LED_1); |
lwtroach | 2:e90526c0bcbe | 14 | DigitalOut Led_2(LED_2); |
lwtroach | 2:e90526c0bcbe | 15 | DigitalOut Led_3(LED_3); |
lwtroach | 2:e90526c0bcbe | 16 | |
lwtroach | 2:e90526c0bcbe | 17 | InterruptIn BTN_Test(BTN); |
lwtroach | 2:e90526c0bcbe | 18 | |
lwtroach | 2:e90526c0bcbe | 19 | RawSerial ATCmdPort(UART_TX,UART_RX); |
lwtroach | 2:e90526c0bcbe | 20 | RawSerial DebugPort(D_UART_TX,D_UART_RX); |
lwtroach | 0:6bdfb6ccd136 | 21 | |
lwtroach | 7:e556528beeba | 22 | #define SLEEP_TIME 500 // (msec) |
lwtroach | 7:e556528beeba | 23 | #define PRINT_AFTER_N_LOOPS 20 |
lwtroach | 0:6bdfb6ccd136 | 24 | |
lwtroach | 2:e90526c0bcbe | 25 | bool flag_BTN = false; |
lwtroach | 7:e556528beeba | 26 | char buf; |
lwtroach | 2:e90526c0bcbe | 27 | void BTN_Change_R() |
lwtroach | 2:e90526c0bcbe | 28 | { |
lwtroach | 2:e90526c0bcbe | 29 | flag_BTN = true; |
lwtroach | 2:e90526c0bcbe | 30 | } |
lwtroach | 2:e90526c0bcbe | 31 | |
lwtroach | 2:e90526c0bcbe | 32 | |
lwtroach | 2:e90526c0bcbe | 33 | void BTN_Change_F() |
lwtroach | 2:e90526c0bcbe | 34 | { |
lwtroach | 2:e90526c0bcbe | 35 | |
lwtroach | 2:e90526c0bcbe | 36 | } |
lwtroach | 2:e90526c0bcbe | 37 | |
lwtroach | 4:418b6d4097e1 | 38 | void CallBackFunc() |
lwtroach | 4:418b6d4097e1 | 39 | { |
lwtroach | 4:418b6d4097e1 | 40 | while(ATCmdPort.readable()){ |
lwtroach | 4:418b6d4097e1 | 41 | DebugPort.putc(ATCmdPort.getc()); |
lwtroach | 7:e556528beeba | 42 | /*ATCmdPort.putc(ATCmdPort.getc());*/ |
lwtroach | 7:e556528beeba | 43 | |
lwtroach | 4:418b6d4097e1 | 44 | } |
lwtroach | 2:e90526c0bcbe | 45 | } |
lwtroach | 2:e90526c0bcbe | 46 | |
lwtroach | 2:e90526c0bcbe | 47 | void Initialize() |
lwtroach | 2:e90526c0bcbe | 48 | { |
lwtroach | 5:b9d12dfdc674 | 49 | ATCmdPort.baud(AT_UART_BR); |
lwtroach | 5:b9d12dfdc674 | 50 | DebugPort.baud(D_UART_BR); |
lwtroach | 2:e90526c0bcbe | 51 | BTN_Test.rise(&BTN_Change_R); |
lwtroach | 2:e90526c0bcbe | 52 | BTN_Test.fall(&BTN_Change_F); |
lwtroach | 4:418b6d4097e1 | 53 | ATCmdPort.attach(&CallBackFunc,Serial::RxIrq); |
lwtroach | 2:e90526c0bcbe | 54 | Led_1.write(0); |
lwtroach | 2:e90526c0bcbe | 55 | Led_2.write(0); |
lwtroach | 2:e90526c0bcbe | 56 | Led_3.write(0); |
lwtroach | 5:b9d12dfdc674 | 57 | LPG_LTEPinControl_LTEPowerOn(); |
lwtroach | 2:e90526c0bcbe | 58 | } |
lwtroach | 2:e90526c0bcbe | 59 | |
lwtroach | 2:e90526c0bcbe | 60 | |
lwtroach | 2:e90526c0bcbe | 61 | |
lwtroach | 0:6bdfb6ccd136 | 62 | // main() runs in its own thread in the OS |
lwtroach | 0:6bdfb6ccd136 | 63 | int main() |
lwtroach | 0:6bdfb6ccd136 | 64 | { |
lwtroach | 0:6bdfb6ccd136 | 65 | SystemReport sys_state( SLEEP_TIME * PRINT_AFTER_N_LOOPS /* Loop delay time in ms */); |
lwtroach | 2:e90526c0bcbe | 66 | Initialize(); |
lwtroach | 0:6bdfb6ccd136 | 67 | int count = 0; |
lwtroach | 2:e90526c0bcbe | 68 | int index = 0; |
lwtroach | 2:e90526c0bcbe | 69 | char buMat[100] = {0}; |
lwtroach | 9:4731ae675a01 | 70 | |
lwtroach | 9:4731ae675a01 | 71 | //LPG_FlashIAP_InitIAP(); |
lwtroach | 0:6bdfb6ccd136 | 72 | while (true) { |
lwtroach | 9:4731ae675a01 | 73 | char* buf; |
lwtroach | 9:4731ae675a01 | 74 | if(index==0) buf = "TEST_0"; |
lwtroach | 9:4731ae675a01 | 75 | else if(index==1) buf = "TEST_1"; |
lwtroach | 9:4731ae675a01 | 76 | else if(index==2) buf = "TEST_2"; |
lwtroach | 9:4731ae675a01 | 77 | else if(index==3) buf = "TEST_3"; |
lwtroach | 9:4731ae675a01 | 78 | else if(index==4) buf = "TEST_4"; |
lwtroach | 9:4731ae675a01 | 79 | else index = -1; |
lwtroach | 9:4731ae675a01 | 80 | DebugPort.puts(buf); |
lwtroach | 9:4731ae675a01 | 81 | DebugPort.puts("\r\n"); |
lwtroach | 3:cb954c31709f | 82 | LPG_FlashIAP_InitIAP(); |
lwtroach | 9:4731ae675a01 | 83 | LPG_FlashIAP_WriteToFlash(&buf[0],0x0807C000,DebugPort); |
lwtroach | 9:4731ae675a01 | 84 | LPG_FlashIAP_DeInitIAP(); |
lwtroach | 0:6bdfb6ccd136 | 85 | // Blink LED and wait 0.5 seconds |
lwtroach | 1:347333bac1fb | 86 | Led_1 = !Led_1; |
lwtroach | 2:e90526c0bcbe | 87 | Led_2 = !Led_2; |
lwtroach | 2:e90526c0bcbe | 88 | Led_3 = !Led_3; |
lwtroach | 4:418b6d4097e1 | 89 | wait_ms(2000); |
lwtroach | 6:86eea1bcf499 | 90 | //ATCmdPort.puts("ATI\r\n"); |
lwtroach | 9:4731ae675a01 | 91 | //LPG_FlashIAP_WriteToFlash(&buf[0],0x0807C000,DebugPort); |
lwtroach | 4:418b6d4097e1 | 92 | /*LPG_FlashIAP_ReadFromFlash(&buMat[0],0x0800BF00); |
lwtroach | 2:e90526c0bcbe | 93 | DebugPort.puts(buMat); |
lwtroach | 4:418b6d4097e1 | 94 | DebugPort.puts("\r\n");*/ |
lwtroach | 9:4731ae675a01 | 95 | index++; |
lwtroach | 0:6bdfb6ccd136 | 96 | if ((0 == count) || (PRINT_AFTER_N_LOOPS == count)) { |
lwtroach | 0:6bdfb6ccd136 | 97 | // Following the main thread wait, report on the current system status |
lwtroach | 0:6bdfb6ccd136 | 98 | sys_state.report_state(); |
lwtroach | 0:6bdfb6ccd136 | 99 | count = 0; |
lwtroach | 0:6bdfb6ccd136 | 100 | } |
lwtroach | 0:6bdfb6ccd136 | 101 | ++count; |
lwtroach | 0:6bdfb6ccd136 | 102 | } |
lwtroach | 0:6bdfb6ccd136 | 103 | } |