diff --git a/Jenkinsfile b/Jenkinsfile index 16f65093a0..80a028869a 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -70,7 +70,7 @@ pipeline { --volume /var/run/dbus:/var/run/dbus \ --net host \ ${env.DOCKER_IMAGE_TAG} \ - bash -c 'cd /tmp/panda && scons -j8 && JUNGLE=058010800f51363038363036 H7_PANDAS_EXCLUDE=\"080021000c51303136383232\" ./tests/canfd/test_canfd.py'" + bash -c 'cd /tmp/panda && scons -j8 && JUNGLE=058010800f51363038363036 H7_PANDAS_EXCLUDE=\"080021000c51303136383232 33000e001051393133353939\" ./tests/canfd/test_canfd.py'" } } } diff --git a/board/boards/board_declarations.h b/board/boards/board_declarations.h index 41eff37d18..1a9f9ac56f 100644 --- a/board/boards/board_declarations.h +++ b/board/boards/board_declarations.h @@ -49,6 +49,7 @@ struct board { #define HW_TYPE_UNO 5U #define HW_TYPE_DOS 6U #define HW_TYPE_RED_PANDA 7U +#define HW_TYPE_RED_PANDA_V2 8U // LED colors #define LED_RED 0U diff --git a/board/boards/red.h b/board/boards/red.h index 2ba2ee1e3d..2d17f8c618 100644 --- a/board/boards/red.h +++ b/board/boards/red.h @@ -99,13 +99,6 @@ bool red_check_ignition(void) { void red_init(void) { common_init_gpio(); - //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); - //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); @@ -117,6 +110,27 @@ void red_init(void) { 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); + + set_gpio_pullup(GPIOB, 3, PULL_NONE); + set_gpio_mode(GPIOB, 3, MODE_OUTPUT); + + set_gpio_pullup(GPIOD, 7, PULL_NONE); + set_gpio_mode(GPIOD, 7, MODE_OUTPUT); + + set_gpio_pullup(GPIOB, 4, PULL_NONE); + set_gpio_mode(GPIOB, 4, MODE_OUTPUT); + + // B14: usb load switch + set_gpio_pullup(GPIOB, 14, PULL_NONE); + set_gpio_mode(GPIOB, 14, MODE_OUTPUT); + + //B1: 5VOUT_S + set_gpio_pullup(GPIOB, 1, PULL_NONE); + set_gpio_mode(GPIOB, 1, MODE_ANALOG); + // Turn on USB load switch. red_set_usb_load_switch(true); diff --git a/board/boards/red_v2.h b/board/boards/red_v2.h new file mode 100644 index 0000000000..d9373aa635 --- /dev/null +++ b/board/boards/red_v2.h @@ -0,0 +1,140 @@ +// ///////////////////// // +// Red Panda V2 with chiplet + Harness // +// ///////////////////// // + +// Most hardware functionality is similar to red panda + +void red_v2_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; + } +} + +void red_v2_enable_can_transceivers(bool enabled) { + uint8_t main_bus = (car_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_v2_enable_can_transceiver(i, true); + } else { + red_v2_enable_can_transceiver(i, enabled); + } + } +} + +void red_v2_set_usb_load_switch(bool enabled) { + set_gpio_output(GPIOD, 3, enabled); +} + +void red_v2_init(void) { + common_init_gpio(); + + //A8, A9 : 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_mode(GPIOA, 8, MODE_OUTPUT); + set_gpio_output(GPIOA, 8, 1); + + set_gpio_output_type(GPIOA, 9, OUTPUT_TYPE_OPEN_DRAIN); + set_gpio_pullup(GPIOA, 9, PULL_NONE); + set_gpio_mode(GPIOA, 9, MODE_OUTPUT); + set_gpio_output(GPIOA, 9, 1); + + // 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); + + // Turn on USB load switch. + red_v2_set_usb_load_switch(true); + + // Initialize harness + harness_init(); + + // Initialize RTC + rtc_init(); + + // Enable CAN transceivers + red_v2_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_set_can_mode(CAN_MODE_NORMAL); + + // flip CAN0 and CAN2 if we are flipped + if (car_harness_status == HARNESS_STATUS_FLIPPED) { + can_flip_buses(0, 2); + } +} + +const harness_configuration red_v2_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 = 9, + .adc_channel_SBU1 = 4, //ADC12_INP4 + .adc_channel_SBU2 = 17 //ADC1_INP17 +}; + +const board board_red_v2 = { + .board_type = "Red_v2", + .board_tick = unused_board_tick, + .harness_config = &red_v2_harness_config, + .has_gps = false, + .has_hw_gmlan = false, + .has_obd = true, + .has_lin = false, + .has_rtc_battery = true, + .fan_max_rpm = 0U, + .init = red_v2_init, + .enable_can_transceiver = red_v2_enable_can_transceiver, + .enable_can_transceivers = red_v2_enable_can_transceivers, + .set_led = red_set_led, + .set_gps_mode = unused_set_gps_mode, + .set_can_mode = red_set_can_mode, + .check_ignition = red_check_ignition, + .read_current = unused_read_current, + .set_fan_enabled = unused_set_fan_enabled, + .set_ir_power = unused_set_ir_power, + .set_phone_power = unused_set_phone_power, + .set_clock_source_mode = unused_set_clock_source_mode, + .set_siren = unused_set_siren +}; diff --git a/board/stm32h7/board.h b/board/stm32h7/board.h index 769e9789e7..108dbfd8d7 100644 --- a/board/stm32h7/board.h +++ b/board/stm32h7/board.h @@ -11,6 +11,8 @@ #include "stm32h7/llrtc.h" #include "drivers/rtc.h" #include "boards/red.h" +#include "boards/red_v2.h" + uint8_t board_id(void) { return detect_with_pull(GPIOF, 7, PULL_UP) | @@ -23,6 +25,9 @@ void detect_board_type(void) { if(board_id() == 0U){ hw_type = HW_TYPE_RED_PANDA; current_board = &board_red; + } else if(board_id() == 1U){ + hw_type = HW_TYPE_RED_PANDA_V2; + current_board = &board_red_v2; } else { hw_type = HW_TYPE_UNKNOWN; puts("Hardware type is UNKNOWN!\n"); @@ -32,5 +37,5 @@ void detect_board_type(void) { bool has_external_debug_serial = 0; void detect_external_debug_serial(void) { // detect if external serial debugging is present - has_external_debug_serial = detect_with_pull(GPIOA, 3, PULL_DOWN); + has_external_debug_serial = detect_with_pull(GPIOA, 3, PULL_DOWN) || detect_with_pull(GPIOE, 7, PULL_DOWN); } diff --git a/board/stm32h7/peripherals.h b/board/stm32h7/peripherals.h index e43c59396a..00ef6bfa05 100644 --- a/board/stm32h7/peripherals.h +++ b/board/stm32h7/peripherals.h @@ -11,6 +11,12 @@ void gpio_usart2_init(void) { set_gpio_alternate(GPIOA, 3, GPIO_AF7_USART2); } +void gpio_uart7_init(void) { + // E7,E8: UART 7 for debugging + set_gpio_alternate(GPIOE, 7, GPIO_AF7_UART7); + set_gpio_alternate(GPIOE, 8, GPIO_AF7_UART7); +} + // Common GPIO initialization void common_init_gpio(void) { /// E2,E3,E4: RGB LED @@ -36,29 +42,14 @@ void common_init_gpio(void) { set_gpio_pullup(GPIOF, 10, PULL_NONE); set_gpio_mode(GPIOF, 10, MODE_INPUT); - // G11,B3,D7,B4: transceiver enable - set_gpio_pullup(GPIOG, 11, PULL_NONE); - set_gpio_mode(GPIOG, 11, MODE_OUTPUT); - - // Speed was set to high by default after reset, changing to low - GPIOB->OSPEEDR = GPIO_OSPEEDR_OSPEED3; - set_gpio_pullup(GPIOB, 3, PULL_NONE); - set_gpio_mode(GPIOB, 3, MODE_OUTPUT); - - set_gpio_pullup(GPIOD, 7, PULL_NONE); - set_gpio_mode(GPIOD, 7, MODE_OUTPUT); + //C4,A1: OBD_SBU1, OBD_SBU2 + set_gpio_pullup(GPIOC, 4, PULL_NONE); + set_gpio_mode(GPIOC, 4, MODE_ANALOG); - set_gpio_pullup(GPIOB, 4, PULL_NONE); - set_gpio_mode(GPIOB, 4, MODE_OUTPUT); - - // B14: usb load switch - set_gpio_pullup(GPIOB, 14, PULL_NONE); - set_gpio_mode(GPIOB, 14, MODE_OUTPUT); - - //B1,F11 5VOUT_S, VOLT_S - set_gpio_pullup(GPIOB, 1, PULL_NONE); - set_gpio_mode(GPIOB, 1, 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); @@ -70,7 +61,7 @@ void common_init_gpio(void) { set_gpio_pullup(GPIOB, 9, PULL_NONE); set_gpio_alternate(GPIOB, 9, GPIO_AF9_FDCAN1); - + // B5,B6 (mplex to B12,B13): FDCAN2 set_gpio_pullup(GPIOB, 12, PULL_NONE); set_gpio_pullup(GPIOB, 13, PULL_NONE); @@ -80,7 +71,7 @@ void common_init_gpio(void) { set_gpio_pullup(GPIOB, 6, PULL_NONE); set_gpio_alternate(GPIOB, 6, GPIO_AF9_FDCAN2); - + // G9,G10: FDCAN3 set_gpio_pullup(GPIOG, 9, PULL_NONE); set_gpio_alternate(GPIOG, 9, GPIO_AF2_FDCAN3); diff --git a/python/__init__.py b/python/__init__.py index d1cec35baa..5c54a44330 100644 --- a/python/__init__.py +++ b/python/__init__.py @@ -172,6 +172,7 @@ class Panda: HW_TYPE_UNO = b'\x05' HW_TYPE_DOS = b'\x06' HW_TYPE_RED_PANDA = b'\x07' + HW_TYPE_RED_PANDA_V2 = b'\x08' CAN_PACKET_VERSION = 2 HEALTH_PACKET_VERSION = 9 @@ -179,10 +180,10 @@ class Panda: F2_DEVICES = (HW_TYPE_PEDAL, ) F4_DEVICES = (HW_TYPE_WHITE_PANDA, HW_TYPE_GREY_PANDA, HW_TYPE_BLACK_PANDA, HW_TYPE_UNO, HW_TYPE_DOS) - H7_DEVICES = (HW_TYPE_RED_PANDA, ) + H7_DEVICES = (HW_TYPE_RED_PANDA, HW_TYPE_RED_PANDA_V2) INTERNAL_DEVICES = (HW_TYPE_UNO, HW_TYPE_DOS) - HAS_OBD = (HW_TYPE_BLACK_PANDA, HW_TYPE_UNO, HW_TYPE_DOS, HW_TYPE_RED_PANDA) + HAS_OBD = (HW_TYPE_BLACK_PANDA, HW_TYPE_UNO, HW_TYPE_DOS, HW_TYPE_RED_PANDA, HW_TYPE_RED_PANDA_V2) CLOCK_SOURCE_MODE_DISABLED = 0 CLOCK_SOURCE_MODE_FREE_RUNNING = 1 diff --git a/tests/automated/helpers.py b/tests/automated/helpers.py index 6dc59a5f8c..a6fe0f05a2 100644 --- a/tests/automated/helpers.py +++ b/tests/automated/helpers.py @@ -13,7 +13,7 @@ SPEED_GMLAN = 33.3 BUS_SPEEDS = [(0, SPEED_NORMAL), (1, SPEED_NORMAL), (2, SPEED_NORMAL), (3, SPEED_GMLAN)] TIMEOUT = 45 -H7_HW_TYPES = [Panda.HW_TYPE_RED_PANDA] +H7_HW_TYPES = [Panda.HW_TYPE_RED_PANDA, Panda.HW_TYPE_RED_PANDA_V2] GEN2_HW_TYPES = [Panda.HW_TYPE_BLACK_PANDA, Panda.HW_TYPE_UNO] + H7_HW_TYPES GPS_HW_TYPES = [Panda.HW_TYPE_GREY_PANDA, Panda.HW_TYPE_BLACK_PANDA, Panda.HW_TYPE_UNO] PEDAL_SERIAL = 'none' @@ -55,7 +55,8 @@ def init_all_pandas(): param(panda_type=Panda.HW_TYPE_GREY_PANDA), param(panda_type=Panda.HW_TYPE_BLACK_PANDA), param(panda_type=Panda.HW_TYPE_UNO), - param(panda_type=Panda.HW_TYPE_RED_PANDA) + param(panda_type=Panda.HW_TYPE_RED_PANDA), + param(panda_type=Panda.HW_TYPE_RED_PANDA_V2) ]) test_all_pandas = parameterized( list(map(lambda x: x[0], _all_pandas)) # type: ignore diff --git a/tests/automated/known_bootstub/bootstub.panda.bin b/tests/automated/known_bootstub/bootstub.panda.bin index 6773fbffb9..6f658e2de2 100755 Binary files a/tests/automated/known_bootstub/bootstub.panda.bin and b/tests/automated/known_bootstub/bootstub.panda.bin differ diff --git a/tests/automated/known_bootstub/bootstub.panda_h7.bin b/tests/automated/known_bootstub/bootstub.panda_h7.bin index 239c3e8056..f587637f92 100755 Binary files a/tests/automated/known_bootstub/bootstub.panda_h7.bin and b/tests/automated/known_bootstub/bootstub.panda_h7.bin differ diff --git a/tests/canfd/test_canfd.py b/tests/canfd/test_canfd.py index 697c5e9c73..70f7c80285 100755 --- a/tests/canfd/test_canfd.py +++ b/tests/canfd/test_canfd.py @@ -6,7 +6,7 @@ from panda import Panda from panda_jungle import PandaJungle # pylint: disable=import-error -H7_HW_TYPES = [Panda.HW_TYPE_RED_PANDA] +H7_HW_TYPES = [Panda.HW_TYPE_RED_PANDA, Panda.HW_TYPE_RED_PANDA_V2] JUNGLE_SERIAL = os.getenv("JUNGLE") H7_PANDAS_EXCLUDE = [] # type: ignore if os.getenv("H7_PANDAS_EXCLUDE"): diff --git a/tests/ci_reset_hw.py b/tests/ci_reset_hw.py index bbbdd663ab..bee012566e 100644 --- a/tests/ci_reset_hw.py +++ b/tests/ci_reset_hw.py @@ -13,7 +13,7 @@ pandas = PandaDFU.list() print(pandas) - assert len(pandas) == 7 + assert len(pandas) == 8 for serial in pandas: p = PandaDFU(serial) @@ -23,7 +23,7 @@ pandas = Panda.list() print(pandas) - assert len(pandas) == 7 + assert len(pandas) == 8 for serial in pandas: pf = Panda(serial)