add lora lowpower at command support
add lora lowpower at command support
This commit is contained in:
@@ -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 >>>
|
|
||||||
|
|
||||||
// <h> Debug MCU configuration register (DBGMCU_CR)
|
|
||||||
// <i> Reserved bits must be kept at reset value
|
|
||||||
// <o.2> DBG_STANDBY <i> Debug Standby Mode
|
|
||||||
// <o.1> DBG_STOP <i> Debug Stop Mode
|
|
||||||
// <o.0> DBG_SLEEP <i> Debug Sleep Mode
|
|
||||||
// </h>
|
|
||||||
DbgMCU_CR = 0x00000007;
|
|
||||||
|
|
||||||
// <h> Debug MCU APB1 freeze register (DBGMCU_APB1_FZ)
|
|
||||||
// <i> Reserved bits must be kept at reset value
|
|
||||||
// <o.31> DBG_LPTIMER_STOP <i> LPTIM1 counter stopped when core is halted
|
|
||||||
// <o.30> DBG_I2C3_STOP <i> I2C3 SMBUS timeout mode stopped when core is halted
|
|
||||||
// <o.22> DBG_I2C2_STOP <i> I2C2 SMBUS timeout mode stopped when core is halted
|
|
||||||
// <o.21> DBG_I2C1_STOP <i> I2C1 SMBUS timeout mode stopped when core is halted
|
|
||||||
// <o.12> DBG_IWDG_STOP <i> Debug independent watchdog stopped when core is halted
|
|
||||||
// <o.11> DBG_WWDG_STOP <i> Debug window watchdog stopped when core is halted
|
|
||||||
// <o.10> DBG_RTC_STOP <i> Debug RTC stopped when core is halted
|
|
||||||
// <o.5> DBG_TIM7_STOP <i> TIM7 counter stopped when core is halted
|
|
||||||
// <o.4> DBG_TIM6_STOP <i> TIM6 counter stopped when core is halted
|
|
||||||
// <o.1> DBG_TIM3_STOP <i> TIM3 counter stopped when core is halted
|
|
||||||
// <o.0> DBG_TIM2_STOP <i> TIM2 counter stopped when core is halted
|
|
||||||
// </h>
|
|
||||||
DbgMCU_APB1_Fz = 0x00000000;
|
|
||||||
|
|
||||||
// <h> Debug MCU APB2 freeze register (DBGMCU_APB2_FZ)
|
|
||||||
// <i> Reserved bits must be kept at reset value
|
|
||||||
// <o.5> DBG_TIM22_STOP <i> TIM22 counter stopped when core is halted
|
|
||||||
// <o.2> DBG_TIM21_STOP <i> TIM21 counter stopped when core is halted
|
|
||||||
// </h>
|
|
||||||
DbgMCU_APB2_Fz = 0x00000000;
|
|
||||||
|
|
||||||
// <<< end of configuration section >>>
|
|
@@ -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 */
|
|
@@ -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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@@ -5,9 +5,16 @@
|
|||||||
#define USART0_GPIO_RX_PIN GPIO_PIN_10
|
#define USART0_GPIO_RX_PIN GPIO_PIN_10
|
||||||
#define USART0_GPIO_PORT GPIOA
|
#define USART0_GPIO_PORT GPIOA
|
||||||
|
|
||||||
#define USART3_GPIO_TX_PIN GPIO_PIN_10
|
#define USART1_GPIO_TX_PIN GPIO_PIN_2
|
||||||
#define USART3_GPIO_RX_PIN GPIO_PIN_11
|
#define USART1_GPIO_RX_PIN GPIO_PIN_3
|
||||||
#define USART3_GPIO_PORT GPIOC
|
#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 usart0_init(int baud);
|
||||||
void uart3_init(int baud);
|
void usart1_init(int baud);
|
||||||
|
void usart2_init(int baud);
|
||||||
#endif // __USART_H
|
#endif // __USART_H
|
||||||
|
@@ -11,16 +11,18 @@ static void led_config(void)
|
|||||||
gpio_bit_set(LED_GPIO_PORT, LED_PIN);
|
gpio_bit_set(LED_GPIO_PORT, LED_PIN);
|
||||||
}
|
}
|
||||||
|
|
||||||
void board_init() {
|
void board_init()
|
||||||
|
{
|
||||||
char *str = "Tencent";
|
char *str = "Tencent";
|
||||||
SystemInit();
|
SystemInit();
|
||||||
led_config();
|
led_config();
|
||||||
uart3_init(115200);
|
usart0_init(115200);
|
||||||
|
usart1_init(115200);
|
||||||
|
usart2_init(115200);
|
||||||
OLED_Init();
|
OLED_Init();
|
||||||
OLED_Clear();
|
OLED_Clear();
|
||||||
OLED_ShowChinese(36,0,0);
|
OLED_ShowChinese(36,0,0);
|
||||||
OLED_ShowChinese(54,0,1);
|
OLED_ShowChinese(54,0,1);
|
||||||
OLED_ShowChinese(72,0,2);
|
OLED_ShowChinese(72,0,2);
|
||||||
OLED_ShowString(36,2,(uint8_t*)str,8);
|
OLED_ShowString(36,2,(uint8_t*)str,8);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -27,39 +27,69 @@ void usart0_init(int baud)
|
|||||||
usart_enable(USART0);
|
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 */
|
/* enable GPIO clock */
|
||||||
rcu_periph_clock_enable(RCU_GPIOC);
|
rcu_periph_clock_enable(RCU_GPIOC);
|
||||||
|
|
||||||
/* enable USART0 clock */
|
/* enable USART2 clock */
|
||||||
rcu_periph_clock_enable(RCU_UART3);
|
rcu_periph_clock_enable(RCU_USART2);
|
||||||
|
|
||||||
/* connect port to USART0_Tx */
|
/* 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 */
|
/* 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 */
|
gpio_pin_remap_config(GPIO_USART2_FULL_REMAP,ENABLE);
|
||||||
usart_deinit(UART3);
|
|
||||||
usart_baudrate_set(UART3, baud);
|
/* USART1 configure */
|
||||||
usart_word_length_set(UART3, USART_WL_8BIT);
|
usart_deinit(USART2);
|
||||||
usart_stop_bit_set(UART3, USART_STB_1BIT);
|
usart_baudrate_set(USART2, baud);
|
||||||
usart_parity_config(UART3, USART_PM_NONE);
|
usart_word_length_set(USART2, USART_WL_8BIT);
|
||||||
usart_hardware_flow_rts_config(UART3, USART_RTS_DISABLE);
|
usart_stop_bit_set(USART2, USART_STB_1BIT);
|
||||||
usart_hardware_flow_cts_config(UART3, USART_CTS_DISABLE);
|
usart_parity_config(USART2, USART_PM_NONE);
|
||||||
usart_receive_config(UART3, USART_RECEIVE_ENABLE);
|
usart_hardware_flow_rts_config(USART2, USART_RTS_DISABLE);
|
||||||
usart_transmit_config(UART3, USART_TRANSMIT_ENABLE);
|
usart_hardware_flow_cts_config(USART2, USART_CTS_DISABLE);
|
||||||
usart_enable(UART3);
|
usart_receive_config(USART2, USART_RECEIVE_ENABLE);
|
||||||
|
usart_transmit_config(USART2, USART_TRANSMIT_ENABLE);
|
||||||
|
usart_enable(USART2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int _put_char(int ch)
|
int _put_char(int ch)
|
||||||
{
|
{
|
||||||
usart_data_transmit(UART3, (uint8_t) ch );
|
usart_data_transmit(USART0, (uint8_t) ch );
|
||||||
while ( usart_flag_get(UART3, USART_FLAG_TBE)== RESET){
|
while ( usart_flag_get(USART0, USART_FLAG_TBE)== RESET){
|
||||||
}
|
}
|
||||||
|
|
||||||
return ch;
|
return ch;
|
||||||
|
@@ -3,6 +3,21 @@
|
|||||||
|
|
||||||
static mcps_indication_t rhf76_mcps_indication;
|
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)
|
static int rhf76_reset(void)
|
||||||
{
|
{
|
||||||
int try = 0;
|
int try = 0;
|
||||||
@@ -186,6 +201,10 @@ static int rhf76_init(void)
|
|||||||
printf("Init RHF76 LoRa ...\n" );
|
printf("Init RHF76 LoRa ...\n" );
|
||||||
|
|
||||||
at_delay_ms(1000);
|
at_delay_ms(1000);
|
||||||
|
if (rhf76_exit_low_power() != 0) {
|
||||||
|
printf("rhf76 reset FAILED\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
if (rhf76_reset() != 0) {
|
if (rhf76_reset() != 0) {
|
||||||
printf("rhf76 reset FAILED\n");
|
printf("rhf76 reset FAILED\n");
|
||||||
|
@@ -51,6 +51,9 @@ typedef enum lora_key_type {
|
|||||||
} lora_key_type_t;
|
} 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_A "AT+CLASS=A\r\n"
|
||||||
#define RHF76_ATCMD_SET_CLASS_B "AT+CLASS=B\r\n"
|
#define RHF76_ATCMD_SET_CLASS_B "AT+CLASS=B\r\n"
|
||||||
#define RHF76_ATCMD_SET_CLASS_C "AT+CLASS=C\r\n"
|
#define RHF76_ATCMD_SET_CLASS_C "AT+CLASS=C\r\n"
|
||||||
|
Reference in New Issue
Block a user