Wen-ting Lo / Mbed OS STM32F303RE_LPG

Dependencies:   MQTT

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /* mbed Microcontroller Library
00002  * Copyright (c) 2018 ARM Limited
00003  * SPDX-License-Identifier: Apache-2.0
00004  */
00005 
00006 #include "mbed.h"
00007 #include "LPG_Config.h"
00008 #include "stats_report.h"
00009 #include "LPG_FlashIAP.h"
00010 #include "LPG_ATCmd_Processing.h"
00011 #include "LPG_LTEPin_Controller.h"
00012 
00013 DigitalOut  Led_1(LED_1);
00014 DigitalOut  Led_2(LED_2);
00015 DigitalOut  Led_3(LED_3);
00016 
00017 InterruptIn BTN_Test(BTN);
00018 
00019 RawSerial ATCmdPort(UART_TX,UART_RX);
00020 RawSerial DebugPort(D_UART_TX,D_UART_RX);
00021 
00022 #define SLEEP_TIME                  500 // (msec)
00023 #define PRINT_AFTER_N_LOOPS         20
00024 
00025 bool flag_BTN = false;
00026 char buf;
00027 void BTN_Change_R()
00028 {
00029     flag_BTN = true;
00030 }
00031 
00032 
00033 void BTN_Change_F()
00034 {
00035     
00036 }
00037 
00038 void CallBackFunc() 
00039 {
00040     while(ATCmdPort.readable()){
00041         DebugPort.putc(ATCmdPort.getc());
00042         /*ATCmdPort.putc(ATCmdPort.getc());*/ 
00043         
00044     }
00045 }
00046 
00047 void Initialize()
00048 {
00049     ATCmdPort.baud(AT_UART_BR);
00050     DebugPort.baud(D_UART_BR);
00051     BTN_Test.rise(&BTN_Change_R);
00052     BTN_Test.fall(&BTN_Change_F);
00053     ATCmdPort.attach(&CallBackFunc,Serial::RxIrq);
00054     Led_1.write(0);    
00055     Led_2.write(0);
00056     Led_3.write(0);
00057     LPG_LTEPinControl_LTEPowerOn();
00058 }
00059 
00060 
00061 
00062 // main() runs in its own thread in the OS
00063 int main()
00064 {
00065     SystemReport sys_state( SLEEP_TIME * PRINT_AFTER_N_LOOPS /* Loop delay time in ms */);
00066     Initialize();
00067     int count = 0;
00068     int index  = 0;
00069     char buMat[100] = {0};
00070     
00071     //LPG_FlashIAP_InitIAP();
00072     while (true) {
00073         char* buf;
00074         if(index==0) buf = "TEST_0";
00075         else if(index==1) buf = "TEST_1";
00076         else if(index==2) buf = "TEST_2";
00077         else if(index==3) buf = "TEST_3";
00078         else if(index==4) buf = "TEST_4";
00079         else index = -1;
00080         DebugPort.puts(buf);
00081         DebugPort.puts("\r\n");
00082         LPG_FlashIAP_InitIAP();
00083         LPG_FlashIAP_WriteToFlash(&buf[0],0x0807C000,DebugPort);
00084         LPG_FlashIAP_DeInitIAP();
00085         // Blink LED and wait 0.5 seconds
00086         Led_1 = !Led_1;
00087         Led_2 = !Led_2;
00088         Led_3 = !Led_3;
00089         wait_ms(2000);
00090         //ATCmdPort.puts("ATI\r\n");
00091         //LPG_FlashIAP_WriteToFlash(&buf[0],0x0807C000,DebugPort);
00092         /*LPG_FlashIAP_ReadFromFlash(&buMat[0],0x0800BF00);
00093         DebugPort.puts(buMat);
00094         DebugPort.puts("\r\n");*/
00095         index++;
00096         if ((0 == count) || (PRINT_AFTER_N_LOOPS == count)) {
00097             // Following the main thread wait, report on the current system status
00098             sys_state.report_state();
00099             count = 0;
00100         }
00101         ++count;
00102     }
00103 }