Implemented LED Indicator Patterns

Dependencies:   mbed

Revision:
13:831ffc0ea56c
Parent:
12:c1cf0e717684
Child:
14:9ba8f6975308
--- a/app/main.cpp	Thu Jan 03 16:12:43 2019 +0000
+++ b/app/main.cpp	Thu Jan 03 17:06:18 2019 +0000
@@ -148,7 +148,7 @@
 AnalogIn LIGHT_2_PIN(A5);
 AnalogIn VCE_PIN(PB_1);
 
-InterruptIn button1(USER_BUTTON);
+InterruptIn button1(D14);
 volatile bool button1_pressed = false; // Used in the main loop
 volatile bool button1_enabled = true; // Used for debouncing
 Timeout button1_timeout; // Used for debouncing
@@ -353,6 +353,16 @@
     }
 }
 
+
+void flash_builtin() {
+    myled = 1;   // turn the LED on (HIGH is the voltage level)
+    wait(2);                       // wait for a second
+    myled = 0;    // turn the LED off by making the voltage LOW
+    wait(1);                       // wait for a second
+}
+
+
+
 // ****************************    COMMUNICATION PACKET DEFINITION METHODS   ********************************   //
 
 void heartbeat_message(uint8_t *hb_data, uint8_t *current_date) {
@@ -894,6 +904,9 @@
 }
 
 void startTest(uint8_t *measurements) {
+  // Signal that test is running
+    flash_builtin();
+    flash_builtin();
     
     // Determine test length & measurement interval
     switch (MessageType)
@@ -983,11 +996,96 @@
 }
 
 
+
+
+
+/**
+ * Main application entry point.
+ */
+Serial pc(SERIAL_TX, SERIAL_RX,115200);
+int MY_SetSysClock_PLL_HSE(void)
+{
+    RCC_ClkInitTypeDef RCC_ClkInitStruct;
+    RCC_OscInitTypeDef RCC_OscInitStruct;
+
+    /* Enable HSE and activate PLL with HSE as source */
+    RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
+    RCC_OscInitStruct.HSEState       = RCC_HSE_ON; /* External 8 MHz xtal on OSC_IN/OSC_OUT */
+
+    // PLLCLK = (8 MHz * 8)/2 = 32 MHz
+    RCC_OscInitStruct.PLL.PLLState        = RCC_PLL_ON;
+    RCC_OscInitStruct.PLL.PLLSource       = RCC_PLLSOURCE_HSE;
+    RCC_OscInitStruct.PLL.PLLMUL          = RCC_PLLMUL_8;
+    RCC_OscInitStruct.PLL.PLLDIV          = RCC_PLLDIV_2;
+    if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
+        return (-1); // FAIL
+    }
+
+    /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2 clocks dividers */
+    RCC_ClkInitStruct.ClockType      = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2);
+    RCC_ClkInitStruct.SYSCLKSource   = RCC_SYSCLKSOURCE_PLLCLK; // 32 MHz
+    RCC_ClkInitStruct.AHBCLKDivider  = RCC_SYSCLK_DIV1;         // 32 MHz
+    RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;           // 32 MHz
+    RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;           // 32 MHz
+    if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK) {
+        return (-2); // FAIL
+    }
+
+    /* Enable HSE and activate PLL with HSE as source */
+    RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI48|RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_MSI;
+    RCC_OscInitStruct.HSIState       = RCC_HSI_OFF;
+    RCC_OscInitStruct.MSIState       = RCC_MSI_OFF;
+    RCC_OscInitStruct.HSI48State     = RCC_HSI48_OFF;
+    RCC_OscInitStruct.PLL.PLLState   = RCC_PLL_NONE;
+    if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
+        return (-3); // FAIL
+    }
+        
+    return 0; // OK
+}
+
+void my_patch(void)
+{
+    int retVal;
+    
+    // Put device into default clock, i.e using MSI = 2MHz
+    HAL_RCC_DeInit();
+    
+    // Enable HSE clock
+    retVal = MY_SetSysClock_PLL_HSE();
+    if(retVal< 0)
+    {
+        // fail
+        //pc.printf("Failed to start HSE, ERR= %d\r\n", retVal);
+        
+        // indicate error
+        while(1)
+        {
+            myled = 1;
+            wait(0.2);
+            myled = 0;
+            wait(0.5);
+        }
+    }    
+}
+
+
+
+
 /**
  * Main application entry point.
  */
 int main( void )
 {
+
+    pc.printf("mbed-os-rev: %d.%d.%d   lib-rev: %d\r\n", \
+            MBED_MAJOR_VERSION, MBED_MINOR_VERSION,MBED_PATCH_VERSION,MBED_LIBRARY_VERSION);
+    pc.printf("BUILD= %s, SysClock= %d, RCC= %0X\r\n", __TIME__, SystemCoreClock, RCC->CR);   
+    my_patch();
+    pc.printf("NEW SysClock= %d, NEW RCC= %0X\r\n", SystemCoreClock, RCC->CR);
+    wait(3);
+    
+    
     LoRaMacPrimitives_t LoRaMacPrimitives;
     LoRaMacCallback_t LoRaMacCallbacks;
     MibRequestConfirm_t mibReq;
@@ -1010,6 +1108,14 @@
     set_time(1514764800);
     relayPin = 0;
     
+
+
+    flash_builtin();
+    flash_builtin();
+    flash_builtin();
+    flash_builtin();
+    
+    
     running_test = false;
     joining = true;
     received_downlink = false;