From e1c19fd194e6f13381c30742ae811a8ba3ff5896 Mon Sep 17 00:00:00 2001 From: supowang Date: Wed, 18 Dec 2019 13:01:35 +0800 Subject: [PATCH] add lora lowpower at command support add lora lowpower at command support --- .../TencentOS_tiny_STM32L073RZTx.dbgconf | 43 ------------ .../RTE/_TencentOS_tiny/RTE_Components.h | 20 ------ .../lorawan/TencentOS_tiny/TencentOS_tiny.sct | 16 ----- board/TencentOS_tiny_EVB_LX/BSP/Inc/usart.h | 15 +++-- .../TencentOS_tiny_EVB_LX/BSP/Src/mcu_init.c | 8 ++- board/TencentOS_tiny_EVB_LX/BSP/Src/usart.c | 66 ++++++++++++++----- devices/rhf76_lora/RHF76.c | 19 ++++++ devices/rhf76_lora/RHF76.h | 3 + 8 files changed, 86 insertions(+), 104 deletions(-) delete mode 100644 board/NUCLEO_STM32L073RZ/KEIL/lorawan/DebugConfig/TencentOS_tiny_STM32L073RZTx.dbgconf delete mode 100644 board/NUCLEO_STM32L073RZ/KEIL/lorawan/RTE/_TencentOS_tiny/RTE_Components.h delete mode 100644 board/NUCLEO_STM32L073RZ/KEIL/lorawan/TencentOS_tiny/TencentOS_tiny.sct diff --git a/board/NUCLEO_STM32L073RZ/KEIL/lorawan/DebugConfig/TencentOS_tiny_STM32L073RZTx.dbgconf b/board/NUCLEO_STM32L073RZ/KEIL/lorawan/DebugConfig/TencentOS_tiny_STM32L073RZTx.dbgconf deleted file mode 100644 index 5b27c4a9..00000000 --- a/board/NUCLEO_STM32L073RZ/KEIL/lorawan/DebugConfig/TencentOS_tiny_STM32L073RZTx.dbgconf +++ /dev/null @@ -1,43 +0,0 @@ -// File: STM32L0x1_0x2_0x3_DBGMCU.ini -// Version: 1.0.0 -// Note: refer to STM32L0x1 reference manual (RM0377) -// refer to STM32L0x1 datasheet -// refer to STM32L0x2 reference manual (RM0376) -// refer to STM32L0x2 datasheet -// refer to STM32L0x3 reference manual (RM0367) -// refer to STM32L0x3 datasheet - -// <<< Use Configuration Wizard in Context Menu >>> - -// Debug MCU configuration register (DBGMCU_CR) -// Reserved bits must be kept at reset value -// DBG_STANDBY Debug Standby Mode -// DBG_STOP Debug Stop Mode -// DBG_SLEEP Debug Sleep Mode -// -DbgMCU_CR = 0x00000007; - -// Debug MCU APB1 freeze register (DBGMCU_APB1_FZ) -// Reserved bits must be kept at reset value -// DBG_LPTIMER_STOP LPTIM1 counter stopped when core is halted -// DBG_I2C3_STOP I2C3 SMBUS timeout mode stopped when core is halted -// DBG_I2C2_STOP I2C2 SMBUS timeout mode stopped when core is halted -// DBG_I2C1_STOP I2C1 SMBUS timeout mode stopped when core is halted -// DBG_IWDG_STOP Debug independent watchdog stopped when core is halted -// DBG_WWDG_STOP Debug window watchdog stopped when core is halted -// DBG_RTC_STOP Debug RTC stopped when core is halted -// DBG_TIM7_STOP TIM7 counter stopped when core is halted -// DBG_TIM6_STOP TIM6 counter stopped when core is halted -// DBG_TIM3_STOP TIM3 counter stopped when core is halted -// DBG_TIM2_STOP TIM2 counter stopped when core is halted -// -DbgMCU_APB1_Fz = 0x00000000; - -// Debug MCU APB2 freeze register (DBGMCU_APB2_FZ) -// Reserved bits must be kept at reset value -// DBG_TIM22_STOP TIM22 counter stopped when core is halted -// DBG_TIM21_STOP TIM21 counter stopped when core is halted -// -DbgMCU_APB2_Fz = 0x00000000; - -// <<< end of configuration section >>> diff --git a/board/NUCLEO_STM32L073RZ/KEIL/lorawan/RTE/_TencentOS_tiny/RTE_Components.h b/board/NUCLEO_STM32L073RZ/KEIL/lorawan/RTE/_TencentOS_tiny/RTE_Components.h deleted file mode 100644 index 4b2a0396..00000000 --- a/board/NUCLEO_STM32L073RZ/KEIL/lorawan/RTE/_TencentOS_tiny/RTE_Components.h +++ /dev/null @@ -1,20 +0,0 @@ - -/* - * Auto generated Run-Time-Environment Component Configuration File - * *** Do not modify ! *** - * - * Project: 'TencentOS_tiny' - * Target: 'TencentOS_tiny' - */ - -#ifndef RTE_COMPONENTS_H -#define RTE_COMPONENTS_H - - -/* - * Define the Device Header File: - */ -#define CMSIS_device_header "stm32l0xx.h" - - -#endif /* RTE_COMPONENTS_H */ diff --git a/board/NUCLEO_STM32L073RZ/KEIL/lorawan/TencentOS_tiny/TencentOS_tiny.sct b/board/NUCLEO_STM32L073RZ/KEIL/lorawan/TencentOS_tiny/TencentOS_tiny.sct deleted file mode 100644 index 2d15c6b4..00000000 --- a/board/NUCLEO_STM32L073RZ/KEIL/lorawan/TencentOS_tiny/TencentOS_tiny.sct +++ /dev/null @@ -1,16 +0,0 @@ -; ************************************************************* -; *** Scatter-Loading Description File generated by uVision *** -; ************************************************************* - -LR_IROM1 0x08000000 0x00030000 { ; load region size_region - ER_IROM1 0x08000000 0x00030000 { ; load address = execution address - *.o (RESET, +First) - *(InRoot$$Sections) - .ANY (+RO) - .ANY (+XO) - } - RW_IRAM1 0x20000000 0x00005000 { ; RW data - .ANY (+RW +ZI) - } -} - diff --git a/board/TencentOS_tiny_EVB_LX/BSP/Inc/usart.h b/board/TencentOS_tiny_EVB_LX/BSP/Inc/usart.h index a5cbe461..68631a13 100644 --- a/board/TencentOS_tiny_EVB_LX/BSP/Inc/usart.h +++ b/board/TencentOS_tiny_EVB_LX/BSP/Inc/usart.h @@ -5,9 +5,16 @@ #define USART0_GPIO_RX_PIN GPIO_PIN_10 #define USART0_GPIO_PORT GPIOA -#define USART3_GPIO_TX_PIN GPIO_PIN_10 -#define USART3_GPIO_RX_PIN GPIO_PIN_11 -#define USART3_GPIO_PORT GPIOC +#define USART1_GPIO_TX_PIN GPIO_PIN_2 +#define USART1_GPIO_RX_PIN GPIO_PIN_3 +#define USART1_GPIO_PORT GPIOA + +#define USART2_GPIO_TX_PIN GPIO_PIN_10 +#define USART2_GPIO_RX_PIN GPIO_PIN_11 +#define USART2_GPIO_PORT GPIOC + + void usart0_init(int baud); -void uart3_init(int baud); +void usart1_init(int baud); +void usart2_init(int baud); #endif // __USART_H diff --git a/board/TencentOS_tiny_EVB_LX/BSP/Src/mcu_init.c b/board/TencentOS_tiny_EVB_LX/BSP/Src/mcu_init.c index 2eee0d82..c2bbf9f3 100644 --- a/board/TencentOS_tiny_EVB_LX/BSP/Src/mcu_init.c +++ b/board/TencentOS_tiny_EVB_LX/BSP/Src/mcu_init.c @@ -11,16 +11,18 @@ static void led_config(void) gpio_bit_set(LED_GPIO_PORT, LED_PIN); } -void board_init() { +void board_init() +{ char *str = "Tencent"; SystemInit(); led_config(); - uart3_init(115200); + usart0_init(115200); + usart1_init(115200); + usart2_init(115200); OLED_Init(); OLED_Clear(); OLED_ShowChinese(36,0,0); OLED_ShowChinese(54,0,1); OLED_ShowChinese(72,0,2); OLED_ShowString(36,2,(uint8_t*)str,8); - } diff --git a/board/TencentOS_tiny_EVB_LX/BSP/Src/usart.c b/board/TencentOS_tiny_EVB_LX/BSP/Src/usart.c index f2ea118d..284eb060 100644 --- a/board/TencentOS_tiny_EVB_LX/BSP/Src/usart.c +++ b/board/TencentOS_tiny_EVB_LX/BSP/Src/usart.c @@ -27,39 +27,69 @@ void usart0_init(int baud) usart_enable(USART0); } +void usart1_init(int baud) +{ + /* enable GPIO clock */ + rcu_periph_clock_enable(RCU_GPIOA); -void uart3_init(int baud) + /* enable USART1 clock */ + rcu_periph_clock_enable(RCU_USART1); + + /* connect port to USART0_Tx */ + gpio_init(USART1_GPIO_PORT, GPIO_MODE_AF_PP, GPIO_OSPEED_50MHZ, USART1_GPIO_TX_PIN); + + /* connect port to USART0_Rx */ + gpio_init(USART1_GPIO_PORT, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_50MHZ, USART1_GPIO_RX_PIN); + + /* USART1 configure */ + usart_deinit(USART1); + usart_baudrate_set(USART1, baud); + usart_word_length_set(USART1, USART_WL_8BIT); + usart_stop_bit_set(USART1, USART_STB_1BIT); + usart_parity_config(USART1, USART_PM_NONE); + usart_hardware_flow_rts_config(USART1, USART_RTS_DISABLE); + usart_hardware_flow_cts_config(USART1, USART_CTS_DISABLE); + usart_receive_config(USART1, USART_RECEIVE_ENABLE); + usart_transmit_config(USART1, USART_TRANSMIT_ENABLE); + usart_enable(USART1); +} + + + +void usart2_init(int baud) { /* enable GPIO clock */ rcu_periph_clock_enable(RCU_GPIOC); - /* enable USART0 clock */ - rcu_periph_clock_enable(RCU_UART3); + /* enable USART2 clock */ + rcu_periph_clock_enable(RCU_USART2); /* connect port to USART0_Tx */ - gpio_init(USART3_GPIO_PORT, GPIO_MODE_AF_PP, GPIO_OSPEED_50MHZ, USART3_GPIO_TX_PIN); + gpio_init(USART2_GPIO_PORT, GPIO_MODE_AF_PP, GPIO_OSPEED_50MHZ, USART2_GPIO_TX_PIN); /* connect port to USART0_Rx */ - gpio_init(USART3_GPIO_PORT, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_50MHZ, USART3_GPIO_RX_PIN); + gpio_init(USART2_GPIO_PORT, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_50MHZ, USART2_GPIO_RX_PIN); - /* USART0 configure */ - usart_deinit(UART3); - usart_baudrate_set(UART3, baud); - usart_word_length_set(UART3, USART_WL_8BIT); - usart_stop_bit_set(UART3, USART_STB_1BIT); - usart_parity_config(UART3, USART_PM_NONE); - usart_hardware_flow_rts_config(UART3, USART_RTS_DISABLE); - usart_hardware_flow_cts_config(UART3, USART_CTS_DISABLE); - usart_receive_config(UART3, USART_RECEIVE_ENABLE); - usart_transmit_config(UART3, USART_TRANSMIT_ENABLE); - usart_enable(UART3); + gpio_pin_remap_config(GPIO_USART2_FULL_REMAP,ENABLE); + + /* USART1 configure */ + usart_deinit(USART2); + usart_baudrate_set(USART2, baud); + usart_word_length_set(USART2, USART_WL_8BIT); + usart_stop_bit_set(USART2, USART_STB_1BIT); + usart_parity_config(USART2, USART_PM_NONE); + usart_hardware_flow_rts_config(USART2, USART_RTS_DISABLE); + usart_hardware_flow_cts_config(USART2, USART_CTS_DISABLE); + usart_receive_config(USART2, USART_RECEIVE_ENABLE); + usart_transmit_config(USART2, USART_TRANSMIT_ENABLE); + usart_enable(USART2); } int _put_char(int ch) { - usart_data_transmit(UART3, (uint8_t) ch ); - while ( usart_flag_get(UART3, USART_FLAG_TBE)== RESET){ + usart_data_transmit(USART0, (uint8_t) ch ); + while ( usart_flag_get(USART0, USART_FLAG_TBE)== RESET){ } return ch; diff --git a/devices/rhf76_lora/RHF76.c b/devices/rhf76_lora/RHF76.c index 32d98446..18eb2d27 100644 --- a/devices/rhf76_lora/RHF76.c +++ b/devices/rhf76_lora/RHF76.c @@ -3,6 +3,21 @@ static mcps_indication_t rhf76_mcps_indication; +static int rhf76_exit_low_power(void) +{ + int try = 0; + at_echo_t echo; + + tos_at_echo_create(&echo, NULL, 0, "+LOWPOWER: AUTOOFF"); + while (try++ < 10) { + tos_at_cmd_exec(&echo, 3000, RHF76_LOWPOWER_SET); + if (echo.status == AT_ECHO_STATUS_OK || echo.status == AT_ECHO_STATUS_EXPECT) { + return 0; + } + } + return -1; +} + static int rhf76_reset(void) { int try = 0; @@ -186,6 +201,10 @@ static int rhf76_init(void) printf("Init RHF76 LoRa ...\n" ); at_delay_ms(1000); + if (rhf76_exit_low_power() != 0) { + printf("rhf76 reset FAILED\n"); + return -1; + } if (rhf76_reset() != 0) { printf("rhf76 reset FAILED\n"); diff --git a/devices/rhf76_lora/RHF76.h b/devices/rhf76_lora/RHF76.h index 55694a21..a8524dc5 100644 --- a/devices/rhf76_lora/RHF76.h +++ b/devices/rhf76_lora/RHF76.h @@ -51,6 +51,9 @@ typedef enum lora_key_type { } lora_key_type_t; +const char RHF76_LOWPOWER_SET[] = { + 0xFF,0xFF,0xFF,0xFF,'A','T','+','L','O','W','P','O','W','E','R','=','a','u','t','o','o','f','f','\r','\n' +}; #define RHF76_ATCMD_SET_CLASS_A "AT+CLASS=A\r\n" #define RHF76_ATCMD_SET_CLASS_B "AT+CLASS=B\r\n" #define RHF76_ATCMD_SET_CLASS_C "AT+CLASS=C\r\n"