Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AP_Periph: added serial options support #25805

Merged
merged 5 commits into from Dec 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions Tools/AP_Periph/AP_Periph.cpp
Expand Up @@ -140,6 +140,10 @@ void AP_Periph_FW::init()
node_stats.init();
#endif

#ifdef HAL_PERIPH_ENABLE_SERIAL_OPTIONS
serial_options.init();
#endif

#ifdef HAL_PERIPH_ENABLE_GPS
if (gps.get_type(0) != AP_GPS::GPS_Type::GPS_TYPE_NONE && g.gps_port >= 0) {
serial_manager.set_protocol_and_baud(g.gps_port, AP_SerialManager::SerialProtocol_GPS, AP_SERIALMANAGER_GPS_BAUD);
Expand Down
5 changes: 5 additions & 0 deletions Tools/AP_Periph/AP_Periph.h
Expand Up @@ -36,6 +36,7 @@
#include "rc_in.h"
#include "batt_balance.h"
#include "networking.h"
#include "serial_options.h"

#include <AP_NMEA_Output/AP_NMEA_Output.h>
#if HAL_NMEA_OUTPUT_ENABLED && !(HAL_GCS_ENABLED && defined(HAL_PERIPH_ENABLE_GPS))
Expand Down Expand Up @@ -331,6 +332,10 @@ class AP_Periph_FW {
void batt_balance_update();
BattBalance battery_balance;
#endif

#ifdef HAL_PERIPH_ENABLE_SERIAL_OPTIONS
SerialOptions serial_options;
#endif

#if AP_TEMPERATURE_SENSOR_ENABLED
AP_TemperatureSensor temperature_sensor;
Expand Down
6 changes: 6 additions & 0 deletions Tools/AP_Periph/Parameters.cpp
Expand Up @@ -610,6 +610,12 @@ const AP_Param::Info AP_Periph_FW::var_info[] = {
GOBJECT(battery_balance, "BAL", BattBalance),
#endif

#ifdef HAL_PERIPH_ENABLE_SERIAL_OPTIONS
// @Group: UART
// @Path: serial_options.cpp
GOBJECT(serial_options, "UART", SerialOptions),
#endif

// NOTE: sim parameters should go last
#if AP_SIM_ENABLED
// @Group: SIM_
Expand Down
1 change: 1 addition & 0 deletions Tools/AP_Periph/Parameters.h
Expand Up @@ -88,6 +88,7 @@ class Parameters {
k_param_can_terminate0,
k_param_can_terminate1,
k_param_can_terminate2,
k_param_serial_options,
};

AP_Int16 format_version;
Expand Down
110 changes: 110 additions & 0 deletions Tools/AP_Periph/serial_options.cpp
@@ -0,0 +1,110 @@
/*
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*
serial options support, for serial over DroneCAN
*/

#include "AP_Periph.h"

#ifdef HAL_PERIPH_ENABLE_SERIAL_OPTIONS

#include "serial_options.h"
#include <AP_SerialManager/AP_SerialManager_config.h>

extern const AP_HAL::HAL &hal;

const AP_Param::GroupInfo SerialOptions::var_info[] {

#if HAL_HAVE_SERIAL0
// @Group: 0_
// @Path: serial_options_dev.cpp
AP_SUBGROUPINFO(devs[0], "0_", 1, SerialOptions, SerialOptionsDev),
#endif

#if HAL_HAVE_SERIAL1
// @Group: 1_
// @Path: serial_options_dev.cpp
AP_SUBGROUPINFO(devs[1], "1_", 2, SerialOptions, SerialOptionsDev),
#endif

#if HAL_HAVE_SERIAL2
// @Group: 2_
// @Path: serial_options_dev.cpp
AP_SUBGROUPINFO(devs[2], "2_", 3, SerialOptions, SerialOptionsDev),
#endif

#if HAL_HAVE_SERIAL3
// @Group: 3_
// @Path: serial_options_dev.cpp
AP_SUBGROUPINFO(devs[3], "3_", 4, SerialOptions, SerialOptionsDev),
#endif

#if HAL_HAVE_SERIAL4
// @Group: 4_
// @Path: serial_options_dev.cpp
AP_SUBGROUPINFO(devs[4], "4_", 5, SerialOptions, SerialOptionsDev),
#endif

#if HAL_HAVE_SERIAL5
// @Group: 5_
// @Path: serial_options_dev.cpp
AP_SUBGROUPINFO(devs[5], "5_", 6, SerialOptions, SerialOptionsDev),
#endif

#if HAL_HAVE_SERIAL6
// @Group: 6_
// @Path: serial_options_dev.cpp
AP_SUBGROUPINFO(devs[6], "6_", 7, SerialOptions, SerialOptionsDev),
#endif

#if HAL_HAVE_SERIAL7
// @Group: 7_
// @Path: serial_options_dev.cpp
AP_SUBGROUPINFO(devs[7], "7_", 8, SerialOptions, SerialOptionsDev),
#endif

#if HAL_HAVE_SERIAL8
// @Group: 8_
// @Path: serial_options_dev.cpp
AP_SUBGROUPINFO(devs[8], "8_", 9, SerialOptions, SerialOptionsDev),
#endif

#if HAL_HAVE_SERIAL9
// @Group: 9_
// @Path: serial_options_dev.cpp
AP_SUBGROUPINFO(devs[9], "9_", 10, SerialOptions, SerialOptionsDev),
#endif

AP_GROUPEND
};

SerialOptions::SerialOptions(void)
{
AP_Param::setup_object_defaults(this, var_info);
}

void SerialOptions::init(void)
{
for (uint8_t i=0; i<ARRAY_SIZE(devs); i++) {
auto *uart = hal.serial(i);
if (uart != nullptr) {
auto &d = devs[i];
uart->set_options(d.options);
uart->set_flow_control(AP_HAL::UARTDriver::flow_control(d.rtscts.get()));
}
}
}

#endif // HAL_PERIPH_ENABLE_SERIAL_OPTIONS
30 changes: 30 additions & 0 deletions Tools/AP_Periph/serial_options.h
@@ -0,0 +1,30 @@
#pragma once

#ifdef HAL_PERIPH_ENABLE_SERIAL_OPTIONS

#ifndef HAL_UART_NUM_SERIAL_PORTS
#define HAL_UART_NUM_SERIAL_PORTS AP_HAL::HAL::num_serial
#endif

class SerialOptionsDev {
public:
SerialOptionsDev(void);
static const struct AP_Param::GroupInfo var_info[];
AP_Int32 options;
AP_Int8 rtscts;
};

class SerialOptions {
public:
friend class AP_Periph_FW;
SerialOptions(void);
void init(void);

static const struct AP_Param::GroupInfo var_info[];

private:
SerialOptionsDev devs[HAL_UART_NUM_SERIAL_PORTS];
};


#endif // HAL_PERIPH_ENABLE_SERIAL_OPTIONS
47 changes: 47 additions & 0 deletions Tools/AP_Periph/serial_options_dev.cpp
@@ -0,0 +1,47 @@
/*
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*
serial options support, for serial over DroneCAN
*/

#include "AP_Periph.h"

#ifdef HAL_PERIPH_ENABLE_SERIAL_OPTIONS

#include "serial_options.h"

SerialOptionsDev::SerialOptionsDev(void)
{
AP_Param::setup_object_defaults(this, var_info);
}

const AP_Param::GroupInfo SerialOptionsDev::var_info[] {

// @Param: OPTIONS
// @DisplayName: Serial options
// @Description: Control over UART options. The InvertRX option controls invert of the receive pin. The InvertTX option controls invert of the transmit pin. The HalfDuplex option controls half-duplex (onewire) mode, where both transmit and receive is done on the transmit wire. The Swap option allows the RX and TX pins to be swapped on STM32F7 based boards.
// @Bitmask: 0:InvertRX, 1:InvertTX, 2:HalfDuplex, 3:SwapTXRX, 4: RX_PullDown, 5: RX_PullUp, 6: TX_PullDown, 7: TX_PullUp, 8: RX_NoDMA, 9: TX_NoDMA, 10: Don't forward mavlink to/from, 11: DisableFIFO, 12: Ignore Streamrate
AP_GROUPINFO("OPTIONS", 1, SerialOptionsDev, options, 0),

// @Param: RTSCTS
tridge marked this conversation as resolved.
Show resolved Hide resolved
// @DisplayName: Serial1 flow control
// @Description: Enable flow control. You must have the RTS and CTS pins available on the port. If this is set to 2 then flow control will be auto-detected by checking for the output buffer filling on startup.
// @Values: 0:Disabled,1:Enabled,2:Auto
AP_GROUPINFO("RTSCTS", 2, SerialOptionsDev, rtscts, float(AP_HAL::UARTDriver::FLOW_CONTROL_DISABLE)),
tridge marked this conversation as resolved.
Show resolved Hide resolved

AP_GROUPEND
};

#endif // HAL_PERIPH_ENABLE_SERIAL_OPTIONS
1 change: 1 addition & 0 deletions Tools/ardupilotwaf/boards.py
Expand Up @@ -849,6 +849,7 @@ def configure_env(self, cfg, env):
HAL_PERIPH_ENABLE_RPM = 1,
HAL_PERIPH_ENABLE_RC_OUT = 1,
HAL_PERIPH_ENABLE_ADSB = 1,
HAL_PERIPH_ENABLE_SERIAL_OPTIONS = 1,
AP_ICENGINE_ENABLED = 0,
AP_AIRSPEED_ENABLED = 1,
AP_AIRSPEED_AUTOCAL_ENABLE = 0,
Expand Down
Binary file added Tools/bootloaders/MatekL431-Serial_bl.bin
Binary file not shown.
2 changes: 2 additions & 0 deletions libraries/AP_HAL_ChibiOS/hwdef/MatekL431-Serial/hwdef-bl.dat
@@ -0,0 +1,2 @@
include ../MatekL431/hwdef-bl.inc

19 changes: 19 additions & 0 deletions libraries/AP_HAL_ChibiOS/hwdef/MatekL431-Serial/hwdef.dat
@@ -0,0 +1,19 @@
include ../MatekL431/hwdef.inc

define HAL_PERIPH_ENABLE_SERIAL_OPTIONS

# enable serial3 port with DMA
undef PB10
undef PB11
PB10 USART3_TX USART3 SPEED_HIGH
PB11 USART3_RX USART3 SPEED_HIGH

# larger CAN pool for faster serial
undef HAL_CAN_POOL_SIZE
define HAL_CAN_POOL_SIZE 12000

define HAL_USE_ADC FALSE

# make the UARTn numbers in parameters match the silkscreen
undef SERIAL_ORDER
SERIAL_ORDER EMPTY USART1 USART2 USART3
2 changes: 1 addition & 1 deletion libraries/AP_HAL_ChibiOS/hwdef/scripts/defaults_periph.h
Expand Up @@ -335,7 +335,7 @@
#endif

#ifndef AP_UART_MONITOR_ENABLED
#define AP_UART_MONITOR_ENABLED defined(HAL_PERIPH_ENABLE_GPS) && (GPS_MOVING_BASELINE || BOARD_FLASH_SIZE>=256)
#define AP_UART_MONITOR_ENABLED defined(HAL_PERIPH_ENABLE_SERIAL_OPTIONS) || (defined(HAL_PERIPH_ENABLE_GPS) && (GPS_MOVING_BASELINE || BOARD_FLASH_SIZE>=256))
#endif

#ifndef HAL_BOARD_LOG_DIRECTORY
Expand Down
31 changes: 0 additions & 31 deletions libraries/AP_SerialManager/AP_SerialManager.cpp
Expand Up @@ -28,37 +28,6 @@
#include "AP_SerialManager.h"
#include <GCS_MAVLink/GCS.h>

#ifndef HAL_HAVE_SERIAL0
#define HAL_HAVE_SERIAL0 HAL_NUM_SERIAL_PORTS > 0
#endif
#ifndef HAL_HAVE_SERIAL1
#define HAL_HAVE_SERIAL1 HAL_NUM_SERIAL_PORTS > 1
#endif
#ifndef HAL_HAVE_SERIAL2
#define HAL_HAVE_SERIAL2 HAL_NUM_SERIAL_PORTS > 2
#endif
#ifndef HAL_HAVE_SERIAL3
#define HAL_HAVE_SERIAL3 HAL_NUM_SERIAL_PORTS > 3
#endif
#ifndef HAL_HAVE_SERIAL4
#define HAL_HAVE_SERIAL4 HAL_NUM_SERIAL_PORTS > 4
#endif
#ifndef HAL_HAVE_SERIAL5
#define HAL_HAVE_SERIAL5 HAL_NUM_SERIAL_PORTS > 5
#endif
#ifndef HAL_HAVE_SERIAL6
#define HAL_HAVE_SERIAL6 HAL_NUM_SERIAL_PORTS > 6
#endif
#ifndef HAL_HAVE_SERIAL7
#define HAL_HAVE_SERIAL7 HAL_NUM_SERIAL_PORTS > 7
#endif
#ifndef HAL_HAVE_SERIAL8
#define HAL_HAVE_SERIAL8 HAL_NUM_SERIAL_PORTS > 8
#endif
#ifndef HAL_HAVE_SERIAL9
#define HAL_HAVE_SERIAL9 HAL_NUM_SERIAL_PORTS > 9
#endif

extern const AP_HAL::HAL& hal;

#ifndef DEFAULT_SERIAL0_PROTOCOL
Expand Down
31 changes: 31 additions & 0 deletions libraries/AP_SerialManager/AP_SerialManager_config.h
Expand Up @@ -136,3 +136,34 @@
#define AP_SERIALMANAGER_IMUOUT_BAUD 921600
#define AP_SERIALMANAGER_IMUOUT_BUFSIZE_RX 128
#define AP_SERIALMANAGER_IMUOUT_BUFSIZE_TX 2048

#ifndef HAL_HAVE_SERIAL0
#define HAL_HAVE_SERIAL0 HAL_NUM_SERIAL_PORTS > 0
#endif
#ifndef HAL_HAVE_SERIAL1
#define HAL_HAVE_SERIAL1 HAL_NUM_SERIAL_PORTS > 1
#endif
#ifndef HAL_HAVE_SERIAL2
#define HAL_HAVE_SERIAL2 HAL_NUM_SERIAL_PORTS > 2
#endif
#ifndef HAL_HAVE_SERIAL3
#define HAL_HAVE_SERIAL3 HAL_NUM_SERIAL_PORTS > 3
#endif
#ifndef HAL_HAVE_SERIAL4
#define HAL_HAVE_SERIAL4 HAL_NUM_SERIAL_PORTS > 4
#endif
#ifndef HAL_HAVE_SERIAL5
#define HAL_HAVE_SERIAL5 HAL_NUM_SERIAL_PORTS > 5
#endif
#ifndef HAL_HAVE_SERIAL6
#define HAL_HAVE_SERIAL6 HAL_NUM_SERIAL_PORTS > 6
#endif
#ifndef HAL_HAVE_SERIAL7
#define HAL_HAVE_SERIAL7 HAL_NUM_SERIAL_PORTS > 7
#endif
#ifndef HAL_HAVE_SERIAL8
#define HAL_HAVE_SERIAL8 HAL_NUM_SERIAL_PORTS > 8
#endif
#ifndef HAL_HAVE_SERIAL9
#define HAL_HAVE_SERIAL9 HAL_NUM_SERIAL_PORTS > 9
#endif