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

Add support for running IOMCU FW on CubeRedSecondary #29094

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
2c43289
modules: update ChibiOS
bugobliterator Jan 17, 2025
f1ddfcf
AP_HAL_ChibiOS: separate method for memory error on IOMCU FW
bugobliterator Jan 17, 2025
4d1722f
AP_HAL_ChibiOS: add support for IOMCU on Secondary
bugobliterator Jan 28, 2025
10f97de
AP_HAL_ChibiOS: add support for using hal serial as IOMCU Serial
bugobliterator Jan 28, 2025
38272df
AP_IOMCU: add support for new version of Bootloader
bugobliterator Jan 17, 2025
6134d07
AP_IOMCU: add support for custom uart options and iomcu flash size
bugobliterator Jan 17, 2025
4222d19
AP_IOMCU: add support for running IOFW on CubeRedSecondary
bugobliterator Jan 31, 2025
e2a939c
AP_HAL_ChibiOS: add CubeRedSecondary-IO hwdef.dat
bugobliterator Jan 17, 2025
c811808
AP_HAL_ChibiOS: fix CubeRedPrimary-PPPGW build
bugobliterator Jan 17, 2025
3eb1b6f
hwdef: add env variable to set IOMCU Heater feature
bugobliterator Jan 23, 2025
1b06686
AP_IOMCU: remove heater polarity setting for IOMCU without heater
bugobliterator Jan 23, 2025
bad025d
scripts: add cuberedsecondary-io build to IOFirmware build script
bugobliterator Jan 23, 2025
40238bd
AP_HAL_ChibiOS: use TRBUFF define instead of hardcoding
bugobliterator Jan 30, 2025
5e287a6
AP_Vehicle: set iomcu serialmanager protocol if iomcu is enabled
bugobliterator Jan 30, 2025
c18910b
AP_IOMCU: ignore call to shutdown if iomcu not initialised
bugobliterator Jan 31, 2025
78effbf
AP_SerialManager: add support for SerialProtocol_IOMCU
bugobliterator Jan 31, 2025
86414c1
AP_OSD: add option for IOMCU SerialProtocol
bugobliterator Jan 31, 2025
d67d2ce
IO_Firmware: add iofirmware_cubered
bugobliterator Jan 29, 2025
3ca947f
AP_HAL_ChibiOS: put tables for declination in external flash
bugobliterator Feb 2, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added Tools/IO_Firmware/iofirmware_cubered.bin
Binary file not shown.
5 changes: 5 additions & 0 deletions Tools/scripts/build_iofirmware.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,8 @@ def run_program(cmd_list):
'Tools/IO_Firmware/iofirmware_f103_8MHz_dshot_lowpolh.bin')
shutil.copy('build/iomcu-f103-8MHz-dshot/bin/iofirmware_highpolh.bin',
'Tools/IO_Firmware/iofirmware_f103_8MHz_dshot_highpolh.bin')

run_program(["./waf", "configure", "--board", 'CubeRedSecondary-IO'])
run_program(["./waf", "clean"])
run_program(["./waf", "iofirmware"])
shutil.copy('build/CubeRedSecondary-IO/bin/iofirmware.bin', 'Tools/IO_Firmware/iofirmware_cubered.bin')
8 changes: 8 additions & 0 deletions libraries/AP_HAL_ChibiOS/Scheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@ THD_WORKING_AREA(_monitor_thread_wa, MONITOR_THD_WA_SIZE);
#define AP_HAL_CHIBIOS_IN_EXPECTED_DELAY_WHEN_NOT_INITIALISED 1
#endif

#if defined(STM32H7) && defined(IOMCU_FW)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#if defined(STM32H7) && defined(IOMCU_FW)
#if AP_REBOOT_ON_MEMGUARD_ERROR

... and default it off and define to true in the hwdef.

void AP_memory_guard_error(uint16_t error);
void AP_memory_guard_error(uint16_t error) {
// simply fast reboot for now
hal.scheduler->reboot(false);
}
#endif

Scheduler::Scheduler()
{
}
Expand Down
4 changes: 2 additions & 2 deletions libraries/AP_HAL_ChibiOS/UARTDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ void UARTDriver::dma_rx_enable(void)
dmamode |= STM32_DMA_CR_CHSEL(sdef.dma_rx_channel_id);
dmamode |= STM32_DMA_CR_PL(0);
#if defined(STM32H7)
dmamode |= 1<<20; // TRBUFF See 2.3.1 in the H743 errata
dmamode |= DMA_SxCR_TRBUFF; // TRBUFF See 2.3.1 in the H743 errata
#endif
rx_bounce_idx ^= 1;
stm32_cacheBufferInvalidate(rx_bounce_buf[rx_bounce_idx], RX_BOUNCE_BUFSIZE);
Expand Down Expand Up @@ -901,7 +901,7 @@ void UARTDriver::write_pending_bytes_DMA(uint32_t n)
dmamode |= STM32_DMA_CR_CHSEL(sdef.dma_tx_channel_id);
dmamode |= STM32_DMA_CR_PL(0);
#if defined(STM32H7)
dmamode |= 1<<20; // TRBUFF See 2.3.1 in the H743 errata
dmamode |= DMA_SxCR_TRBUFF; // TRBUFF See 2.3.1 in the H743 errata
#endif
dmaStreamSetMode(txdma, dmamode | STM32_DMA_CR_DIR_M2P |
STM32_DMA_CR_MINC | STM32_DMA_CR_TCIE);
Expand Down
17 changes: 8 additions & 9 deletions libraries/AP_HAL_ChibiOS/Util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -658,14 +658,17 @@ void Util::uart_info(ExpandingString &str)
for (uint8_t i = 0; i < HAL_UART_NUM_SERIAL_PORTS; i++) {
auto *uart = hal.serial(i);
if (uart) {
str.printf("SERIAL%u ", i);
#if HAL_WITH_IO_MCU
if (i == HAL_UART_IOMCU_IDX) {
str.printf("IOMCU ");
} else
#endif
{
str.printf("SERIAL%u ", i);
}
uart->uart_info(str, sys_uart_stats.serial[i], dt_ms);
}
}
#if HAL_WITH_IO_MCU
str.printf("IOMCU ");
uart_io.uart_info(str, sys_uart_stats.io, dt_ms);
#endif
}

// Log UART message for each serial port
Expand All @@ -684,10 +687,6 @@ void Util::uart_log()
uart->log_stats(i, log_uart_stats.serial[i], dt_ms);
}
}
#if HAL_WITH_IO_MCU
// Use magic instance 100 for IOMCU
uart_io.log_stats(100, log_uart_stats.io, dt_ms);
#endif
}
#endif // HAL_LOGGING_ENABLED
#endif // HAL_UART_STATS_ENABLED
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ undef HAL_WITH_IO_MCU_BIDIR_DSHOT
undef COMPASS
undef BARO
undef DEFAULT_SERIAL7_PROTOCOL
undef IOMCU_UART

define AP_ADVANCEDFAILSAFE_ENABLED 0

Expand Down
9 changes: 9 additions & 0 deletions libraries/AP_HAL_ChibiOS/hwdef/CubeRedPrimary/hwdef.dat
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,16 @@ INT_FLASH_PRIMARY 1
define DEFAULT_SERIAL7_PROTOCOL SerialProtocol_PPP
define DEFAULT_SERIAL7_BAUD 8000000

IOMCU_UART UART7
define HAL_IOMCU_UART_OPTIONS 8

define AP_NETWORKING_DEFAULT_STATIC_IP_ADDR "192.168.144.100"
define AP_NETWORKING_DEFAULT_STATIC_NETMASK "255.255.255.0"
define AP_NETWORKING_DEFAULT_STATIC_GW_ADDR "192.168.144.11"
define AP_NETWORKING_BACKEND_PPP 1

ROMFS io_firmware.bin Tools/IO_Firmware/iofirmware_cubered.bin
define HAL_IOMCU_FW_FLASH_SIZE (0x200000 - 0x20000 - 0x40000)
define HAL_IOMCU_BOOTLOADER_BAUDRATE 2000000

DMA_NOSHARE SPI1* SPI2* SPI4* UART7*
170 changes: 170 additions & 0 deletions libraries/AP_HAL_ChibiOS/hwdef/CubeRedSecondary-IO/hwdef.dat
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
# hw definition file for processing by chibios_hwdef.py
# for H757

# MCU class and specific type
MCU STM32H7xx STM32H757xx

define CORE_CM7
define SMPS_PWR

env OPTIMIZE -O3

# crystal frequency
OSCILLATOR_HZ 24000000

# board ID for firmware load
APJ_BOARD_ID 1070

FLASH_SIZE_KB 2048

# bootloader is installed at zero offset
FLASH_RESERVE_START_KB 128

# the location where the bootloader will put the firmware
# the H743 has 128k sectors
FLASH_BOOTLOADER_LOAD_KB 128

define HAL_LED_ON 0

define IOMCU_FW TRUE
define AP_FASTBOOT_ENABLED 1
IOMCU_FW 1

define HAL_USE_RTC FALSE
define HAL_NO_UARTDRIVER TRUE
define HAL_LOGGING_ENABLED 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are these in here? These are the default for io firmware... (defaults_periph.h)

define AP_CRASHDUMP_ENABLED 0
define HAL_ENABLE_SAVE_PERSISTENT_PARAMS 0

define HAL_USE_EMPTY_STORAGE 1
define HAL_STORAGE_SIZE 16384

# avoid timer threads to save memory
define HAL_NO_TIMER_THREAD
define HAL_NO_RCOUT_THREAD # also disables LED thread

# ADC setup
PF11 FMU_SERVORAIL_VCC_SENS ADC1
PA6 RSSI_IN ADC1 SCALE(2)

define HAL_IOMCU_RSSI_ADC_CHANNEL 3

# CAN config
PB14 GPIOCAN2_TERM OUTPUT LOW
PC12 GPIOCAN1_SHUTDOWN OUTPUT HIGH
PF1 GPIOCAN2_SHUTDOWN OUTPUT HIGH

define HAL_CHIBIOS_ARCH_FMUV3 1

define BOARD_TYPE_DEFAULT 3

# RCIN
PC8 TIM8_CH3 TIM8 RCININT PULLDOWN

# SWD
PA13 JTMS-SWDIO SWD
PA14 JTCK-SWCLK SWD

# GPIO
PD10 AMBER_LED OUTPUT HIGH OPENDRAIN GPIO(0)
PE15 VDD_BRICK_nVALID INPUT PULLUP
PG0 VDD_BRICK2_nVALID INPUT PULLUP
PG5 VDD_SERVO_FAULT INPUT PULLUP
PG1 PWM_VOLT_SEL OUTPUT HIGH GPIO(3)

# Control of Spektrum power pin
PB2 SPEKTRUM_PWR_EN OUTPUT HIGH GPIO(73)
define HAL_GPIO_SPEKTRUM_PWR 73

# Spektrum Power is Active High
define HAL_SPEKTRUM_PWR_ENABLED 1


# Timer
PA8 TIM1_CH1 TIM1 PWM(1) GPIO(50)
PA9 TIM1_CH2 TIM1 PWM(2) GPIO(51)
PA10 TIM1_CH3 TIM1 PWM(3) GPIO(52)
PA11 TIM1_CH4 TIM1 PWM(4) GPIO(53)
PA5 TIM2_CH1 TIM2 PWM(5) GPIO(54)
PA1 TIM2_CH2 TIM2 PWM(6) GPIO(55)
PB10 TIM2_CH3 TIM2 PWM(7) GPIO(56)
PB11 TIM2_CH4 TIM2 PWM(8) GPIO(57)

# Correctly set Direction of PWMs
# if UNIDIR is set then BIDIR must be reset
PA7 HP_UNIDIR_ENABLED OUTPUT HIGH GPIO(5)


# UART connected to FMU, uses DMA
PE7 UART7_RX UART7 SPEED_VERYLOW
PE8 UART7_TX UART7 SPEED_VERYLOW

# UART for SBUS out
PC7 USART6_RX USART6 SPEED_HIGH LOW
PC6 USART6_TX USART6

# UART for DSM input
# TX side is for IO debug, and is unused
PC10 USART3_TX USART3 SPEED_HIGH
PC11 USART3_RX USART3 SPEED_HIGH

# UART for debug
PE1 UART8_TX UART8
PE0 UART8_RX UART8

# UART for RCIN
PD1 UART4_TX UART4

# USART for future use
PD5 USART2_TX USART2 SPEED_HIGH
PD6 USART2_RX USART2 SPEED_HIGH
PD4 USART2_RTS USART2 SPEED_HIGH
PD3 USART2_CTS USART2 SPEED_HIGH

# order of UARTs
SERIAL_ORDER EMPTY EMPTY EMPTY EMPTY

define HAL_USE_UART TRUE
define STM32_UART_USE_UART7 TRUE
define HAL_IO_FMU_COMMS UARTD7
define HAL_IO_FMU_COMMS_TX_DMA_STREAM STM32_UART_UART7_TX_DMA_STREAM
define HAL_IO_FMU_COMMS_TX_DMA_CHANNEL STM32_UART_UART7_TX_DMA_CHAN
define HAL_IO_FMU_COMMS_TX_IRQ_PRIORITY STM32_UART_UART7_IRQ_PRIORITY
define HAL_IO_FMU_COMMS_RX_DMA_STREAM STM32_UART_UART7_RX_DMA_STREAM
define HAL_IO_FMU_COMMS_RX_DMA_CHANNEL STM32_UART_UART7_RX_DMA_CHAN

define HAL_USE_SERIAL TRUE
define STM32_SERIAL_USE_UART7 FALSE
define STM32_SERIAL_USE_UART4 TRUE
define STM32_SERIAL_USE_USART3 TRUE
define STM32_SERIAL_USE_USART6 TRUE

define HAL_IOMCU_RCIN_SERIAL_DRIVER SD4
define HAL_IOMCU_DSM_SERIAL_DRIVER SD3
define HAL_IOMCU_SBUS_OUT_SERIAL_DRIVER SD6
define HAL_GPIO_PIN_SPEKTRUM_OUT PAL_LINE(GPIOC,11U)


define AP_NETWORKING_BACKEND_PPP 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is odd?


# only use pulse input for PPM, other protocols
# are on serial
define HAL_RCIN_PULSE_PPM_ONLY


define HAL_DSHOT_ENABLED TRUE
define HAL_IOMCU_SEPARATE_SBUS_OUT_RCIN 1


PC4 SAFETY_INPUT INPUT PULLDOWN
PE3 SAFETY_LED OUTPUT HIGH OPENDRAIN

define HAL_IOMCU_APP_SIZE_MAX (0x200000 - 0x20000 - 0x40000)
define HAL_IOMCU_APP_LOAD_ADDRESS 0x08020000

define IOMCU_DEBUG SD8
define STM32_SERIAL_USE_UART8 TRUE
define HAL_BL_IOMCU_FW_DETECT 1

define AP_HAL_UARTDRIVER_ENABLED 0
define HAL_SERIAL_SBUS_SWAPPED 1
1 change: 1 addition & 0 deletions libraries/AP_HAL_ChibiOS/hwdef/common/common_mixf.ld
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ SECTIONS
*(.ap_romfs*)
/* moving GCS_MAVLink to ext_flash */
lib/lib*.a:GCS*.*(.text* .rodata*)
lib/lib*.a:tables.*(.text* .rodata*) /* tables for AP_Declination */
*(.extflash)
} > ext_flash

Expand Down
24 changes: 17 additions & 7 deletions libraries/AP_HAL_ChibiOS/hwdef/scripts/chibios_hwdef.py
Original file line number Diff line number Diff line change
Expand Up @@ -1052,6 +1052,12 @@ def write_mcu_config(self, f):
else:
self.env_vars['IOMCU_FW'] = 0

# check if heater pin defined
if 'HEATER' in self.bylabel.keys():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we already handle not having a heater with the HEATER_SET() macro, why also handle it at the build level?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is needed to disable multiple builds for highpol and lowpol heaters. With hwdef without Heaters we were still doing that.

self.env_vars['IOMCU_FW_WITH_HEATER'] = 1
else:
self.env_vars['IOMCU_FW_WITH_HEATER'] = 0

if self.get_config('PERIPH_FW', required=False):
self.env_vars['PERIPH_FW'] = self.get_config('PERIPH_FW')
else:
Expand Down Expand Up @@ -1866,6 +1872,8 @@ def get_extra_bylabel(self, label, name, default=None):
def write_UART_config(self, f):
'''write UART config defines'''
serial_list = self.get_config('SERIAL_ORDER', required=False, aslist=True)
if 'IOMCU_UART' in self.config and self.config['IOMCU_UART'][0] not in serial_list:
serial_list.append(self.config['IOMCU_UART'][0])
if serial_list is None:
return
while len(serial_list) < 3: # enough ports for CrashCatcher UART discovery
Expand Down Expand Up @@ -1903,11 +1911,15 @@ def write_UART_config(self, f):
self.error("Need io_firmware.bin in ROMFS for IOMCU")

self.write_defaulting_define(f, 'HAL_WITH_IO_MCU', 1)
f.write('#define HAL_UART_IOMCU_IDX %u\n' % len(serial_list))
f.write(
'#define HAL_UART_IO_DRIVER ChibiOS::UARTDriver uart_io(HAL_UART_IOMCU_IDX)\n'
)
serial_list.append(self.config['IOMCU_UART'][0])

if self.config['IOMCU_UART'][0]:
# get index of serial port in serial_list
index = serial_list.index(self.config['IOMCU_UART'][0])
f.write('#define HAL_UART_IOMCU_IDX %u\n' % int(index))
f.write(
'#define HAL_UART_IO_DRIVER constexpr ChibiOS::UARTDriver &uart_io = serial%sDriver;\n' % (index)
)

f.write('#define HAL_HAVE_SERVO_VOLTAGE 1\n') # make the assumption that IO gurantees servo monitoring
# all IOMCU capable boards have SBUS out
f.write('#define AP_FEATURE_SBUS_OUT 1\n')
Expand Down Expand Up @@ -2054,8 +2066,6 @@ def get_RTS_alt_function():
#endif
''')
num_ports = len(devlist)
if 'IOMCU_UART' in self.config:
num_ports -= 1
if num_ports > 10:
self.error("Exceeded max num SERIALs of 10 (%u)" % num_ports)
f.write('#define HAL_UART_NUM_SERIAL_PORTS %u\n' % num_ports)
Expand Down
14 changes: 13 additions & 1 deletion libraries/AP_IOMCU/AP_IOMCU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <AP_Arming/AP_Arming.h>
#include <AP_BLHeli/AP_BLHeli.h>
#include <ch.h>
#include <AP_SerialManager/AP_SerialManager.h>

extern const AP_HAL::HAL &hal;

Expand Down Expand Up @@ -78,6 +79,9 @@ void AP_IOMCU::init(void)
{
// uart runs at 1.5MBit
uart.begin(1500*1000, 128, 128);
#ifdef HAL_IOMCU_UART_OPTIONS
uart.set_options(HAL_IOMCU_UART_OPTIONS);
#endif
uart.set_unbuffered_writes(true);

#if IOMCU_DEBUG_ENABLE
Expand Down Expand Up @@ -1092,10 +1096,14 @@ void AP_IOMCU::send_rc_protocols()
/*
check ROMFS firmware against CRC on IOMCU, and if incorrect then upload new firmware
*/
#ifndef HAL_IOMCU_FW_FLASH_SIZE
#define HAL_IOMCU_FW_FLASH_SIZE (0x10000 - 0x1000)
#endif

bool AP_IOMCU::check_crc(void)
{
// flash size minus 4k bootloader
const uint32_t flash_size = 0x10000 - 0x1000;
const uint32_t flash_size = HAL_IOMCU_FW_FLASH_SIZE;
const char *path = AP_BoardConfig::io_dshot() ? dshot_fw_name : fw_name;

fw = AP_ROMFS::find_decompress(path, fw_size);
Expand Down Expand Up @@ -1188,6 +1196,10 @@ bool AP_IOMCU::healthy(void)
*/
void AP_IOMCU::shutdown(void)
{
if (!initialised) {
// we're not initialised yet, so cannot shutdown
return;
}
do_shutdown = true;
while (!done_shutdown) {
hal.scheduler->delay(1);
Expand Down
Loading
Loading