串口发送(未成功)
This commit is contained in:
parent
938e2f7025
commit
dc65d8d19b
2
.config
2
.config
@ -1660,7 +1660,7 @@ CONFIG_BSP_USING_UART1=y
|
|||||||
# CONFIG_BSP_UART1_RX_USING_DMA is not set
|
# CONFIG_BSP_UART1_RX_USING_DMA is not set
|
||||||
# CONFIG_BSP_UART1_TX_USING_DMA is not set
|
# CONFIG_BSP_UART1_TX_USING_DMA is not set
|
||||||
CONFIG_BSP_USING_UART2=y
|
CONFIG_BSP_USING_UART2=y
|
||||||
CONFIG_BSP_UART2_RX_USING_DMA=y
|
# CONFIG_BSP_UART2_RX_USING_DMA is not set
|
||||||
# CONFIG_BSP_UART2_TX_USING_DMA is not set
|
# CONFIG_BSP_UART2_TX_USING_DMA is not set
|
||||||
# CONFIG_BSP_USING_UART3 is not set
|
# CONFIG_BSP_USING_UART3 is not set
|
||||||
# CONFIG_BSP_USING_UART4 is not set
|
# CONFIG_BSP_USING_UART4 is not set
|
||||||
|
3
.vscode/c_cpp_properties.json
vendored
3
.vscode/c_cpp_properties.json
vendored
@ -422,7 +422,8 @@
|
|||||||
"d:\\src",
|
"d:\\src",
|
||||||
"d:\\src\\klibc",
|
"d:\\src\\klibc",
|
||||||
"d:\\Develop\\libraries\\STM32F4xx_HAL\\STM32F4xx_HAL_Driver\\Src",
|
"d:\\Develop\\libraries\\STM32F4xx_HAL\\STM32F4xx_HAL_Driver\\Src",
|
||||||
"d:\\Develop\\libraries\\STM32F4xx_HAL\\CMSIS\\Device\\ST\\STM32F4xx\\Source\\Templates"
|
"d:\\Develop\\libraries\\STM32F4xx_HAL\\CMSIS\\Device\\ST\\STM32F4xx\\Source\\Templates",
|
||||||
|
"${workspaceFolder}/packages/aht10-latest/inc"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
@ -25,6 +25,10 @@ extern "C" {
|
|||||||
#define STM32_FLASH_SIZE (1024 * 1024)
|
#define STM32_FLASH_SIZE (1024 * 1024)
|
||||||
#define STM32_FLASH_END_ADDRESS ((uint32_t)(STM32_FLASH_START_ADRESS + STM32_FLASH_SIZE))
|
#define STM32_FLASH_END_ADDRESS ((uint32_t)(STM32_FLASH_START_ADRESS + STM32_FLASH_SIZE))
|
||||||
|
|
||||||
|
|
||||||
|
#define BSP_UART2_TX "PA2"
|
||||||
|
#define BSP_UART2_RX "PA3"
|
||||||
|
|
||||||
#if defined(__ARMCC_VERSION)
|
#if defined(__ARMCC_VERSION)
|
||||||
extern int Image$$RW_IRAM1$$ZI$$Limit;
|
extern int Image$$RW_IRAM1$$ZI$$Limit;
|
||||||
#define HEAP_BEGIN ((void *)&Image$$RW_IRAM1$$ZI$$Limit)
|
#define HEAP_BEGIN ((void *)&Image$$RW_IRAM1$$ZI$$Limit)
|
||||||
|
@ -7,6 +7,8 @@
|
|||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
#define LCD_MAX 240
|
#define LCD_MAX 240
|
||||||
|
//串口
|
||||||
|
rt_device_t serial;
|
||||||
|
|
||||||
extern char tmp[];
|
extern char tmp[];
|
||||||
void lcd_black(int x, int y)
|
void lcd_black(int x, int y)
|
||||||
|
@ -6,7 +6,8 @@
|
|||||||
#define LCD_MAX 240
|
#define LCD_MAX 240
|
||||||
#define EVENT_MQTT_ENABLE (1<<3)
|
#define EVENT_MQTT_ENABLE (1<<3)
|
||||||
// struct rt_event my_event;
|
// struct rt_event my_event;
|
||||||
|
//串口
|
||||||
|
extern rt_device_t serial;
|
||||||
|
|
||||||
void mytime();
|
void mytime();
|
||||||
void greattime();
|
void greattime();
|
||||||
|
@ -30,20 +30,41 @@ void snake_compare(rt_uint8_t key, rt_uint8_t repeat)
|
|||||||
rt_atomic_store(&snake_pressed, snake_max + 1);
|
rt_atomic_store(&snake_pressed, snake_max + 1);
|
||||||
// 上
|
// 上
|
||||||
if (rt_strcmp(tmp, "30") == 0 || rt_strcmp(tmp, "53") == 0)
|
if (rt_strcmp(tmp, "30") == 0 || rt_strcmp(tmp, "53") == 0)
|
||||||
|
{
|
||||||
if (rt_atomic_load(&now_direction) != 2)
|
if (rt_atomic_load(&now_direction) != 2)
|
||||||
rt_atomic_store(&now_direction, 0);
|
rt_atomic_store(&now_direction, 0);
|
||||||
|
char str[] = "forward";
|
||||||
|
rt_device_write(serial, 0, str, (sizeof(str) - 1));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// 左
|
// 左
|
||||||
if (rt_strcmp(tmp, "E8") == 0 || rt_strcmp(tmp, "99") == 0)
|
if (rt_strcmp(tmp, "E8") == 0 || rt_strcmp(tmp, "99") == 0)
|
||||||
|
{
|
||||||
if (rt_atomic_load(&now_direction) != 3)
|
if (rt_atomic_load(&now_direction) != 3)
|
||||||
rt_atomic_store(&now_direction, 1);
|
rt_atomic_store(&now_direction, 1);
|
||||||
|
char str[] = "left";
|
||||||
|
rt_device_write(serial, 0, str, (sizeof(str) - 1));
|
||||||
|
}
|
||||||
|
|
||||||
// 下
|
// 下
|
||||||
if (rt_strcmp(tmp, "B0") == 0 || rt_strcmp(tmp, "4B") == 0)
|
if (rt_strcmp(tmp, "B0") == 0 || rt_strcmp(tmp, "4B") == 0)
|
||||||
|
{
|
||||||
if (rt_atomic_load(&now_direction) != 0)
|
if (rt_atomic_load(&now_direction) != 0)
|
||||||
rt_atomic_store(&now_direction, 2);
|
rt_atomic_store(&now_direction, 2);
|
||||||
|
char str[] = "back";
|
||||||
|
rt_device_write(serial, 0, str, (sizeof(str) - 1));
|
||||||
|
}
|
||||||
|
|
||||||
// 右
|
// 右
|
||||||
if (rt_strcmp(tmp, "68") == 0 || rt_strcmp(tmp, "83") == 0)
|
if (rt_strcmp(tmp, "68") == 0 || rt_strcmp(tmp, "83") == 0)
|
||||||
|
{
|
||||||
if (rt_atomic_load(&now_direction) != 1)
|
if (rt_atomic_load(&now_direction) != 1)
|
||||||
rt_atomic_store(&now_direction, 3);
|
rt_atomic_store(&now_direction, 3);
|
||||||
|
char str[] = "right";
|
||||||
|
rt_device_write(serial, 0, str, (sizeof(str) - 1));
|
||||||
|
}
|
||||||
|
|
||||||
// 菜单(切换页面)
|
// 菜单(切换页面)
|
||||||
if (repeat == 0 && (rt_strcmp(tmp, "88") == 0 || rt_strcmp(tmp, "11") == 0))
|
if (repeat == 0 && (rt_strcmp(tmp, "88") == 0 || rt_strcmp(tmp, "11") == 0))
|
||||||
{
|
{
|
||||||
@ -58,7 +79,9 @@ void snake_compare(rt_uint8_t key, rt_uint8_t repeat)
|
|||||||
// 确认(暂停、页面冻结)
|
// 确认(暂停、页面冻结)
|
||||||
if (repeat == 0 && (rt_strcmp(tmp, "73") == 0||rt_strcmp(tmp, "FF") == 0))
|
if (repeat == 0 && (rt_strcmp(tmp, "73") == 0||rt_strcmp(tmp, "FF") == 0))
|
||||||
{
|
{
|
||||||
|
char str[] = "OK";
|
||||||
|
/* 发送字符串 */
|
||||||
|
rt_device_write(serial, 0, str, (sizeof(str) - 1));
|
||||||
if (page_chosen == 4&& page_stop == 0)
|
if (page_chosen == 4&& page_stop == 0)
|
||||||
{
|
{
|
||||||
// rt_event_send(&my_event, EVENT_MQTT_ENABLE);
|
// rt_event_send(&my_event, EVENT_MQTT_ENABLE);
|
||||||
|
@ -9,6 +9,8 @@
|
|||||||
#include <ap3216c.h>
|
#include <ap3216c.h>
|
||||||
#include <dfs_posix.h>
|
#include <dfs_posix.h>
|
||||||
#include <drv_lcd.h>
|
#include <drv_lcd.h>
|
||||||
|
#include "rtdevice.h"
|
||||||
|
// #include "serial_v2.h"
|
||||||
#include "mysnake.h"
|
#include "mysnake.h"
|
||||||
#include "infrared.h"
|
#include "infrared.h"
|
||||||
#include <ulog.h>
|
#include <ulog.h>
|
||||||
@ -401,7 +403,32 @@ void cdc_entry(void *parameter)
|
|||||||
rt_thread_mdelay(500);
|
rt_thread_mdelay(500);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/* 接收数据回调函数 */
|
||||||
|
static rt_err_t uart_input(rt_device_t dev, rt_size_t size)
|
||||||
|
{
|
||||||
|
/* 串口接收到数据后产生中断,调用此回调函数,然后发送接收信号量 */
|
||||||
|
rt_sem_release(&rx_sem);
|
||||||
|
|
||||||
|
return RT_EOK;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void serial_thread_entry(void *parameter)
|
||||||
|
{
|
||||||
|
char ch;
|
||||||
|
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
/* 从串口读取一个字节的数据,没有读取到则等待接收信号量 */
|
||||||
|
while (rt_device_read(serial, -1, &ch, 1) != 1)
|
||||||
|
{
|
||||||
|
/* 阻塞等待接收信号量,等到信号量后再次读取数据 */
|
||||||
|
rt_sem_take(&rx_sem, RT_WAITING_FOREVER);
|
||||||
|
}
|
||||||
|
/* 读取到的数据通过串口错位输出 */
|
||||||
|
ch = ch + 1;
|
||||||
|
rt_device_write(serial, 0, &ch, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -418,12 +445,28 @@ void ath_init(void)
|
|||||||
void serial_init(void)
|
void serial_init(void)
|
||||||
{
|
{
|
||||||
// 初始化设备
|
// 初始化设备
|
||||||
Dev = aht10_init(AHT10_I2C_BUS);
|
serial = rt_device_find("uart2");
|
||||||
if (Dev == RT_NULL)
|
if (Dev == RT_NULL)
|
||||||
{
|
{
|
||||||
rt_kprintf("AHT10_init Fail");
|
rt_kprintf("uart1 not find. Fail");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
struct serial_configure config = RT_SERIAL_CONFIG_DEFAULT; /* 初始化配置参数 */
|
||||||
|
|
||||||
|
config.baud_rate = BAUD_RATE_9600; // 修改波特率为 9600
|
||||||
|
config.data_bits = DATA_BITS_8; // 数据位 8
|
||||||
|
config.stop_bits = STOP_BITS_1; // 停止位 1
|
||||||
|
config.bufsz = 1024; // 修改缓冲区 buff size 为 128
|
||||||
|
config.parity = PARITY_NONE; // 无奇偶校验位
|
||||||
|
|
||||||
|
/* step3:控制串口设备。通过控制接口传入命令控制字,与控制参数 */
|
||||||
|
rt_device_control(serial, RT_DEVICE_CTRL_CONFIG, &config);
|
||||||
|
|
||||||
|
/* 以 DMA 接收及轮询发送方式打开串口设备 */
|
||||||
|
rt_device_open(serial, RT_DEVICE_FLAG_INT_RX);
|
||||||
|
char str[] = "hello RTT\r\n";
|
||||||
|
/* 发送字符串 */
|
||||||
|
rt_device_write(serial, 0, str, (sizeof(str) - 1));
|
||||||
}
|
}
|
||||||
void mqt_init(void)
|
void mqt_init(void)
|
||||||
{
|
{
|
||||||
@ -537,5 +580,7 @@ void my_project(void)
|
|||||||
cdc_init();
|
cdc_init();
|
||||||
|
|
||||||
tst_init(); // 不知道为什么不能在mqtt_init()之前,不然报错
|
tst_init(); // 不知道为什么不能在mqtt_init()之前,不然报错
|
||||||
|
|
||||||
|
serial_init();
|
||||||
}
|
}
|
||||||
MSH_CMD_EXPORT_ALIAS(my_project, myproject, run my project);
|
MSH_CMD_EXPORT_ALIAS(my_project, myproject, run my project);
|
@ -11,6 +11,8 @@
|
|||||||
#define KEY_DOWN GET_PIN(C, 1)
|
#define KEY_DOWN GET_PIN(C, 1)
|
||||||
#define KEY_LEFT GET_PIN(C, 0)
|
#define KEY_LEFT GET_PIN(C, 0)
|
||||||
#define KEY_RIGHT GET_PIN(C, 4)
|
#define KEY_RIGHT GET_PIN(C, 4)
|
||||||
|
|
||||||
|
|
||||||
extern rt_atomic_t now_direction ;
|
extern rt_atomic_t now_direction ;
|
||||||
extern rt_atomic_t snake_pressed ;
|
extern rt_atomic_t snake_pressed ;
|
||||||
extern int snake_max;
|
extern int snake_max;
|
||||||
|
@ -639,7 +639,6 @@
|
|||||||
#define BSP_USING_UART
|
#define BSP_USING_UART
|
||||||
#define BSP_USING_UART1
|
#define BSP_USING_UART1
|
||||||
#define BSP_USING_UART2
|
#define BSP_USING_UART2
|
||||||
#define BSP_UART2_RX_USING_DMA
|
|
||||||
#define BSP_USING_UART6
|
#define BSP_USING_UART6
|
||||||
#define BSP_USING_TIM
|
#define BSP_USING_TIM
|
||||||
#define BSP_USING_TIM11
|
#define BSP_USING_TIM11
|
||||||
|
Loading…
x
Reference in New Issue
Block a user