diff --git a/Tools/AP_Periph/AP_Periph.cpp b/Tools/AP_Periph/AP_Periph.cpp index 4d5cfdcbea155..85672d9d62f63 100644 --- a/Tools/AP_Periph/AP_Periph.cpp +++ b/Tools/AP_Periph/AP_Periph.cpp @@ -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); diff --git a/Tools/AP_Periph/AP_Periph.h b/Tools/AP_Periph/AP_Periph.h index 26468de8c1e6a..97c89cdd3b5b2 100644 --- a/Tools/AP_Periph/AP_Periph.h +++ b/Tools/AP_Periph/AP_Periph.h @@ -36,6 +36,7 @@ #include "rc_in.h" #include "batt_balance.h" #include "networking.h" +#include "serial_options.h" #include #if HAL_NMEA_OUTPUT_ENABLED && !(HAL_GCS_ENABLED && defined(HAL_PERIPH_ENABLE_GPS)) @@ -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; diff --git a/Tools/AP_Periph/Parameters.cpp b/Tools/AP_Periph/Parameters.cpp index 27c985a3bf621..2faf850167d59 100644 --- a/Tools/AP_Periph/Parameters.cpp +++ b/Tools/AP_Periph/Parameters.cpp @@ -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_ diff --git a/Tools/AP_Periph/Parameters.h b/Tools/AP_Periph/Parameters.h index ff64f16d1e950..9ff079217a22e 100644 --- a/Tools/AP_Periph/Parameters.h +++ b/Tools/AP_Periph/Parameters.h @@ -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; diff --git a/Tools/AP_Periph/serial_options.cpp b/Tools/AP_Periph/serial_options.cpp new file mode 100644 index 0000000000000..cc480eee5b7f7 --- /dev/null +++ b/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 . + */ +/* + serial options support, for serial over DroneCAN + */ + +#include "AP_Periph.h" + +#ifdef HAL_PERIPH_ENABLE_SERIAL_OPTIONS + +#include "serial_options.h" +#include + +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; iset_options(d.options); + uart->set_flow_control(AP_HAL::UARTDriver::flow_control(d.rtscts.get())); + } + } +} + +#endif // HAL_PERIPH_ENABLE_SERIAL_OPTIONS diff --git a/Tools/AP_Periph/serial_options.h b/Tools/AP_Periph/serial_options.h new file mode 100644 index 0000000000000..d71bdf4313811 --- /dev/null +++ b/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 diff --git a/Tools/AP_Periph/serial_options_dev.cpp b/Tools/AP_Periph/serial_options_dev.cpp new file mode 100644 index 0000000000000..26ba2bb137453 --- /dev/null +++ b/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 . + */ +/* + 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 + // @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)), + + AP_GROUPEND +}; + +#endif // HAL_PERIPH_ENABLE_SERIAL_OPTIONS diff --git a/Tools/ardupilotwaf/boards.py b/Tools/ardupilotwaf/boards.py index d785c6161b82d..2c9432d85eb65 100644 --- a/Tools/ardupilotwaf/boards.py +++ b/Tools/ardupilotwaf/boards.py @@ -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, diff --git a/Tools/bootloaders/MatekL431-Serial_bl.bin b/Tools/bootloaders/MatekL431-Serial_bl.bin new file mode 100755 index 0000000000000..80b78370907fa Binary files /dev/null and b/Tools/bootloaders/MatekL431-Serial_bl.bin differ diff --git a/libraries/AP_HAL_ChibiOS/hwdef/MatekL431-Serial/hwdef-bl.dat b/libraries/AP_HAL_ChibiOS/hwdef/MatekL431-Serial/hwdef-bl.dat new file mode 100644 index 0000000000000..b9005f84941a6 --- /dev/null +++ b/libraries/AP_HAL_ChibiOS/hwdef/MatekL431-Serial/hwdef-bl.dat @@ -0,0 +1,2 @@ +include ../MatekL431/hwdef-bl.inc + diff --git a/libraries/AP_HAL_ChibiOS/hwdef/MatekL431-Serial/hwdef.dat b/libraries/AP_HAL_ChibiOS/hwdef/MatekL431-Serial/hwdef.dat new file mode 100644 index 0000000000000..e9ace8923ddcb --- /dev/null +++ b/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 diff --git a/libraries/AP_HAL_ChibiOS/hwdef/scripts/defaults_periph.h b/libraries/AP_HAL_ChibiOS/hwdef/scripts/defaults_periph.h index 3a0a8c372330d..e0b0f894a666a 100644 --- a/libraries/AP_HAL_ChibiOS/hwdef/scripts/defaults_periph.h +++ b/libraries/AP_HAL_ChibiOS/hwdef/scripts/defaults_periph.h @@ -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 diff --git a/libraries/AP_SerialManager/AP_SerialManager.cpp b/libraries/AP_SerialManager/AP_SerialManager.cpp index 5b961da0722ea..24a694e2d074b 100644 --- a/libraries/AP_SerialManager/AP_SerialManager.cpp +++ b/libraries/AP_SerialManager/AP_SerialManager.cpp @@ -28,37 +28,6 @@ #include "AP_SerialManager.h" #include -#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 diff --git a/libraries/AP_SerialManager/AP_SerialManager_config.h b/libraries/AP_SerialManager/AP_SerialManager_config.h index 386d15dbfbc4e..88bf3ccaa3c7d 100644 --- a/libraries/AP_SerialManager/AP_SerialManager_config.h +++ b/libraries/AP_SerialManager/AP_SerialManager_config.h @@ -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