Skip to content

Commit 6a3c575

Browse files
authored
Merge pull request #3990 from thread-liu/develop
[update] openamp driver and add rs485 driver
2 parents 9cd3897 + d2d6fc4 commit 6a3c575

File tree

6 files changed

+167
-10
lines changed

6 files changed

+167
-10
lines changed

bsp/stm32/stm32mp157a-st-discovery/board/Kconfig

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,24 @@ menu "Onboard Peripheral Drivers"
3535

3636
config BSP_USING_OPENAMP
3737
bool "Enable OpenAMP"
38-
select RT_USING_OPENAMP
3938
default n
4039

40+
menuconfig BSP_USING_RS485
41+
bool "Enable RS485 "
42+
default n
43+
if BSP_USING_RS485
44+
comment "set rts pin number "
45+
config BSP_RS485_RTS_PIN
46+
int "RS485 rts pin number"
47+
range 1 176
48+
default 5
49+
50+
config RS485_UART_DEVICE_NAME
51+
string "the uart name for rs485"
52+
default "uart3"
53+
54+
endif
55+
4156
endmenu
4257

4358
menu "On-chip Peripheral Drivers"
@@ -59,12 +74,10 @@ menu "On-chip Peripheral Drivers"
5974
config BSP_USING_UART3
6075
bool "Enable UART3"
6176
default y
62-
6377
config BSP_UART3_RX_USING_DMA
6478
bool "Enable UART3 RX DMA"
65-
depends on BSP_USING_UART4 && RT_SERIAL_USING_DMA
79+
depends on BSP_USING_UART3 && RT_SERIAL_USING_DMA
6680
default n
67-
6881
config BSP_UART3_TX_USING_DMA
6982
bool "Enable UART3 TX DMA"
7083
depends on BSP_USING_UART3 && RT_SERIAL_USING_DMA
@@ -73,12 +86,10 @@ menu "On-chip Peripheral Drivers"
7386
config BSP_USING_UART4
7487
bool "Enable UART4"
7588
default y
76-
7789
config BSP_UART4_RX_USING_DMA
7890
bool "Enable UART4 RX DMA"
7991
depends on BSP_USING_UART4 && RT_SERIAL_USING_DMA
8092
default n
81-
8293
config BSP_UART4_TX_USING_DMA
8394
bool "Enable UART4 TX DMA"
8495
depends on BSP_USING_UART4 && RT_SERIAL_USING_DMA

bsp/stm32/stm32mp157a-st-discovery/board/SConscript

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ if GetDepend(['BSP_USING_TIM14']):
3737
if GetDepend(['BSP_USING_PMIC']):
3838
src += Glob('ports/drv_pmic.c')
3939

40+
if GetDepend(['BSP_USING_RS485']):
41+
src += Glob('ports/drv_rs485.c')
42+
4043
if GetDepend(['BSP_USING_OPENAMP']):
4144
src += Glob('CubeMX_Config/CM4/Src/ipcc.c')
4245
src += Glob('CubeMX_Config/CM4/Src/openamp.c')

bsp/stm32/stm32mp157a-st-discovery/board/ports/OpenAMP/drv_openamp.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#ifdef BSP_USING_OPENAMP
1414

15+
#include <finsh.h>
1516
#include <drv_openamp.h>
1617
#include <openamp.h>
1718
#include <virt_uart.h>
@@ -234,6 +235,11 @@ int rt_hw_openamp_init(void)
234235
openamp_init();
235236

236237
rt_hw_openamp_register(&dev_openamp, "openamp", 0, NULL);
238+
239+
if (RT_CONSOLE_DEVICE_NAME == "openamp")
240+
{
241+
rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
242+
}
237243

238244
return RT_EOK;
239245
}

bsp/stm32/stm32mp157a-st-discovery/board/ports/drv_rcc.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
*/
1010

1111
#include "board.h"
12+
1213
//#define DRV_DEBUG
1314
#define LOG_TAG "drv.rcc"
1415
#include <drv_log.h>
@@ -17,12 +18,12 @@
1718

1819
static void enable_clock(void)
1920
{
20-
__HAL_RCC_GPIOD_CLK_ENABLE();
21+
__HAL_RCC_GPIOH_CLK_ENABLE();
2122
}
2223

2324
static void disable_clock(void)
2425
{
25-
__HAL_RCC_GPIOD_CLK_DISABLE();
26+
__HAL_RCC_GPIOH_CLK_DISABLE();
2627
}
2728

2829
static int rcc_sample(int argc, char *argv[])
@@ -47,8 +48,8 @@ static int rcc_sample(int argc, char *argv[])
4748
_exit:
4849
{
4950
rt_kprintf("Usage:\n");
50-
rt_kprintf("rcc_sample enable - enable GPIOD clock, the LD8 will blink '\n");
51-
rt_kprintf("rcc_sample disable - disable GPIOD clock, the LD8 will stop blink'\n");
51+
rt_kprintf("rcc_sample enable - enable GPIOH clock, the LD7 will blink '\n");
52+
rt_kprintf("rcc_sample disable - disable GPIOH clock, the LD7 will stop blink'\n");
5253
}
5354

5455
return -RT_ERROR;
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
/*
2+
* Copyright (c) 2006-2022, RT-Thread Development Team
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Change Logs:
7+
* Date Author Notes
8+
* 2020-10-24 thread-liu first version
9+
*/
10+
11+
#include <board.h>
12+
#include "drv_rs485.h"
13+
14+
#ifdef BSP_USING_RS485
15+
16+
#define RS485_OUT rt_pin_write(BSP_RS485_RTS_PIN, PIN_HIGH)
17+
#define RS485_IN rt_pin_write(BSP_RS485_RTS_PIN, PIN_LOW)
18+
19+
static rt_device_t serial = {0};
20+
static struct rt_semaphore rx_sem = {0};
21+
22+
/* uart send data callback function */
23+
static rt_err_t rs485_output(rt_device_t dev, void * buffer)
24+
{
25+
return RT_EOK;
26+
}
27+
28+
/* uart receive data callback function */
29+
static rt_err_t rs485_input(rt_device_t dev, rt_size_t size)
30+
{
31+
rt_sem_release(&rx_sem);
32+
33+
return RT_EOK;
34+
}
35+
36+
/* send string */
37+
int rs485_send_data(char *tbuf, rt_uint16_t t_len)
38+
{
39+
/* change rs485 mode */
40+
RS485_OUT;
41+
42+
/* send data */
43+
rt_device_write(serial, 0, tbuf, t_len);
44+
45+
/* change rs485 mode */
46+
RS485_IN;
47+
48+
return RT_EOK;
49+
}
50+
51+
static void rs485_thread_entry(void *parameter)
52+
{
53+
char ch;
54+
55+
while (1)
56+
{
57+
/* A byte of data is read from a serial port, and if it is not read, it waits for the received semaphore */
58+
while (rt_device_read(serial, -1, &ch, 1) != 1)
59+
{
60+
rt_sem_take(&rx_sem, RT_WAITING_FOREVER);
61+
}
62+
63+
/* The data read through the serial port output dislocation */
64+
ch = ch + 1;
65+
66+
/* send char */
67+
rs485_send_data(&ch, 1);
68+
}
69+
}
70+
71+
/* rs485 rts pin init */
72+
static int rs485_init(void)
73+
{
74+
/* find uart device */
75+
serial = rt_device_find(RS485_UART_DEVICE_NAME);
76+
if (!serial)
77+
{
78+
rt_kprintf("find %s failed!\n", RS485_UART_DEVICE_NAME);
79+
return RT_ERROR;
80+
}
81+
82+
rt_device_open(serial, RT_DEVICE_FLAG_INT_RX);
83+
84+
/* set receive data callback function */
85+
rt_device_set_rx_indicate(serial, rs485_input);
86+
87+
/* set the send completion callback function */
88+
rt_device_set_tx_complete(serial, rs485_output);
89+
90+
rt_pin_mode(BSP_RS485_RTS_PIN, PIN_MODE_OUTPUT);
91+
92+
RS485_IN;
93+
94+
rt_sem_init(&rx_sem, "rx_sem", 0, RT_IPC_FLAG_FIFO);
95+
/* create rs485 thread */
96+
rt_thread_t thread = rt_thread_create("rs485", rs485_thread_entry, RT_NULL, 1024, 25, 10);
97+
98+
if (thread != RT_NULL)
99+
{
100+
rt_thread_startup(thread);
101+
}
102+
else
103+
{
104+
return RT_ERROR;
105+
}
106+
107+
return RT_EOK;
108+
}
109+
INIT_DEVICE_EXPORT(rs485_init);
110+
111+
#endif /* bsp_using_RS485 */
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Copyright (c) 2006-2022, RT-Thread Development Team
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Change Logs:
7+
* Date Author Notes
8+
* 2020-10-24 thread-liu first version
9+
*/
10+
11+
#ifndef __DRV_RS485_H__
12+
#define __DRV_RS485_H__
13+
14+
#ifdef __cplusplus
15+
extern "C" {
16+
#endif
17+
18+
#define RS485_SEND_MODE 0
19+
#define RS485_RECV_MODE 1
20+
21+
#ifdef __cplusplus
22+
}
23+
#endif
24+
25+
#endif /* drv_rs485.h */

0 commit comments

Comments
 (0)