From 266d4573b79802e5ad67b5558ace089417c64106 Mon Sep 17 00:00:00 2001 From: Shane Smiskol Date: Mon, 29 Jan 2024 04:03:35 -0600 Subject: [PATCH 01/14] safety: test with default pytest dist (load) (#1840) * faster safety test * wondering how fast this is * 4 threads too? --- tests/safety/test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/safety/test.sh b/tests/safety/test.sh index 36f3c971563..d01c5009c2e 100755 --- a/tests/safety/test.sh +++ b/tests/safety/test.sh @@ -7,5 +7,5 @@ cd $DIR HW_TYPES=( 6 9 ) for hw_type in "${HW_TYPES[@]}"; do echo "Testing HW_TYPE: $hw_type" - HW_TYPE=$hw_type pytest -n auto --dist loadfile test_*.py -k 'not Base' + HW_TYPE=$hw_type pytest -n auto test_*.py -k 'not Base' done From a5604de24f8bab406ec8ceff1ed8a35d3b620e88 Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Mon, 29 Jan 2024 20:19:50 -0800 Subject: [PATCH 02/14] ensure cppcheck is always the right version (#1843) --- tests/misra/install.sh | 4 ++-- tests/misra/test_misra.sh | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/misra/install.sh b/tests/misra/install.sh index 58ae77d443b..21396264501 100755 --- a/tests/misra/install.sh +++ b/tests/misra/install.sh @@ -10,7 +10,7 @@ fi cd $CPPCHECK_DIR VERS="2.13.0" -git fetch origin $VERS +git fetch --tags origin $VERS git checkout $VERS -make clean +#make clean make MATCHCOMPILTER=yes CXXFLAGS="-O2" -j8 diff --git a/tests/misra/test_misra.sh b/tests/misra/test_misra.sh index 28249a3d8ab..f7d8580e2ac 100755 --- a/tests/misra/test_misra.sh +++ b/tests/misra/test_misra.sh @@ -10,7 +10,7 @@ NC='\033[0m' : "${CPPCHECK_DIR:=$DIR/cppcheck/}" # install cppcheck if missing -if [ ! -d $CPPCHECK_DIR ]; then +if [ -z "${SKIP_BUILD}" ]; then $DIR/install.sh fi From ec17f75efca05c04313049e1d6dd376ef54d42ec Mon Sep 17 00:00:00 2001 From: Shane Smiskol Date: Mon, 29 Jan 2024 22:23:57 -0600 Subject: [PATCH 03/14] ELM safety: allow GM diagnostic camera address (0x24B) (#1842) * allow 0x200 addresses for Bolt camera * fix test * only gm address * think 15765-2 is the source * test the data * label * should be here * already labeled * use constant! * update table * fix misra * Revert "update table" This reverts commit 71ef3fde7c195c303bb4d771c9643f11b9e5410b. * new cppcheck gets this --- board/safety/safety_elm327.h | 13 ++++++++++++- tests/safety/test_elm327.py | 10 +++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/board/safety/safety_elm327.h b/board/safety/safety_elm327.h index 5c4fd221661..954efca8d59 100644 --- a/board/safety/safety_elm327.h +++ b/board/safety/safety_elm327.h @@ -1,3 +1,5 @@ +const int GM_CAMERA_DIAG_ADDR = 0x24B; + static bool elm327_tx_hook(const CANPacket_t *to_send) { bool tx = true; int addr = GET_ADDR(to_send); @@ -11,9 +13,18 @@ static bool elm327_tx_hook(const CANPacket_t *to_send) { // Check valid 29 bit send addresses for ISO 15765-4 // Check valid 11 bit send addresses for ISO 15765-4 if ((addr != 0x18DB33F1) && ((addr & 0x1FFF00FF) != 0x18DA00F1) && - ((addr & 0x1FFFFF00) != 0x600) && ((addr & 0x1FFFFF00) != 0x700)) { + ((addr & 0x1FFFFF00) != 0x600) && ((addr & 0x1FFFFF00) != 0x700) && + (addr != GM_CAMERA_DIAG_ADDR)) { tx = false; } + + // GM camera uses non-standard diagnostic address, this has no control message address collisions + if ((addr == GM_CAMERA_DIAG_ADDR) && (len == 8)) { + // Only allow known frame types for ISO 15765-2 + if ((GET_BYTE(to_send, 0) & 0xF0U) > 0x30U) { + tx = false; + } + } return tx; } diff --git a/tests/safety/test_elm327.py b/tests/safety/test_elm327.py index 31cd74e9d6c..f133b2ead9c 100755 --- a/tests/safety/test_elm327.py +++ b/tests/safety/test_elm327.py @@ -7,9 +7,11 @@ from panda.tests.libpanda import libpanda_py from panda.tests.safety.test_defaults import TestDefaultRxHookBase +GM_CAMERA_DIAG_ADDR = 0x24B + class TestElm327(TestDefaultRxHookBase): - TX_MSGS = [[addr, bus] for addr in [*range(0x600, 0x800), + TX_MSGS = [[addr, bus] for addr in [GM_CAMERA_DIAG_ADDR, *range(0x600, 0x800), *range(0x18DA00F1, 0x18DB00F1, 0x100), # 29-bit UDS physical addressing *[0x18DB33F1], # 29-bit UDS functional address ] for bus in range(4)] @@ -31,6 +33,12 @@ def test_tx_hook(self): should_tx = msg_len == 8 self.assertEqual(should_tx, self._tx(common.make_msg(0, 0x700, msg_len))) + # TODO: perform this check for all addresses + # 4 to 15 are reserved ISO-TP frame types (https://en.wikipedia.org/wiki/ISO_15765-2) + for byte in range(0xff): + should_tx = (byte >> 4) <= 3 + self.assertEqual(should_tx, self._tx(common.make_msg(0, GM_CAMERA_DIAG_ADDR, dat=bytes([byte] * 8)))) + def test_tx_hook_on_wrong_safety_mode(self): # No point, since we allow many diagnostic addresses pass From 3afab68196dd96ee12b372c46f7f07c4bf62837e Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Tue, 30 Jan 2024 13:17:28 -0800 Subject: [PATCH 04/14] pre-commit: autoupdate hooks (#1844) Update pre-commit hook versions Co-authored-by: adeebshihadeh --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 9d2dfc9c3ad..bffb7447e33 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -15,6 +15,6 @@ repos: additional_dependencies: ['git+https://github.com/numpy/numpy-stubs', 'types-requests', 'types-atomicwrites', 'types-pycurl'] - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.1.14 + rev: v0.1.15 hooks: - id: ruff From bca1162ae9af0e9718aad9f801b595865da997f5 Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Tue, 30 Jan 2024 13:25:22 -0800 Subject: [PATCH 05/14] cuatro: setup CAN (#1836) * cuatro: setup CAN * fix misra --------- Co-authored-by: Comma Device --- board/boards/cuatro.h | 19 +++++++++++++++++-- board/boards/tres.h | 1 - 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/board/boards/cuatro.h b/board/boards/cuatro.h index 4eb4bcc283e..4fc630d5f4a 100644 --- a/board/boards/cuatro.h +++ b/board/boards/cuatro.h @@ -14,9 +14,25 @@ void cuatro_set_led(uint8_t color, bool enabled) { } } +void cuatro_enable_can_transceiver(uint8_t transceiver, bool enabled) { + if (transceiver == 1U) { + set_gpio_output(GPIOB, 7, !enabled); + } else if (transceiver == 3U) { + set_gpio_output(GPIOD, 8, !enabled); + } else { + red_enable_can_transceiver(transceiver, enabled); + } +} + void cuatro_init(void) { red_chiplet_init(); + // CAN FD 0 transceiver enable (rest are done in red init) + set_gpio_pullup(GPIOB, 7, PULL_NONE); + set_gpio_mode(GPIOB, 7, MODE_OUTPUT); + set_gpio_pullup(GPIOD, 8, PULL_NONE); + set_gpio_mode(GPIOD, 8, MODE_OUTPUT); + // C2: SOM GPIO used as input (fan control at boot) set_gpio_mode(GPIOC, 2, MODE_INPUT); set_gpio_pullup(GPIOC, 2, PULL_DOWN); @@ -57,8 +73,7 @@ const board board_cuatro = { .fan_enable_cooldown_time = 3U, .init = cuatro_init, .init_bootloader = unused_init_bootloader, - .enable_can_transceiver = red_chiplet_enable_can_transceiver, - .enable_can_transceivers = red_chiplet_enable_can_transceivers, + .enable_can_transceiver = cuatro_enable_can_transceiver, .set_led = cuatro_set_led, .set_can_mode = red_chiplet_set_can_mode, .check_ignition = red_check_ignition, diff --git a/board/boards/tres.h b/board/boards/tres.h index d4faa9c0a33..4f7036b9e96 100644 --- a/board/boards/tres.h +++ b/board/boards/tres.h @@ -83,7 +83,6 @@ const board board_tres = { .fan_enable_cooldown_time = 3U, .init = tres_init, .init_bootloader = unused_init_bootloader, - .enable_can_transceiver = red_chiplet_enable_can_transceiver, .enable_can_transceivers = red_chiplet_enable_can_transceivers, .set_led = red_set_led, .set_can_mode = red_chiplet_set_can_mode, From 457e3b262d798aa6e400033c92d12a0b0f52a7ed Mon Sep 17 00:00:00 2001 From: Comma Device Date: Sat, 3 Feb 2024 01:36:15 +0000 Subject: [PATCH 06/14] fix enable_can_transceiver --- board/boards/cuatro.h | 1 + board/boards/tres.h | 1 + 2 files changed, 2 insertions(+) diff --git a/board/boards/cuatro.h b/board/boards/cuatro.h index 4fc630d5f4a..8b05c4600de 100644 --- a/board/boards/cuatro.h +++ b/board/boards/cuatro.h @@ -74,6 +74,7 @@ const board board_cuatro = { .init = cuatro_init, .init_bootloader = unused_init_bootloader, .enable_can_transceiver = cuatro_enable_can_transceiver, + .enable_can_transceivers = red_chiplet_enable_can_transceivers, .set_led = cuatro_set_led, .set_can_mode = red_chiplet_set_can_mode, .check_ignition = red_check_ignition, diff --git a/board/boards/tres.h b/board/boards/tres.h index 4f7036b9e96..d4faa9c0a33 100644 --- a/board/boards/tres.h +++ b/board/boards/tres.h @@ -83,6 +83,7 @@ const board board_tres = { .fan_enable_cooldown_time = 3U, .init = tres_init, .init_bootloader = unused_init_bootloader, + .enable_can_transceiver = red_chiplet_enable_can_transceiver, .enable_can_transceivers = red_chiplet_enable_can_transceivers, .set_led = red_set_led, .set_can_mode = red_chiplet_set_can_mode, From 5ab46d52fd24b3cb9d507f8593deab8761c04cc3 Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Sat, 3 Feb 2024 15:28:15 -0800 Subject: [PATCH 07/14] set cppcheck level to exhaustive (#1846) --- tests/misra/test_misra.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/misra/test_misra.sh b/tests/misra/test_misra.sh index f7d8580e2ac..5504e3cd8c1 100755 --- a/tests/misra/test_misra.sh +++ b/tests/misra/test_misra.sh @@ -37,7 +37,7 @@ cppcheck() { -I $gcc_inc "$(arm-none-eabi-gcc -print-file-name=include)" \ --suppressions-list=$DIR/suppressions.txt --suppress=*:*inc/* \ --suppress=*:*include/* --error-exitcode=2 --addon=misra \ - --cppcheck-build-dir=$build_dir \ + --check-level=exhaustive --cppcheck-build-dir=$build_dir \ "$@" } From 93a06f1257d4a22dbfa2913b76c7664538b1d7e7 Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Sat, 3 Feb 2024 23:18:33 -0800 Subject: [PATCH 08/14] remove HW GMLAN support (#1848) --- board/boards/black.h | 1 - board/boards/board_declarations.h | 1 - board/boards/cuatro.h | 1 - board/boards/dos.h | 1 - board/boards/grey.h | 1 - board/boards/pedal.h | 1 - board/boards/red.h | 1 - board/boards/tres.h | 1 - board/boards/uno.h | 1 - board/boards/white.h | 1 - board/drivers/bxcan.h | 50 ------------------------ board/drivers/fdcan.h | 5 --- board/jungle/boards/board_declarations.h | 1 - board/main_comms.h | 13 ------ board/power_saving.h | 6 --- 15 files changed, 85 deletions(-) diff --git a/board/boards/black.h b/board/boards/black.h index d3d0f8619dc..2e50157000f 100644 --- a/board/boards/black.h +++ b/board/boards/black.h @@ -165,7 +165,6 @@ const harness_configuration black_harness_config = { const board board_black = { .set_bootkick = unused_set_bootkick, .harness_config = &black_harness_config, - .has_hw_gmlan = false, .has_obd = true, .has_spi = false, .has_canfd = false, diff --git a/board/boards/board_declarations.h b/board/boards/board_declarations.h index ee7103b06ac..06382ceb76e 100644 --- a/board/boards/board_declarations.h +++ b/board/boards/board_declarations.h @@ -21,7 +21,6 @@ typedef bool (*board_read_som_gpio)(void); struct board { const harness_configuration *harness_config; - const bool has_hw_gmlan; const bool has_obd; const bool has_spi; const bool has_canfd; diff --git a/board/boards/cuatro.h b/board/boards/cuatro.h index 8b05c4600de..b30abccfad6 100644 --- a/board/boards/cuatro.h +++ b/board/boards/cuatro.h @@ -62,7 +62,6 @@ void cuatro_init(void) { const board board_cuatro = { .harness_config = &red_chiplet_harness_config, - .has_hw_gmlan = false, .has_obd = true, .has_spi = true, .has_canfd = true, diff --git a/board/boards/dos.h b/board/boards/dos.h index b76f8993fff..b234d51a8c5 100644 --- a/board/boards/dos.h +++ b/board/boards/dos.h @@ -193,7 +193,6 @@ const harness_configuration dos_harness_config = { const board board_dos = { .harness_config = &dos_harness_config, - .has_hw_gmlan = false, .has_obd = true, #ifdef ENABLE_SPI .has_spi = true, diff --git a/board/boards/grey.h b/board/boards/grey.h index 6065c3d227a..a7a4cc0445d 100644 --- a/board/boards/grey.h +++ b/board/boards/grey.h @@ -7,7 +7,6 @@ const board board_grey = { .set_bootkick = unused_set_bootkick, .harness_config = &white_harness_config, - .has_hw_gmlan = true, .has_obd = false, .has_spi = false, .has_canfd = false, diff --git a/board/boards/pedal.h b/board/boards/pedal.h index 1909b2a5311..c1569beac00 100644 --- a/board/boards/pedal.h +++ b/board/boards/pedal.h @@ -69,7 +69,6 @@ const harness_configuration pedal_harness_config = { const board board_pedal = { .set_bootkick = unused_set_bootkick, .harness_config = &pedal_harness_config, - .has_hw_gmlan = false, .has_obd = false, .has_spi = false, .has_canfd = false, diff --git a/board/boards/red.h b/board/boards/red.h index 709d44df50d..05e6e7530df 100644 --- a/board/boards/red.h +++ b/board/boards/red.h @@ -173,7 +173,6 @@ const harness_configuration red_harness_config = { const board board_red = { .set_bootkick = unused_set_bootkick, .harness_config = &red_harness_config, - .has_hw_gmlan = false, .has_obd = true, .has_spi = false, .has_canfd = true, diff --git a/board/boards/tres.h b/board/boards/tres.h index d4faa9c0a33..3a5d8961852 100644 --- a/board/boards/tres.h +++ b/board/boards/tres.h @@ -72,7 +72,6 @@ void tres_init(void) { const board board_tres = { .harness_config = &red_chiplet_harness_config, - .has_hw_gmlan = false, .has_obd = true, .has_spi = true, .has_canfd = true, diff --git a/board/boards/uno.h b/board/boards/uno.h index 15759b85809..947d60d1325 100644 --- a/board/boards/uno.h +++ b/board/boards/uno.h @@ -200,7 +200,6 @@ const harness_configuration uno_harness_config = { const board board_uno = { .harness_config = &uno_harness_config, - .has_hw_gmlan = false, .has_obd = true, .has_spi = false, .has_canfd = false, diff --git a/board/boards/white.h b/board/boards/white.h index c8b8606bcf4..680e3cb05ca 100644 --- a/board/boards/white.h +++ b/board/boards/white.h @@ -224,7 +224,6 @@ const harness_configuration white_harness_config = { const board board_white = { .set_bootkick = unused_set_bootkick, .harness_config = &white_harness_config, - .has_hw_gmlan = true, .has_obd = false, .has_spi = false, .has_canfd = false, diff --git a/board/drivers/bxcan.h b/board/drivers/bxcan.h index 080c9f4a9d4..ea2705d9d06 100644 --- a/board/drivers/bxcan.h +++ b/board/drivers/bxcan.h @@ -23,56 +23,6 @@ bool can_set_speed(uint8_t can_number) { return ret; } -// TODO: Cleanup with new abstraction -void can_set_gmlan(uint8_t bus) { - if(current_board->has_hw_gmlan){ - // first, disable GMLAN on prev bus - uint8_t prev_bus = bus_config[3].can_num_lookup; - if (bus != prev_bus) { - switch (prev_bus) { - case 1: - case 2: - print("Disable GMLAN on CAN"); - puth(prev_bus + 1U); - print("\n"); - current_board->set_can_mode(CAN_MODE_NORMAL); - bus_config[prev_bus].bus_lookup = prev_bus; - bus_config[prev_bus].can_num_lookup = prev_bus; - bus_config[3].can_num_lookup = -1; - bool ret = can_init(prev_bus); - UNUSED(ret); - break; - default: - // GMLAN was not set on either BUS 1 or 2 - break; - } - } - - // now enable GMLAN on the new bus - switch (bus) { - case 1: - case 2: - print("Enable GMLAN on CAN"); - puth(bus + 1U); - print("\n"); - current_board->set_can_mode((bus == 1U) ? CAN_MODE_GMLAN_CAN2 : CAN_MODE_GMLAN_CAN3); - bus_config[bus].bus_lookup = 3; - bus_config[bus].can_num_lookup = -1; - bus_config[3].can_num_lookup = bus; - bool ret = can_init(bus); - UNUSED(ret); - break; - case 0xFF: //-1 unsigned - break; - default: - print("GMLAN can only be set on CAN2 or CAN3\n"); - break; - } - } else { - print("GMLAN not available on black panda\n"); - } -} - void update_can_health_pkt(uint8_t can_number, uint32_t ir_reg) { CAN_TypeDef *CANx = CANIF_FROM_CAN_NUM(can_number); uint32_t esr_reg = CANx->ESR; diff --git a/board/drivers/fdcan.h b/board/drivers/fdcan.h index 4343d5c97f6..bc4c2a532e3 100644 --- a/board/drivers/fdcan.h +++ b/board/drivers/fdcan.h @@ -35,11 +35,6 @@ bool can_set_speed(uint8_t can_number) { return ret; } -void can_set_gmlan(uint8_t bus) { - UNUSED(bus); - print("GMLAN not available on red panda\n"); -} - void update_can_health_pkt(uint8_t can_number, uint32_t ir_reg) { FDCAN_GlobalTypeDef *FDCANx = CANIF_FROM_CAN_NUM(can_number); uint32_t psr_reg = FDCANx->PSR; diff --git a/board/jungle/boards/board_declarations.h b/board/jungle/boards/board_declarations.h index 1288b5354df..925918921f8 100644 --- a/board/jungle/boards/board_declarations.h +++ b/board/jungle/boards/board_declarations.h @@ -35,7 +35,6 @@ struct board { // TODO: shouldn't need these bool has_spi; - bool has_hw_gmlan; }; // ******************* Definitions ******************** diff --git a/board/main_comms.h b/board/main_comms.h index 4adfc8d744a..01c47ba07af 100644 --- a/board/main_comms.h +++ b/board/main_comms.h @@ -274,19 +274,6 @@ int comms_control_handler(ControlPacket_t *req, uint8_t *resp) { // Disable OBD CAN current_board->set_can_mode(CAN_MODE_NORMAL); } - } else { - if (req->param1 == 1U) { - // GMLAN ON - if (req->param2 == 1U) { - can_set_gmlan(1); - } else if (req->param2 == 2U) { - can_set_gmlan(2); - } else { - print("Invalid bus num for GMLAN CAN set\n"); - } - } else { - can_set_gmlan(-1); - } } break; diff --git a/board/power_saving.h b/board/power_saving.h index dcd64dc58d2..61541cae9ee 100644 --- a/board/power_saving.h +++ b/board/power_saving.h @@ -36,12 +36,6 @@ void set_power_save_state(int state) { current_board->enable_can_transceivers(enable); - if(current_board->has_hw_gmlan){ - // turn on GMLAN - set_gpio_output(GPIOB, 14, enable); - set_gpio_output(GPIOB, 15, enable); - } - // Switch off IR when in power saving if(!enable){ current_board->set_ir_power(0U); From 3bd980eb3972cd1791e946bba99d83345a1efcaa Mon Sep 17 00:00:00 2001 From: Ruben Medina Date: Sat, 3 Feb 2024 23:20:30 -0800 Subject: [PATCH 09/14] enable misra-c2012-17.3 (#1806) --- board/main_comms.h | 3 ++- board/safety.h | 3 ++- board/safety/safety_chrysler.h | 4 +++- board/safety/safety_ford.h | 3 ++- board/safety/safety_honda.h | 4 +++- tests/misra/suppressions.txt | 1 - 6 files changed, 12 insertions(+), 6 deletions(-) diff --git a/board/main_comms.h b/board/main_comms.h index 01c47ba07af..116f95d0ede 100644 --- a/board/main_comms.h +++ b/board/main_comms.h @@ -311,7 +311,8 @@ int comms_control_handler(ControlPacket_t *req, uint8_t *resp) { } // read - while ((resp_len < MIN(req->length, USBPACKET_MAX_SIZE)) && + uint16_t req_length = MIN(req->length, USBPACKET_MAX_SIZE); + while ((resp_len < req_length) && get_char(ur, (char*)&resp[resp_len])) { ++resp_len; } diff --git a/board/safety.h b/board/safety.h index e48a75502e8..50669e3bfb4 100644 --- a/board/safety.h +++ b/board/safety.h @@ -390,7 +390,8 @@ int set_safety_hooks(uint16_t mode, uint16_t param) { // convert a trimmed integer to signed 32 bit int int to_signed(int d, int bits) { int d_signed = d; - if (d >= (1 << MAX((bits - 1), 0))) { + int max_value = (1 << MAX((bits - 1), 0)); + if (d >= max_value) { d_signed = d - (1 << MAX(bits, 0)); } return d_signed; diff --git a/board/safety/safety_chrysler.h b/board/safety/safety_chrysler.h index 71bd19d3003..1e11871286f 100644 --- a/board/safety/safety_chrysler.h +++ b/board/safety/safety_chrysler.h @@ -264,7 +264,9 @@ static int chrysler_fwd_hook(int bus_num, int addr) { static safety_config chrysler_init(uint16_t param) { safety_config ret; - if (GET_FLAG(param, CHRYSLER_PARAM_RAM_DT)) { + + bool enable_ram_dt = GET_FLAG(param, CHRYSLER_PARAM_RAM_DT); + if (enable_ram_dt) { chrysler_platform = CHRYSLER_RAM_DT; chrysler_addrs = &CHRYSLER_RAM_DT_ADDRS; ret = BUILD_SAFETY_CFG(chrysler_ram_dt_rx_checks, CHRYSLER_RAM_DT_TX_MSGS); diff --git a/board/safety/safety_ford.h b/board/safety/safety_ford.h index 6ab123be69b..0424b9d09c7 100644 --- a/board/safety/safety_ford.h +++ b/board/safety/safety_ford.h @@ -222,7 +222,8 @@ static void ford_rx_hook(const CANPacket_t *to_push) { // Disable controls if speeds from ABS and PCM ECUs are too far apart. // Signal: Veh_V_ActlEng float filtered_pcm_speed = ((GET_BYTE(to_push, 6) << 8) | GET_BYTE(to_push, 7)) * 0.01 / 3.6; - if (ABS(filtered_pcm_speed - ((float)vehicle_speed.values[0] / VEHICLE_SPEED_FACTOR)) > FORD_MAX_SPEED_DELTA) { + bool is_invalid_speed = ABS(filtered_pcm_speed - ((float)vehicle_speed.values[0] / VEHICLE_SPEED_FACTOR)) > FORD_MAX_SPEED_DELTA; + if (is_invalid_speed) { controls_allowed = false; } } diff --git a/board/safety/safety_honda.h b/board/safety/safety_honda.h index 7bbc8e66165..968a1a446da 100644 --- a/board/safety/safety_honda.h +++ b/board/safety/safety_honda.h @@ -383,7 +383,9 @@ static safety_config honda_nidec_init(uint16_t param) { enable_gas_interceptor = GET_FLAG(param, HONDA_PARAM_GAS_INTERCEPTOR); safety_config ret; - if (GET_FLAG(param, HONDA_PARAM_NIDEC_ALT)) { + + bool enable_nidec_alt = GET_FLAG(param, HONDA_PARAM_NIDEC_ALT); + if (enable_nidec_alt) { enable_gas_interceptor ? SET_RX_CHECKS(honda_nidec_alt_interceptor_rx_checks, ret) : \ SET_RX_CHECKS(honda_nidec_alt_rx_checks, ret); } else { diff --git a/tests/misra/suppressions.txt b/tests/misra/suppressions.txt index 57db05a5fb6..2c91f868ab4 100644 --- a/tests/misra/suppressions.txt +++ b/tests/misra/suppressions.txt @@ -25,5 +25,4 @@ misra-c2012-8.7 misra-c2012-8.4 misra-c2012-10.6 misra-c2012-10.3 -misra-c2012-17.3 misra-c2012-21.15 From f48fc21a17079bc04cfb3d8042fd2d67d0aac104 Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Sun, 4 Feb 2024 15:11:52 -0800 Subject: [PATCH 10/14] cuatro: fix FDCAN2 (#1851) Co-authored-by: Comma Device --- board/boards/cuatro.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/board/boards/cuatro.h b/board/boards/cuatro.h index b30abccfad6..0950e1e5320 100644 --- a/board/boards/cuatro.h +++ b/board/boards/cuatro.h @@ -33,6 +33,12 @@ void cuatro_init(void) { set_gpio_pullup(GPIOD, 8, PULL_NONE); set_gpio_mode(GPIOD, 8, MODE_OUTPUT); + // FDCAN2 + set_gpio_pullup(GPIOD, 12, PULL_NONE); + set_gpio_alternate(GPIOD, 12, GPIO_AF9_FDCAN2); + set_gpio_pullup(GPIOD, 13, PULL_NONE); + set_gpio_alternate(GPIOD, 13, GPIO_AF9_FDCAN2); + // C2: SOM GPIO used as input (fan control at boot) set_gpio_mode(GPIOC, 2, MODE_INPUT); set_gpio_pullup(GPIOC, 2, PULL_DOWN); From 94418a0d93ab5e17f72bc133611446d544d5e22d Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Tue, 6 Feb 2024 11:14:58 -0800 Subject: [PATCH 11/14] pre-commit: autoupdate hooks (#1857) Update pre-commit hook versions Co-authored-by: adeebshihadeh --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index bffb7447e33..5788e16b2c8 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -15,6 +15,6 @@ repos: additional_dependencies: ['git+https://github.com/numpy/numpy-stubs', 'types-requests', 'types-atomicwrites', 'types-pycurl'] - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.1.15 + rev: v0.2.1 hooks: - id: ruff From 5c5287dabb50f31aa53ad6d17319fea8699dfb2f Mon Sep 17 00:00:00 2001 From: dzid26 Date: Tue, 6 Feb 2024 19:15:22 +0000 Subject: [PATCH 12/14] Fix CAN comment (#1854) --- board/boards/black.h | 2 +- board/boards/dos.h | 2 +- board/boards/red.h | 2 +- board/boards/red_chiplet.h | 2 +- board/boards/uno.h | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/board/boards/black.h b/board/boards/black.h index 2e50157000f..bf8d5bd7436 100644 --- a/board/boards/black.h +++ b/board/boards/black.h @@ -136,7 +136,7 @@ void black_init(void) { // Set normal CAN mode black_set_can_mode(CAN_MODE_NORMAL); - // flip CAN0 and CAN2 if we are flipped + // change CAN mapping when flipped if (harness.status == HARNESS_STATUS_FLIPPED) { can_flip_buses(0, 2); } diff --git a/board/boards/dos.h b/board/boards/dos.h index b234d51a8c5..69e9169c2de 100644 --- a/board/boards/dos.h +++ b/board/boards/dos.h @@ -168,7 +168,7 @@ void dos_init(void) { // Set normal CAN mode dos_set_can_mode(CAN_MODE_NORMAL); - // flip CAN0 and CAN2 if we are flipped + // change CAN mapping when flipped if (harness.status == HARNESS_STATUS_FLIPPED) { can_flip_buses(0, 2); } diff --git a/board/boards/red.h b/board/boards/red.h index 05e6e7530df..1bf33d60982 100644 --- a/board/boards/red.h +++ b/board/boards/red.h @@ -150,7 +150,7 @@ void red_init(void) { // Set normal CAN mode red_set_can_mode(CAN_MODE_NORMAL); - // flip CAN0 and CAN2 if we are flipped + // change CAN mapping when flipped if (harness.status == HARNESS_STATUS_FLIPPED) { can_flip_buses(0, 2); } diff --git a/board/boards/red_chiplet.h b/board/boards/red_chiplet.h index 1301cd3e54f..205574f203d 100644 --- a/board/boards/red_chiplet.h +++ b/board/boards/red_chiplet.h @@ -133,7 +133,7 @@ void red_chiplet_init(void) { // Set normal CAN mode red_chiplet_set_can_mode(CAN_MODE_NORMAL); - // flip CAN0 and CAN2 if we are flipped + // change CAN mapping when flipped if (harness.status == HARNESS_STATUS_FLIPPED) { can_flip_buses(0, 2); } diff --git a/board/boards/uno.h b/board/boards/uno.h index 947d60d1325..29f0a0c5977 100644 --- a/board/boards/uno.h +++ b/board/boards/uno.h @@ -161,7 +161,7 @@ void uno_init(void) { // Set normal CAN mode uno_set_can_mode(CAN_MODE_NORMAL); - // flip CAN0 and CAN2 if we are flipped + // change CAN mapping when flipped if (harness.status == HARNESS_STATUS_FLIPPED) { can_flip_buses(0, 2); } From 04c5a00a9ecc96401d2e59a06bd15c84abd641de Mon Sep 17 00:00:00 2001 From: dzid26 Date: Tue, 6 Feb 2024 19:15:46 +0000 Subject: [PATCH 13/14] Board chip type (#1853) Board chip type title --- board/boards/black.h | 6 +++--- board/boards/cuatro.h | 4 ++++ board/boards/dos.h | 6 +++--- board/boards/grey.h | 6 +++--- board/boards/pedal.h | 6 +++--- board/boards/red.h | 6 +++--- board/boards/red_chiplet.h | 6 +++--- board/boards/tres.h | 6 +++--- board/boards/uno.h | 6 +++--- board/boards/white.h | 6 +++--- board/jungle/boards/board_v1.h | 3 +++ board/jungle/boards/board_v2.h | 3 +++ 12 files changed, 37 insertions(+), 27 deletions(-) diff --git a/board/boards/black.h b/board/boards/black.h index bf8d5bd7436..d72ab39aa12 100644 --- a/board/boards/black.h +++ b/board/boards/black.h @@ -1,6 +1,6 @@ -// ///////////////////// // -// Black Panda + Harness // -// ///////////////////// // +// /////////////////////////////// // +// Black Panda (STM32F4) + Harness // +// /////////////////////////////// // void black_enable_can_transceiver(uint8_t transceiver, bool enabled) { switch (transceiver){ diff --git a/board/boards/cuatro.h b/board/boards/cuatro.h index 0950e1e5320..049e6e20a61 100644 --- a/board/boards/cuatro.h +++ b/board/boards/cuatro.h @@ -1,3 +1,7 @@ +// ////////////////////////// // +// Cuatro (STM32H7) + Harness // +// ////////////////////////// // + void cuatro_set_led(uint8_t color, bool enabled) { switch (color) { case LED_RED: diff --git a/board/boards/dos.h b/board/boards/dos.h index 69e9169c2de..e93c0159113 100644 --- a/board/boards/dos.h +++ b/board/boards/dos.h @@ -1,6 +1,6 @@ -// ///////////// // -// Dos + Harness // -// ///////////// // +// /////////////////////// // +// Dos (STM32F4) + Harness // +// /////////////////////// // void dos_enable_can_transceiver(uint8_t transceiver, bool enabled) { switch (transceiver){ diff --git a/board/boards/grey.h b/board/boards/grey.h index a7a4cc0445d..e8f90e263d9 100644 --- a/board/boards/grey.h +++ b/board/boards/grey.h @@ -1,6 +1,6 @@ -// ////////// // -// Grey Panda // -// ////////// // +// //////////////////// // +// Grey Panda (STM32F4) // +// //////////////////// // // Most hardware functionality is similar to white panda diff --git a/board/boards/pedal.h b/board/boards/pedal.h index c1569beac00..2b653e9ed1a 100644 --- a/board/boards/pedal.h +++ b/board/boards/pedal.h @@ -1,6 +1,6 @@ -// ///// // -// Pedal // -// ///// // +// ///////////// // +// Pedal STM32F2 // +// ///////////// // void pedal_enable_can_transceiver(uint8_t transceiver, bool enabled) { switch (transceiver){ diff --git a/board/boards/red.h b/board/boards/red.h index 1bf33d60982..58410894bc4 100644 --- a/board/boards/red.h +++ b/board/boards/red.h @@ -1,6 +1,6 @@ -// ///////////////////// // -// Red Panda + Harness // -// ///////////////////// // +// ///////////////////////////// // +// Red Panda (STM32H7) + Harness // +// ///////////////////////////// // void red_enable_can_transceiver(uint8_t transceiver, bool enabled) { switch (transceiver) { diff --git a/board/boards/red_chiplet.h b/board/boards/red_chiplet.h index 205574f203d..eec3d95cdf5 100644 --- a/board/boards/red_chiplet.h +++ b/board/boards/red_chiplet.h @@ -1,6 +1,6 @@ -// ///////////////////// // -// Red Panda chiplet + Harness // -// ///////////////////// // +// ///////////////////////////////////// // +// Red Panda chiplet (STM32H7) + Harness // +// ///////////////////////////////////// // // Most hardware functionality is similar to red panda diff --git a/board/boards/tres.h b/board/boards/tres.h index 3a5d8961852..4e8564b20d0 100644 --- a/board/boards/tres.h +++ b/board/boards/tres.h @@ -1,6 +1,6 @@ -// ///////////////// -// Tres + Harness // -// ///////////////// +// /////////////////////////// +// Tres (STM32H7) + Harness // +// /////////////////////////// bool tres_ir_enabled; bool tres_fan_enabled; diff --git a/board/boards/uno.h b/board/boards/uno.h index 29f0a0c5977..5f8af593dc3 100644 --- a/board/boards/uno.h +++ b/board/boards/uno.h @@ -1,6 +1,6 @@ -// ///////////// // -// Uno + Harness // -// ///////////// // +// /////////////////////// // +// Uno (STM32F4) + Harness // +// /////////////////////// // void uno_enable_can_transceiver(uint8_t transceiver, bool enabled) { switch (transceiver){ diff --git a/board/boards/white.h b/board/boards/white.h index 680e3cb05ca..5048c0779d8 100644 --- a/board/boards/white.h +++ b/board/boards/white.h @@ -1,6 +1,6 @@ -// /////////// // -// White Panda // -// /////////// // +// ///////////////////// // +// White Panda (STM32F4) // +// ///////////////////// // void white_enable_can_transceiver(uint8_t transceiver, bool enabled) { switch (transceiver){ diff --git a/board/jungle/boards/board_v1.h b/board/jungle/boards/board_v1.h index 29c23d6df7a..9581686e2a3 100644 --- a/board/jungle/boards/board_v1.h +++ b/board/jungle/boards/board_v1.h @@ -1,3 +1,6 @@ +// ///////////////////////// // +// Jungle board v1 (STM32F4) // +// ///////////////////////// // void board_v1_set_led(uint8_t color, bool enabled) { switch (color) { diff --git a/board/jungle/boards/board_v2.h b/board/jungle/boards/board_v2.h index 7bce61ebb30..095114825b8 100644 --- a/board/jungle/boards/board_v2.h +++ b/board/jungle/boards/board_v2.h @@ -1,3 +1,6 @@ +// ///////////////////////// // +// Jungle board v2 (STM32H7) // +// ///////////////////////// // const gpio_t power_pins[] = { {.bank = GPIOA, .pin = 0}, From ad0f372adabef438d67340c6b9c76ba7146d0671 Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Tue, 6 Feb 2024 22:29:42 -0800 Subject: [PATCH 14/14] cuatro can fixes (#1858) * more can * other af * cleanup * misra fix --------- Co-authored-by: Comma Device --- board/boards/cuatro.h | 43 ++++++++++++++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/board/boards/cuatro.h b/board/boards/cuatro.h index 049e6e20a61..ed120bb052f 100644 --- a/board/boards/cuatro.h +++ b/board/boards/cuatro.h @@ -19,29 +19,50 @@ void cuatro_set_led(uint8_t color, bool enabled) { } void cuatro_enable_can_transceiver(uint8_t transceiver, bool enabled) { - if (transceiver == 1U) { - set_gpio_output(GPIOB, 7, !enabled); - } else if (transceiver == 3U) { - set_gpio_output(GPIOD, 8, !enabled); - } else { - red_enable_can_transceiver(transceiver, enabled); + switch (transceiver) { + case 1U: + set_gpio_output(GPIOB, 7, !enabled); + break; + case 2U: + set_gpio_output(GPIOB, 10, !enabled); + break; + case 3U: + set_gpio_output(GPIOD, 8, !enabled); + break; + case 4U: + set_gpio_output(GPIOB, 11, !enabled); + break; + default: + break; + } +} + +void cuatro_enable_can_transceivers(bool enabled) { + uint8_t main_bus = (harness.status == HARNESS_STATUS_FLIPPED) ? 3U : 1U; + for (uint8_t i=1U; i<=4U; i++) { + // Leave main CAN always on for CAN-based ignition detection + if (i == main_bus) { + cuatro_enable_can_transceiver(i, true); + } else { + cuatro_enable_can_transceiver(i, enabled); + } } } void cuatro_init(void) { red_chiplet_init(); - // CAN FD 0 transceiver enable (rest are done in red init) + // CAN transceiver enables set_gpio_pullup(GPIOB, 7, PULL_NONE); set_gpio_mode(GPIOB, 7, MODE_OUTPUT); set_gpio_pullup(GPIOD, 8, PULL_NONE); set_gpio_mode(GPIOD, 8, MODE_OUTPUT); - // FDCAN2 + // FDCAN3, different pins on this package than the rest of the reds set_gpio_pullup(GPIOD, 12, PULL_NONE); - set_gpio_alternate(GPIOD, 12, GPIO_AF9_FDCAN2); + set_gpio_alternate(GPIOD, 12, GPIO_AF5_FDCAN3); set_gpio_pullup(GPIOD, 13, PULL_NONE); - set_gpio_alternate(GPIOD, 13, GPIO_AF9_FDCAN2); + set_gpio_alternate(GPIOD, 13, GPIO_AF5_FDCAN3); // C2: SOM GPIO used as input (fan control at boot) set_gpio_mode(GPIOC, 2, MODE_INPUT); @@ -83,7 +104,7 @@ const board board_cuatro = { .init = cuatro_init, .init_bootloader = unused_init_bootloader, .enable_can_transceiver = cuatro_enable_can_transceiver, - .enable_can_transceivers = red_chiplet_enable_can_transceivers, + .enable_can_transceivers = cuatro_enable_can_transceivers, .set_led = cuatro_set_led, .set_can_mode = red_chiplet_set_can_mode, .check_ignition = red_check_ignition,