From 10bbb3db8dc1d64d09fa34571383014d92120bc7 Mon Sep 17 00:00:00 2001 From: jiejieTop <1161959934@qq.com> Date: Sun, 22 Mar 2020 12:20:58 +0800 Subject: [PATCH] mqttclient supports at framework and add gokit3 board demo... --- board/GoKit3_STM32F103C8T6/BSP/Inc/bsp_dwt.h | 52 + board/GoKit3_STM32F103C8T6/BSP/Inc/bsp_init.h | 23 + board/GoKit3_STM32F103C8T6/BSP/Inc/bsp_led.h | 34 + .../GoKit3_STM32F103C8T6/BSP/Inc/bsp_motor.h | 43 + .../GoKit3_STM32F103C8T6/BSP/Inc/bsp_usart.h | 57 + .../BSP/Inc/stm32f1xx_hal_conf.h | 2 +- board/GoKit3_STM32F103C8T6/BSP/Inc/tos_at.h | 460 ++++++ .../BSP/Inc/tos_at_utils.h | 23 + board/GoKit3_STM32F103C8T6/BSP/Src/bsp_dwt.c | 129 ++ board/GoKit3_STM32F103C8T6/BSP/Src/bsp_init.c | 56 + board/GoKit3_STM32F103C8T6/BSP/Src/bsp_led.c | 113 ++ .../GoKit3_STM32F103C8T6/BSP/Src/bsp_motor.c | 103 ++ .../GoKit3_STM32F103C8T6/BSP/Src/bsp_usart.c | 144 ++ .../BSP/Src/tos_hal_uart.c | 73 + .../mqttclient/GoKit3_STM32F103C8T6.uvoptx | 1450 +++++++++++++++++ .../mqttclient/GoKit3_STM32F103C8T6.uvprojx | 942 +++++++++++ .../KEIL/mqttclient/startup_stm32f103xb.s | 307 ++++ .../KEIL/mqttclient/stm32f1xx_it.c | 211 +++ .../TOS-CONFIG/mqtt_config.h | 48 + .../TOS-CONFIG/tos_config.h | 2 +- .../TencentOS-tiny/platform_net_socket.c | 36 + .../TencentOS-tiny/platform_net_socket.h | 11 + examples/mqttclient/gokit3_mqttclient.c | 105 ++ examples/mqttclient/mqttclient.c | 12 +- 24 files changed, 4432 insertions(+), 4 deletions(-) create mode 100644 board/GoKit3_STM32F103C8T6/BSP/Inc/bsp_dwt.h create mode 100644 board/GoKit3_STM32F103C8T6/BSP/Inc/bsp_init.h create mode 100644 board/GoKit3_STM32F103C8T6/BSP/Inc/bsp_led.h create mode 100644 board/GoKit3_STM32F103C8T6/BSP/Inc/bsp_motor.h create mode 100644 board/GoKit3_STM32F103C8T6/BSP/Inc/bsp_usart.h create mode 100644 board/GoKit3_STM32F103C8T6/BSP/Inc/tos_at.h create mode 100644 board/GoKit3_STM32F103C8T6/BSP/Inc/tos_at_utils.h create mode 100644 board/GoKit3_STM32F103C8T6/BSP/Src/bsp_dwt.c create mode 100644 board/GoKit3_STM32F103C8T6/BSP/Src/bsp_init.c create mode 100644 board/GoKit3_STM32F103C8T6/BSP/Src/bsp_led.c create mode 100644 board/GoKit3_STM32F103C8T6/BSP/Src/bsp_motor.c create mode 100644 board/GoKit3_STM32F103C8T6/BSP/Src/bsp_usart.c create mode 100644 board/GoKit3_STM32F103C8T6/BSP/Src/tos_hal_uart.c create mode 100644 board/GoKit3_STM32F103C8T6/KEIL/mqttclient/GoKit3_STM32F103C8T6.uvoptx create mode 100644 board/GoKit3_STM32F103C8T6/KEIL/mqttclient/GoKit3_STM32F103C8T6.uvprojx create mode 100644 board/GoKit3_STM32F103C8T6/KEIL/mqttclient/startup_stm32f103xb.s create mode 100644 board/GoKit3_STM32F103C8T6/KEIL/mqttclient/stm32f1xx_it.c create mode 100644 board/GoKit3_STM32F103C8T6/TOS-CONFIG/mqtt_config.h create mode 100644 examples/mqttclient/gokit3_mqttclient.c diff --git a/board/GoKit3_STM32F103C8T6/BSP/Inc/bsp_dwt.h b/board/GoKit3_STM32F103C8T6/BSP/Inc/bsp_dwt.h new file mode 100644 index 00000000..87a08b4d --- /dev/null +++ b/board/GoKit3_STM32F103C8T6/BSP/Inc/bsp_dwt.h @@ -0,0 +1,52 @@ +/* + * @Author: jiejie + * @Github: https://github.com/jiejieTop + * @Date: 2020-02-15 20:51:38 + * @LastEditTime: 2020-02-16 00:07:34 + * @Description: the code belongs to jiejie, please keep the author information and source code according to the license. + */ +#ifndef _BSP_DWT_H +#define _BSP_DWT_H + +#include "stdint.h" + +#define USE_DWT_DELAY 1 /* 使用dwt内核精确延时 */ + +#if USE_DWT_DELAY +#define USE_TICK_DELAY 0 /* 不使用SysTick延时 */ +#else +#define USE_TICK_DELAY 1 /* 使用SysTick延时 */ +#endif + +#if USE_DWT_DELAY + +/* 获取内核时钟频率 */ +#define get_cpu_clk_freq() (72000000U) +#define system_clk_freq (72000000U) +/* 为方便使用,在延时函数内部调用dwt_init函数初始化时间戳寄存器, + 这样每次调用函数都会初始化一遍。 + 把本宏值设置为0,然后在main函数刚运行时调用dwt_init可避免每次都初始化 */ + +#define CPU_TS_INIT_IN_DELAY_FUNCTION 0 + + +/******************************************************************************* + * 函数声明 + ******************************************************************************/ +uint32_t dwt_read(void); +void dwt_init(void); + +//使用以下函数前必须先调用dwt_init函数使能计数器,或使能宏CPU_TS_INIT_IN_DELAY_FUNCTION +//最大延时值为60秒 +void dwt_delay_us(uint32_t us); +#define dwt_delay_ms(ms) dwt_delay_us(ms*1000) +#define dwt_delay_s(s) dwt_delay_ms(s*1000) + +/* 最大延时 60s=2的32次方/72000000 */ +#define delay_ms(ms) dwt_delay_ms(ms) +#define delay_us(us) dwt_delay_us(us) +#define delay_s(s) dwt_delay_s(s) + +#endif + +#endif /* _BSP_DWT_H */ diff --git a/board/GoKit3_STM32F103C8T6/BSP/Inc/bsp_init.h b/board/GoKit3_STM32F103C8T6/BSP/Inc/bsp_init.h new file mode 100644 index 00000000..5ddda0a5 --- /dev/null +++ b/board/GoKit3_STM32F103C8T6/BSP/Inc/bsp_init.h @@ -0,0 +1,23 @@ +/* + * @Author: jiejie + * @Github: https://github.com/jiejieTop + * @Date: 2020-02-14 22:37:23 + * @LastEditTime : 2020-02-14 23:37:18 + * @Description: the code belongs to jiejie, please keep the author information and source code according to the license. + */ +#ifndef _BSP_INIT_H_ +#define _BSP_INIT_H_ + +#include "stm32f1xx.h" +#include "stm32f1xx_hal.h" +#include "bsp_led.h" +#include "bsp_dwt.h" +#include "bsp_usart.h" +#include "bsp_motor.h" + +void bsp_init(void); +void SystemClock_Config(void); + +#endif + + diff --git a/board/GoKit3_STM32F103C8T6/BSP/Inc/bsp_led.h b/board/GoKit3_STM32F103C8T6/BSP/Inc/bsp_led.h new file mode 100644 index 00000000..a01e6a61 --- /dev/null +++ b/board/GoKit3_STM32F103C8T6/BSP/Inc/bsp_led.h @@ -0,0 +1,34 @@ +/* + * @Author: jiejie + * @Github: https://github.com/jiejieTop + * @Date: 2020-02-15 20:51:38 + * @LastEditTime : 2020-02-16 00:24:14 + * @Description: the code belongs to jiejie, please keep the author information and source code according to the license. + */ +#ifndef _BSP_LED_H +#define _BSP_LED_H + +#include "stm32f1xx_hal.h" + +#define R_MAX 255 +#define G_MAX 255 +#define B_MAX 255 + +#define RGB_LED_CLK_PIN GPIO_PIN_8 +#define RGB_LED_CLK_GPIO_PORT GPIOB + +#define RGB_LED_SDA_PIN GPIO_PIN_9 +#define RGB_LED_SDA_GPIO_PORT GPIOB + +#define RGB_LED_GPIO_CLK_ENABLE() __HAL_RCC_GPIOB_CLK_ENABLE() + +#define SCL_LOW HAL_GPIO_WritePin(RGB_LED_CLK_GPIO_PORT, RGB_LED_CLK_PIN, GPIO_PIN_RESET) +#define SCL_HIGH HAL_GPIO_WritePin(RGB_LED_CLK_GPIO_PORT, RGB_LED_CLK_PIN, GPIO_PIN_SET) + +#define SDA_LOW HAL_GPIO_WritePin(RGB_LED_SDA_GPIO_PORT, RGB_LED_SDA_PIN, GPIO_PIN_RESET) +#define SDA_HIGH HAL_GPIO_WritePin(RGB_LED_SDA_GPIO_PORT, RGB_LED_SDA_PIN, GPIO_PIN_SET) + +void rgb_led_init(void); +void rgb_led_control(uint8_t r,uint8_t g,uint8_t b); + +#endif /* _BSP_LED_H */ diff --git a/board/GoKit3_STM32F103C8T6/BSP/Inc/bsp_motor.h b/board/GoKit3_STM32F103C8T6/BSP/Inc/bsp_motor.h new file mode 100644 index 00000000..394bee29 --- /dev/null +++ b/board/GoKit3_STM32F103C8T6/BSP/Inc/bsp_motor.h @@ -0,0 +1,43 @@ +/* + * @Author: jiejie + * @Github: https://github.com/jiejieTop + * @Date: 2020-02-16 00:02:40 + * @LastEditTime : 2020-02-16 00:31:10 + * @Description: the code belongs to jiejie, please keep the author information and source code according to the license. + */ +#ifndef _BSP_MOTOR_H +#define _BSP_MOTOR_H + +#include "stm32f1xx_hal.h" + +#define MOTOR_FORWARD_PORT GPIOB +#define MOTOR_FORWARD_PIN GPIO_PIN_4 +#define MOTOR_FORWARD_CHANNEL TIM_CHANNEL_1 + + +#define MOTOR_REVERSE_PORT GPIOB +#define MOTOR_REVERSE_PIN GPIO_PIN_5 +#define MOTOR_REVERSE_CHANNEL TIM_CHANNEL_2 + +#define MOTOR_TIM TIM3 +#define MOTOR_TIM_RCC_CLK_ENABLE() __HAL_RCC_TIM3_CLK_ENABLE() +#define MOTOR_TIM_AFIO_REMAP() __HAL_AFIO_REMAP_TIM3_PARTIAL() +#define MOTOR_TIM_RCC_CLK_DISABLE() __HAL_RCC_TIM3_CLK_DISABLE() +#define MOTOR_TIM_GPIO_RCC_CLK_ENABLE() __HAL_RCC_GPIOB_CLK_ENABLE(); + +//72M/72=1MļƵʣԶװΪ500ôPWMƵΪ1M/250=4kHZ +#define MOTOR_PRESCALER 71 //ʱԤƵ +#define MOTOR_PERIOD 249 // ʱװֵ + +#define MOTOR_MAX_DUTY 100 // ռձ + +typedef enum motor_mode { + MOTOR_STOP = 0, + MOTOR_FORWARD = 1, + MOTOR_REVERSE = 2 +} motor_mode_t; + +void motor_init(void); +void motor_set_speed(motor_mode_t s, uint8_t pwm); + +#endif /* _BSP_MOTOR_H */ diff --git a/board/GoKit3_STM32F103C8T6/BSP/Inc/bsp_usart.h b/board/GoKit3_STM32F103C8T6/BSP/Inc/bsp_usart.h new file mode 100644 index 00000000..e8c05bfa --- /dev/null +++ b/board/GoKit3_STM32F103C8T6/BSP/Inc/bsp_usart.h @@ -0,0 +1,57 @@ +#ifndef __USART_H +#define __USART_H + +#include "stm32f1xx.h" +#include + +//ڲ +#define DEBUG_USART_BAUDRATE 115200 + +//Ŷ +/*******************************************************/ +#define DEBUG_USART USART1 +#define DEBUG_USART_CLK_ENABLE() __HAL_RCC_USART1_CLK_ENABLE(); + +#define DEBUG_USART_RX_GPIO_PORT GPIOA +#define DEBUG_USART_RX_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE() +#define DEBUG_USART_RX_PIN GPIO_PIN_10 + +#define DEBUG_USART_TX_GPIO_PORT GPIOA +#define DEBUG_USART_TX_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE() +#define DEBUG_USART_TX_PIN GPIO_PIN_9 + +#define DEBUG_USART_IRQHandler USART1_IRQHandler +#define DEBUG_USART_IRQ USART1_IRQn +/************************************************************/ + + +//ڲ +#define WIFI_USART_BAUDRATE 115200 + +//Ŷ +/*******************************************************/ +#define WIFI_USART USART2 +#define WIFI_USART_CLK_ENABLE() __HAL_RCC_USART2_CLK_ENABLE(); + +#define WIFI_USART_RX_GPIO_PORT GPIOA +#define WIFI_USART_RX_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE() +#define WIFI_USART_RX_PIN GPIO_PIN_3 + +#define WIFI_USART_TX_GPIO_PORT GPIOA +#define WIFI_USART_TX_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE() +#define WIFI_USART_TX_PIN GPIO_PIN_2 + +#define WIFI_USART_IRQHandler USART2_IRQHandler +#define WIFI_USART_IRQ USART2_IRQn +/************************************************************/ + +void wifi_usart_init(void); +void debug_usart_init(void); +void usart_send_string(UART_HandleTypeDef *huart, uint8_t *str); +int fputc(int ch, FILE *f); +int fgetc(FILE *f); + +extern UART_HandleTypeDef debug_usart; +extern UART_HandleTypeDef wifi_usart; + +#endif /* __USART_H */ diff --git a/board/GoKit3_STM32F103C8T6/BSP/Inc/stm32f1xx_hal_conf.h b/board/GoKit3_STM32F103C8T6/BSP/Inc/stm32f1xx_hal_conf.h index c307f4bc..3a609b4e 100644 --- a/board/GoKit3_STM32F103C8T6/BSP/Inc/stm32f1xx_hal_conf.h +++ b/board/GoKit3_STM32F103C8T6/BSP/Inc/stm32f1xx_hal_conf.h @@ -63,7 +63,7 @@ /*#define HAL_SMARTCARD_MODULE_ENABLED */ /*#define HAL_SPI_MODULE_ENABLED */ /*#define HAL_SRAM_MODULE_ENABLED */ -/*#define HAL_TIM_MODULE_ENABLED */ +#define HAL_TIM_MODULE_ENABLED #define HAL_UART_MODULE_ENABLED /*#define HAL_USART_MODULE_ENABLED */ /*#define HAL_WWDG_MODULE_ENABLED */ diff --git a/board/GoKit3_STM32F103C8T6/BSP/Inc/tos_at.h b/board/GoKit3_STM32F103C8T6/BSP/Inc/tos_at.h new file mode 100644 index 00000000..70a67e79 --- /dev/null +++ b/board/GoKit3_STM32F103C8T6/BSP/Inc/tos_at.h @@ -0,0 +1,460 @@ +/*---------------------------------------------------------------------------- + * Tencent is pleased to support the open source community by making TencentOS + * available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * If you have downloaded a copy of the TencentOS binary from Tencent, please + * note that the TencentOS binary is licensed under the BSD 3-Clause License. + * + * If you have downloaded a copy of the TencentOS source code from Tencent, + * please note that TencentOS source code is licensed under the BSD 3-Clause + * License, except for the third-party components listed below which are + * subject to different license terms. Your integration of TencentOS into your + * own projects may require compliance with the BSD 3-Clause License, as well + * as the other licenses applicable to the third-party components included + * within TencentOS. + *---------------------------------------------------------------------------*/ + +#ifndef _TOS_AT_H_ +#define _TOS_AT_H_ + +#include "tos_k.h" +#include "tos_at_utils.h" +#include "tos_hal.h" + +#define AT_AGENT_ECHO_OK "OK" +#define AT_AGENT_ECHO_FAIL "FAIL" +#define AT_AGENT_ECHO_ERROR "ERROR" + +#define AT_DATA_CHANNEL_NUM 1 +#define AT_DATA_CHANNEL_FIFO_BUFFER_SIZE (0 + 1024) + +#define AT_UART_RX_FIFO_BUFFER_SIZE (0 + 1024) +#define AT_RECV_CACHE_SIZE 1024 + +#define AT_CMD_BUFFER_SIZE 512 + +#define AT_PARSER_TASK_STACK_SIZE 1024 +#define AT_PARSER_TASK_PRIO 2 + +typedef enum at_status_en { + AT_STATUS_OK, + AT_STATUS_ERROR, + AT_STATUS_INVALID_ARGS, +} at_status_t; + +typedef struct at_cache_st { + uint8_t *buffer; + size_t buffer_size; + size_t recv_len; +} at_cache_t; + +typedef enum at_parse_status_en { + AT_PARSE_STATUS_NONE, + AT_PARSE_STATUS_NEWLINE, + AT_PARSE_STATUS_EVENT, + AT_PARSE_STATUS_EXPECT, + AT_PARSE_STATUS_OVERFLOW, +} at_parse_status_t; + +typedef enum at_echo_status_en { + AT_ECHO_STATUS_NONE, + AT_ECHO_STATUS_OK, + AT_ECHO_STATUS_FAIL, + AT_ECHO_STATUS_ERROR, + AT_ECHO_STATUS_EXPECT, +} at_echo_status_t; + +typedef enum at_channel_status_en { + AT_CHANNEL_STATUS_NONE, /*< usually means we are try to get a channel status with invalid id */ + AT_CHANNEL_STATUS_HANGING, /*< channel is not used */ + AT_CHANNEL_STATUS_WORKING, /*< channel is being using */ + AT_CHANNEL_STATUS_BROKEN, /*< channel is broken(module link to remote server is broken) */ +} at_channel_status_t; + +typedef struct at_data_channel_st { + uint8_t is_free; + k_chr_fifo_t rx_fifo; + uint8_t *rx_fifo_buffer; + k_mutex_t rx_lock; + + at_channel_status_t status; + + const char *remote_ip; + const char *remote_port; +} at_data_channel_t; + +typedef struct at_echo_st { + char *buffer; + size_t buffer_size; + char *echo_expect; + int line_num; + at_echo_status_t status; + size_t __w_idx; + int __is_expecting; + k_sem_t __expect_notify; +} at_echo_t; + +typedef void (*at_event_callback_t)(void); + +typedef struct at_event_st { + const char *event_header; + at_event_callback_t event_callback; +} at_event_t; + +typedef struct at_agent_st { + at_data_channel_t data_channel[AT_DATA_CHANNEL_NUM]; + + at_event_t *event_table; + size_t event_table_size; + + at_echo_t *echo; + + k_task_t parser; + at_cache_t recv_cache; + + at_timer_t timer; + + k_mutex_t global_lock; + + char *cmd_buf; + k_mutex_t cmd_buf_lock; + + hal_uart_t uart; + k_mutex_t uart_tx_lock; + k_mutex_t uart_rx_lock; + k_sem_t uart_rx_sem; + k_chr_fifo_t uart_rx_fifo; + uint8_t *uart_rx_fifo_buffer; +} at_agent_t; + +#define AT_AGENT ((at_agent_t *)(&at_agent)) + +/** + * @brief Write data to a channel. + * Write data to a channel with certain id. + * + * @attention None + * + * @param[in] channel_id id of the channel. + * @param[in] buffer data buffer to write. + * @param[in] buffer_len length of the buffer. + * + * @return errcode + * @retval -1 write failed(error). + * @retval none -1 the number of bytes written. + */ +__API__ int tos_at_channel_write(int channel_id, uint8_t *buffer, size_t buffer_len); + +/** + * @brief Read data from a channel. + * Read data from a channel with a timeout. + * + * @attention None + * + * @param[in] channel_id id of the channel. + * @param[out] buffer buffer to hold the data read. + * @param[in] buffer_len length of the buffer. + * @param[in] timeout timeout. + * + * @return errcode + * @retval -1 read failed(error). + * @retval none -1 the number of bytes read. + */ +__API__ int tos_at_channel_read_timed(int channel_id, uint8_t *buffer, size_t buffer_len, uint32_t timeout); + +/** + * @brief Read data from a channel. + * Read data from a channel. + * + * @attention None + * + * @param[in] channel_id id of the channel. + * @param[out] buffer buffer to hold the data read. + * @param[in] buffer_len length of the buffer. + * + * @return errcode + * @retval -1 read failed(error). + * @retval none -1 the number of bytes read. + */ +__API__ int tos_at_channel_read(int channel_id, uint8_t *buffer, size_t buffer_len); + +/** + * @brief Allocate a channel. + * Allocate a channel with certain id. + * + * @attention None + * + * @param[in] channel_id id of the channel. + * @param[in] ip remote ip of the channel. + * @param[in] port remote port of the channel. + * + * @return errcode + * @retval -1 allocate failed(error). + * @retval none -1 the id of the channel. + */ +__API__ int tos_at_channel_alloc_id(int channel_id, const char *ip, const char *port); + +/** + * @brief Allocate a channel. + * Allocate a channel. + * + * @attention None + * + * @param[in] ip remote ip of the channel. + * @param[in] port remote port of the channel. + * + * @return errcode + * @retval -1 allocate failed(error). + * @retval none -1 the id of the channel. + */ +__API__ int tos_at_channel_alloc(const char *ip, const char *port); + +/** + * @brief Free a channel. + * Free a channel with certain id. + * + * @attention None + * + * @param[in] channel_id id of the channel. + * + * @return errcode + * @retval -1 free failed(error). + * @retval 0 free successfully. + */ +__API__ int tos_at_channel_free(int channel_id); + +/** + * @brief Set channel broken. + * + * @attention None + * + * @param[in] channel_id id of the channel. + * + * @return errcode + * @retval -1 set failed(error). + * @retval 0 set successfully. + */ +__API__ int tos_at_channel_set_broken(int channel_id); + +/** + * @brief Judge whether channel is working. + * + * @attention None + * + * @param[in] channel_id id of the channel. + * + * @return at channel status(type of at_channel_status_t) + */ +__API__ int tos_at_channel_is_working(int channel_id); + +/** + * @brief Initialize the at framework. + * + * @attention None + * + * @param[in] uart_port port number of the uart thougth which the module connect to the MCU. + * @param[in] event_table the listened event table. + * @param[in] event_table_size the size of the listened event table. + * + * @return errcode + * @retval -1 initialize failed(error). + * @retval 0 initialize successfully. + */ +__API__ int tos_at_init(hal_uart_port_t uart_port, at_event_t *event_table, size_t event_table_size); + +/** + * @brief De-initialize the at framework. + * + * @attention None + * + * @return +None + */ +__API__ void tos_at_deinit(void); + +/** + * @brief Create a echo struct. + * + * @attention None + * + * @param[in] echo pointer to the echo struct. + * @param[out] buffer buffer to hold the received message from the module. + * @param[in] buffer_size size of the buffer. + * @param[in] echo_expect the expected echo message. + * + * @return errcode + * @retval -1 create failed(error). + * @retval 0 create successfully. + */ +__API__ int tos_at_echo_create(at_echo_t *echo, char *buffer, size_t buffer_size, char *echo_expect); + +/** + * @brief Execute an at command. + * + * @attention None + * + * @param[in] echo pointer to the echo struct. + * @param[in] timeout command wait timeout . + * @param[in] cmd at command. + * + * @return errcode + * @retval -1 execute failed(error). + * @retval 0 execute successfully. + */ +__API__ int tos_at_cmd_exec(at_echo_t *echo, uint32_t timeout, const char *cmd, ...); + +/** + * @brief Execute an at command. + * Execute an at command and wait until the expected echo message received or timeout. + * + * @attention None + * + * @param[in] echo pointer to the echo struct. + * @param[in] timeout command wait timeout . + * @param[in] cmd at command. + * + * @return errcode + * @retval -1 execute failed(error). + * @retval 0 execute successfully. + */ +__API__ int tos_at_cmd_exec_until(at_echo_t *echo, uint32_t timeout, const char *cmd, ...); + +/** + * @brief Send raw data througth uart. + * + * @attention None + * + * @param[in] echo pointer to the echo struct. + * @param[in] timeout command wait timeout . + * @param[in] buf data to send. + * @param[in] size size of the buf. + * + * @return errcode + * @retval -1 execute failed(error). + * @retval 0 execute successfully. + */ +__API__ int tos_at_raw_data_send(at_echo_t *echo, uint32_t timeout, const uint8_t *buf, size_t size); + +/** + * @brief Send raw data througth uart. + * Send raw data througth uart and wait until the expected echo message received or timeout. + * + * @attention None + * + * @param[in] echo pointer to the echo struct. + * @param[in] timeout command wait timeout . + * @param[in] buf data to send. + * @param[in] size size of the buf. + * + * @return errcode + * @retval -1 execute failed(error). + * @retval 0 execute successfully. + */ +__API__ int tos_at_raw_data_send_until(at_echo_t *echo, uint32_t timeout, const uint8_t *buf, size_t size); + +/** + * @brief Write byte to the at uart. + * The function called by the uart interrupt, to put the data from the uart to the at framework. + * + * @attention None + * + * @param[in] data uart received data. + * + * @return None + */ +__API__ void tos_at_uart_input_byte(uint8_t data); + +/** + * @brief A global lock provided by at framework. + * The lock usually used to make a atomic function. + * + * @attention None + * + * @param None. + * + * @return errcode + * @retval -1 pend failed(error). + * @retval 0 pend successfully. + */ +__API__ int tos_at_global_lock_pend(void); + +/** + * @brief A global lock provided by at framework. + * The lock usually used to make a atomic function. + * + * @attention None + * + * @param None. + * + * @return errcode + * @retval -1 post failed(error). + * @retval 0 post successfully. + */ +__API__ int tos_at_global_lock_post(void); + +/** + * @brief Read data from the uart. + * Read data from the uart, usually called in listened event callback. + * + * @attention None + * + * @param[out] buffer buffer to hold the data read from the uart. + * @param[in] buffer_len length of the buffer. + * + * @return length of the data read from the uart. + */ +__API__ int tos_at_uart_read(uint8_t *buffer, size_t buffer_len); + +/** + * @brief Read data from the uart. + * Read data from the uart until meet a '\n', usually called in listened event callback. + * + * @attention None + * + * @param[out] buffer buffer to hold the data read from the uart. + * @param[in] buffer_len length of the buffer. + * + * @return length of the data read from the uart. + */ +__API__ int tos_at_uart_readline(uint8_t *buffer, size_t buffer_len); + +/** + * @brief Read data from the uart. + * Read data from the uart until no more incoming data, usually called in listened event callback. + * + * @attention None + * + * @param[out] buffer buffer to hold the data read from the uart. + * @param[in] buffer_len length of the buffer. + * + * @return length of the data read from the uart. + */ +__API__ int tos_at_uart_drain(uint8_t *buffer, size_t buffer_len); + +/** + * @brief Get the remote ip of a channel. + * Get the remote ip of a channel with certain id. + * + * @attention None + * + * @param[in] channel_id id of the channel. + * + * @return remote ip of the channel. + */ +__API__ const char *tos_at_agent_channel_ip_get(int channel_id); + +/** + * @brief Get the remote port of a channel. + * Get the remote port of a channel with certain id. + * + * @attention None + * + * @param[in] channel_id id of the channel. + * + * @return remote port of the channel. + */ +__API__ const char *tos_at_agent_channel_port_get(int channel_id); + +#endif /* __AT_AGENT_H_ */ + diff --git a/board/GoKit3_STM32F103C8T6/BSP/Inc/tos_at_utils.h b/board/GoKit3_STM32F103C8T6/BSP/Inc/tos_at_utils.h new file mode 100644 index 00000000..b4930d7a --- /dev/null +++ b/board/GoKit3_STM32F103C8T6/BSP/Inc/tos_at_utils.h @@ -0,0 +1,23 @@ +#ifndef _TOS_AT_UTILS_H_ +#define _TOS_AT_UTILS_H_ + +typedef struct at_timer_st { + k_tick_t end_time; +} at_timer_t; + +void at_delay(k_tick_t tick); + +void at_delay_ms(uint32_t millisec); + +int at_timer_is_expired(at_timer_t *tmr); + +void at_timer_countdown(at_timer_t *tmr, k_tick_t tick); + +void at_timer_countdown_ms(at_timer_t *tmr, uint32_t millisec); + +k_tick_t at_timer_remain(at_timer_t *tmr); + +void at_timer_init(at_timer_t *tmr); + +#endif + diff --git a/board/GoKit3_STM32F103C8T6/BSP/Src/bsp_dwt.c b/board/GoKit3_STM32F103C8T6/BSP/Src/bsp_dwt.c new file mode 100644 index 00000000..38b94c0f --- /dev/null +++ b/board/GoKit3_STM32F103C8T6/BSP/Src/bsp_dwt.c @@ -0,0 +1,129 @@ +/* + * @Author: jiejie + * @Github: https://github.com/jiejieTop + * @Date: 2020-02-15 20:51:38 + * @LastEditTime : 2020-02-16 00:06:40 + * @Description: the code belongs to jiejie, please keep the author information and source code according to the license. + */ + +#include "bsp_dwt.h" +#include "stm32f1xx_hal.h" +/* +********************************************************************** +* ʱؼĴ +********************************************************************** +*/ +/* + Cortex-MһDWT(Data Watchpoint and Trace) + һ32λļĴCYCCNTһϵļ + ¼ںʱеĸܼ¼ʱΪ + 60s=232η/72000000 + (ںƵΪ72MںһεʱΪ1/72M=13.8ns) + CYCCNT֮󣬻0¿ʼϼ + ʹCYCCNTIJ裺 + 1ʹDWT裬ں˵ԼĴDEMCRλ24ƣд1ʹ + 2ʹCYCCNTĴ֮ǰ0 + 3ʹCYCCNTĴDWT_CTRL(Ϻ궨ΪDWT_CR)λ0ƣд1ʹ + */ + +#if USE_DWT_DELAY + + +#define DWT_CR *(__IO uint32_t *)0xE0001000 +#define DWT_CYCCNT *(__IO uint32_t *)0xE0001004 +#define DEM_CR *(__IO uint32_t *)0xE000EDFC + + +#define DEM_CR_TRCENA (1 << 24) +#define DWT_CR_CYCCNTENA (1 << 0) + + +/** + * @brief ʼʱ + * @param + * @retval + * @note ʹʱǰñ + */ +void dwt_init(void) +{ + /* ʹDWT */ + DEM_CR |= (uint32_t)DEM_CR_TRCENA; + + /* DWT CYCCNTĴ0 */ + DWT_CYCCNT = (uint32_t)0u; + + /* ʹCortex-M DWT CYCCNTĴ */ + DWT_CR |= (uint32_t)DWT_CR_CYCCNTENA; +} + +/** + * @brief ȡǰʱ + * @param + * @retval ǰʱDWT_CYCCNTĴֵ + */ +uint32_t dwt_read(void) +{ + return ((uint32_t)DWT_CYCCNT); +} + +///** +// * @brief ȡǰʱ +// * @param +// * @retval ǰʱDWT_CYCCNTĴֵ +// * ˴HAL滻HAL_GetTickos +// */ +//uint32_t HAL_GetTick(void) +//{ +// //ȳˣֹ +// return ((uint32_t)DWT_CYCCNT / system_clk_freq * 1000); +//} + +/** + * @brief CPUڲʵ־ȷʱ32λ + * @param us : ӳٳȣλ1 us + * @retval + * @note ʹñǰȵdwt_initʹܼ + ʹܺCPU_TS_INIT_IN_DELAY_FUNCTION + ʱֵΪ8룬8*1000*1000 + */ +void dwt_delay_us(__IO uint32_t us) +{ + uint32_t ticks; + uint32_t told,tnow,tcnt=0; + + /* ںڲʼʱĴ */ +#if (CPU_TS_INIT_IN_DELAY_FUNCTION) + /* ʼʱ */ + dwt_init(); +#endif + + ticks = us * (get_cpu_clk_freq() / 1000000); /* ҪĽ */ + tcnt = 0; + told = (uint32_t)dwt_read(); /* սʱļֵ */ + + while(1) + { + tnow = (uint32_t)dwt_read(); + if(tnow != told) + { + /* 32λǵ */ + if(tnow > told) + { + tcnt += tnow - told; + } + /* װ */ + else + { + tcnt += UINT32_MAX - told + tnow; + } + + told = tnow; + + /*ʱ䳬/Ҫӳٵʱ,˳ */ + if(tcnt >= ticks)break; + } + } +} + +#endif + diff --git a/board/GoKit3_STM32F103C8T6/BSP/Src/bsp_init.c b/board/GoKit3_STM32F103C8T6/BSP/Src/bsp_init.c new file mode 100644 index 00000000..ffac8d97 --- /dev/null +++ b/board/GoKit3_STM32F103C8T6/BSP/Src/bsp_init.c @@ -0,0 +1,56 @@ +/* + * @Author: jiejie + * @Github: https://github.com/jiejieTop + * @Date: 2020-02-15 20:51:14 + * @LastEditTime: 2020-02-16 00:08:19 + * @Description: the code belongs to jiejie, please keep the author information and source code according to the license. + */ +#include "bsp_init.h" + +static void system_clock_init(void) +{ + RCC_OscInitTypeDef RCC_OscInitStruct; + RCC_ClkInitTypeDef RCC_ClkInitStruct; + + RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; + RCC_OscInitStruct.HSEState = RCC_HSE_ON; + RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1; + RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; + RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; + RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9; + if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) + while(1); + + RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK + |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2; + RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; + RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; + RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2; + RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; + if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK) + while(1); + + HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000); + + HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK); + + /* SysTick_IRQn interrupt configuration */ + HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0); +} + +void bsp_init(void) +{ + HAL_Init(); + + system_clock_init(); + + dwt_init(); + + debug_usart_init(); + + rgb_led_init(); + + motor_init(); + +} + diff --git a/board/GoKit3_STM32F103C8T6/BSP/Src/bsp_led.c b/board/GoKit3_STM32F103C8T6/BSP/Src/bsp_led.c new file mode 100644 index 00000000..502eda62 --- /dev/null +++ b/board/GoKit3_STM32F103C8T6/BSP/Src/bsp_led.c @@ -0,0 +1,113 @@ +/* + * @Author: jiejie + * @Github: https://github.com/jiejieTop + * @Date: 2020-02-15 20:51:38 + * @LastEditTime : 2020-02-16 00:05:59 + * @Description: the code belongs to jiejie, please keep the author information and source code according to the license. + */ +#include "bsp_led.h" +#include "bsp_dwt.h" + + +void clk_produce(void) +{ + SCL_LOW; // SCL=0 + delay_us(50); + + SCL_HIGH; // SCL=1 + delay_us(50); +} + + +void send_32bit_zero(void) +{ + unsigned char i; + SDA_LOW; // SDA=0 + for (i=0; i<32; i++) + { + clk_produce(); + } +} + + +uint8_t take_anti_code(uint8_t dat) +{ + uint8_t tmp = 0; + + tmp=((~dat) & 0xC0)>>6; + return tmp; +} + + +void send_data(uint32_t dx) +{ + uint8_t i; + + for (i=0; i<32; i++) + { + if ((dx & 0x80000000) != 0) + SDA_HIGH; // SDA=1; + else + SDA_LOW; // SDA=0; + + dx <<= 1; + clk_produce(); + } +} + + +void data_deal_with_send(uint8_t r, uint8_t g, uint8_t b) +{ + uint32_t dx = 0; + + dx |= (uint32_t)0x03 << 30; // The front of the two bits 1 is flag bits + dx |= (uint32_t)take_anti_code(b) << 28; + dx |= (uint32_t)take_anti_code(g) << 26; + dx |= (uint32_t)take_anti_code(r) << 24; + + dx |= (uint32_t)b << 16; + dx |= (uint32_t)g << 8; + dx |= r; + + send_data(dx); +} + +void rgb_led_init(void) +{ + /*һGPIO_InitTypeDef͵Ľṹ*/ + GPIO_InitTypeDef GPIO_InitStruct; + + RGB_LED_GPIO_CLK_ENABLE(); + + /*ѡҪƵGPIO*/ + GPIO_InitStruct.Pin = RGB_LED_CLK_PIN; + + /*ŵΪ*/ + GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; + + /*Ϊģʽ*/ + GPIO_InitStruct.Pull = GPIO_PULLUP; + + /*Ϊ */ + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; + + /*ÿ⺯ʹõGPIO_InitStructureʼGPIO*/ + HAL_GPIO_Init(RGB_LED_CLK_GPIO_PORT, &GPIO_InitStruct); + + /*ѡҪƵGPIO*/ + GPIO_InitStruct.Pin = RGB_LED_SDA_PIN; + HAL_GPIO_Init(RGB_LED_SDA_GPIO_PORT, &GPIO_InitStruct); + + send_32bit_zero(); + data_deal_with_send(0,0,0); + data_deal_with_send(0,0,0); +} + +void rgb_led_control(uint8_t r, uint8_t g, uint8_t b) +{ + send_32bit_zero(); + data_deal_with_send(r, g, b); + data_deal_with_send(r, g, b); +} + +/*********************************************END OF FILE**********************/ diff --git a/board/GoKit3_STM32F103C8T6/BSP/Src/bsp_motor.c b/board/GoKit3_STM32F103C8T6/BSP/Src/bsp_motor.c new file mode 100644 index 00000000..74f1f7c1 --- /dev/null +++ b/board/GoKit3_STM32F103C8T6/BSP/Src/bsp_motor.c @@ -0,0 +1,103 @@ +/* + * @Author: jiejie + * @Github: https://github.com/jiejieTop + * @Date: 2020-02-16 00:02:40 + * @LastEditTime : 2020-02-16 00:23:28 + * @Description: the code belongs to jiejie, please keep the author information and source code according to the license. + */ +#include "bsp_motor.h" +#include +#include + +TIM_HandleTypeDef motor_tim; + +void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* htim_base) +{ + MOTOR_TIM_RCC_CLK_ENABLE(); +} + +static void motor_control(uint32_t m1, uint32_t m2) +{ + if (m1 >= MOTOR_PERIOD) + m1 = MOTOR_PERIOD; + + if (m2 > MOTOR_PERIOD) + m2 = MOTOR_PERIOD; + + __HAL_TIM_SET_COMPARE(&motor_tim, MOTOR_FORWARD_CHANNEL, m1); + __HAL_TIM_SET_COMPARE(&motor_tim, MOTOR_REVERSE_CHANNEL, m2); +} + +void motor_set_speed(motor_mode_t s, uint8_t pwm) +{ + uint32_t pulse; + + if (pwm > MOTOR_MAX_DUTY) + pwm = MOTOR_MAX_DUTY; + + pulse = (pwm * MOTOR_PERIOD) / MOTOR_MAX_DUTY; + + if (MOTOR_STOP == s) + motor_control(0, 0); + else if (MOTOR_FORWARD == s) + motor_control(pulse, 0); + else + motor_control(0, pulse); +} + +static void Error_Handler(void) +{ + while(1); +} + +void HAL_TIM_MspPostInit(TIM_HandleTypeDef *htim) +{ + GPIO_InitTypeDef gpio_init; + + if(htim->Instance == MOTOR_TIM) { + + MOTOR_TIM_GPIO_RCC_CLK_ENABLE(); + MOTOR_TIM_AFIO_REMAP(); + + gpio_init.Pin = MOTOR_FORWARD_PIN | MOTOR_REVERSE_PIN; + gpio_init.Mode = GPIO_MODE_AF_PP; + gpio_init.Speed = GPIO_SPEED_FREQ_HIGH; + HAL_GPIO_Init(GPIOB, &gpio_init); + } +} + +void motor_init(void) +{ + TIM_OC_InitTypeDef oc_init; + + motor_tim.Instance = MOTOR_TIM; + motor_tim.Init.Prescaler = MOTOR_PRESCALER; + motor_tim.Init.CounterMode = TIM_COUNTERMODE_UP; + motor_tim.Init.Period = MOTOR_PERIOD; + motor_tim.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; + + if (HAL_TIM_Base_Init(&motor_tim) != HAL_OK) + Error_Handler(); + + HAL_TIM_Base_Start(&motor_tim); + + if (HAL_TIM_PWM_Init(&motor_tim) != HAL_OK) + Error_Handler(); + + HAL_TIM_MspPostInit(&motor_tim); + + oc_init.OCMode = TIM_OCMODE_PWM1; + oc_init.Pulse = MOTOR_PERIOD; + oc_init.OCPolarity = TIM_OCPOLARITY_HIGH; + + if (HAL_TIM_PWM_ConfigChannel(&motor_tim, &oc_init, MOTOR_FORWARD_CHANNEL) != HAL_OK) + Error_Handler(); + + if (HAL_TIM_PWM_ConfigChannel(&motor_tim, &oc_init, MOTOR_REVERSE_CHANNEL) != HAL_OK) + Error_Handler(); + + HAL_TIM_PWM_Start(&motor_tim, MOTOR_FORWARD_CHANNEL);//PWMͨ1 + HAL_TIM_PWM_Start(&motor_tim, MOTOR_REVERSE_CHANNEL);//PWMͨ2 + + motor_set_speed(MOTOR_STOP, 0); +} diff --git a/board/GoKit3_STM32F103C8T6/BSP/Src/bsp_usart.c b/board/GoKit3_STM32F103C8T6/BSP/Src/bsp_usart.c new file mode 100644 index 00000000..6154a4e1 --- /dev/null +++ b/board/GoKit3_STM32F103C8T6/BSP/Src/bsp_usart.c @@ -0,0 +1,144 @@ +#include "bsp_usart.h" + +UART_HandleTypeDef debug_usart; +UART_HandleTypeDef wifi_usart; + + /** + * @brief DEBUG_USART GPIO ,ģʽá115200 8-N-1 + * @param + * @retval + */ +void debug_usart_init(void) +{ + + debug_usart.Instance = DEBUG_USART; + + debug_usart.Init.BaudRate = DEBUG_USART_BAUDRATE; + debug_usart.Init.WordLength = UART_WORDLENGTH_8B; + debug_usart.Init.StopBits = UART_STOPBITS_1; + debug_usart.Init.Parity = UART_PARITY_NONE; + debug_usart.Init.HwFlowCtl = UART_HWCONTROL_NONE; + debug_usart.Init.Mode = UART_MODE_TX_RX; + + HAL_UART_Init(&debug_usart); + + /*ʹܴڽն */ + __HAL_UART_ENABLE_IT(&debug_usart, UART_IT_RXNE); +} + +void wifi_usart_init(void) +{ + + wifi_usart.Instance = WIFI_USART; + + wifi_usart.Init.BaudRate = WIFI_USART_BAUDRATE; + wifi_usart.Init.WordLength = UART_WORDLENGTH_8B; + wifi_usart.Init.StopBits = UART_STOPBITS_1; + wifi_usart.Init.Parity = UART_PARITY_NONE; + wifi_usart.Init.HwFlowCtl = UART_HWCONTROL_NONE; + wifi_usart.Init.Mode = UART_MODE_TX_RX; + + HAL_UART_Init(&wifi_usart); + + /*ʹܴڽն */ + __HAL_UART_ENABLE_IT(&wifi_usart, UART_IT_RXNE); +} + +/** + * @brief UART MSP ʼ + * @param huart: UART handle + * @retval + */ +void HAL_UART_MspInit(UART_HandleTypeDef *huart) +{ + GPIO_InitTypeDef GPIO_InitStruct; + + if (huart->Instance == DEBUG_USART) + { + DEBUG_USART_CLK_ENABLE(); + + DEBUG_USART_RX_GPIO_CLK_ENABLE(); + DEBUG_USART_TX_GPIO_CLK_ENABLE(); + + /**USART1 GPIO Configuration + PA9 ------> USART1_TX + PA10 ------> USART1_RX + */ + /* TxΪù */ + GPIO_InitStruct.Pin = DEBUG_USART_TX_PIN; + GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; + GPIO_InitStruct.Pull = GPIO_PULLUP; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; + HAL_GPIO_Init(DEBUG_USART_TX_GPIO_PORT, &GPIO_InitStruct); + + /* RxΪù */ + GPIO_InitStruct.Pin = DEBUG_USART_RX_PIN; + GPIO_InitStruct.Mode=GPIO_MODE_AF_INPUT; //ģʽҪΪģʽ + HAL_GPIO_Init(DEBUG_USART_RX_GPIO_PORT, &GPIO_InitStruct); + //ռȼ0ȼ1 + HAL_NVIC_SetPriority(DEBUG_USART_IRQ ,6,0); + //ʹUSART1жͨ + HAL_NVIC_EnableIRQ(DEBUG_USART_IRQ ); + } else if (huart->Instance == WIFI_USART) + { + WIFI_USART_CLK_ENABLE(); + + WIFI_USART_RX_GPIO_CLK_ENABLE(); + WIFI_USART_TX_GPIO_CLK_ENABLE(); + + /**USART1 GPIO Configuration + PA9 ------> USART1_TX + PA10 ------> USART1_RX + */ + /* TxΪù */ + GPIO_InitStruct.Pin = WIFI_USART_TX_PIN; + GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; + GPIO_InitStruct.Pull = GPIO_PULLUP; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; + HAL_GPIO_Init(WIFI_USART_TX_GPIO_PORT, &GPIO_InitStruct); + + /* RxΪù */ + GPIO_InitStruct.Pin = WIFI_USART_RX_PIN; + GPIO_InitStruct.Mode=GPIO_MODE_AF_INPUT; //ģʽҪΪģʽ + HAL_GPIO_Init(WIFI_USART_RX_GPIO_PORT, &GPIO_InitStruct); + //ռȼ0ȼ1 + HAL_NVIC_SetPriority(WIFI_USART_IRQ ,2,0); + //ʹUSART1жͨ + HAL_NVIC_EnableIRQ(WIFI_USART_IRQ ); + } +} + +/***************** ַ **********************/ +void usart_send_string(UART_HandleTypeDef *huart, uint8_t *str) +{ + unsigned int k=0; + do { + HAL_UART_Transmit(huart,(uint8_t *)(str + k) ,1,1000); + k++; + } while(*(str + k)!='\0'); + +} +//ضc⺯printfDEBUG_USARTضʹprintf +int fputc(int ch, FILE *f) +{ + /* һֽݵDEBUG_USART */ + HAL_UART_Transmit(&debug_usart, (uint8_t *)&ch, 1, 1); + + return (ch); +} + +//ضc⺯scanfDEBUG_USARTдʹscanfgetcharȺ +int fgetc(FILE *f) +{ + int ch; + HAL_UART_Receive(&debug_usart, (uint8_t *)&ch, 1, 1); + return (ch); +} + +int send_buff(char *buf, int len) +{ + usart_send_string(&debug_usart, (uint8_t *)buf); + return len; +} + +/*********************************************END OF FILE**********************/ diff --git a/board/GoKit3_STM32F103C8T6/BSP/Src/tos_hal_uart.c b/board/GoKit3_STM32F103C8T6/BSP/Src/tos_hal_uart.c new file mode 100644 index 00000000..c8ec9b09 --- /dev/null +++ b/board/GoKit3_STM32F103C8T6/BSP/Src/tos_hal_uart.c @@ -0,0 +1,73 @@ +#include "tos_k.h" +#include "tos_hal.h" +#include "stm32f1xx.h" +#include "bsp_usart.h" + +__API__ int tos_hal_uart_init(hal_uart_t *uart, hal_uart_port_t port) +{ + if (!uart) { + return -1; + } + if (port == HAL_UART_PORT_1) { + uart->private_uart = &debug_usart; + debug_usart_init(); + } else if (port == HAL_UART_PORT_2) { + uart->private_uart = &wifi_usart; + wifi_usart_init(); + } + + return 0; +} + +__API__ int tos_hal_uart_write(hal_uart_t *uart, const uint8_t *buf, size_t size, uint32_t timeout) +{ + HAL_StatusTypeDef hal_status; + UART_HandleTypeDef *uart_handle; + + if (!uart || !buf) { + return -1; + } + + if (!uart->private_uart) { + return -1; + } + + uart_handle = (UART_HandleTypeDef *)uart->private_uart; + + hal_status = HAL_UART_Transmit(uart_handle, (uint8_t *)buf, size, timeout); + if (hal_status != HAL_OK) { + return -1; + } + return 0; +} + +__API__ int tos_hal_uart_read(hal_uart_t *uart, const uint8_t *buf, size_t size, uint32_t timeout) +{ + return 0; +} + +__API__ int tos_hal_uart_deinit(hal_uart_t *uart) +{ + HAL_StatusTypeDef hal_status; + UART_HandleTypeDef *uart_handle; + + if (!uart) { + return -1; + } + + if (!uart->private_uart) { + return -1; + } + + uart_handle = (UART_HandleTypeDef *)uart->private_uart; + + hal_status = HAL_UART_DeInit(uart_handle); + HAL_UART_MspDeInit(uart_handle); + + if (hal_status != HAL_OK) { + return -1; + } + + return 0; +} + diff --git a/board/GoKit3_STM32F103C8T6/KEIL/mqttclient/GoKit3_STM32F103C8T6.uvoptx b/board/GoKit3_STM32F103C8T6/KEIL/mqttclient/GoKit3_STM32F103C8T6.uvoptx new file mode 100644 index 00000000..59bc3c56 --- /dev/null +++ b/board/GoKit3_STM32F103C8T6/KEIL/mqttclient/GoKit3_STM32F103C8T6.uvoptx @@ -0,0 +1,1450 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + GoKit3_STM32F103C8T6 + 0x4 + ARM-ADS + + 72000000 + + 1 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 1 + 0 + 1 + + 18 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 0 + 0 + 3 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + CMSIS_AGDI + -X"Any" -UAny -O206 -S8 -C0 -P00000000 -N00("ARM CoreSight SW-DP") -D00(1BA01477) -L00(0) -TO65554 -TC10000000 -TT10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0STM32F10x_128.FLM -FS08000000 -FL020000 -FP0($$Device:STM32F103C8$Flash\STM32F10x_128.FLM) + + + 0 + ARMRTXEVENTFLAGS + -L70 -Z18 -C0 -M0 -T1 + + + 0 + DLGTARM + (1010=-1,-1,-1,-1,0)(1007=-1,-1,-1,-1,0)(1008=-1,-1,-1,-1,0)(1009=-1,-1,-1,-1,0) + + + 0 + ARMDBGFLAGS + + + + 0 + DLGUARM + + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0STM32F10x_128 -FS08000000 -FL020000 -FP0($$Device:STM32F103C8$Flash\STM32F10x_128.FLM)) + + + 0 + ST-LINKIII-KEIL_SWO + -U303030303030303030303031 -O10446 -SF10000 -C0 -A0 -I0 -HNlocalhost -HP7184 -P1 -N00("ARM CoreSight SW-DP") -D00(1BA01477) -L00(0) -TO131090 -TC10000000 -TP21 -TDS8000 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC800 -FN1 -FF0STM32F10x_128.FLM -FS08000000 -FL010000 -FP0($$Device:STM32F103C8$Flash\STM32F10x_128.FLM) + + + + + 0 + 0 + 926 + 1 +
134236382
+ 0 + 0 + 0 + 0 + 0 + 1 + ..\..\..\..\components\connectivity\mqttclient\mqttclient\mqttclient.c + + \\GoKit3_STM32F103C8T6\../../../../components/connectivity/mqttclient/mqttclient/mqttclient.c\926 +
+
+ + 0 + + + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + 1 + 0 + 0 + 2 + 10000000 + +
+
+ + + Application/MDK-ARM + 0 + 0 + 0 + 0 + + 1 + 1 + 2 + 0 + 0 + 0 + startup_stm32f103xb.s + startup_stm32f103xb.s + 0 + 0 + + + + + Application/User + 1 + 0 + 0 + 0 + + 2 + 2 + 1 + 0 + 0 + 0 + ..\..\BSP\Src\stm32f1xx_hal_msp.c + stm32f1xx_hal_msp.c + 0 + 0 + + + 2 + 3 + 1 + 0 + 0 + 0 + .\stm32f1xx_it.c + stm32f1xx_it.c + 0 + 0 + + + + + Application/Bsp + 0 + 0 + 0 + 0 + + 3 + 4 + 1 + 0 + 0 + 0 + ..\..\BSP\Src\bsp_dwt.c + bsp_dwt.c + 0 + 0 + + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\BSP\Src\bsp_init.c + bsp_init.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\BSP\Src\bsp_led.c + bsp_led.c + 0 + 0 + + + 3 + 7 + 1 + 0 + 0 + 0 + ..\..\BSP\Src\bsp_motor.c + bsp_motor.c + 0 + 0 + + + 3 + 8 + 1 + 0 + 0 + 0 + ..\..\BSP\Src\bsp_usart.c + bsp_usart.c + 0 + 0 + + + + + examples + 1 + 0 + 0 + 0 + + 4 + 9 + 1 + 0 + 0 + 0 + ..\..\..\..\examples\mqttclient\gokit3_mqttclient.c + gokit3_mqttclient.c + 0 + 0 + + + + + Drivers/STM32F1xx_HAL_Driver + 0 + 0 + 0 + 0 + + 5 + 10 + 1 + 0 + 0 + 0 + ..\..\..\..\platform\vendor_bsp\st\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal.c + stm32f1xx_hal.c + 0 + 0 + + + 5 + 11 + 1 + 0 + 0 + 0 + ..\..\..\..\platform\vendor_bsp\st\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_cortex.c + stm32f1xx_hal_cortex.c + 0 + 0 + + + 5 + 12 + 1 + 0 + 0 + 0 + ..\..\..\..\platform\vendor_bsp\st\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_dma.c + stm32f1xx_hal_dma.c + 0 + 0 + + + 5 + 13 + 1 + 0 + 0 + 0 + ..\..\..\..\platform\vendor_bsp\st\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_exti.c + stm32f1xx_hal_exti.c + 0 + 0 + + + 5 + 14 + 1 + 0 + 0 + 0 + ..\..\..\..\platform\vendor_bsp\st\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_flash.c + stm32f1xx_hal_flash.c + 0 + 0 + + + 5 + 15 + 1 + 0 + 0 + 0 + ..\..\..\..\platform\vendor_bsp\st\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_flash_ex.c + stm32f1xx_hal_flash_ex.c + 0 + 0 + + + 5 + 16 + 1 + 0 + 0 + 0 + ..\..\..\..\platform\vendor_bsp\st\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_gpio.c + stm32f1xx_hal_gpio.c + 0 + 0 + + + 5 + 17 + 1 + 0 + 0 + 0 + ..\..\..\..\platform\vendor_bsp\st\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_gpio_ex.c + stm32f1xx_hal_gpio_ex.c + 0 + 0 + + + 5 + 18 + 1 + 0 + 0 + 0 + ..\..\..\..\platform\vendor_bsp\st\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_pcd.c + stm32f1xx_hal_pcd.c + 0 + 0 + + + 5 + 19 + 1 + 0 + 0 + 0 + ..\..\..\..\platform\vendor_bsp\st\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_pcd_ex.c + stm32f1xx_hal_pcd_ex.c + 0 + 0 + + + 5 + 20 + 1 + 0 + 0 + 0 + ..\..\..\..\platform\vendor_bsp\st\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_pwr.c + stm32f1xx_hal_pwr.c + 0 + 0 + + + 5 + 21 + 1 + 0 + 0 + 0 + ..\..\..\..\platform\vendor_bsp\st\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_rcc.c + stm32f1xx_hal_rcc.c + 0 + 0 + + + 5 + 22 + 1 + 0 + 0 + 0 + ..\..\..\..\platform\vendor_bsp\st\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_rcc_ex.c + stm32f1xx_hal_rcc_ex.c + 0 + 0 + + + 5 + 23 + 1 + 0 + 0 + 0 + ..\..\..\..\platform\vendor_bsp\st\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_tim.c + stm32f1xx_hal_tim.c + 0 + 0 + + + 5 + 24 + 1 + 0 + 0 + 0 + ..\..\..\..\platform\vendor_bsp\st\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_tim_ex.c + stm32f1xx_hal_tim_ex.c + 0 + 0 + + + 5 + 25 + 1 + 0 + 0 + 0 + ..\..\..\..\platform\vendor_bsp\st\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_uart.c + stm32f1xx_hal_uart.c + 0 + 0 + + + + + Drivers/CMSIS + 0 + 0 + 0 + 0 + + 6 + 26 + 1 + 0 + 0 + 0 + ..\..\BSP\Src\system_stm32f1xx.c + system_stm32f1xx.c + 0 + 0 + + + + + tos/arch + 0 + 0 + 0 + 0 + + 7 + 27 + 1 + 0 + 0 + 0 + ..\..\..\..\arch\arm\arm-v7m\common\tos_cpu.c + tos_cpu.c + 0 + 0 + + + 7 + 28 + 1 + 0 + 0 + 0 + ..\..\..\..\arch\arm\arm-v7m\cortex-m3\armcc\port_c.c + port_c.c + 0 + 0 + + + 7 + 29 + 2 + 0 + 0 + 0 + ..\..\..\..\arch\arm\arm-v7m\cortex-m3\armcc\port_s.S + port_s.S + 0 + 0 + + + + + tos/kernel + 0 + 0 + 0 + 0 + + 8 + 30 + 1 + 0 + 0 + 0 + ..\..\..\..\kernel\core\tos_binary_heap.c + tos_binary_heap.c + 0 + 0 + + + 8 + 31 + 1 + 0 + 0 + 0 + ..\..\..\..\kernel\core\tos_char_fifo.c + tos_char_fifo.c + 0 + 0 + + + 8 + 32 + 1 + 0 + 0 + 0 + ..\..\..\..\kernel\core\tos_completion.c + tos_completion.c + 0 + 0 + + + 8 + 33 + 1 + 0 + 0 + 0 + ..\..\..\..\kernel\core\tos_countdownlatch.c + tos_countdownlatch.c + 0 + 0 + + + 8 + 34 + 1 + 0 + 0 + 0 + ..\..\..\..\kernel\core\tos_event.c + tos_event.c + 0 + 0 + + + 8 + 35 + 1 + 0 + 0 + 0 + ..\..\..\..\kernel\core\tos_global.c + tos_global.c + 0 + 0 + + + 8 + 36 + 1 + 0 + 0 + 0 + ..\..\..\..\kernel\core\tos_mail_queue.c + tos_mail_queue.c + 0 + 0 + + + 8 + 37 + 1 + 0 + 0 + 0 + ..\..\..\..\kernel\core\tos_message_queue.c + tos_message_queue.c + 0 + 0 + + + 8 + 38 + 1 + 0 + 0 + 0 + ..\..\..\..\kernel\core\tos_mmblk.c + tos_mmblk.c + 0 + 0 + + + 8 + 39 + 1 + 0 + 0 + 0 + ..\..\..\..\kernel\core\tos_mmheap.c + tos_mmheap.c + 0 + 0 + + + 8 + 40 + 1 + 0 + 0 + 0 + ..\..\..\..\kernel\core\tos_mutex.c + tos_mutex.c + 0 + 0 + + + 8 + 41 + 1 + 0 + 0 + 0 + ..\..\..\..\kernel\core\tos_pend.c + tos_pend.c + 0 + 0 + + + 8 + 42 + 1 + 0 + 0 + 0 + ..\..\..\..\kernel\core\tos_priority_mail_queue.c + tos_priority_mail_queue.c + 0 + 0 + + + 8 + 43 + 1 + 0 + 0 + 0 + ..\..\..\..\kernel\core\tos_priority_message_queue.c + tos_priority_message_queue.c + 0 + 0 + + + 8 + 44 + 1 + 0 + 0 + 0 + ..\..\..\..\kernel\core\tos_priority_queue.c + tos_priority_queue.c + 0 + 0 + + + 8 + 45 + 1 + 0 + 0 + 0 + ..\..\..\..\kernel\core\tos_ring_queue.c + tos_ring_queue.c + 0 + 0 + + + 8 + 46 + 1 + 0 + 0 + 0 + ..\..\..\..\kernel\core\tos_robin.c + tos_robin.c + 0 + 0 + + + 8 + 47 + 1 + 0 + 0 + 0 + ..\..\..\..\kernel\core\tos_sched.c + tos_sched.c + 0 + 0 + + + 8 + 48 + 1 + 0 + 0 + 0 + ..\..\..\..\kernel\core\tos_sem.c + tos_sem.c + 0 + 0 + + + 8 + 49 + 1 + 0 + 0 + 0 + ..\..\..\..\kernel\core\tos_sys.c + tos_sys.c + 0 + 0 + + + 8 + 50 + 1 + 0 + 0 + 0 + ..\..\..\..\kernel\core\tos_task.c + tos_task.c + 0 + 0 + + + 8 + 51 + 1 + 0 + 0 + 0 + ..\..\..\..\kernel\core\tos_tick.c + tos_tick.c + 0 + 0 + + + 8 + 52 + 1 + 0 + 0 + 0 + ..\..\..\..\kernel\core\tos_time.c + tos_time.c + 0 + 0 + + + 8 + 53 + 1 + 0 + 0 + 0 + ..\..\..\..\kernel\core\tos_timer.c + tos_timer.c + 0 + 0 + + + + + tos/cmsis + 0 + 0 + 0 + 0 + + 9 + 54 + 1 + 0 + 0 + 0 + ..\..\..\..\osal\cmsis_os\cmsis_os.c + cmsis_os.c + 0 + 0 + + + + + tos/at + 0 + 0 + 0 + 0 + + 10 + 55 + 1 + 0 + 0 + 0 + ..\..\..\..\net\at\src\tos_at.c + tos_at.c + 0 + 0 + + + 10 + 56 + 1 + 0 + 0 + 0 + ..\..\..\..\net\at\src\tos_at_utils.c + tos_at_utils.c + 0 + 0 + + + + + tos/sal + 0 + 0 + 0 + 0 + + 11 + 57 + 1 + 0 + 0 + 0 + ..\..\..\..\net\sal_module_wrapper\sal_module_wrapper.c + sal_module_wrapper.c + 0 + 0 + + + + + tos/hal + 0 + 0 + 0 + 0 + + 12 + 58 + 1 + 0 + 0 + 0 + ..\..\BSP\Src\tos_hal_uart.c + tos_hal_uart.c + 0 + 0 + + + + + tos/devices + 0 + 0 + 0 + 0 + + 13 + 59 + 1 + 0 + 0 + 0 + ..\..\..\..\devices\esp8266\esp8266.c + esp8266.c + 0 + 0 + + + + + mqttclient + 0 + 0 + 0 + 0 + + 14 + 60 + 1 + 0 + 0 + 0 + ..\..\..\..\components\connectivity\mqttclient\mqttclient\mqttclient.c + mqttclient.c + 0 + 0 + + + + + mqttclient/mqtt + 0 + 0 + 0 + 0 + + 15 + 61 + 1 + 0 + 0 + 0 + ..\..\..\..\components\connectivity\mqttclient\mqtt\MQTTConnectClient.c + MQTTConnectClient.c + 0 + 0 + + + 15 + 62 + 1 + 0 + 0 + 0 + ..\..\..\..\components\connectivity\mqttclient\mqtt\MQTTConnectServer.c + MQTTConnectServer.c + 0 + 0 + + + 15 + 63 + 1 + 0 + 0 + 0 + ..\..\..\..\components\connectivity\mqttclient\mqtt\MQTTDeserializePublish.c + MQTTDeserializePublish.c + 0 + 0 + + + 15 + 64 + 1 + 0 + 0 + 0 + ..\..\..\..\components\connectivity\mqttclient\mqtt\MQTTFormat.c + MQTTFormat.c + 0 + 0 + + + 15 + 65 + 1 + 0 + 0 + 0 + ..\..\..\..\components\connectivity\mqttclient\mqtt\MQTTPacket.c + MQTTPacket.c + 0 + 0 + + + 15 + 66 + 1 + 0 + 0 + 0 + ..\..\..\..\components\connectivity\mqttclient\mqtt\MQTTSerializePublish.c + MQTTSerializePublish.c + 0 + 0 + + + 15 + 67 + 1 + 0 + 0 + 0 + ..\..\..\..\components\connectivity\mqttclient\mqtt\MQTTSubscribeClient.c + MQTTSubscribeClient.c + 0 + 0 + + + 15 + 68 + 1 + 0 + 0 + 0 + ..\..\..\..\components\connectivity\mqttclient\mqtt\MQTTSubscribeServer.c + MQTTSubscribeServer.c + 0 + 0 + + + 15 + 69 + 1 + 0 + 0 + 0 + ..\..\..\..\components\connectivity\mqttclient\mqtt\MQTTUnsubscribeClient.c + MQTTUnsubscribeClient.c + 0 + 0 + + + 15 + 70 + 1 + 0 + 0 + 0 + ..\..\..\..\components\connectivity\mqttclient\mqtt\MQTTUnsubscribeServer.c + MQTTUnsubscribeServer.c + 0 + 0 + + + + + mqttclient/salof + 0 + 0 + 0 + 0 + + 16 + 71 + 1 + 0 + 0 + 0 + ..\..\..\..\components\connectivity\mqttclient\common\log\fifo.c + fifo.c + 0 + 0 + + + 16 + 72 + 1 + 0 + 0 + 0 + ..\..\..\..\components\connectivity\mqttclient\common\log\format.c + format.c + 0 + 0 + + + 16 + 73 + 1 + 0 + 0 + 0 + ..\..\..\..\components\connectivity\mqttclient\common\log\salof.c + salof.c + 0 + 0 + + + 16 + 74 + 1 + 0 + 0 + 0 + ..\..\..\..\components\connectivity\mqttclient\common\log\arch\tencentos-tiny\arch.c + arch.c + 0 + 0 + + + 16 + 75 + 5 + 0 + 0 + 0 + ..\..\..\..\components\connectivity\mqttclient\common\log\salof_config.h + salof_config.h + 0 + 0 + + + + + mqttclient/common + 0 + 0 + 0 + 0 + + 17 + 76 + 1 + 0 + 0 + 0 + ..\..\..\..\components\connectivity\mqttclient\common\list.c + list.c + 0 + 0 + + + 17 + 77 + 1 + 0 + 0 + 0 + ..\..\..\..\components\connectivity\mqttclient\common\random.c + random.c + 0 + 0 + + + 17 + 78 + 5 + 0 + 0 + 0 + ..\..\..\..\components\connectivity\mqttclient\common\log.h + log.h + 0 + 0 + + + 17 + 79 + 5 + 0 + 0 + 0 + ..\..\..\..\components\connectivity\mqttclient\common\error.h + error.h + 0 + 0 + + + + + mqttclient/network + 0 + 0 + 0 + 0 + + 18 + 80 + 1 + 0 + 0 + 0 + ..\..\..\..\components\connectivity\mqttclient\network\network.c + network.c + 0 + 0 + + + + + mqttclient/platform + 0 + 0 + 0 + 0 + + 19 + 81 + 1 + 0 + 0 + 0 + ..\..\..\..\components\connectivity\mqttclient\platform\TencentOS-tiny\platform_memory.c + platform_memory.c + 0 + 0 + + + 19 + 82 + 1 + 0 + 0 + 0 + ..\..\..\..\components\connectivity\mqttclient\platform\TencentOS-tiny\platform_mutex.c + platform_mutex.c + 0 + 0 + + + 19 + 83 + 1 + 0 + 0 + 0 + ..\..\..\..\components\connectivity\mqttclient\platform\TencentOS-tiny\platform_net_socket.c + platform_net_socket.c + 0 + 0 + + + 19 + 84 + 1 + 0 + 0 + 0 + ..\..\..\..\components\connectivity\mqttclient\platform\TencentOS-tiny\platform_nettype_tcp.c + platform_nettype_tcp.c + 0 + 0 + + + 19 + 85 + 1 + 0 + 0 + 0 + ..\..\..\..\components\connectivity\mqttclient\platform\TencentOS-tiny\platform_nettype_tls.c + platform_nettype_tls.c + 0 + 0 + + + 19 + 86 + 1 + 0 + 0 + 0 + ..\..\..\..\components\connectivity\mqttclient\platform\TencentOS-tiny\platform_thread.c + platform_thread.c + 0 + 0 + + + 19 + 87 + 1 + 0 + 0 + 0 + ..\..\..\..\components\connectivity\mqttclient\platform\TencentOS-tiny\platform_timer.c + platform_timer.c + 0 + 0 + + + + + mqttclient/config + 1 + 0 + 0 + 0 + + 20 + 88 + 5 + 0 + 0 + 0 + ..\..\TOS-CONFIG\mqtt_config.h + mqtt_config.h + 0 + 0 + + + + + ::CMSIS + 0 + 0 + 0 + 1 + + +
diff --git a/board/GoKit3_STM32F103C8T6/KEIL/mqttclient/GoKit3_STM32F103C8T6.uvprojx b/board/GoKit3_STM32F103C8T6/KEIL/mqttclient/GoKit3_STM32F103C8T6.uvprojx new file mode 100644 index 00000000..7e557580 --- /dev/null +++ b/board/GoKit3_STM32F103C8T6/KEIL/mqttclient/GoKit3_STM32F103C8T6.uvprojx @@ -0,0 +1,942 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + GoKit3_STM32F103C8T6 + 0x4 + ARM-ADS + 5060750::V5.06 update 6 (build 750)::ARMCC + 0 + + + STM32F103C8 + STMicroelectronics + Keil.STM32F1xx_DFP.2.2.0 + http://www.keil.com/pack/ + IRAM(0x20000000-0x20004FFF) IROM(0x8000000-0x800FFFF) CLOCK(8000000) CPUTYPE("Cortex-M3") + + + + + + + + + + + + + + + $$Device:STM32F103C8$SVD\STM32F103xx.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + GoKit3_STM32F103C8T6\ + GoKit3_STM32F103C8T6 + 1 + 0 + 0 + 1 + 0 + + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 0 + + + SARMCM3.DLL + -REMAP + DCM.DLL + -pCM3 + SARMCM3.DLL + + TCM.DLL + -pCM3 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4107 + + 1 + STLink\ST-LINKIII-KEIL_SWO.dll + + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M3" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0x5000 + + + 1 + 0x8000000 + 0x10000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x8000000 + 0x10000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0x5000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 2 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 0 + + + USE_HAL_DRIVER,STM32F103xB + + ..\..\BSP\Inc;..\..\..\..\platform\vendor_bsp\st\STM32F1xx_HAL_Driver\Inc;..\..\..\..\platform\vendor_bsp\st\STM32F1xx_HAL_Driver\Inc\Legacy;..\..\..\..\platform\vendor_bsp\st\CMSIS\Device\ST\STM32F1xx\Include;..\..\..\..\platform\vendor_bsp\st\CMSIS\Include;..\..\..\..\arch\arm\arm-v7m\common\include;..\..\..\..\arch\arm\arm-v7m\cortex-m3\armcc;..\..\..\..\kernel\core\include;..\..\..\..\kernel\pm\include;..\..\..\..\osal\cmsis_os;..\..\TOS-CONFIG;..\..\BSP\HardWare\OLED;..\..\..\..\components\connectivity\mqttclient\common;..\..\..\..\components\connectivity\mqttclient\common\log;..\..\..\..\components\connectivity\mqttclient\mqtt;..\..\..\..\components\connectivity\mqttclient\mqttclient;..\..\..\..\components\connectivity\mqttclient\network;..\..\..\..\components\connectivity\mqttclient\platform\TencentOS-tiny;..\..\..\..\net\sal_module_wrapper;..\..\..\..\devices\esp8266;..\..\..\..\kernel\hal\include + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x08000000 + 0x20000000 + + + + + + + + + + + + + Application/MDK-ARM + + + startup_stm32f103xb.s + 2 + startup_stm32f103xb.s + + + + + Application/User + + + stm32f1xx_hal_msp.c + 1 + ..\..\BSP\Src\stm32f1xx_hal_msp.c + + + stm32f1xx_it.c + 1 + .\stm32f1xx_it.c + + + + + Application/Bsp + + + bsp_dwt.c + 1 + ..\..\BSP\Src\bsp_dwt.c + + + bsp_init.c + 1 + ..\..\BSP\Src\bsp_init.c + + + bsp_led.c + 1 + ..\..\BSP\Src\bsp_led.c + + + bsp_motor.c + 1 + ..\..\BSP\Src\bsp_motor.c + + + bsp_usart.c + 1 + ..\..\BSP\Src\bsp_usart.c + + + + + examples + + + gokit3_mqttclient.c + 1 + ..\..\..\..\examples\mqttclient\gokit3_mqttclient.c + + + + + Drivers/STM32F1xx_HAL_Driver + + + stm32f1xx_hal.c + 1 + ..\..\..\..\platform\vendor_bsp\st\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal.c + + + stm32f1xx_hal_cortex.c + 1 + ..\..\..\..\platform\vendor_bsp\st\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_cortex.c + + + stm32f1xx_hal_dma.c + 1 + ..\..\..\..\platform\vendor_bsp\st\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_dma.c + + + stm32f1xx_hal_exti.c + 1 + ..\..\..\..\platform\vendor_bsp\st\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_exti.c + + + stm32f1xx_hal_flash.c + 1 + ..\..\..\..\platform\vendor_bsp\st\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_flash.c + + + stm32f1xx_hal_flash_ex.c + 1 + ..\..\..\..\platform\vendor_bsp\st\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_flash_ex.c + + + stm32f1xx_hal_gpio.c + 1 + ..\..\..\..\platform\vendor_bsp\st\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_gpio.c + + + stm32f1xx_hal_gpio_ex.c + 1 + ..\..\..\..\platform\vendor_bsp\st\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_gpio_ex.c + + + stm32f1xx_hal_pcd.c + 1 + ..\..\..\..\platform\vendor_bsp\st\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_pcd.c + + + stm32f1xx_hal_pcd_ex.c + 1 + ..\..\..\..\platform\vendor_bsp\st\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_pcd_ex.c + + + stm32f1xx_hal_pwr.c + 1 + ..\..\..\..\platform\vendor_bsp\st\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_pwr.c + + + stm32f1xx_hal_rcc.c + 1 + ..\..\..\..\platform\vendor_bsp\st\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_rcc.c + + + stm32f1xx_hal_rcc_ex.c + 1 + ..\..\..\..\platform\vendor_bsp\st\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_rcc_ex.c + + + stm32f1xx_hal_tim.c + 1 + ..\..\..\..\platform\vendor_bsp\st\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_tim.c + + + stm32f1xx_hal_tim_ex.c + 1 + ..\..\..\..\platform\vendor_bsp\st\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_tim_ex.c + + + stm32f1xx_hal_uart.c + 1 + ..\..\..\..\platform\vendor_bsp\st\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_uart.c + + + + + Drivers/CMSIS + + + system_stm32f1xx.c + 1 + ..\..\BSP\Src\system_stm32f1xx.c + + + + + tos/arch + + + tos_cpu.c + 1 + ..\..\..\..\arch\arm\arm-v7m\common\tos_cpu.c + + + port_c.c + 1 + ..\..\..\..\arch\arm\arm-v7m\cortex-m3\armcc\port_c.c + + + port_s.S + 2 + ..\..\..\..\arch\arm\arm-v7m\cortex-m3\armcc\port_s.S + + + + + tos/kernel + + + tos_binary_heap.c + 1 + ..\..\..\..\kernel\core\tos_binary_heap.c + + + tos_char_fifo.c + 1 + ..\..\..\..\kernel\core\tos_char_fifo.c + + + tos_completion.c + 1 + ..\..\..\..\kernel\core\tos_completion.c + + + tos_countdownlatch.c + 1 + ..\..\..\..\kernel\core\tos_countdownlatch.c + + + tos_event.c + 1 + ..\..\..\..\kernel\core\tos_event.c + + + tos_global.c + 1 + ..\..\..\..\kernel\core\tos_global.c + + + tos_mail_queue.c + 1 + ..\..\..\..\kernel\core\tos_mail_queue.c + + + tos_message_queue.c + 1 + ..\..\..\..\kernel\core\tos_message_queue.c + + + tos_mmblk.c + 1 + ..\..\..\..\kernel\core\tos_mmblk.c + + + tos_mmheap.c + 1 + ..\..\..\..\kernel\core\tos_mmheap.c + + + tos_mutex.c + 1 + ..\..\..\..\kernel\core\tos_mutex.c + + + tos_pend.c + 1 + ..\..\..\..\kernel\core\tos_pend.c + + + tos_priority_mail_queue.c + 1 + ..\..\..\..\kernel\core\tos_priority_mail_queue.c + + + tos_priority_message_queue.c + 1 + ..\..\..\..\kernel\core\tos_priority_message_queue.c + + + tos_priority_queue.c + 1 + ..\..\..\..\kernel\core\tos_priority_queue.c + + + tos_ring_queue.c + 1 + ..\..\..\..\kernel\core\tos_ring_queue.c + + + tos_robin.c + 1 + ..\..\..\..\kernel\core\tos_robin.c + + + tos_sched.c + 1 + ..\..\..\..\kernel\core\tos_sched.c + + + tos_sem.c + 1 + ..\..\..\..\kernel\core\tos_sem.c + + + tos_sys.c + 1 + ..\..\..\..\kernel\core\tos_sys.c + + + tos_task.c + 1 + ..\..\..\..\kernel\core\tos_task.c + + + tos_tick.c + 1 + ..\..\..\..\kernel\core\tos_tick.c + + + tos_time.c + 1 + ..\..\..\..\kernel\core\tos_time.c + + + tos_timer.c + 1 + ..\..\..\..\kernel\core\tos_timer.c + + + + + tos/cmsis + + + cmsis_os.c + 1 + ..\..\..\..\osal\cmsis_os\cmsis_os.c + + + + + tos/at + + + tos_at.c + 1 + ..\..\..\..\net\at\src\tos_at.c + + + tos_at_utils.c + 1 + ..\..\..\..\net\at\src\tos_at_utils.c + + + + + tos/sal + + + sal_module_wrapper.c + 1 + ..\..\..\..\net\sal_module_wrapper\sal_module_wrapper.c + + + + + tos/hal + + + tos_hal_uart.c + 1 + ..\..\BSP\Src\tos_hal_uart.c + + + + + tos/devices + + + esp8266.c + 1 + ..\..\..\..\devices\esp8266\esp8266.c + + + + + mqttclient + + + mqttclient.c + 1 + ..\..\..\..\components\connectivity\mqttclient\mqttclient\mqttclient.c + + + + + mqttclient/mqtt + + + MQTTConnectClient.c + 1 + ..\..\..\..\components\connectivity\mqttclient\mqtt\MQTTConnectClient.c + + + MQTTConnectServer.c + 1 + ..\..\..\..\components\connectivity\mqttclient\mqtt\MQTTConnectServer.c + + + MQTTDeserializePublish.c + 1 + ..\..\..\..\components\connectivity\mqttclient\mqtt\MQTTDeserializePublish.c + + + MQTTFormat.c + 1 + ..\..\..\..\components\connectivity\mqttclient\mqtt\MQTTFormat.c + + + MQTTPacket.c + 1 + ..\..\..\..\components\connectivity\mqttclient\mqtt\MQTTPacket.c + + + MQTTSerializePublish.c + 1 + ..\..\..\..\components\connectivity\mqttclient\mqtt\MQTTSerializePublish.c + + + MQTTSubscribeClient.c + 1 + ..\..\..\..\components\connectivity\mqttclient\mqtt\MQTTSubscribeClient.c + + + MQTTSubscribeServer.c + 1 + ..\..\..\..\components\connectivity\mqttclient\mqtt\MQTTSubscribeServer.c + + + MQTTUnsubscribeClient.c + 1 + ..\..\..\..\components\connectivity\mqttclient\mqtt\MQTTUnsubscribeClient.c + + + MQTTUnsubscribeServer.c + 1 + ..\..\..\..\components\connectivity\mqttclient\mqtt\MQTTUnsubscribeServer.c + + + + + mqttclient/salof + + + fifo.c + 1 + ..\..\..\..\components\connectivity\mqttclient\common\log\fifo.c + + + format.c + 1 + ..\..\..\..\components\connectivity\mqttclient\common\log\format.c + + + salof.c + 1 + ..\..\..\..\components\connectivity\mqttclient\common\log\salof.c + + + arch.c + 1 + ..\..\..\..\components\connectivity\mqttclient\common\log\arch\tencentos-tiny\arch.c + + + salof_config.h + 5 + ..\..\..\..\components\connectivity\mqttclient\common\log\salof_config.h + + + + + mqttclient/common + + + list.c + 1 + ..\..\..\..\components\connectivity\mqttclient\common\list.c + + + random.c + 1 + ..\..\..\..\components\connectivity\mqttclient\common\random.c + + + log.h + 5 + ..\..\..\..\components\connectivity\mqttclient\common\log.h + + + error.h + 5 + ..\..\..\..\components\connectivity\mqttclient\common\error.h + + + + + mqttclient/network + + + network.c + 1 + ..\..\..\..\components\connectivity\mqttclient\network\network.c + + + + + mqttclient/platform + + + platform_memory.c + 1 + ..\..\..\..\components\connectivity\mqttclient\platform\TencentOS-tiny\platform_memory.c + + + platform_mutex.c + 1 + ..\..\..\..\components\connectivity\mqttclient\platform\TencentOS-tiny\platform_mutex.c + + + platform_net_socket.c + 1 + ..\..\..\..\components\connectivity\mqttclient\platform\TencentOS-tiny\platform_net_socket.c + + + platform_nettype_tcp.c + 1 + ..\..\..\..\components\connectivity\mqttclient\platform\TencentOS-tiny\platform_nettype_tcp.c + + + platform_nettype_tls.c + 1 + ..\..\..\..\components\connectivity\mqttclient\platform\TencentOS-tiny\platform_nettype_tls.c + + + platform_thread.c + 1 + ..\..\..\..\components\connectivity\mqttclient\platform\TencentOS-tiny\platform_thread.c + + + platform_timer.c + 1 + ..\..\..\..\components\connectivity\mqttclient\platform\TencentOS-tiny\platform_timer.c + + + + + mqttclient/config + + + mqtt_config.h + 5 + ..\..\TOS-CONFIG\mqtt_config.h + + + + + ::CMSIS + + + + + + + + + + + + + + + + + + +
diff --git a/board/GoKit3_STM32F103C8T6/KEIL/mqttclient/startup_stm32f103xb.s b/board/GoKit3_STM32F103C8T6/KEIL/mqttclient/startup_stm32f103xb.s new file mode 100644 index 00000000..b10b2ed3 --- /dev/null +++ b/board/GoKit3_STM32F103C8T6/KEIL/mqttclient/startup_stm32f103xb.s @@ -0,0 +1,307 @@ +;******************** (C) COPYRIGHT 2017 STMicroelectronics ******************** +;* File Name : startup_stm32f103xb.s +;* Author : MCD Application Team +;* Description : STM32F103xB Devices vector table for MDK-ARM toolchain. +;* This module performs: +;* - Set the initial SP +;* - Set the initial PC == Reset_Handler +;* - Set the vector table entries with the exceptions ISR address +;* - Configure the clock system +;* - Branches to __main in the C library (which eventually +;* calls main()). +;* After Reset the Cortex-M3 processor is in Thread mode, +;* priority is Privileged, and the Stack is set to Main. +;****************************************************************************** +;* @attention +;* +;* Copyright (c) 2017 STMicroelectronics. +;* All rights reserved. +;* +;* This software component is licensed by ST under BSD 3-Clause license, +;* the "License"; You may not use this file except in compliance with the +;* License. You may obtain a copy of the License at: +;* opensource.org/licenses/BSD-3-Clause +;* +;****************************************************************************** + +; Amount of memory (in bytes) allocated for Stack +; Tailor this value to your application needs +; Stack Configuration +; Stack Size (in Bytes) <0x0-0xFFFFFFFF:8> +; + +Stack_Size EQU 0x400 + + AREA STACK, NOINIT, READWRITE, ALIGN=3 +Stack_Mem SPACE Stack_Size +__initial_sp + + +; Heap Configuration +; Heap Size (in Bytes) <0x0-0xFFFFFFFF:8> +; + +Heap_Size EQU 0x200 + + AREA HEAP, NOINIT, READWRITE, ALIGN=3 +__heap_base +Heap_Mem SPACE Heap_Size +__heap_limit + + PRESERVE8 + THUMB + + +; Vector Table Mapped to Address 0 at Reset + AREA RESET, DATA, READONLY + EXPORT __Vectors + EXPORT __Vectors_End + EXPORT __Vectors_Size + +__Vectors DCD __initial_sp ; Top of Stack + DCD Reset_Handler ; Reset Handler + DCD NMI_Handler ; NMI Handler + DCD HardFault_Handler ; Hard Fault Handler + DCD MemManage_Handler ; MPU Fault Handler + DCD BusFault_Handler ; Bus Fault Handler + DCD UsageFault_Handler ; Usage Fault Handler + DCD 0 ; Reserved + DCD 0 ; Reserved + DCD 0 ; Reserved + DCD 0 ; Reserved + DCD SVC_Handler ; SVCall Handler + DCD DebugMon_Handler ; Debug Monitor Handler + DCD 0 ; Reserved + DCD PendSV_Handler ; PendSV Handler + DCD SysTick_Handler ; SysTick Handler + + ; External Interrupts + DCD WWDG_IRQHandler ; Window Watchdog + DCD PVD_IRQHandler ; PVD through EXTI Line detect + DCD TAMPER_IRQHandler ; Tamper + DCD RTC_IRQHandler ; RTC + DCD FLASH_IRQHandler ; Flash + DCD RCC_IRQHandler ; RCC + DCD EXTI0_IRQHandler ; EXTI Line 0 + DCD EXTI1_IRQHandler ; EXTI Line 1 + DCD EXTI2_IRQHandler ; EXTI Line 2 + DCD EXTI3_IRQHandler ; EXTI Line 3 + DCD EXTI4_IRQHandler ; EXTI Line 4 + DCD DMA1_Channel1_IRQHandler ; DMA1 Channel 1 + DCD DMA1_Channel2_IRQHandler ; DMA1 Channel 2 + DCD DMA1_Channel3_IRQHandler ; DMA1 Channel 3 + DCD DMA1_Channel4_IRQHandler ; DMA1 Channel 4 + DCD DMA1_Channel5_IRQHandler ; DMA1 Channel 5 + DCD DMA1_Channel6_IRQHandler ; DMA1 Channel 6 + DCD DMA1_Channel7_IRQHandler ; DMA1 Channel 7 + DCD ADC1_2_IRQHandler ; ADC1_2 + DCD USB_HP_CAN1_TX_IRQHandler ; USB High Priority or CAN1 TX + DCD USB_LP_CAN1_RX0_IRQHandler ; USB Low Priority or CAN1 RX0 + DCD CAN1_RX1_IRQHandler ; CAN1 RX1 + DCD CAN1_SCE_IRQHandler ; CAN1 SCE + DCD EXTI9_5_IRQHandler ; EXTI Line 9..5 + DCD TIM1_BRK_IRQHandler ; TIM1 Break + DCD TIM1_UP_IRQHandler ; TIM1 Update + DCD TIM1_TRG_COM_IRQHandler ; TIM1 Trigger and Commutation + DCD TIM1_CC_IRQHandler ; TIM1 Capture Compare + DCD TIM2_IRQHandler ; TIM2 + DCD TIM3_IRQHandler ; TIM3 + DCD TIM4_IRQHandler ; TIM4 + DCD I2C1_EV_IRQHandler ; I2C1 Event + DCD I2C1_ER_IRQHandler ; I2C1 Error + DCD I2C2_EV_IRQHandler ; I2C2 Event + DCD I2C2_ER_IRQHandler ; I2C2 Error + DCD SPI1_IRQHandler ; SPI1 + DCD SPI2_IRQHandler ; SPI2 + DCD USART1_IRQHandler ; USART1 + DCD USART2_IRQHandler ; USART2 + DCD USART3_IRQHandler ; USART3 + DCD EXTI15_10_IRQHandler ; EXTI Line 15..10 + DCD RTC_Alarm_IRQHandler ; RTC Alarm through EXTI Line + DCD USBWakeUp_IRQHandler ; USB Wakeup from suspend +__Vectors_End + +__Vectors_Size EQU __Vectors_End - __Vectors + + AREA |.text|, CODE, READONLY + +; Reset handler +Reset_Handler PROC + EXPORT Reset_Handler [WEAK] + IMPORT __main + IMPORT SystemInit + LDR R0, =SystemInit + BLX R0 + LDR R0, =__main + BX R0 + ENDP + +; Dummy Exception Handlers (infinite loops which can be modified) + +NMI_Handler PROC + EXPORT NMI_Handler [WEAK] + B . + ENDP +HardFault_Handler\ + PROC + EXPORT HardFault_Handler [WEAK] + B . + ENDP +MemManage_Handler\ + PROC + EXPORT MemManage_Handler [WEAK] + B . + ENDP +BusFault_Handler\ + PROC + EXPORT BusFault_Handler [WEAK] + B . + ENDP +UsageFault_Handler\ + PROC + EXPORT UsageFault_Handler [WEAK] + B . + ENDP +SVC_Handler PROC + EXPORT SVC_Handler [WEAK] + B . + ENDP +DebugMon_Handler\ + PROC + EXPORT DebugMon_Handler [WEAK] + B . + ENDP +PendSV_Handler PROC + EXPORT PendSV_Handler [WEAK] + B . + ENDP +SysTick_Handler PROC + EXPORT SysTick_Handler [WEAK] + B . + ENDP + +Default_Handler PROC + + EXPORT WWDG_IRQHandler [WEAK] + EXPORT PVD_IRQHandler [WEAK] + EXPORT TAMPER_IRQHandler [WEAK] + EXPORT RTC_IRQHandler [WEAK] + EXPORT FLASH_IRQHandler [WEAK] + EXPORT RCC_IRQHandler [WEAK] + EXPORT EXTI0_IRQHandler [WEAK] + EXPORT EXTI1_IRQHandler [WEAK] + EXPORT EXTI2_IRQHandler [WEAK] + EXPORT EXTI3_IRQHandler [WEAK] + EXPORT EXTI4_IRQHandler [WEAK] + EXPORT DMA1_Channel1_IRQHandler [WEAK] + EXPORT DMA1_Channel2_IRQHandler [WEAK] + EXPORT DMA1_Channel3_IRQHandler [WEAK] + EXPORT DMA1_Channel4_IRQHandler [WEAK] + EXPORT DMA1_Channel5_IRQHandler [WEAK] + EXPORT DMA1_Channel6_IRQHandler [WEAK] + EXPORT DMA1_Channel7_IRQHandler [WEAK] + EXPORT ADC1_2_IRQHandler [WEAK] + EXPORT USB_HP_CAN1_TX_IRQHandler [WEAK] + EXPORT USB_LP_CAN1_RX0_IRQHandler [WEAK] + EXPORT CAN1_RX1_IRQHandler [WEAK] + EXPORT CAN1_SCE_IRQHandler [WEAK] + EXPORT EXTI9_5_IRQHandler [WEAK] + EXPORT TIM1_BRK_IRQHandler [WEAK] + EXPORT TIM1_UP_IRQHandler [WEAK] + EXPORT TIM1_TRG_COM_IRQHandler [WEAK] + EXPORT TIM1_CC_IRQHandler [WEAK] + EXPORT TIM2_IRQHandler [WEAK] + EXPORT TIM3_IRQHandler [WEAK] + EXPORT TIM4_IRQHandler [WEAK] + EXPORT I2C1_EV_IRQHandler [WEAK] + EXPORT I2C1_ER_IRQHandler [WEAK] + EXPORT I2C2_EV_IRQHandler [WEAK] + EXPORT I2C2_ER_IRQHandler [WEAK] + EXPORT SPI1_IRQHandler [WEAK] + EXPORT SPI2_IRQHandler [WEAK] + EXPORT USART1_IRQHandler [WEAK] + EXPORT USART2_IRQHandler [WEAK] + EXPORT USART3_IRQHandler [WEAK] + EXPORT EXTI15_10_IRQHandler [WEAK] + EXPORT RTC_Alarm_IRQHandler [WEAK] + EXPORT USBWakeUp_IRQHandler [WEAK] + +WWDG_IRQHandler +PVD_IRQHandler +TAMPER_IRQHandler +RTC_IRQHandler +FLASH_IRQHandler +RCC_IRQHandler +EXTI0_IRQHandler +EXTI1_IRQHandler +EXTI2_IRQHandler +EXTI3_IRQHandler +EXTI4_IRQHandler +DMA1_Channel1_IRQHandler +DMA1_Channel2_IRQHandler +DMA1_Channel3_IRQHandler +DMA1_Channel4_IRQHandler +DMA1_Channel5_IRQHandler +DMA1_Channel6_IRQHandler +DMA1_Channel7_IRQHandler +ADC1_2_IRQHandler +USB_HP_CAN1_TX_IRQHandler +USB_LP_CAN1_RX0_IRQHandler +CAN1_RX1_IRQHandler +CAN1_SCE_IRQHandler +EXTI9_5_IRQHandler +TIM1_BRK_IRQHandler +TIM1_UP_IRQHandler +TIM1_TRG_COM_IRQHandler +TIM1_CC_IRQHandler +TIM2_IRQHandler +TIM3_IRQHandler +TIM4_IRQHandler +I2C1_EV_IRQHandler +I2C1_ER_IRQHandler +I2C2_EV_IRQHandler +I2C2_ER_IRQHandler +SPI1_IRQHandler +SPI2_IRQHandler +USART1_IRQHandler +USART2_IRQHandler +USART3_IRQHandler +EXTI15_10_IRQHandler +RTC_Alarm_IRQHandler +USBWakeUp_IRQHandler + + B . + + ENDP + + ALIGN + +;******************************************************************************* +; User Stack and Heap initialization +;******************************************************************************* + IF :DEF:__MICROLIB + + EXPORT __initial_sp + EXPORT __heap_base + EXPORT __heap_limit + + ELSE + + IMPORT __use_two_region_memory + EXPORT __user_initial_stackheap + +__user_initial_stackheap + + LDR R0, = Heap_Mem + LDR R1, =(Stack_Mem + Stack_Size) + LDR R2, = (Heap_Mem + Heap_Size) + LDR R3, = Stack_Mem + BX LR + + ALIGN + + ENDIF + + END + +;************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE***** diff --git a/board/GoKit3_STM32F103C8T6/KEIL/mqttclient/stm32f1xx_it.c b/board/GoKit3_STM32F103C8T6/KEIL/mqttclient/stm32f1xx_it.c new file mode 100644 index 00000000..1905a9b6 --- /dev/null +++ b/board/GoKit3_STM32F103C8T6/KEIL/mqttclient/stm32f1xx_it.c @@ -0,0 +1,211 @@ +/** + ****************************************************************************** + * @file stm32f1xx_it.c + * @brief Interrupt Service Routines. + ****************************************************************************** + * + * COPYRIGHT(c) 2016 STMicroelectronics + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of STMicroelectronics nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************** + */ +/* Includes ------------------------------------------------------------------*/ +#include "stm32f1xx_hal.h" +#include "stm32f1xx.h" +#include "stm32f1xx_it.h" +#include "tos_k.h" +#include "bsp_usart.h" +#include "tos_at.h" + +/* USER CODE BEGIN 0 */ + +/* USER CODE END 0 */ + +/* External variables --------------------------------------------------------*/ + +/******************************************************************************/ +/* Cortex-M3 Processor Interruption and Exception Handlers */ +/******************************************************************************/ + +/** +* @brief This function handles Non maskable interrupt. +*/ +void NMI_Handler(void) +{ + /* USER CODE BEGIN NonMaskableInt_IRQn 0 */ + + /* USER CODE END NonMaskableInt_IRQn 0 */ + /* USER CODE BEGIN NonMaskableInt_IRQn 1 */ + + /* USER CODE END NonMaskableInt_IRQn 1 */ +} + +/** +* @brief This function handles Hard fault interrupt. +*/ +void HardFault_Handler(void) +{ + /* USER CODE BEGIN HardFault_IRQn 0 */ + + /* USER CODE END HardFault_IRQn 0 */ + while (1) + { + } + /* USER CODE BEGIN HardFault_IRQn 1 */ + + /* USER CODE END HardFault_IRQn 1 */ +} + +/** +* @brief This function handles Memory management fault. +*/ +void MemManage_Handler(void) +{ + /* USER CODE BEGIN MemoryManagement_IRQn 0 */ + + /* USER CODE END MemoryManagement_IRQn 0 */ + while (1) + { + } + /* USER CODE BEGIN MemoryManagement_IRQn 1 */ + + /* USER CODE END MemoryManagement_IRQn 1 */ +} + +/** +* @brief This function handles Prefetch fault, memory access fault. +*/ +void BusFault_Handler(void) +{ + /* USER CODE BEGIN BusFault_IRQn 0 */ + + /* USER CODE END BusFault_IRQn 0 */ + while (1) + { + } + /* USER CODE BEGIN BusFault_IRQn 1 */ + + /* USER CODE END BusFault_IRQn 1 */ +} + +/** +* @brief This function handles Undefined instruction or illegal state. +*/ +void UsageFault_Handler(void) +{ + /* USER CODE BEGIN UsageFault_IRQn 0 */ + + /* USER CODE END UsageFault_IRQn 0 */ + while (1) + { + } + /* USER CODE BEGIN UsageFault_IRQn 1 */ + + /* USER CODE END UsageFault_IRQn 1 */ +} + +/** +* @brief This function handles System service call via SWI instruction. +*/ +void SVC_Handler(void) +{ + /* USER CODE BEGIN SVCall_IRQn 0 */ + + /* USER CODE END SVCall_IRQn 0 */ + /* USER CODE BEGIN SVCall_IRQn 1 */ + + /* USER CODE END SVCall_IRQn 1 */ +} + +/** +* @brief This function handles Debug monitor. +*/ +void DebugMon_Handler(void) +{ + /* USER CODE BEGIN DebugMonitor_IRQn 0 */ + + /* USER CODE END DebugMonitor_IRQn 0 */ + /* USER CODE BEGIN DebugMonitor_IRQn 1 */ + + /* USER CODE END DebugMonitor_IRQn 1 */ +} + +/** +* @brief This function handles System tick timer. +*/ +void SysTick_Handler(void) +{ + HAL_IncTick(); + + if (tos_knl_is_running()) + { + tos_knl_irq_enter(); + tos_tick_handler(); + tos_knl_irq_leave(); + } +} + + + +void DEBUG_USART_IRQHandler(void) +{ + uint8_t data; + + tos_knl_irq_enter(); + + if(__HAL_UART_GET_FLAG( &debug_usart, UART_FLAG_RXNE ) != RESET) + { + HAL_UART_Receive(&debug_usart, &data, 1, 1); + HAL_UART_Transmit(&debug_usart, &data, 1, 1); + } + + tos_knl_irq_leave(); +} + +void WIFI_USART_IRQHandler(void) +{ + uint8_t data; + + tos_knl_irq_enter(); + + if(__HAL_UART_GET_FLAG( &wifi_usart, UART_FLAG_RXNE ) != RESET) + { + HAL_UART_Receive(&wifi_usart, &data, 1, 1); + tos_at_uart_input_byte(data); + } + + tos_knl_irq_leave(); +} + +/******************************************************************************/ +/* STM32F1xx Peripheral Interrupt Handlers */ +/* Add here the Interrupt Handlers for the used peripherals. */ +/* For the available peripheral interrupt handler names, */ +/* please refer to the startup file (startup_stm32f1xx.s). */ +/******************************************************************************/ + +/* USER CODE BEGIN 1 */ + +/* USER CODE END 1 */ +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/board/GoKit3_STM32F103C8T6/TOS-CONFIG/mqtt_config.h b/board/GoKit3_STM32F103C8T6/TOS-CONFIG/mqtt_config.h new file mode 100644 index 00000000..c2caeb53 --- /dev/null +++ b/board/GoKit3_STM32F103C8T6/TOS-CONFIG/mqtt_config.h @@ -0,0 +1,48 @@ +/* + * @Author: jiejie + * @Github: https://github.com/jiejieTop + * @Date: 2019-12-15 00:42:16 + * @LastEditTime: 2020-02-25 09:25:35 + * @Description: the code belongs to jiejie, please keep the author information and source code according to the license. + */ +#ifndef _MQTT_CONFIG_H_ +#define _MQTT_CONFIG_H_ + +//#define LOG_IS_SALOF + +#define LOG_LEVEL DEBUG_LEVEL //WARN_LEVEL DEBUG_LEVEL + +#ifdef LOG_IS_SALOF + #define USE_LOG (1U) + #define USE_SALOF (1U) + #define SALOF_OS USE_TENCENTOS + #define USE_IDLE_HOOK (0U) + #define LOG_COLOR (0U) + #define LOG_TS (0U) + #define LOG_TAR (0U) + #define SALOF_BUFF_SIZE (512U) + #define SALOF_FIFO_SIZE (1024U) + #define SALOF_TASK_STACK_SIZE (1024U) + #define SALOF_TASK_TICK (50U) +#endif + + +#define MQTT_MAX_PACKET_ID (0xFFFF - 1) +#define MQTT_TOPIC_LEN_MAX 64 +#define MQTT_ACK_HANDLER_NUM_MAX 64 +#define MQTT_DEFAULT_BUF_SIZE 1024 +#define MQTT_DEFAULT_CMD_TIMEOUT 4000 +#define MQTT_MAX_CMD_TIMEOUT 20000 +#define MQTT_MIN_CMD_TIMEOUT 1000 +#define MQTT_KEEP_ALIVE_INTERVAL 100 // unit: second +#define MQTT_VERSION 4 // 4 is mqtt 3.1.1 +#define MQTT_RECONNECT_DEFAULT_DURATION 1000 +#define MQTT_THREAD_STACK_SIZE 2048 +#define MQTT_THREAD_PRIO 5 +#define MQTT_THREAD_TICK 50 + +#define MQTT_NETSOCKET_USE_AT + +//#define MQTT_NETWORK_TYPE_TLS + +#endif /* _MQTT_CONFIG_H_ */ diff --git a/board/GoKit3_STM32F103C8T6/TOS-CONFIG/tos_config.h b/board/GoKit3_STM32F103C8T6/TOS-CONFIG/tos_config.h index cd1116f3..818fb90f 100644 --- a/board/GoKit3_STM32F103C8T6/TOS-CONFIG/tos_config.h +++ b/board/GoKit3_STM32F103C8T6/TOS-CONFIG/tos_config.h @@ -19,7 +19,7 @@ #define TOS_CFG_MMHEAP_EN 1u -#define TOS_CFG_MMHEAP_DEFAULT_POOL_SIZE 0x1000 +#define TOS_CFG_MMHEAP_DEFAULT_POOL_SIZE 0x2C00 #define TOS_CFG_MUTEX_EN 1u diff --git a/components/connectivity/mqttclient/platform/TencentOS-tiny/platform_net_socket.c b/components/connectivity/mqttclient/platform/TencentOS-tiny/platform_net_socket.c index 6baebe0c..9c9e1971 100644 --- a/components/connectivity/mqttclient/platform/TencentOS-tiny/platform_net_socket.c +++ b/components/connectivity/mqttclient/platform/TencentOS-tiny/platform_net_socket.c @@ -10,6 +10,17 @@ int platform_net_socket_connect(const char *host, const char *port, int proto) { int fd, ret = MQTT_SOCKET_UNKNOWN_HOST; +#ifdef MQTT_NETSOCKET_USE_AT + + fd = tos_sal_module_connect(host, port, TOS_SAL_PROTO_TCP); + + if (fd < 0) { + return MQTT_CONNECT_FAILED_ERROR; + } + ret = fd; + +#else + struct addrinfo hints, *addr_list, *cur; /* Do name resolution with both IPv6 and IPv4 */ @@ -39,16 +50,25 @@ int platform_net_socket_connect(const char *host, const char *port, int proto) } freeaddrinfo(addr_list); +#endif + return ret; } int platform_net_socket_recv(int fd, void *buf, size_t len, int flags) { +#ifdef MQTT_NETSOCKET_USE_AT + return tos_sal_module_recv(fd, buf, len); +#else return recv(fd, buf, len, flags); +#endif } int platform_net_socket_recv_timeout(int fd, unsigned char *buf, int len, int timeout) { +#ifdef MQTT_NETSOCKET_USE_AT + return tos_sal_module_recv_timeout(fd, buf, len, timeout); +#else int rc; int bytes = 0; struct timeval tv = { @@ -73,15 +93,23 @@ int platform_net_socket_recv_timeout(int fd, unsigned char *buf, int len, int ti } } return bytes; +#endif } int platform_net_socket_write(int fd, void *buf, size_t len) { +#ifdef MQTT_NETSOCKET_USE_AT + return tos_sal_module_send(fd, buf, len); +#else return write(fd, buf, len); +#endif } int platform_net_socket_write_timeout(int fd, unsigned char *buf, int len, int timeout) { +#ifdef MQTT_NETSOCKET_USE_AT + return tos_sal_module_send(fd, buf, len); +#else struct timeval tv = { timeout / 1000, (timeout % 1000) * 1000 @@ -95,13 +123,20 @@ int platform_net_socket_write_timeout(int fd, unsigned char *buf, int len, int t platform_net_socket_setsockopt(fd, SOL_SOCKET, SO_SNDTIMEO, (char *)&tv,sizeof(struct timeval)); return write(fd, buf, len); +#endif } int platform_net_socket_close(int fd) { +#ifdef MQTT_NETSOCKET_USE_AT + return tos_sal_module_close(fd); +#else return close(fd); +#endif } +#ifndef MQTT_NETSOCKET_USE_AT + int platform_net_socket_set_block(int fd) { return fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, F_GETFL) & ~O_NONBLOCK); @@ -117,3 +152,4 @@ int platform_net_socket_setsockopt(int fd, int level, int optname, const void *o return setsockopt(fd, level, optname, optval, optlen); } +#endif diff --git a/components/connectivity/mqttclient/platform/TencentOS-tiny/platform_net_socket.h b/components/connectivity/mqttclient/platform/TencentOS-tiny/platform_net_socket.h index ec704d28..ef696d92 100644 --- a/components/connectivity/mqttclient/platform/TencentOS-tiny/platform_net_socket.h +++ b/components/connectivity/mqttclient/platform/TencentOS-tiny/platform_net_socket.h @@ -11,12 +11,20 @@ #include "network.h" #include "error.h" +#ifdef MQTT_NETSOCKET_USE_AT + +#include "sal_module_wrapper.h" + +#else + #include "lwip/opt.h" #include "lwip/sys.h" #include "lwip/api.h" #include #include "lwip/netdb.h" +#endif + #define PLATFORM_NET_PROTO_TCP 0 /**< The TCP transport protocol */ #define PLATFORM_NET_PROTO_UDP 1 /**< The UDP transport protocol */ @@ -26,8 +34,11 @@ int platform_net_socket_recv_timeout(int fd, unsigned char *buf, int len, int ti int platform_net_socket_write(int fd, void *buf, size_t len); int platform_net_socket_write_timeout(int fd, unsigned char *buf, int len, int timeout); int platform_net_socket_close(int fd); + +#ifndef MQTT_NETSOCKET_USE_AT int platform_net_socket_set_block(int fd); int platform_net_socket_set_nonblock(int fd); int platform_net_socket_setsockopt(int fd, int level, int optname, const void *optval, socklen_t optlen); +#endif #endif /* _PLATFORM_NET_SOCKET_H_ */ diff --git a/examples/mqttclient/gokit3_mqttclient.c b/examples/mqttclient/gokit3_mqttclient.c new file mode 100644 index 00000000..837f36ae --- /dev/null +++ b/examples/mqttclient/gokit3_mqttclient.c @@ -0,0 +1,105 @@ +#include "stm32f1xx_hal.h" +#include "bsp_init.h" +#include "tos_k.h" +#include "esp8266.h" +#include "mqttclient.h" + +k_task_t task; +k_stack_t task_stack[2048]; + +mqtt_client_t client; +client_init_params_t init_params; + +static void tos_topic_handler(void* client, message_data_t* msg) +{ + (void) client; + LOG_I("-----------------------------------------------------------------------------------"); + LOG_I("%s:%d %s()...\ntopic: %s, qos: %d. \nmessage:\n\t%s\n", __FILE__, __LINE__, __FUNCTION__, + msg->topic_name, msg->message->qos, (char*)msg->message->payload); + LOG_I("-----------------------------------------------------------------------------------\n"); +} + + +void mqttclient_task(void *Parameter) +{ + int error; + + char buf[100] = { 0 }; + + mqtt_message_t msg; + + memset(&msg, 0, sizeof(msg)); + + esp8266_sal_init(HAL_UART_PORT_2); + esp8266_join_ap("wifii", "woshijiejie"); + + init_params.read_buf_size = 256; + init_params.write_buf_size = 256; + +#ifdef MQTT_NETWORK_TYPE_TLS + init_params.connect_params.network_params.network_ssl_params.ca_crt = test_ca_get(); + init_params.connect_params.network_params.port = "8883"; +#else + init_params.connect_params.network_params.port = "1883"; +#endif + init_params.connect_params.network_params.addr = "www.jiejie01.top"; //"47.95.164.112";//"jiejie01.top"; //"129.204.201.235"; //"192.168.1.101"; + + init_params.connect_params.user_name = random_string(10); // random_string(10); //"jiejietop-acer1"; + init_params.connect_params.password = random_string(10);; //random_string(10); // "123456"; + init_params.connect_params.client_id = random_string(10);; //random_string(10); // "clientid-acer1"; + init_params.connect_params.clean_session = 1; + + log_init(); + + mqtt_init(&client, &init_params); + + error = mqtt_connect(&client); + + LOG_D("mqtt connect error is %#x", error); + + mqtt_subscribe(&client, "tos-topic", QOS0, tos_topic_handler); + + LOG_D("mqtt subscribe error is %#x", error); + + memset(&msg, 0, sizeof(msg)); + + for (;;) { + + sprintf(buf, "welcome to mqttclient, this is a publish test, a rand number: %d ...", random_number()); + + msg.qos = QOS0; + msg.payload = (void *) buf; + + error = mqtt_publish(&client, "tos-topic", &msg); + + tos_task_delay(4000); + } +} + + +int main(void) +{ + + k_err_t err; + + bsp_init(); + + printf("Welcome to TencentOS tiny\r\n"); + + tos_knl_init(); // TOS Tiny kernel initialize + + printf("create mqttclient task\r\n"); + err = tos_task_create(&task, + "mqttclient-task", + mqttclient_task, + NULL, + 3, + task_stack, + 1024, + 20); + if(err != K_ERR_NONE) + printf("TencentOS Create mqttclient task fail! code : %d \r\n",err); + + tos_knl_start(); // Start TOS Tiny + +} diff --git a/examples/mqttclient/mqttclient.c b/examples/mqttclient/mqttclient.c index 99dd4ed2..a1b48c04 100644 --- a/examples/mqttclient/mqttclient.c +++ b/examples/mqttclient/mqttclient.c @@ -46,9 +46,15 @@ void application_entry(void *arg) init_params.read_buf_size = 1024; init_params.write_buf_size = 1024; + +#ifdef MQTT_NETWORK_TYPE_TLS init_params.connect_params.network_params.network_ssl_params.ca_crt = test_ca_get(); - init_params.connect_params.network_params.addr = "www.jiejie01.top"; init_params.connect_params.network_params.port = "8883"; +#else + init_params.connect_params.network_params.port = "1883"; +#endif + init_params.connect_params.network_params.addr = "www.jiejie01.top"; //"47.95.164.112";//"jiejie01.top"; //"129.204.201.235"; //"192.168.1.101"; + init_params.connect_params.user_name = random_string(10); init_params.connect_params.password = random_string(10); init_params.connect_params.client_id = random_string(10); @@ -69,7 +75,9 @@ void application_entry(void *arg) memset(&msg, 0, sizeof(msg)); for (;;) { - + + sprintf(buf, "welcome to mqttclient, this is a publish test, a rand number: %d ...", random_number()); + msg.qos = QOS0; msg.payload = (void *) buf;