Kashish Haresh Shah
/
HXCClientShield
HXC Client Shield Repository.
main.cpp@3:5e1a54378107, 2021-04-19 (annotated)
- Committer:
- kashish_mbed
- Date:
- Mon Apr 19 17:43:09 2021 +0000
- Revision:
- 3:5e1a54378107
- Parent:
- 0:bacc6e701fb4
Successful Build file with CmdProcess Functionality
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kashish_mbed | 0:bacc6e701fb4 | 1 | /* |
kashish_mbed | 0:bacc6e701fb4 | 2 | _ _ _____ _______ |
kashish_mbed | 0:bacc6e701fb4 | 3 | | | | | |_ _| |__ __| |
kashish_mbed | 0:bacc6e701fb4 | 4 | | |__| | __ ___ __ | | ___ | | |
kashish_mbed | 0:bacc6e701fb4 | 5 | | __ |/ _` \ \/ / | | / _ \| | |
kashish_mbed | 0:bacc6e701fb4 | 6 | | | | | (_| |> < _| || (_) | | |
kashish_mbed | 0:bacc6e701fb4 | 7 | |_| |_|\__,_/_/\_\_____\___/|_| |
kashish_mbed | 0:bacc6e701fb4 | 8 | (C)2017 HaxIoT |
kashish_mbed | 0:bacc6e701fb4 | 9 | */ |
kashish_mbed | 0:bacc6e701fb4 | 10 | /******************************************************************************* |
kashish_mbed | 0:bacc6e701fb4 | 11 | * @File : main.cpp |
kashish_mbed | 0:bacc6e701fb4 | 12 | * @Author : Fahad Mirza (Haxiot) |
kashish_mbed | 0:bacc6e701fb4 | 13 | * @Version : V1.0.0 |
kashish_mbed | 0:bacc6e701fb4 | 14 | * @Modified: 18 October, 2018 |
kashish_mbed | 0:bacc6e701fb4 | 15 | * @Brief : Main file |
kashish_mbed | 0:bacc6e701fb4 | 16 | ****************************************************************************** |
kashish_mbed | 0:bacc6e701fb4 | 17 | * @attention |
kashish_mbed | 0:bacc6e701fb4 | 18 | * |
kashish_mbed | 0:bacc6e701fb4 | 19 | * <h2><center>© COPYRIGHT(c) 2017 Haxiot</center></h2> |
kashish_mbed | 0:bacc6e701fb4 | 20 | * |
kashish_mbed | 0:bacc6e701fb4 | 21 | * Redistribution and use in source and binary forms, with or without modification, |
kashish_mbed | 0:bacc6e701fb4 | 22 | * are permitted provided that the following conditions are met: |
kashish_mbed | 0:bacc6e701fb4 | 23 | * 1. Redistributions of source code must retain the above copyright notice, |
kashish_mbed | 0:bacc6e701fb4 | 24 | * this list of conditions and the following disclaimer. |
kashish_mbed | 0:bacc6e701fb4 | 25 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
kashish_mbed | 0:bacc6e701fb4 | 26 | * this list of conditions and the following disclaimer in the documentation |
kashish_mbed | 0:bacc6e701fb4 | 27 | * and/or other materials provided with the distribution. |
kashish_mbed | 0:bacc6e701fb4 | 28 | * 3. Neither the name of Haxiot nor the names of its contributors |
kashish_mbed | 0:bacc6e701fb4 | 29 | * may be used to endorse or promote products derived from this software |
kashish_mbed | 0:bacc6e701fb4 | 30 | * without specific prior written permission. |
kashish_mbed | 0:bacc6e701fb4 | 31 | * |
kashish_mbed | 0:bacc6e701fb4 | 32 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
kashish_mbed | 0:bacc6e701fb4 | 33 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
kashish_mbed | 0:bacc6e701fb4 | 34 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
kashish_mbed | 0:bacc6e701fb4 | 35 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
kashish_mbed | 0:bacc6e701fb4 | 36 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
kashish_mbed | 0:bacc6e701fb4 | 37 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
kashish_mbed | 0:bacc6e701fb4 | 38 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
kashish_mbed | 0:bacc6e701fb4 | 39 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
kashish_mbed | 0:bacc6e701fb4 | 40 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
kashish_mbed | 0:bacc6e701fb4 | 41 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
kashish_mbed | 0:bacc6e701fb4 | 42 | * |
kashish_mbed | 0:bacc6e701fb4 | 43 | ****************************************************************************** |
kashish_mbed | 0:bacc6e701fb4 | 44 | */ |
kashish_mbed | 0:bacc6e701fb4 | 45 | #include "mbed.h" |
kashish_mbed | 0:bacc6e701fb4 | 46 | #include "hw.h" |
kashish_mbed | 0:bacc6e701fb4 | 47 | #include "hxcclient_bsp.h" |
kashish_mbed | 3:5e1a54378107 | 48 | #include "lora_driver.h" |
kashish_mbed | 0:bacc6e701fb4 | 49 | #include "lora_conf.h" |
kashish_mbed | 3:5e1a54378107 | 50 | #include "CmdProcess.h" |
kashish_mbed | 0:bacc6e701fb4 | 51 | /* Variables -----------------------------------------------------------------*/ |
kashish_mbed | 0:bacc6e701fb4 | 52 | //Flag to indicate if the MCU is Initialized |
kashish_mbed | 0:bacc6e701fb4 | 53 | static bool McuInitialized = false; |
kashish_mbed | 0:bacc6e701fb4 | 54 | |
kashish_mbed | 0:bacc6e701fb4 | 55 | /* Function Declarations -----------------------------------------------------*/ |
kashish_mbed | 0:bacc6e701fb4 | 56 | void SystemClock_Config(void); |
kashish_mbed | 0:bacc6e701fb4 | 57 | void HW_Init(void); |
kashish_mbed | 0:bacc6e701fb4 | 58 | |
kashish_mbed | 0:bacc6e701fb4 | 59 | int main() |
kashish_mbed | 0:bacc6e701fb4 | 60 | { |
kashish_mbed | 0:bacc6e701fb4 | 61 | HW_Init(); |
kashish_mbed | 0:bacc6e701fb4 | 62 | |
kashish_mbed | 0:bacc6e701fb4 | 63 | DBG_PRINTF("HXC900-NucleoL053R8 Demo Application\r\n"); |
kashish_mbed | 0:bacc6e701fb4 | 64 | Lora_init(&LoraConfigParam, &LoraDriverParam); |
kashish_mbed | 3:5e1a54378107 | 65 | CmdModeProcess(); |
kashish_mbed | 0:bacc6e701fb4 | 66 | while(1) |
kashish_mbed | 0:bacc6e701fb4 | 67 | { |
kashish_mbed | 0:bacc6e701fb4 | 68 | Lora_fsm(); |
kashish_mbed | 0:bacc6e701fb4 | 69 | } |
kashish_mbed | 0:bacc6e701fb4 | 70 | } |
kashish_mbed | 0:bacc6e701fb4 | 71 | |
kashish_mbed | 0:bacc6e701fb4 | 72 | /****************************************************************************** |
kashish_mbed | 0:bacc6e701fb4 | 73 | * @Brief : This function initializes the hardware |
kashish_mbed | 0:bacc6e701fb4 | 74 | * @Param : None |
kashish_mbed | 0:bacc6e701fb4 | 75 | * @Return: None |
kashish_mbed | 0:bacc6e701fb4 | 76 | ******************************************************************************/ |
kashish_mbed | 0:bacc6e701fb4 | 77 | void HW_Init(void) |
kashish_mbed | 0:bacc6e701fb4 | 78 | { |
kashish_mbed | 0:bacc6e701fb4 | 79 | if(McuInitialized == false) |
kashish_mbed | 0:bacc6e701fb4 | 80 | { |
kashish_mbed | 0:bacc6e701fb4 | 81 | // Reset of all peripherals, Initializes the Flash interface and the Systick. |
kashish_mbed | 0:bacc6e701fb4 | 82 | HAL_Init(); |
kashish_mbed | 0:bacc6e701fb4 | 83 | SystemClock_Config(); |
kashish_mbed | 0:bacc6e701fb4 | 84 | Debug_UART_Init(); |
kashish_mbed | 0:bacc6e701fb4 | 85 | HW_RTC_Init(); |
kashish_mbed | 0:bacc6e701fb4 | 86 | BSP_LED_Init(LED_GREEN);// LED on Nucleo board |
kashish_mbed | 0:bacc6e701fb4 | 87 | HXC_BSP_Init(); |
kashish_mbed | 0:bacc6e701fb4 | 88 | McuInitialized = true; |
kashish_mbed | 0:bacc6e701fb4 | 89 | } |
kashish_mbed | 0:bacc6e701fb4 | 90 | } |
kashish_mbed | 0:bacc6e701fb4 | 91 | |
kashish_mbed | 0:bacc6e701fb4 | 92 | /****************************************************************************** |
kashish_mbed | 0:bacc6e701fb4 | 93 | * @Brief : System Clock Configuration |
kashish_mbed | 0:bacc6e701fb4 | 94 | * The system Clock is configured as follow : |
kashish_mbed | 0:bacc6e701fb4 | 95 | * System Clock source = PLL (HSI) |
kashish_mbed | 0:bacc6e701fb4 | 96 | * SYSCLK(Hz) = 32000000 |
kashish_mbed | 0:bacc6e701fb4 | 97 | * HCLK(Hz) = 32000000 |
kashish_mbed | 0:bacc6e701fb4 | 98 | * AHB Prescaler = 1 |
kashish_mbed | 0:bacc6e701fb4 | 99 | * APB1 Prescaler = 1 |
kashish_mbed | 0:bacc6e701fb4 | 100 | * APB2 Prescaler = 1 |
kashish_mbed | 0:bacc6e701fb4 | 101 | * HSI Frequency(Hz) = 16000000 |
kashish_mbed | 0:bacc6e701fb4 | 102 | * PLLMUL = 6 |
kashish_mbed | 0:bacc6e701fb4 | 103 | * PLLDIV = 3 |
kashish_mbed | 0:bacc6e701fb4 | 104 | * Flash Latency(WS) = 1 |
kashish_mbed | 0:bacc6e701fb4 | 105 | * @Return: None |
kashish_mbed | 0:bacc6e701fb4 | 106 | * @Note : This function enables all the clock necessary for the demo |
kashish_mbed | 0:bacc6e701fb4 | 107 | * including UARTs |
kashish_mbed | 0:bacc6e701fb4 | 108 | ******************************************************************************/ |
kashish_mbed | 0:bacc6e701fb4 | 109 | void SystemClock_Config(void) |
kashish_mbed | 0:bacc6e701fb4 | 110 | { |
kashish_mbed | 0:bacc6e701fb4 | 111 | RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; |
kashish_mbed | 0:bacc6e701fb4 | 112 | RCC_OscInitTypeDef RCC_OscInitStruct = {0}; |
kashish_mbed | 0:bacc6e701fb4 | 113 | |
kashish_mbed | 0:bacc6e701fb4 | 114 | // Enable HSI48 Oscillator for RNG analog part |
kashish_mbed | 0:bacc6e701fb4 | 115 | RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI48; |
kashish_mbed | 0:bacc6e701fb4 | 116 | RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE; |
kashish_mbed | 0:bacc6e701fb4 | 117 | RCC_OscInitStruct.HSI48State = RCC_HSI48_ON; |
kashish_mbed | 0:bacc6e701fb4 | 118 | if(HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) |
kashish_mbed | 0:bacc6e701fb4 | 119 | { |
kashish_mbed | 0:bacc6e701fb4 | 120 | // Initialization Error |
kashish_mbed | 0:bacc6e701fb4 | 121 | Error_Handler(); |
kashish_mbed | 0:bacc6e701fb4 | 122 | } |
kashish_mbed | 0:bacc6e701fb4 | 123 | |
kashish_mbed | 0:bacc6e701fb4 | 124 | // Set Voltage scale1 as MCU will run at 32MHz |
kashish_mbed | 0:bacc6e701fb4 | 125 | __HAL_RCC_PWR_CLK_ENABLE(); |
kashish_mbed | 0:bacc6e701fb4 | 126 | __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1); |
kashish_mbed | 0:bacc6e701fb4 | 127 | |
kashish_mbed | 0:bacc6e701fb4 | 128 | // Poll VOSF bit of in PWR_CSR. Wait until it is reset to 0 |
kashish_mbed | 0:bacc6e701fb4 | 129 | while (__HAL_PWR_GET_FLAG(PWR_FLAG_VOS) != RESET) {}; |
kashish_mbed | 0:bacc6e701fb4 | 130 | |
kashish_mbed | 0:bacc6e701fb4 | 131 | // Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2 clocks dividers |
kashish_mbed | 0:bacc6e701fb4 | 132 | RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2); |
kashish_mbed | 0:bacc6e701fb4 | 133 | RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; |
kashish_mbed | 0:bacc6e701fb4 | 134 | RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; |
kashish_mbed | 0:bacc6e701fb4 | 135 | RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1; |
kashish_mbed | 0:bacc6e701fb4 | 136 | RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; |
kashish_mbed | 0:bacc6e701fb4 | 137 | if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK) |
kashish_mbed | 0:bacc6e701fb4 | 138 | { |
kashish_mbed | 0:bacc6e701fb4 | 139 | Error_Handler(); |
kashish_mbed | 0:bacc6e701fb4 | 140 | } |
kashish_mbed | 0:bacc6e701fb4 | 141 | |
kashish_mbed | 0:bacc6e701fb4 | 142 | HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000); |
kashish_mbed | 0:bacc6e701fb4 | 143 | HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK); |
kashish_mbed | 0:bacc6e701fb4 | 144 | |
kashish_mbed | 0:bacc6e701fb4 | 145 | // SysTick_IRQn interrupt configuration |
kashish_mbed | 0:bacc6e701fb4 | 146 | HAL_NVIC_SetPriority(SysTick_IRQn, 1, 0); |
kashish_mbed | 0:bacc6e701fb4 | 147 | } |
kashish_mbed | 0:bacc6e701fb4 | 148 | |
kashish_mbed | 0:bacc6e701fb4 | 149 | /****************************************************************************** |
kashish_mbed | 0:bacc6e701fb4 | 150 | * @Brief : Initializes the MSP. |
kashish_mbed | 0:bacc6e701fb4 | 151 | * @Param : None |
kashish_mbed | 0:bacc6e701fb4 | 152 | * @Return: None |
kashish_mbed | 0:bacc6e701fb4 | 153 | ******************************************************************************/ |
kashish_mbed | 0:bacc6e701fb4 | 154 | void HAL_MspInit(void) |
kashish_mbed | 0:bacc6e701fb4 | 155 | { |
kashish_mbed | 0:bacc6e701fb4 | 156 | __HAL_RCC_PWR_CLK_ENABLE(); |
kashish_mbed | 0:bacc6e701fb4 | 157 | |
kashish_mbed | 0:bacc6e701fb4 | 158 | // Disable the Power Voltage Detector |
kashish_mbed | 0:bacc6e701fb4 | 159 | HAL_PWR_DisablePVD(); |
kashish_mbed | 0:bacc6e701fb4 | 160 | |
kashish_mbed | 0:bacc6e701fb4 | 161 | // Enables the Ultra Low Power mode |
kashish_mbed | 0:bacc6e701fb4 | 162 | HAL_PWREx_EnableUltraLowPower(); |
kashish_mbed | 0:bacc6e701fb4 | 163 | |
kashish_mbed | 0:bacc6e701fb4 | 164 | __HAL_FLASH_SLEEP_POWERDOWN_ENABLE(); |
kashish_mbed | 0:bacc6e701fb4 | 165 | |
kashish_mbed | 0:bacc6e701fb4 | 166 | /* In debug mode, e.g. when DBGMCU is activated, Arm core has always clocks |
kashish_mbed | 0:bacc6e701fb4 | 167 | * And will not wait that the FLACH is ready to be read. It can miss in this |
kashish_mbed | 0:bacc6e701fb4 | 168 | * case the first instruction. To overcome this issue, the flash remain clocked during sleep mode |
kashish_mbed | 0:bacc6e701fb4 | 169 | */ |
kashish_mbed | 0:bacc6e701fb4 | 170 | DBG( __HAL_FLASH_SLEEP_POWERDOWN_DISABLE(); ); |
kashish_mbed | 0:bacc6e701fb4 | 171 | /*Enable fast wakeUp*/ |
kashish_mbed | 0:bacc6e701fb4 | 172 | HAL_PWREx_EnableFastWakeUp( ); |
kashish_mbed | 0:bacc6e701fb4 | 173 | } |
kashish_mbed | 0:bacc6e701fb4 | 174 | |
kashish_mbed | 0:bacc6e701fb4 | 175 | #ifdef USE_FULL_ASSERT |
kashish_mbed | 0:bacc6e701fb4 | 176 | |
kashish_mbed | 0:bacc6e701fb4 | 177 | /****************************************************************************** |
kashish_mbed | 0:bacc6e701fb4 | 178 | * @Brief : Reports the name of the source file and the source line number |
kashish_mbed | 0:bacc6e701fb4 | 179 | * where the assert_param error has occurred. |
kashish_mbed | 0:bacc6e701fb4 | 180 | * @Param : file: pointer to the source file name |
kashish_mbed | 0:bacc6e701fb4 | 181 | * line: assert_param error line source number |
kashish_mbed | 0:bacc6e701fb4 | 182 | * @Return: None |
kashish_mbed | 0:bacc6e701fb4 | 183 | ******************************************************************************/ |
kashish_mbed | 0:bacc6e701fb4 | 184 | void assert_failed(uint8_t* file, uint32_t line) |
kashish_mbed | 0:bacc6e701fb4 | 185 | { |
kashish_mbed | 0:bacc6e701fb4 | 186 | /* User can add his own implementation to report the file name and line number, |
kashish_mbed | 0:bacc6e701fb4 | 187 | ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ |
kashish_mbed | 0:bacc6e701fb4 | 188 | } |
kashish_mbed | 0:bacc6e701fb4 | 189 | |
kashish_mbed | 0:bacc6e701fb4 | 190 | #endif |
kashish_mbed | 0:bacc6e701fb4 | 191 | |
kashish_mbed | 0:bacc6e701fb4 | 192 | /************************ (C) COPYRIGHT Haxiot ***** END OF FILE ****/ |
kashish_mbed | 0:bacc6e701fb4 | 193 |