From e7abbf2e0dc6fddaa770ae421bcf013e2e1e7a79 Mon Sep 17 00:00:00 2001 From: Robbe Derks Date: Fri, 29 Nov 2024 18:00:41 +0100 Subject: [PATCH 1/9] refactor out red chiplet --- board/boards/cuatro.h | 31 +++++++- board/boards/red_chiplet.h | 151 ------------------------------------- board/boards/tres.h | 124 ++++++++++++++++++++++++++++-- board/stm32h7/board.h | 1 - 4 files changed, 146 insertions(+), 161 deletions(-) delete mode 100644 board/boards/red_chiplet.h diff --git a/board/boards/cuatro.h b/board/boards/cuatro.h index 90d0627517..ea463c3b24 100644 --- a/board/boards/cuatro.h +++ b/board/boards/cuatro.h @@ -80,7 +80,32 @@ static void cuatro_set_amp_enabled(bool enabled){ } static void cuatro_init(void) { - red_chiplet_init(); + common_init_gpio(); + + // A8, A3: OBD_SBU1_RELAY, OBD_SBU2_RELAY + set_gpio_output_type(GPIOA, 8, OUTPUT_TYPE_OPEN_DRAIN); + set_gpio_pullup(GPIOA, 8, PULL_NONE); + set_gpio_output(GPIOA, 8, 1); + set_gpio_mode(GPIOA, 8, MODE_OUTPUT); + + set_gpio_output_type(GPIOA, 3, OUTPUT_TYPE_OPEN_DRAIN); + set_gpio_pullup(GPIOA, 3, PULL_NONE); + set_gpio_output(GPIOA, 3, 1); + set_gpio_mode(GPIOA, 3, MODE_OUTPUT); + + // Initialize harness + harness_init(); + + // Enable CAN transceivers + cuatro_enable_can_transceivers(true); + + // Disable LEDs + red_set_led(LED_RED, false); + red_set_led(LED_GREEN, false); + red_set_led(LED_BLUE, false); + + // Set normal CAN mode + tres_set_can_mode(CAN_MODE_NORMAL); // init LEDs as open drain set_gpio_output_type(GPIOE, 2, OUTPUT_TYPE_OPEN_DRAIN); @@ -150,7 +175,7 @@ static void cuatro_init(void) { } board board_cuatro = { - .harness_config = &red_chiplet_harness_config, + .harness_config = &tres_harness_config, .has_obd = true, .has_spi = true, .has_canfd = true, @@ -164,7 +189,7 @@ board board_cuatro = { .enable_can_transceiver = cuatro_enable_can_transceiver, .enable_can_transceivers = cuatro_enable_can_transceivers, .set_led = cuatro_set_led, - .set_can_mode = red_chiplet_set_can_mode, + .set_can_mode = tres_set_can_mode, .check_ignition = red_check_ignition, .read_voltage_mV = cuatro_read_voltage_mV, .read_current_mA = cuatro_read_current_mA, diff --git a/board/boards/red_chiplet.h b/board/boards/red_chiplet.h deleted file mode 100644 index e5d1aa097f..0000000000 --- a/board/boards/red_chiplet.h +++ /dev/null @@ -1,151 +0,0 @@ -#pragma once - -#include "board_declarations.h" - -// ///////////////////////////////////// // -// Red Panda chiplet (STM32H7) + Harness // -// ///////////////////////////////////// // - -// Most hardware functionality is similar to red panda - -static void red_chiplet_enable_can_transceiver(uint8_t transceiver, bool enabled) { - switch (transceiver) { - case 1U: - set_gpio_output(GPIOG, 11, !enabled); - break; - case 2U: - set_gpio_output(GPIOB, 10, !enabled); - break; - case 3U: - set_gpio_output(GPIOD, 7, !enabled); - break; - case 4U: - set_gpio_output(GPIOB, 11, !enabled); - break; - default: - break; - } -} - -static void red_chiplet_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) { - red_chiplet_enable_can_transceiver(i, true); - } else { - red_chiplet_enable_can_transceiver(i, enabled); - } - } -} - -static void red_chiplet_set_can_mode(uint8_t mode) { - red_chiplet_enable_can_transceiver(2U, false); - red_chiplet_enable_can_transceiver(4U, false); - switch (mode) { - case CAN_MODE_NORMAL: - case CAN_MODE_OBD_CAN2: - if ((bool)(mode == CAN_MODE_NORMAL) != (bool)(harness.status == HARNESS_STATUS_FLIPPED)) { - // B12,B13: disable normal mode - set_gpio_pullup(GPIOB, 12, PULL_NONE); - set_gpio_mode(GPIOB, 12, MODE_ANALOG); - - set_gpio_pullup(GPIOB, 13, PULL_NONE); - set_gpio_mode(GPIOB, 13, MODE_ANALOG); - - // B5,B6: FDCAN2 mode - set_gpio_pullup(GPIOB, 5, PULL_NONE); - set_gpio_alternate(GPIOB, 5, GPIO_AF9_FDCAN2); - - set_gpio_pullup(GPIOB, 6, PULL_NONE); - set_gpio_alternate(GPIOB, 6, GPIO_AF9_FDCAN2); - red_chiplet_enable_can_transceiver(2U, true); - } else { - // B5,B6: disable normal mode - set_gpio_pullup(GPIOB, 5, PULL_NONE); - set_gpio_mode(GPIOB, 5, MODE_ANALOG); - - set_gpio_pullup(GPIOB, 6, PULL_NONE); - set_gpio_mode(GPIOB, 6, MODE_ANALOG); - // B12,B13: FDCAN2 mode - set_gpio_pullup(GPIOB, 12, PULL_NONE); - set_gpio_alternate(GPIOB, 12, GPIO_AF9_FDCAN2); - - set_gpio_pullup(GPIOB, 13, PULL_NONE); - set_gpio_alternate(GPIOB, 13, GPIO_AF9_FDCAN2); - red_chiplet_enable_can_transceiver(4U, true); - } - break; - default: - break; - } -} - -static void red_chiplet_set_fan_or_usb_load_switch(bool enabled) { - set_gpio_output(GPIOD, 3, enabled); -} - -static void red_chiplet_init(void) { - common_init_gpio(); - - // A8, A3: OBD_SBU1_RELAY, OBD_SBU2_RELAY - set_gpio_output_type(GPIOA, 8, OUTPUT_TYPE_OPEN_DRAIN); - set_gpio_pullup(GPIOA, 8, PULL_NONE); - set_gpio_output(GPIOA, 8, 1); - set_gpio_mode(GPIOA, 8, MODE_OUTPUT); - - set_gpio_output_type(GPIOA, 3, OUTPUT_TYPE_OPEN_DRAIN); - set_gpio_pullup(GPIOA, 3, PULL_NONE); - set_gpio_output(GPIOA, 3, 1); - set_gpio_mode(GPIOA, 3, MODE_OUTPUT); - - // G11,B10,D7,B11: transceiver enable - set_gpio_pullup(GPIOG, 11, PULL_NONE); - set_gpio_mode(GPIOG, 11, MODE_OUTPUT); - - set_gpio_pullup(GPIOB, 10, PULL_NONE); - set_gpio_mode(GPIOB, 10, MODE_OUTPUT); - - set_gpio_pullup(GPIOD, 7, PULL_NONE); - set_gpio_mode(GPIOD, 7, MODE_OUTPUT); - - set_gpio_pullup(GPIOB, 11, PULL_NONE); - set_gpio_mode(GPIOB, 11, MODE_OUTPUT); - - // D3: usb load switch - set_gpio_pullup(GPIOD, 3, PULL_NONE); - set_gpio_mode(GPIOD, 3, MODE_OUTPUT); - - // B0: 5VOUT_S - set_gpio_pullup(GPIOB, 0, PULL_NONE); - set_gpio_mode(GPIOB, 0, MODE_ANALOG); - - // Initialize harness - harness_init(); - - - // Enable CAN transceivers - red_chiplet_enable_can_transceivers(true); - - // Disable LEDs - red_set_led(LED_RED, false); - red_set_led(LED_GREEN, false); - red_set_led(LED_BLUE, false); - - // Set normal CAN mode - red_chiplet_set_can_mode(CAN_MODE_NORMAL); -} - -static harness_configuration red_chiplet_harness_config = { - .has_harness = true, - .GPIO_SBU1 = GPIOC, - .GPIO_SBU2 = GPIOA, - .GPIO_relay_SBU1 = GPIOA, - .GPIO_relay_SBU2 = GPIOA, - .pin_SBU1 = 4, - .pin_SBU2 = 1, - .pin_relay_SBU1 = 8, - .pin_relay_SBU2 = 3, - .adc_channel_SBU1 = 4, // ADC12_INP4 - .adc_channel_SBU2 = 17 // ADC1_INP17 -}; diff --git a/board/boards/tres.h b/board/boards/tres.h index f0602ae60b..0de0beb94c 100644 --- a/board/boards/tres.h +++ b/board/boards/tres.h @@ -9,7 +9,7 @@ static bool tres_ir_enabled; static bool tres_fan_enabled; static void tres_update_fan_ir_power(void) { - red_chiplet_set_fan_or_usb_load_switch(tres_ir_enabled || tres_fan_enabled); + set_gpio_output(GPIOD, 3, tres_ir_enabled || tres_fan_enabled); } static void tres_set_ir_power(uint8_t percentage){ @@ -29,6 +29,79 @@ static void tres_set_fan_enabled(bool enabled) { tres_update_fan_ir_power(); } +static void tres_enable_can_transceiver(uint8_t transceiver, bool enabled) { + switch (transceiver) { + case 1U: + set_gpio_output(GPIOG, 11, !enabled); + break; + case 2U: + set_gpio_output(GPIOB, 10, !enabled); + break; + case 3U: + set_gpio_output(GPIOD, 7, !enabled); + break; + case 4U: + set_gpio_output(GPIOB, 11, !enabled); + break; + default: + break; + } +} + +static void tres_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) { + tres_enable_can_transceiver(i, true); + } else { + tres_enable_can_transceiver(i, enabled); + } + } +} + +static void tres_set_can_mode(uint8_t mode) { + current_board->enable_can_transceiver(2U, false); + current_board->enable_can_transceiver(4U, false); + switch (mode) { + case CAN_MODE_NORMAL: + case CAN_MODE_OBD_CAN2: + if ((bool)(mode == CAN_MODE_NORMAL) != (bool)(harness.status == HARNESS_STATUS_FLIPPED)) { + // B12,B13: disable normal mode + set_gpio_pullup(GPIOB, 12, PULL_NONE); + set_gpio_mode(GPIOB, 12, MODE_ANALOG); + + set_gpio_pullup(GPIOB, 13, PULL_NONE); + set_gpio_mode(GPIOB, 13, MODE_ANALOG); + + // B5,B6: FDCAN2 mode + set_gpio_pullup(GPIOB, 5, PULL_NONE); + set_gpio_alternate(GPIOB, 5, GPIO_AF9_FDCAN2); + + set_gpio_pullup(GPIOB, 6, PULL_NONE); + set_gpio_alternate(GPIOB, 6, GPIO_AF9_FDCAN2); + current_board->enable_can_transceiver(2U, true); + } else { + // B5,B6: disable normal mode + set_gpio_pullup(GPIOB, 5, PULL_NONE); + set_gpio_mode(GPIOB, 5, MODE_ANALOG); + + set_gpio_pullup(GPIOB, 6, PULL_NONE); + set_gpio_mode(GPIOB, 6, MODE_ANALOG); + // B12,B13: FDCAN2 mode + set_gpio_pullup(GPIOB, 12, PULL_NONE); + set_gpio_alternate(GPIOB, 12, GPIO_AF9_FDCAN2); + + set_gpio_pullup(GPIOB, 13, PULL_NONE); + set_gpio_alternate(GPIOB, 13, GPIO_AF9_FDCAN2); + current_board->enable_can_transceiver(4U, true); + } + break; + default: + break; + } +} + static bool tres_read_som_gpio (void) { return (get_gpio_input(GPIOC, 2) != 0); } @@ -39,7 +112,32 @@ static void tres_init(void) { register_set_bits(&(PWR->CR3), PWR_CR3_USB33DEN); while ((PWR->CR3 & PWR_CR3_USB33RDY) == 0U); - red_chiplet_init(); + common_init_gpio(); + + // A8, A3: OBD_SBU1_RELAY, OBD_SBU2_RELAY + set_gpio_output_type(GPIOA, 8, OUTPUT_TYPE_OPEN_DRAIN); + set_gpio_pullup(GPIOA, 8, PULL_NONE); + set_gpio_output(GPIOA, 8, 1); + set_gpio_mode(GPIOA, 8, MODE_OUTPUT); + + set_gpio_output_type(GPIOA, 3, OUTPUT_TYPE_OPEN_DRAIN); + set_gpio_pullup(GPIOA, 3, PULL_NONE); + set_gpio_output(GPIOA, 3, 1); + set_gpio_mode(GPIOA, 3, MODE_OUTPUT); + + // Initialize harness + harness_init(); + + // Enable CAN transceivers + tres_enable_can_transceivers(true); + + // Disable LEDs + red_set_led(LED_RED, false); + red_set_led(LED_GREEN, false); + red_set_led(LED_BLUE, false); + + // Set normal CAN mode + tres_set_can_mode(CAN_MODE_NORMAL); // C2: SOM GPIO used as input (fan control at boot) set_gpio_mode(GPIOC, 2, MODE_INPUT); @@ -74,8 +172,22 @@ static void tres_init(void) { clock_source_init(); } +static harness_configuration tres_harness_config = { + .has_harness = true, + .GPIO_SBU1 = GPIOC, + .GPIO_SBU2 = GPIOA, + .GPIO_relay_SBU1 = GPIOA, + .GPIO_relay_SBU2 = GPIOA, + .pin_SBU1 = 4, + .pin_SBU2 = 1, + .pin_relay_SBU1 = 8, + .pin_relay_SBU2 = 3, + .adc_channel_SBU1 = 4, // ADC12_INP4 + .adc_channel_SBU2 = 17 // ADC1_INP17 +}; + board board_tres = { - .harness_config = &red_chiplet_harness_config, + .harness_config = &tres_harness_config, .has_obd = true, .has_spi = true, .has_canfd = true, @@ -86,10 +198,10 @@ 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, + .enable_can_transceiver = tres_enable_can_transceiver, + .enable_can_transceivers = tres_enable_can_transceivers, .set_led = red_set_led, - .set_can_mode = red_chiplet_set_can_mode, + .set_can_mode = tres_set_can_mode, .check_ignition = red_check_ignition, .read_voltage_mV = red_read_voltage_mV, .read_current_mA = unused_read_current, diff --git a/board/stm32h7/board.h b/board/stm32h7/board.h index ea4812245e..143e431c74 100644 --- a/board/stm32h7/board.h +++ b/board/stm32h7/board.h @@ -15,7 +15,6 @@ #include "stm32h7/sound.h" #include "drivers/clock_source.h" #include "boards/red.h" -#include "boards/red_chiplet.h" #include "boards/tres.h" #include "boards/cuatro.h" From b7445593052b292fb6ad30347350ac7a070ce067 Mon Sep 17 00:00:00 2001 From: Robbe Derks Date: Fri, 29 Nov 2024 18:06:12 +0100 Subject: [PATCH 2/9] global can mode set --- board/boards/black.h | 4 ---- board/boards/cuatro.h | 3 --- board/boards/dos.h | 3 --- board/boards/red.h | 3 --- board/boards/tres.h | 3 --- board/boards/uno.h | 3 --- board/boards/white.h | 3 --- board/main.c | 1 + 8 files changed, 1 insertion(+), 22 deletions(-) diff --git a/board/boards/black.h b/board/boards/black.h index 133c11fb2d..968031f3b0 100644 --- a/board/boards/black.h +++ b/board/boards/black.h @@ -126,7 +126,6 @@ static void black_init(void) { // Initialize harness harness_init(); - // Enable CAN transceivers black_enable_can_transceivers(true); @@ -134,9 +133,6 @@ static void black_init(void) { black_set_led(LED_RED, false); black_set_led(LED_GREEN, false); black_set_led(LED_BLUE, false); - - // Set normal CAN mode - black_set_can_mode(CAN_MODE_NORMAL); } static void black_init_bootloader(void) { diff --git a/board/boards/cuatro.h b/board/boards/cuatro.h index ea463c3b24..e740c72a54 100644 --- a/board/boards/cuatro.h +++ b/board/boards/cuatro.h @@ -104,9 +104,6 @@ static void cuatro_init(void) { red_set_led(LED_GREEN, false); red_set_led(LED_BLUE, false); - // Set normal CAN mode - tres_set_can_mode(CAN_MODE_NORMAL); - // init LEDs as open drain set_gpio_output_type(GPIOE, 2, OUTPUT_TYPE_OPEN_DRAIN); set_gpio_output_type(GPIOB, 2, OUTPUT_TYPE_OPEN_DRAIN); diff --git a/board/boards/dos.h b/board/boards/dos.h index d96cee4ca4..5d379522c0 100644 --- a/board/boards/dos.h +++ b/board/boards/dos.h @@ -163,9 +163,6 @@ static void dos_init(void) { // Bootkick dos_set_bootkick(true); - // Set normal CAN mode - dos_set_can_mode(CAN_MODE_NORMAL); - // Init clock source (camera strobe) using PWM clock_source_init(); } diff --git a/board/boards/red.h b/board/boards/red.h index f1d8d9c44b..23eb4b302a 100644 --- a/board/boards/red.h +++ b/board/boards/red.h @@ -152,9 +152,6 @@ static void red_init(void) { red_set_led(LED_RED, false); red_set_led(LED_GREEN, false); red_set_led(LED_BLUE, false); - - // Set normal CAN mode - red_set_can_mode(CAN_MODE_NORMAL); } static harness_configuration red_harness_config = { diff --git a/board/boards/tres.h b/board/boards/tres.h index 0de0beb94c..31ce58dc6c 100644 --- a/board/boards/tres.h +++ b/board/boards/tres.h @@ -136,9 +136,6 @@ static void tres_init(void) { red_set_led(LED_GREEN, false); red_set_led(LED_BLUE, false); - // Set normal CAN mode - tres_set_can_mode(CAN_MODE_NORMAL); - // C2: SOM GPIO used as input (fan control at boot) set_gpio_mode(GPIOC, 2, MODE_INPUT); set_gpio_pullup(GPIOC, 2, PULL_DOWN); diff --git a/board/boards/uno.h b/board/boards/uno.h index d1728f1f9f..b6a792a78b 100644 --- a/board/boards/uno.h +++ b/board/boards/uno.h @@ -160,9 +160,6 @@ static void uno_init(void) { uno_set_led(LED_GREEN, false); uno_set_led(LED_BLUE, false); - // Set normal CAN mode - uno_set_can_mode(CAN_MODE_NORMAL); - // Switch to phone usb mode if harness connection is powered by less than 7V if(white_read_voltage_mV() < 7000U){ uno_set_usb_switch(true); diff --git a/board/boards/white.h b/board/boards/white.h index c4a2559353..5c5f88979a 100644 --- a/board/boards/white.h +++ b/board/boards/white.h @@ -161,9 +161,6 @@ static void white_grey_init(void) { white_set_led(LED_GREEN, false); white_set_led(LED_BLUE, false); - // Set normal CAN mode - white_set_can_mode(CAN_MODE_NORMAL); - // Init usb power mode // Init in CDP mode only if panda is powered by 12V. // Otherwise a PC would not be able to flash a standalone panda diff --git a/board/main.c b/board/main.c index aaea95d089..b190edd28a 100644 --- a/board/main.c +++ b/board/main.c @@ -322,6 +322,7 @@ int main(void) { // init board current_board->init(); + current_board->set_can_mode(CAN_MODE_NORMAL); // panda has an FPU, let's use it! enable_fpu(); From ccc8d05f43069d41f4f05d562d72b8d60544c2eb Mon Sep 17 00:00:00 2001 From: Robbe Derks Date: Fri, 29 Nov 2024 18:07:36 +0100 Subject: [PATCH 3/9] global led disable --- board/boards/black.h | 5 ----- board/boards/cuatro.h | 5 ----- board/boards/dos.h | 5 ----- board/boards/red.h | 5 ----- board/boards/tres.h | 5 ----- board/boards/uno.h | 5 ----- board/boards/white.h | 5 ----- board/main.c | 1 + 8 files changed, 1 insertion(+), 35 deletions(-) diff --git a/board/boards/black.h b/board/boards/black.h index 968031f3b0..6b3f49ce54 100644 --- a/board/boards/black.h +++ b/board/boards/black.h @@ -128,11 +128,6 @@ static void black_init(void) { // Enable CAN transceivers black_enable_can_transceivers(true); - - // Disable LEDs - black_set_led(LED_RED, false); - black_set_led(LED_GREEN, false); - black_set_led(LED_BLUE, false); } static void black_init_bootloader(void) { diff --git a/board/boards/cuatro.h b/board/boards/cuatro.h index e740c72a54..3c543cf0b1 100644 --- a/board/boards/cuatro.h +++ b/board/boards/cuatro.h @@ -99,11 +99,6 @@ static void cuatro_init(void) { // Enable CAN transceivers cuatro_enable_can_transceivers(true); - // Disable LEDs - red_set_led(LED_RED, false); - red_set_led(LED_GREEN, false); - red_set_led(LED_BLUE, false); - // init LEDs as open drain set_gpio_output_type(GPIOE, 2, OUTPUT_TYPE_OPEN_DRAIN); set_gpio_output_type(GPIOB, 2, OUTPUT_TYPE_OPEN_DRAIN); diff --git a/board/boards/dos.h b/board/boards/dos.h index 5d379522c0..bef9f381e4 100644 --- a/board/boards/dos.h +++ b/board/boards/dos.h @@ -155,11 +155,6 @@ static void dos_init(void) { // Enable CAN transceivers dos_enable_can_transceivers(true); - // Disable LEDs - dos_set_led(LED_RED, false); - dos_set_led(LED_GREEN, false); - dos_set_led(LED_BLUE, false); - // Bootkick dos_set_bootkick(true); diff --git a/board/boards/red.h b/board/boards/red.h index 23eb4b302a..51fdfa487e 100644 --- a/board/boards/red.h +++ b/board/boards/red.h @@ -147,11 +147,6 @@ static void red_init(void) { // Enable CAN transceivers red_enable_can_transceivers(true); - - // Disable LEDs - red_set_led(LED_RED, false); - red_set_led(LED_GREEN, false); - red_set_led(LED_BLUE, false); } static harness_configuration red_harness_config = { diff --git a/board/boards/tres.h b/board/boards/tres.h index 31ce58dc6c..1c232b09d2 100644 --- a/board/boards/tres.h +++ b/board/boards/tres.h @@ -131,11 +131,6 @@ static void tres_init(void) { // Enable CAN transceivers tres_enable_can_transceivers(true); - // Disable LEDs - red_set_led(LED_RED, false); - red_set_led(LED_GREEN, false); - red_set_led(LED_BLUE, false); - // C2: SOM GPIO used as input (fan control at boot) set_gpio_mode(GPIOC, 2, MODE_INPUT); set_gpio_pullup(GPIOC, 2, PULL_DOWN); diff --git a/board/boards/uno.h b/board/boards/uno.h index b6a792a78b..4fbd51ee15 100644 --- a/board/boards/uno.h +++ b/board/boards/uno.h @@ -155,11 +155,6 @@ static void uno_init(void) { // Enable CAN transceivers uno_enable_can_transceivers(true); - // Disable LEDs - uno_set_led(LED_RED, false); - uno_set_led(LED_GREEN, false); - uno_set_led(LED_BLUE, false); - // Switch to phone usb mode if harness connection is powered by less than 7V if(white_read_voltage_mV() < 7000U){ uno_set_usb_switch(true); diff --git a/board/boards/white.h b/board/boards/white.h index 5c5f88979a..8efa1acc08 100644 --- a/board/boards/white.h +++ b/board/boards/white.h @@ -156,11 +156,6 @@ static void white_grey_init(void) { // Enable CAN transceivers white_enable_can_transceivers(true); - // Disable LEDs - white_set_led(LED_RED, false); - white_set_led(LED_GREEN, false); - white_set_led(LED_BLUE, false); - // Init usb power mode // Init in CDP mode only if panda is powered by 12V. // Otherwise a PC would not be able to flash a standalone panda diff --git a/board/main.c b/board/main.c index b190edd28a..ade10c84d3 100644 --- a/board/main.c +++ b/board/main.c @@ -361,6 +361,7 @@ int main(void) { current_board->set_led(LED_RED, false); current_board->set_led(LED_GREEN, false); + current_board->set_led(LED_BLUE, false); print("**** INTERRUPTS ON ****\n"); enable_interrupts(); From d6d816a7d8df0d9ed035b350150feb7bdec73c22 Mon Sep 17 00:00:00 2001 From: Robbe Derks Date: Fri, 29 Nov 2024 18:09:10 +0100 Subject: [PATCH 4/9] this is already done globally --- board/boards/black.h | 3 --- board/boards/cuatro.h | 3 --- board/boards/dos.h | 4 ---- board/boards/red.h | 4 ---- board/boards/tres.h | 3 --- board/boards/uno.h | 4 ---- board/boards/white.h | 4 ---- 7 files changed, 25 deletions(-) diff --git a/board/boards/black.h b/board/boards/black.h index 6b3f49ce54..8613ac7797 100644 --- a/board/boards/black.h +++ b/board/boards/black.h @@ -125,9 +125,6 @@ static void black_init(void) { // Initialize harness harness_init(); - - // Enable CAN transceivers - black_enable_can_transceivers(true); } static void black_init_bootloader(void) { diff --git a/board/boards/cuatro.h b/board/boards/cuatro.h index 3c543cf0b1..5ce45da064 100644 --- a/board/boards/cuatro.h +++ b/board/boards/cuatro.h @@ -96,9 +96,6 @@ static void cuatro_init(void) { // Initialize harness harness_init(); - // Enable CAN transceivers - cuatro_enable_can_transceivers(true); - // init LEDs as open drain set_gpio_output_type(GPIOE, 2, OUTPUT_TYPE_OPEN_DRAIN); set_gpio_output_type(GPIOB, 2, OUTPUT_TYPE_OPEN_DRAIN); diff --git a/board/boards/dos.h b/board/boards/dos.h index bef9f381e4..8427e56496 100644 --- a/board/boards/dos.h +++ b/board/boards/dos.h @@ -151,10 +151,6 @@ static void dos_init(void) { // Initialize harness harness_init(); - - // Enable CAN transceivers - dos_enable_can_transceivers(true); - // Bootkick dos_set_bootkick(true); diff --git a/board/boards/red.h b/board/boards/red.h index 51fdfa487e..9f44f03a3e 100644 --- a/board/boards/red.h +++ b/board/boards/red.h @@ -143,10 +143,6 @@ static void red_init(void) { // Initialize harness harness_init(); - - - // Enable CAN transceivers - red_enable_can_transceivers(true); } static harness_configuration red_harness_config = { diff --git a/board/boards/tres.h b/board/boards/tres.h index 1c232b09d2..57b7a042d2 100644 --- a/board/boards/tres.h +++ b/board/boards/tres.h @@ -128,9 +128,6 @@ static void tres_init(void) { // Initialize harness harness_init(); - // Enable CAN transceivers - tres_enable_can_transceivers(true); - // C2: SOM GPIO used as input (fan control at boot) set_gpio_mode(GPIOC, 2, MODE_INPUT); set_gpio_pullup(GPIOC, 2, PULL_DOWN); diff --git a/board/boards/uno.h b/board/boards/uno.h index 4fbd51ee15..9458d3f000 100644 --- a/board/boards/uno.h +++ b/board/boards/uno.h @@ -151,10 +151,6 @@ static void uno_init(void) { // Initialize harness harness_init(); - - // Enable CAN transceivers - uno_enable_can_transceivers(true); - // Switch to phone usb mode if harness connection is powered by less than 7V if(white_read_voltage_mV() < 7000U){ uno_set_usb_switch(true); diff --git a/board/boards/white.h b/board/boards/white.h index 8efa1acc08..44bbf832f4 100644 --- a/board/boards/white.h +++ b/board/boards/white.h @@ -152,10 +152,6 @@ static void white_grey_init(void) { set_gpio_alternate(GPIOC, 11, GPIO_AF7_USART3); set_gpio_pullup(GPIOC, 11, PULL_UP); - - // Enable CAN transceivers - white_enable_can_transceivers(true); - // Init usb power mode // Init in CDP mode only if panda is powered by 12V. // Otherwise a PC would not be able to flash a standalone panda From ffe4de871a918f1008b5a26740ce1481c641b6ee Mon Sep 17 00:00:00 2001 From: Robbe Derks Date: Fri, 29 Nov 2024 18:12:15 +0100 Subject: [PATCH 5/9] global harness init --- board/boards/black.h | 3 --- board/boards/cuatro.h | 3 --- board/boards/dos.h | 3 --- board/boards/red.h | 3 --- board/boards/tres.h | 3 --- board/boards/uno.h | 3 --- board/main.c | 3 +++ 7 files changed, 3 insertions(+), 18 deletions(-) diff --git a/board/boards/black.h b/board/boards/black.h index 8613ac7797..8d0588fc65 100644 --- a/board/boards/black.h +++ b/board/boards/black.h @@ -122,9 +122,6 @@ static void black_init(void) { // Turn on USB load switch. black_set_usb_load_switch(true); - - // Initialize harness - harness_init(); } static void black_init_bootloader(void) { diff --git a/board/boards/cuatro.h b/board/boards/cuatro.h index 5ce45da064..4570e364fe 100644 --- a/board/boards/cuatro.h +++ b/board/boards/cuatro.h @@ -93,9 +93,6 @@ static void cuatro_init(void) { set_gpio_output(GPIOA, 3, 1); set_gpio_mode(GPIOA, 3, MODE_OUTPUT); - // Initialize harness - harness_init(); - // init LEDs as open drain set_gpio_output_type(GPIOE, 2, OUTPUT_TYPE_OPEN_DRAIN); set_gpio_output_type(GPIOB, 2, OUTPUT_TYPE_OPEN_DRAIN); diff --git a/board/boards/dos.h b/board/boards/dos.h index 8427e56496..d9e13e92b8 100644 --- a/board/boards/dos.h +++ b/board/boards/dos.h @@ -148,9 +148,6 @@ static void dos_init(void) { pwm_init(TIM4, 2); dos_set_ir_power(0U); - // Initialize harness - harness_init(); - // Bootkick dos_set_bootkick(true); diff --git a/board/boards/red.h b/board/boards/red.h index 9f44f03a3e..53ded0edae 100644 --- a/board/boards/red.h +++ b/board/boards/red.h @@ -140,9 +140,6 @@ static void red_init(void) { set_gpio_pullup(GPIOB, 14, PULL_UP); set_gpio_mode(GPIOB, 14, MODE_OUTPUT); set_gpio_output(GPIOB, 14, 1); - - // Initialize harness - harness_init(); } static harness_configuration red_harness_config = { diff --git a/board/boards/tres.h b/board/boards/tres.h index 57b7a042d2..c0b93f9683 100644 --- a/board/boards/tres.h +++ b/board/boards/tres.h @@ -125,9 +125,6 @@ static void tres_init(void) { set_gpio_output(GPIOA, 3, 1); set_gpio_mode(GPIOA, 3, MODE_OUTPUT); - // Initialize harness - harness_init(); - // C2: SOM GPIO used as input (fan control at boot) set_gpio_mode(GPIOC, 2, MODE_INPUT); set_gpio_pullup(GPIOC, 2, PULL_DOWN); diff --git a/board/boards/uno.h b/board/boards/uno.h index 9458d3f000..cd44948892 100644 --- a/board/boards/uno.h +++ b/board/boards/uno.h @@ -148,9 +148,6 @@ static void uno_init(void) { pwm_init(TIM4, 2); uno_set_ir_power(0U); - // Initialize harness - harness_init(); - // Switch to phone usb mode if harness connection is powered by less than 7V if(white_read_voltage_mV() < 7000U){ uno_set_usb_switch(true); diff --git a/board/main.c b/board/main.c index ade10c84d3..2e54bcdb16 100644 --- a/board/main.c +++ b/board/main.c @@ -323,6 +323,9 @@ int main(void) { // init board current_board->init(); current_board->set_can_mode(CAN_MODE_NORMAL); + if (current_board->harness_config->has_harness) { + harness_init(); + } // panda has an FPU, let's use it! enable_fpu(); From b0d78dc1ce91f4eee5a689ea61106a1bfa73cdf3 Mon Sep 17 00:00:00 2001 From: Robbe Derks Date: Mon, 2 Dec 2024 20:53:10 -0800 Subject: [PATCH 6/9] global spi gpio init --- board/boards/cuatro.h | 3 --- board/boards/dos.h | 5 ----- board/boards/tres.h | 3 --- board/main.c | 1 + 4 files changed, 1 insertion(+), 11 deletions(-) diff --git a/board/boards/cuatro.h b/board/boards/cuatro.h index 4570e364fe..d7c4a52d3d 100644 --- a/board/boards/cuatro.h +++ b/board/boards/cuatro.h @@ -129,9 +129,6 @@ static void cuatro_init(void) { gpio_uart7_init(); uart_init(&uart_ring_som_debug, 115200); - // SPI init - gpio_spi_init(); - // fan setup set_gpio_alternate(GPIOC, 8, GPIO_AF2_TIM3); register_set_bits(&(GPIOC->OTYPER), GPIO_OTYPER_OT8); // open drain diff --git a/board/boards/dos.h b/board/boards/dos.h index d9e13e92b8..55401111e0 100644 --- a/board/boards/dos.h +++ b/board/boards/dos.h @@ -131,11 +131,6 @@ static void dos_init(void) { set_gpio_output(GPIOC, 10, 1); set_gpio_output(GPIOC, 11, 1); -#ifdef ENABLE_SPI - // SPI init - gpio_spi_init(); -#endif - // C8: FAN PWM aka TIM3_CH3 set_gpio_alternate(GPIOC, 8, GPIO_AF2_TIM3); diff --git a/board/boards/tres.h b/board/boards/tres.h index c0b93f9683..cb5af558ac 100644 --- a/board/boards/tres.h +++ b/board/boards/tres.h @@ -138,9 +138,6 @@ static void tres_init(void) { gpio_uart7_init(); uart_init(&uart_ring_som_debug, 115200); - // SPI init - gpio_spi_init(); - // fan setup set_gpio_alternate(GPIOC, 8, GPIO_AF2_TIM3); diff --git a/board/main.c b/board/main.c index 2e54bcdb16..1c86ebe30f 100644 --- a/board/main.c +++ b/board/main.c @@ -358,6 +358,7 @@ int main(void) { #ifdef ENABLE_SPI if (current_board->has_spi) { + gpio_spi_init(); spi_init(); } #endif From fff34b7fb0fb8b4c58e111b293ac5760bd6462d5 Mon Sep 17 00:00:00 2001 From: Robbe Derks Date: Mon, 2 Dec 2024 21:07:18 -0800 Subject: [PATCH 7/9] init OBD_SBUx_RELAY pins in harness init --- board/boards/black.h | 9 --------- board/boards/cuatro.h | 11 ----------- board/boards/dos.h | 9 --------- board/boards/red.h | 11 ----------- board/boards/tres.h | 11 ----------- board/boards/uno.h | 9 --------- board/drivers/harness.h | 6 ++++++ 7 files changed, 6 insertions(+), 60 deletions(-) diff --git a/board/boards/black.h b/board/boards/black.h index 8d0588fc65..4e51798254 100644 --- a/board/boards/black.h +++ b/board/boards/black.h @@ -111,15 +111,6 @@ static void black_init(void) { set_gpio_output(GPIOC, 5, 0); set_gpio_output(GPIOC, 12, 0); - // C10: OBD_SBU1_RELAY (harness relay driving output) - // C11: OBD_SBU2_RELAY (harness relay driving output) - set_gpio_mode(GPIOC, 10, MODE_OUTPUT); - set_gpio_mode(GPIOC, 11, MODE_OUTPUT); - set_gpio_output_type(GPIOC, 10, OUTPUT_TYPE_OPEN_DRAIN); - set_gpio_output_type(GPIOC, 11, OUTPUT_TYPE_OPEN_DRAIN); - set_gpio_output(GPIOC, 10, 1); - set_gpio_output(GPIOC, 11, 1); - // Turn on USB load switch. black_set_usb_load_switch(true); } diff --git a/board/boards/cuatro.h b/board/boards/cuatro.h index d7c4a52d3d..cda262df0e 100644 --- a/board/boards/cuatro.h +++ b/board/boards/cuatro.h @@ -82,17 +82,6 @@ static void cuatro_set_amp_enabled(bool enabled){ static void cuatro_init(void) { common_init_gpio(); - // A8, A3: OBD_SBU1_RELAY, OBD_SBU2_RELAY - set_gpio_output_type(GPIOA, 8, OUTPUT_TYPE_OPEN_DRAIN); - set_gpio_pullup(GPIOA, 8, PULL_NONE); - set_gpio_output(GPIOA, 8, 1); - set_gpio_mode(GPIOA, 8, MODE_OUTPUT); - - set_gpio_output_type(GPIOA, 3, OUTPUT_TYPE_OPEN_DRAIN); - set_gpio_pullup(GPIOA, 3, PULL_NONE); - set_gpio_output(GPIOA, 3, 1); - set_gpio_mode(GPIOA, 3, MODE_OUTPUT); - // init LEDs as open drain set_gpio_output_type(GPIOE, 2, OUTPUT_TYPE_OPEN_DRAIN); set_gpio_output_type(GPIOB, 2, OUTPUT_TYPE_OPEN_DRAIN); diff --git a/board/boards/dos.h b/board/boards/dos.h index 55401111e0..21edacdefd 100644 --- a/board/boards/dos.h +++ b/board/boards/dos.h @@ -122,15 +122,6 @@ static void dos_init(void) { set_gpio_mode(GPIOC, 0, MODE_ANALOG); set_gpio_mode(GPIOC, 3, MODE_ANALOG); - // C10: OBD_SBU1_RELAY (harness relay driving output) - // C11: OBD_SBU2_RELAY (harness relay driving output) - set_gpio_mode(GPIOC, 10, MODE_OUTPUT); - set_gpio_mode(GPIOC, 11, MODE_OUTPUT); - set_gpio_output_type(GPIOC, 10, OUTPUT_TYPE_OPEN_DRAIN); - set_gpio_output_type(GPIOC, 11, OUTPUT_TYPE_OPEN_DRAIN); - set_gpio_output(GPIOC, 10, 1); - set_gpio_output(GPIOC, 11, 1); - // C8: FAN PWM aka TIM3_CH3 set_gpio_alternate(GPIOC, 8, GPIO_AF2_TIM3); diff --git a/board/boards/red.h b/board/boards/red.h index 53ded0edae..1893442a31 100644 --- a/board/boards/red.h +++ b/board/boards/red.h @@ -107,17 +107,6 @@ static uint32_t red_read_voltage_mV(void){ static void red_init(void) { common_init_gpio(); - //C10,C11 : OBD_SBU1_RELAY, OBD_SBU2_RELAY - set_gpio_output_type(GPIOC, 10, OUTPUT_TYPE_OPEN_DRAIN); - set_gpio_pullup(GPIOC, 10, PULL_NONE); - set_gpio_mode(GPIOC, 10, MODE_OUTPUT); - set_gpio_output(GPIOC, 10, 1); - - set_gpio_output_type(GPIOC, 11, OUTPUT_TYPE_OPEN_DRAIN); - set_gpio_pullup(GPIOC, 11, PULL_NONE); - set_gpio_mode(GPIOC, 11, MODE_OUTPUT); - set_gpio_output(GPIOC, 11, 1); - // G11,B3,D7,B4: transceiver enable set_gpio_pullup(GPIOG, 11, PULL_NONE); set_gpio_mode(GPIOG, 11, MODE_OUTPUT); diff --git a/board/boards/tres.h b/board/boards/tres.h index cb5af558ac..ab26e4c564 100644 --- a/board/boards/tres.h +++ b/board/boards/tres.h @@ -114,17 +114,6 @@ static void tres_init(void) { common_init_gpio(); - // A8, A3: OBD_SBU1_RELAY, OBD_SBU2_RELAY - set_gpio_output_type(GPIOA, 8, OUTPUT_TYPE_OPEN_DRAIN); - set_gpio_pullup(GPIOA, 8, PULL_NONE); - set_gpio_output(GPIOA, 8, 1); - set_gpio_mode(GPIOA, 8, MODE_OUTPUT); - - set_gpio_output_type(GPIOA, 3, OUTPUT_TYPE_OPEN_DRAIN); - set_gpio_pullup(GPIOA, 3, PULL_NONE); - set_gpio_output(GPIOA, 3, 1); - set_gpio_mode(GPIOA, 3, 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); diff --git a/board/boards/uno.h b/board/boards/uno.h index cd44948892..2fcefd58d1 100644 --- a/board/boards/uno.h +++ b/board/boards/uno.h @@ -128,15 +128,6 @@ static void uno_init(void) { set_gpio_output(GPIOC, 5, 0); set_gpio_output(GPIOC, 12, 0); - // C10: OBD_SBU1_RELAY (harness relay driving output) - // C11: OBD_SBU2_RELAY (harness relay driving output) - set_gpio_mode(GPIOC, 10, MODE_OUTPUT); - set_gpio_mode(GPIOC, 11, MODE_OUTPUT); - set_gpio_output_type(GPIOC, 10, OUTPUT_TYPE_OPEN_DRAIN); - set_gpio_output_type(GPIOC, 11, OUTPUT_TYPE_OPEN_DRAIN); - set_gpio_output(GPIOC, 10, 1); - set_gpio_output(GPIOC, 11, 1); - // C8: FAN PWM aka TIM3_CH3 set_gpio_alternate(GPIOC, 8, GPIO_AF2_TIM3); diff --git a/board/drivers/harness.h b/board/drivers/harness.h index cfb6965c03..efe319d0d3 100644 --- a/board/drivers/harness.h +++ b/board/drivers/harness.h @@ -94,6 +94,12 @@ void harness_tick(void) { } void harness_init(void) { + // init OBD_SBUx_RELAY + set_gpio_output_type(current_board->harness_config->GPIO_relay_SBU1, current_board->harness_config->pin_relay_SBU1, OUTPUT_TYPE_OPEN_DRAIN); + set_gpio_output_type(current_board->harness_config->GPIO_relay_SBU2, current_board->harness_config->pin_relay_SBU2, OUTPUT_TYPE_OPEN_DRAIN); + set_gpio_output(current_board->harness_config->GPIO_relay_SBU1, current_board->harness_config->pin_relay_SBU1, 1); + set_gpio_output(current_board->harness_config->GPIO_relay_SBU2, current_board->harness_config->pin_relay_SBU2, 1); + // try to detect orientation harness.status = harness_detect_orientation(); if (harness.status != HARNESS_STATUS_NC) { From 574c3ee52a66fb949351bc50095b995400086753 Mon Sep 17 00:00:00 2001 From: Robbe Derks Date: Mon, 2 Dec 2024 21:08:45 -0800 Subject: [PATCH 8/9] this is already done in harness init --- board/boards/black.h | 5 ----- board/boards/dos.h | 5 ----- board/boards/uno.h | 5 ----- board/stm32h7/peripherals.h | 7 ------- 4 files changed, 22 deletions(-) diff --git a/board/boards/black.h b/board/boards/black.h index 4e51798254..fd23ed4897 100644 --- a/board/boards/black.h +++ b/board/boards/black.h @@ -102,11 +102,6 @@ static void black_init(void) { set_gpio_alternate(GPIOA, 8, GPIO_AF11_CAN3); set_gpio_alternate(GPIOA, 15, GPIO_AF11_CAN3); - // C0: OBD_SBU1 (orientation detection) - // C3: OBD_SBU2 (orientation detection) - set_gpio_mode(GPIOC, 0, MODE_ANALOG); - set_gpio_mode(GPIOC, 3, MODE_ANALOG); - // GPS OFF set_gpio_output(GPIOC, 5, 0); set_gpio_output(GPIOC, 12, 0); diff --git a/board/boards/dos.h b/board/boards/dos.h index 21edacdefd..12ac363ac9 100644 --- a/board/boards/dos.h +++ b/board/boards/dos.h @@ -117,11 +117,6 @@ static void dos_init(void) { set_gpio_alternate(GPIOA, 8, GPIO_AF11_CAN3); set_gpio_alternate(GPIOA, 15, GPIO_AF11_CAN3); - // C0: OBD_SBU1 (orientation detection) - // C3: OBD_SBU2 (orientation detection) - set_gpio_mode(GPIOC, 0, MODE_ANALOG); - set_gpio_mode(GPIOC, 3, MODE_ANALOG); - // C8: FAN PWM aka TIM3_CH3 set_gpio_alternate(GPIOC, 8, GPIO_AF2_TIM3); diff --git a/board/boards/uno.h b/board/boards/uno.h index 2fcefd58d1..da9a2529a3 100644 --- a/board/boards/uno.h +++ b/board/boards/uno.h @@ -118,11 +118,6 @@ static void uno_init(void) { set_gpio_alternate(GPIOA, 8, GPIO_AF11_CAN3); set_gpio_alternate(GPIOA, 15, GPIO_AF11_CAN3); - // C0: OBD_SBU1 (orientation detection) - // C3: OBD_SBU2 (orientation detection) - set_gpio_mode(GPIOC, 0, MODE_ANALOG); - set_gpio_mode(GPIOC, 3, MODE_ANALOG); - // GPS off set_gpio_output(GPIOB, 1, 0); set_gpio_output(GPIOC, 5, 0); diff --git a/board/stm32h7/peripherals.h b/board/stm32h7/peripherals.h index c6874b8ac3..222f3c0dc3 100644 --- a/board/stm32h7/peripherals.h +++ b/board/stm32h7/peripherals.h @@ -44,13 +44,6 @@ void common_init_gpio(void) { set_gpio_mode(GPIOE, 4, MODE_OUTPUT); set_gpio_output_type(GPIOE, 4, OUTPUT_TYPE_OPEN_DRAIN); - //C4,A1: OBD_SBU1, OBD_SBU2 - set_gpio_pullup(GPIOC, 4, PULL_NONE); - set_gpio_mode(GPIOC, 4, MODE_ANALOG); - - set_gpio_pullup(GPIOA, 1, PULL_NONE); - set_gpio_mode(GPIOA, 1, MODE_ANALOG); - //F11: VOLT_S set_gpio_pullup(GPIOF, 11, PULL_NONE); set_gpio_mode(GPIOF, 11, MODE_ANALOG); From c3b0612e71b54ee6c16b3f75a39a8e045117e7a9 Mon Sep 17 00:00:00 2001 From: Robbe Derks Date: Mon, 2 Dec 2024 21:37:38 -0800 Subject: [PATCH 9/9] global set_can_mode --- board/boards/black.h | 44 +++++------------------ board/boards/board_declarations.h | 2 -- board/boards/cuatro.h | 1 - board/boards/dos.h | 43 +++++----------------- board/boards/grey.h | 1 - board/boards/red.h | 53 +++++----------------------- board/boards/tres.h | 53 +++++----------------------- board/boards/uno.h | 43 +++++----------------- board/boards/white.h | 37 +++++++++---------- board/drivers/harness.h | 33 +++++++++++++++++ board/drivers/harness_declarations.h | 12 +++++++ board/main.c | 11 +++--- board/main_comms.h | 4 +-- board/stm32f4/stm32f4_config.h | 1 + board/stm32h7/stm32h7_config.h | 1 + 15 files changed, 115 insertions(+), 224 deletions(-) diff --git a/board/boards/black.h b/board/boards/black.h index fd23ed4897..3403a0353f 100644 --- a/board/boards/black.h +++ b/board/boards/black.h @@ -57,39 +57,6 @@ static void black_set_usb_load_switch(bool enabled) { set_gpio_output(GPIOB, 1, !enabled); } -static void black_set_can_mode(uint8_t mode) { - black_enable_can_transceiver(2U, false); - black_enable_can_transceiver(4U, false); - switch (mode) { - case CAN_MODE_NORMAL: - case CAN_MODE_OBD_CAN2: - if ((bool)(mode == CAN_MODE_NORMAL) != (bool)(harness.status == HARNESS_STATUS_FLIPPED)) { - // B12,B13: disable OBD mode - set_gpio_mode(GPIOB, 12, MODE_INPUT); - set_gpio_mode(GPIOB, 13, MODE_INPUT); - - // B5,B6: normal CAN2 mode - set_gpio_alternate(GPIOB, 5, GPIO_AF9_CAN2); - set_gpio_alternate(GPIOB, 6, GPIO_AF9_CAN2); - black_enable_can_transceiver(2U, true); - - } else { - // B5,B6: disable normal CAN2 mode - set_gpio_mode(GPIOB, 5, MODE_INPUT); - set_gpio_mode(GPIOB, 6, MODE_INPUT); - - // B12,B13: OBD mode - set_gpio_alternate(GPIOB, 12, GPIO_AF9_CAN2); - set_gpio_alternate(GPIOB, 13, GPIO_AF9_CAN2); - black_enable_can_transceiver(4U, true); - } - break; - default: - print("Tried to set unsupported CAN mode: "); puth(mode); print("\n"); - break; - } -} - static bool black_check_ignition(void){ // ignition is checked through harness return harness_check_ignition(); @@ -127,7 +94,15 @@ static harness_configuration black_harness_config = { .pin_relay_SBU1 = 10, .pin_relay_SBU2 = 11, .adc_channel_SBU1 = 10, - .adc_channel_SBU2 = 13 + .adc_channel_SBU2 = 13, + .GPIO_CAN2_RX_NORMAL = GPIOB, + .GPIO_CAN2_TX_NORMAL = GPIOB, + .GPIO_CAN2_RX_FLIPPED = GPIOB, + .GPIO_CAN2_TX_FLIPPED = GPIOB, + .pin_CAN2_RX_NORMAL = 12, + .pin_CAN2_TX_NORMAL = 13, + .pin_CAN2_RX_FLIPPED = 5, + .pin_CAN2_TX_FLIPPED = 6 }; board board_black = { @@ -146,7 +121,6 @@ board board_black = { .enable_can_transceiver = black_enable_can_transceiver, .enable_can_transceivers = black_enable_can_transceivers, .set_led = black_set_led, - .set_can_mode = black_set_can_mode, .check_ignition = black_check_ignition, .read_voltage_mV = white_read_voltage_mV, .read_current_mA = unused_read_current, diff --git a/board/boards/board_declarations.h b/board/boards/board_declarations.h index 61e9ce2d8e..99a1f21d64 100644 --- a/board/boards/board_declarations.h +++ b/board/boards/board_declarations.h @@ -15,7 +15,6 @@ typedef void (*board_init_bootloader)(void); typedef void (*board_enable_can_transceiver)(uint8_t transceiver, bool enabled); typedef void (*board_enable_can_transceivers)(bool enabled); typedef void (*board_set_led)(uint8_t color, bool enabled); -typedef void (*board_set_can_mode)(uint8_t mode); typedef bool (*board_check_ignition)(void); typedef uint32_t (*board_read_voltage_mV)(void); typedef uint32_t (*board_read_current_mA)(void); @@ -41,7 +40,6 @@ struct board { board_enable_can_transceiver enable_can_transceiver; board_enable_can_transceivers enable_can_transceivers; board_set_led set_led; - board_set_can_mode set_can_mode; board_check_ignition check_ignition; board_read_voltage_mV read_voltage_mV; board_read_current_mA read_current_mA; diff --git a/board/boards/cuatro.h b/board/boards/cuatro.h index cda262df0e..e514ea295b 100644 --- a/board/boards/cuatro.h +++ b/board/boards/cuatro.h @@ -161,7 +161,6 @@ board board_cuatro = { .enable_can_transceiver = cuatro_enable_can_transceiver, .enable_can_transceivers = cuatro_enable_can_transceivers, .set_led = cuatro_set_led, - .set_can_mode = tres_set_can_mode, .check_ignition = red_check_ignition, .read_voltage_mV = cuatro_read_voltage_mV, .read_current_mA = cuatro_read_current_mA, diff --git a/board/boards/dos.h b/board/boards/dos.h index 12ac363ac9..bda207aec1 100644 --- a/board/boards/dos.h +++ b/board/boards/dos.h @@ -57,38 +57,6 @@ static void dos_set_bootkick(BootState state) { set_gpio_output(GPIOC, 4, state != BOOT_BOOTKICK); } -static void dos_set_can_mode(uint8_t mode) { - dos_enable_can_transceiver(2U, false); - dos_enable_can_transceiver(4U, false); - switch (mode) { - case CAN_MODE_NORMAL: - case CAN_MODE_OBD_CAN2: - if ((bool)(mode == CAN_MODE_NORMAL) != (bool)(harness.status == HARNESS_STATUS_FLIPPED)) { - // B12,B13: disable OBD mode - set_gpio_mode(GPIOB, 12, MODE_INPUT); - set_gpio_mode(GPIOB, 13, MODE_INPUT); - - // B5,B6: normal CAN2 mode - set_gpio_alternate(GPIOB, 5, GPIO_AF9_CAN2); - set_gpio_alternate(GPIOB, 6, GPIO_AF9_CAN2); - dos_enable_can_transceiver(2U, true); - } else { - // B5,B6: disable normal CAN2 mode - set_gpio_mode(GPIOB, 5, MODE_INPUT); - set_gpio_mode(GPIOB, 6, MODE_INPUT); - - // B12,B13: OBD mode - set_gpio_alternate(GPIOB, 12, GPIO_AF9_CAN2); - set_gpio_alternate(GPIOB, 13, GPIO_AF9_CAN2); - dos_enable_can_transceiver(4U, true); - } - break; - default: - print("Tried to set unsupported CAN mode: "); puth(mode); print("\n"); - break; - } -} - static bool dos_check_ignition(void){ // ignition is checked through harness return harness_check_ignition(); @@ -147,7 +115,15 @@ static harness_configuration dos_harness_config = { .pin_relay_SBU1 = 10, .pin_relay_SBU2 = 11, .adc_channel_SBU1 = 10, - .adc_channel_SBU2 = 13 + .adc_channel_SBU2 = 13, + .GPIO_CAN2_RX_NORMAL = GPIOB, + .GPIO_CAN2_TX_NORMAL = GPIOB, + .GPIO_CAN2_RX_FLIPPED = GPIOB, + .GPIO_CAN2_TX_FLIPPED = GPIOB, + .pin_CAN2_RX_NORMAL = 12, + .pin_CAN2_TX_NORMAL = 13, + .pin_CAN2_RX_FLIPPED = 5, + .pin_CAN2_TX_FLIPPED = 6 }; board board_dos = { @@ -169,7 +145,6 @@ board board_dos = { .enable_can_transceiver = dos_enable_can_transceiver, .enable_can_transceivers = dos_enable_can_transceivers, .set_led = dos_set_led, - .set_can_mode = dos_set_can_mode, .check_ignition = dos_check_ignition, .read_voltage_mV = white_read_voltage_mV, .read_current_mA = unused_read_current, diff --git a/board/boards/grey.h b/board/boards/grey.h index b3e40bc6fe..cfd98481ab 100644 --- a/board/boards/grey.h +++ b/board/boards/grey.h @@ -24,7 +24,6 @@ board board_grey = { .enable_can_transceiver = white_enable_can_transceiver, .enable_can_transceivers = white_enable_can_transceivers, .set_led = white_set_led, - .set_can_mode = white_set_can_mode, .check_ignition = white_check_ignition, .read_voltage_mV = white_read_voltage_mV, .read_current_mA = white_read_current_mA, diff --git a/board/boards/red.h b/board/boards/red.h index 1893442a31..a6b04fe6b4 100644 --- a/board/boards/red.h +++ b/board/boards/red.h @@ -53,48 +53,6 @@ static void red_set_led(uint8_t color, bool enabled) { } } -static void red_set_can_mode(uint8_t mode) { - red_enable_can_transceiver(2U, false); - red_enable_can_transceiver(4U, false); - switch (mode) { - case CAN_MODE_NORMAL: - case CAN_MODE_OBD_CAN2: - if ((bool)(mode == CAN_MODE_NORMAL) != (bool)(harness.status == HARNESS_STATUS_FLIPPED)) { - // B12,B13: disable normal mode - set_gpio_pullup(GPIOB, 12, PULL_NONE); - set_gpio_mode(GPIOB, 12, MODE_ANALOG); - - set_gpio_pullup(GPIOB, 13, PULL_NONE); - set_gpio_mode(GPIOB, 13, MODE_ANALOG); - - // B5,B6: FDCAN2 mode - set_gpio_pullup(GPIOB, 5, PULL_NONE); - set_gpio_alternate(GPIOB, 5, GPIO_AF9_FDCAN2); - - set_gpio_pullup(GPIOB, 6, PULL_NONE); - set_gpio_alternate(GPIOB, 6, GPIO_AF9_FDCAN2); - red_enable_can_transceiver(2U, true); - } else { - // B5,B6: disable normal mode - set_gpio_pullup(GPIOB, 5, PULL_NONE); - set_gpio_mode(GPIOB, 5, MODE_ANALOG); - - set_gpio_pullup(GPIOB, 6, PULL_NONE); - set_gpio_mode(GPIOB, 6, MODE_ANALOG); - // B12,B13: FDCAN2 mode - set_gpio_pullup(GPIOB, 12, PULL_NONE); - set_gpio_alternate(GPIOB, 12, GPIO_AF9_FDCAN2); - - set_gpio_pullup(GPIOB, 13, PULL_NONE); - set_gpio_alternate(GPIOB, 13, GPIO_AF9_FDCAN2); - red_enable_can_transceiver(4U, true); - } - break; - default: - break; - } -} - static bool red_check_ignition(void) { // ignition is checked through harness return harness_check_ignition(); @@ -142,7 +100,15 @@ static harness_configuration red_harness_config = { .pin_relay_SBU1 = 10, .pin_relay_SBU2 = 11, .adc_channel_SBU1 = 4, //ADC12_INP4 - .adc_channel_SBU2 = 17 //ADC1_INP17 + .adc_channel_SBU2 = 17, //ADC1_INP17 + .GPIO_CAN2_RX_NORMAL = GPIOB, + .GPIO_CAN2_TX_NORMAL = GPIOB, + .GPIO_CAN2_RX_FLIPPED = GPIOB, + .GPIO_CAN2_TX_FLIPPED = GPIOB, + .pin_CAN2_RX_NORMAL = 12, + .pin_CAN2_TX_NORMAL = 13, + .pin_CAN2_RX_FLIPPED = 5, + .pin_CAN2_TX_FLIPPED = 6 }; board board_red = { @@ -161,7 +127,6 @@ board board_red = { .enable_can_transceiver = red_enable_can_transceiver, .enable_can_transceivers = red_enable_can_transceivers, .set_led = red_set_led, - .set_can_mode = red_set_can_mode, .check_ignition = red_check_ignition, .read_voltage_mV = red_read_voltage_mV, .read_current_mA = unused_read_current, diff --git a/board/boards/tres.h b/board/boards/tres.h index ab26e4c564..3919b8e52c 100644 --- a/board/boards/tres.h +++ b/board/boards/tres.h @@ -60,48 +60,6 @@ static void tres_enable_can_transceivers(bool enabled) { } } -static void tres_set_can_mode(uint8_t mode) { - current_board->enable_can_transceiver(2U, false); - current_board->enable_can_transceiver(4U, false); - switch (mode) { - case CAN_MODE_NORMAL: - case CAN_MODE_OBD_CAN2: - if ((bool)(mode == CAN_MODE_NORMAL) != (bool)(harness.status == HARNESS_STATUS_FLIPPED)) { - // B12,B13: disable normal mode - set_gpio_pullup(GPIOB, 12, PULL_NONE); - set_gpio_mode(GPIOB, 12, MODE_ANALOG); - - set_gpio_pullup(GPIOB, 13, PULL_NONE); - set_gpio_mode(GPIOB, 13, MODE_ANALOG); - - // B5,B6: FDCAN2 mode - set_gpio_pullup(GPIOB, 5, PULL_NONE); - set_gpio_alternate(GPIOB, 5, GPIO_AF9_FDCAN2); - - set_gpio_pullup(GPIOB, 6, PULL_NONE); - set_gpio_alternate(GPIOB, 6, GPIO_AF9_FDCAN2); - current_board->enable_can_transceiver(2U, true); - } else { - // B5,B6: disable normal mode - set_gpio_pullup(GPIOB, 5, PULL_NONE); - set_gpio_mode(GPIOB, 5, MODE_ANALOG); - - set_gpio_pullup(GPIOB, 6, PULL_NONE); - set_gpio_mode(GPIOB, 6, MODE_ANALOG); - // B12,B13: FDCAN2 mode - set_gpio_pullup(GPIOB, 12, PULL_NONE); - set_gpio_alternate(GPIOB, 12, GPIO_AF9_FDCAN2); - - set_gpio_pullup(GPIOB, 13, PULL_NONE); - set_gpio_alternate(GPIOB, 13, GPIO_AF9_FDCAN2); - current_board->enable_can_transceiver(4U, true); - } - break; - default: - break; - } -} - static bool tres_read_som_gpio (void) { return (get_gpio_input(GPIOC, 2) != 0); } @@ -155,7 +113,15 @@ static harness_configuration tres_harness_config = { .pin_relay_SBU1 = 8, .pin_relay_SBU2 = 3, .adc_channel_SBU1 = 4, // ADC12_INP4 - .adc_channel_SBU2 = 17 // ADC1_INP17 + .adc_channel_SBU2 = 17, // ADC1_INP17 + .GPIO_CAN2_RX_NORMAL = GPIOB, + .GPIO_CAN2_TX_NORMAL = GPIOB, + .GPIO_CAN2_RX_FLIPPED = GPIOB, + .GPIO_CAN2_TX_FLIPPED = GPIOB, + .pin_CAN2_RX_NORMAL = 12, + .pin_CAN2_TX_NORMAL = 13, + .pin_CAN2_RX_FLIPPED = 5, + .pin_CAN2_TX_FLIPPED = 6 }; board board_tres = { @@ -173,7 +139,6 @@ board board_tres = { .enable_can_transceiver = tres_enable_can_transceiver, .enable_can_transceivers = tres_enable_can_transceivers, .set_led = red_set_led, - .set_can_mode = tres_set_can_mode, .check_ignition = red_check_ignition, .read_voltage_mV = red_read_voltage_mV, .read_current_mA = unused_read_current, diff --git a/board/boards/uno.h b/board/boards/uno.h index da9a2529a3..d033db7648 100644 --- a/board/boards/uno.h +++ b/board/boards/uno.h @@ -62,38 +62,6 @@ static void uno_set_bootkick(BootState state) { } } -static void uno_set_can_mode(uint8_t mode) { - uno_enable_can_transceiver(2U, false); - uno_enable_can_transceiver(4U, false); - switch (mode) { - case CAN_MODE_NORMAL: - case CAN_MODE_OBD_CAN2: - if ((bool)(mode == CAN_MODE_NORMAL) != (bool)(harness.status == HARNESS_STATUS_FLIPPED)) { - // B12,B13: disable OBD mode - set_gpio_mode(GPIOB, 12, MODE_INPUT); - set_gpio_mode(GPIOB, 13, MODE_INPUT); - - // B5,B6: normal CAN2 mode - set_gpio_alternate(GPIOB, 5, GPIO_AF9_CAN2); - set_gpio_alternate(GPIOB, 6, GPIO_AF9_CAN2); - uno_enable_can_transceiver(2U, true); - } else { - // B5,B6: disable normal CAN2 mode - set_gpio_mode(GPIOB, 5, MODE_INPUT); - set_gpio_mode(GPIOB, 6, MODE_INPUT); - - // B12,B13: OBD mode - set_gpio_alternate(GPIOB, 12, GPIO_AF9_CAN2); - set_gpio_alternate(GPIOB, 13, GPIO_AF9_CAN2); - uno_enable_can_transceiver(4U, true); - } - break; - default: - print("Tried to set unsupported CAN mode: "); puth(mode); print("\n"); - break; - } -} - static bool uno_check_ignition(void){ // ignition is checked through harness return harness_check_ignition(); @@ -163,7 +131,15 @@ static harness_configuration uno_harness_config = { .pin_relay_SBU1 = 10, .pin_relay_SBU2 = 11, .adc_channel_SBU1 = 10, - .adc_channel_SBU2 = 13 + .adc_channel_SBU2 = 13, + .GPIO_CAN2_RX_NORMAL = GPIOB, + .GPIO_CAN2_TX_NORMAL = GPIOB, + .GPIO_CAN2_RX_FLIPPED = GPIOB, + .GPIO_CAN2_TX_FLIPPED = GPIOB, + .pin_CAN2_RX_NORMAL = 12, + .pin_CAN2_TX_NORMAL = 13, + .pin_CAN2_RX_FLIPPED = 5, + .pin_CAN2_TX_FLIPPED = 6 }; board board_uno = { @@ -181,7 +157,6 @@ board board_uno = { .enable_can_transceiver = uno_enable_can_transceiver, .enable_can_transceivers = uno_enable_can_transceivers, .set_led = uno_set_led, - .set_can_mode = uno_set_can_mode, .check_ignition = uno_check_ignition, .read_voltage_mV = white_read_voltage_mV, .read_current_mA = unused_read_current, diff --git a/board/boards/white.h b/board/boards/white.h index 44bbf832f4..795d8ad946 100644 --- a/board/boards/white.h +++ b/board/boards/white.h @@ -69,26 +69,6 @@ static void white_set_usb_power_mode(uint8_t mode){ } } -static void white_set_can_mode(uint8_t mode){ - if (mode == CAN_MODE_NORMAL) { - // B12,B13: disable GMLAN mode - set_gpio_mode(GPIOB, 12, MODE_INPUT); - set_gpio_mode(GPIOB, 13, MODE_INPUT); - - // B3,B4: disable GMLAN mode - set_gpio_mode(GPIOB, 3, MODE_INPUT); - set_gpio_mode(GPIOB, 4, MODE_INPUT); - - // B5,B6: normal CAN2 mode - set_gpio_alternate(GPIOB, 5, GPIO_AF9_CAN2); - set_gpio_alternate(GPIOB, 6, GPIO_AF9_CAN2); - - // A8,A15: normal CAN3 mode - set_gpio_alternate(GPIOA, 8, GPIO_AF11_CAN3); - set_gpio_alternate(GPIOA, 15, GPIO_AF11_CAN3); - } -} - static uint32_t white_read_voltage_mV(void){ return adc_get_mV(12) * 11U; } @@ -152,6 +132,22 @@ static void white_grey_init(void) { set_gpio_alternate(GPIOC, 11, GPIO_AF7_USART3); set_gpio_pullup(GPIOC, 11, PULL_UP); + // B12,B13: disable GMLAN mode + set_gpio_mode(GPIOB, 12, MODE_INPUT); + set_gpio_mode(GPIOB, 13, MODE_INPUT); + + // B3,B4: disable GMLAN mode + set_gpio_mode(GPIOB, 3, MODE_INPUT); + set_gpio_mode(GPIOB, 4, MODE_INPUT); + + // B5,B6: normal CAN2 mode + set_gpio_alternate(GPIOB, 5, GPIO_AF9_CAN2); + set_gpio_alternate(GPIOB, 6, GPIO_AF9_CAN2); + + // A8,A15: normal CAN3 mode + set_gpio_alternate(GPIOA, 8, GPIO_AF11_CAN3); + set_gpio_alternate(GPIOA, 15, GPIO_AF11_CAN3); + // Init usb power mode // Init in CDP mode only if panda is powered by 12V. // Otherwise a PC would not be able to flash a standalone panda @@ -192,7 +188,6 @@ board board_white = { .enable_can_transceiver = white_enable_can_transceiver, .enable_can_transceivers = white_enable_can_transceivers, .set_led = white_set_led, - .set_can_mode = white_set_can_mode, .check_ignition = white_check_ignition, .read_voltage_mV = white_read_voltage_mV, .read_current_mA = white_read_current_mA, diff --git a/board/drivers/harness.h b/board/drivers/harness.h index efe319d0d3..44c54da738 100644 --- a/board/drivers/harness.h +++ b/board/drivers/harness.h @@ -32,6 +32,37 @@ void set_intercept_relay(bool intercept, bool ignition_relay) { } } +void set_can_mode(uint8_t mode) { + current_board->enable_can_transceiver(2U, false); + current_board->enable_can_transceiver(4U, false); + switch (mode) { + case CAN_MODE_NORMAL: + case CAN_MODE_OBD_CAN2: + if ((bool)(mode == CAN_MODE_NORMAL) != (bool)(harness.status == HARNESS_STATUS_FLIPPED)) { + // normal pins + set_gpio_mode(current_board->harness_config->GPIO_CAN2_RX_NORMAL, current_board->harness_config->pin_CAN2_RX_NORMAL, MODE_ANALOG); + set_gpio_mode(current_board->harness_config->GPIO_CAN2_TX_NORMAL, current_board->harness_config->pin_CAN2_TX_NORMAL, MODE_ANALOG); + + // flipped pins + set_gpio_mode(current_board->harness_config->GPIO_CAN2_RX_FLIPPED, current_board->harness_config->pin_CAN2_RX_FLIPPED, GPIO_CAN2_AF); + set_gpio_mode(current_board->harness_config->GPIO_CAN2_TX_FLIPPED, current_board->harness_config->pin_CAN2_TX_FLIPPED, GPIO_CAN2_AF); + current_board->enable_can_transceiver(2U, true); + } else { + // normal pins + set_gpio_mode(current_board->harness_config->GPIO_CAN2_RX_FLIPPED, current_board->harness_config->pin_CAN2_RX_FLIPPED, MODE_ANALOG); + set_gpio_mode(current_board->harness_config->GPIO_CAN2_TX_FLIPPED, current_board->harness_config->pin_CAN2_TX_FLIPPED, MODE_ANALOG); + + // flipped pins + set_gpio_mode(current_board->harness_config->GPIO_CAN2_RX_NORMAL, current_board->harness_config->pin_CAN2_RX_NORMAL, GPIO_CAN2_AF); + set_gpio_mode(current_board->harness_config->GPIO_CAN2_TX_NORMAL, current_board->harness_config->pin_CAN2_TX_NORMAL, GPIO_CAN2_AF); + current_board->enable_can_transceiver(4U, true); + } + break; + default: + break; + } +} + bool harness_check_ignition(void) { bool ret = false; @@ -94,6 +125,8 @@ void harness_tick(void) { } void harness_init(void) { + set_can_mode(CAN_MODE_NORMAL); + // init OBD_SBUx_RELAY set_gpio_output_type(current_board->harness_config->GPIO_relay_SBU1, current_board->harness_config->pin_relay_SBU1, OUTPUT_TYPE_OPEN_DRAIN); set_gpio_output_type(current_board->harness_config->GPIO_relay_SBU2, current_board->harness_config->pin_relay_SBU2, OUTPUT_TYPE_OPEN_DRAIN); diff --git a/board/drivers/harness_declarations.h b/board/drivers/harness_declarations.h index 953941f621..0f2828a2a3 100644 --- a/board/drivers/harness_declarations.h +++ b/board/drivers/harness_declarations.h @@ -15,6 +15,8 @@ extern struct harness_t harness; struct harness_configuration { const bool has_harness; + + // harness control GPIO_TypeDef * const GPIO_SBU1; GPIO_TypeDef * const GPIO_SBU2; GPIO_TypeDef * const GPIO_relay_SBU1; @@ -25,6 +27,16 @@ struct harness_configuration { const uint8_t pin_relay_SBU2; const uint8_t adc_channel_SBU1; const uint8_t adc_channel_SBU2; + + // CAN control + GPIO_TypeDef * const GPIO_CAN2_RX_NORMAL; + GPIO_TypeDef * const GPIO_CAN2_TX_NORMAL; + GPIO_TypeDef * const GPIO_CAN2_RX_FLIPPED; + GPIO_TypeDef * const GPIO_CAN2_TX_FLIPPED; + const uint8_t pin_CAN2_RX_NORMAL; + const uint8_t pin_CAN2_TX_NORMAL; + const uint8_t pin_CAN2_RX_FLIPPED; + const uint8_t pin_CAN2_TX_FLIPPED; }; // The ignition relay is only used for testing purposes diff --git a/board/main.c b/board/main.c index 1c86ebe30f..edfa36c07f 100644 --- a/board/main.c +++ b/board/main.c @@ -77,14 +77,14 @@ void set_safety_mode(uint16_t mode, uint16_t param) { case SAFETY_SILENT: set_intercept_relay(false, false); if (current_board->has_obd) { - current_board->set_can_mode(CAN_MODE_NORMAL); + set_can_mode(CAN_MODE_NORMAL); } can_silent = ALL_CAN_SILENT; break; case SAFETY_NOOUTPUT: set_intercept_relay(false, false); if (current_board->has_obd) { - current_board->set_can_mode(CAN_MODE_NORMAL); + set_can_mode(CAN_MODE_NORMAL); } can_silent = ALL_CAN_LIVE; break; @@ -97,9 +97,9 @@ void set_safety_mode(uint16_t mode, uint16_t param) { // TODO: rewrite using hardware queues rather than fifo to cancel specific messages can_clear_send(CANIF_FROM_CAN_NUM(1), 1); if (param == 0U) { - current_board->set_can_mode(CAN_MODE_OBD_CAN2); + set_can_mode(CAN_MODE_OBD_CAN2); } else { - current_board->set_can_mode(CAN_MODE_NORMAL); + set_can_mode(CAN_MODE_NORMAL); } } can_silent = ALL_CAN_LIVE; @@ -109,7 +109,7 @@ void set_safety_mode(uint16_t mode, uint16_t param) { heartbeat_counter = 0U; heartbeat_lost = false; if (current_board->has_obd) { - current_board->set_can_mode(CAN_MODE_NORMAL); + set_can_mode(CAN_MODE_NORMAL); } can_silent = ALL_CAN_LIVE; break; @@ -322,7 +322,6 @@ int main(void) { // init board current_board->init(); - current_board->set_can_mode(CAN_MODE_NORMAL); if (current_board->harness_config->has_harness) { harness_init(); } diff --git a/board/main_comms.h b/board/main_comms.h index e366b19a09..88b0af65bf 100644 --- a/board/main_comms.h +++ b/board/main_comms.h @@ -215,10 +215,10 @@ int comms_control_handler(ControlPacket_t *req, uint8_t *resp) { if (current_board->has_obd) { if (req->param1 == 1U) { // Enable OBD CAN - current_board->set_can_mode(CAN_MODE_OBD_CAN2); + set_can_mode(CAN_MODE_OBD_CAN2); } else { // Disable OBD CAN - current_board->set_can_mode(CAN_MODE_NORMAL); + set_can_mode(CAN_MODE_NORMAL); } } break; diff --git a/board/stm32f4/stm32f4_config.h b/board/stm32f4/stm32f4_config.h index eae9222a9d..726e8198b2 100644 --- a/board/stm32f4/stm32f4_config.h +++ b/board/stm32f4/stm32f4_config.h @@ -12,6 +12,7 @@ // Around (1Mbps / 8 bits/byte / 12 bytes per message) #define CAN_INTERRUPT_RATE 12000U +#define GPIO_CAN2_AF GPIO_AF9_CAN2 #define MAX_LED_FADE 8192U diff --git a/board/stm32h7/stm32h7_config.h b/board/stm32h7/stm32h7_config.h index bfc12e8c3a..e60b8da34f 100644 --- a/board/stm32h7/stm32h7_config.h +++ b/board/stm32h7/stm32h7_config.h @@ -24,6 +24,7 @@ separate IRQs for RX and TX. 1 / ((29 bits / 0.5Mbps) + (23 bits / 2Mbps)) = 14388Hz */ #define CAN_INTERRUPT_RATE 16000U +#define GPIO_CAN2_AF GPIO_AF9_FDCAN2 #define MAX_LED_FADE 10240U