Skip to content

Commit

Permalink
H7: add chiplet panda support (RPv2) (commaai#1049)
Browse files Browse the repository at this point in the history
* temporarily disable Jenkins

* firmware

* python lib

* tests

* ..

* usb load switch to high

* it is still red

* usb power mode remove

* Revert "temporarily disable Jenkins"

This reverts commit a911cfa.

* forgot this

* common periph

* change name

* board tick

* add V2 to CI

* update known bootstub
  • Loading branch information
briskspirit authored Sep 10, 2022
1 parent 1b210a8 commit ac21dbe
Show file tree
Hide file tree
Showing 12 changed files with 192 additions and 39 deletions.
2 changes: 1 addition & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -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'"
}
}
}
Expand Down
1 change: 1 addition & 0 deletions board/boards/board_declarations.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 21 additions & 7 deletions board/boards/red.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);

Expand Down
140 changes: 140 additions & 0 deletions board/boards/red_v2.h
Original file line number Diff line number Diff line change
@@ -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
};
7 changes: 6 additions & 1 deletion board/stm32h7/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) |
Expand All @@ -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");
Expand All @@ -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);
}
37 changes: 14 additions & 23 deletions board/stm32h7/peripherals.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);

Expand All @@ -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);
Expand All @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions python/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,17 +172,18 @@ 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
HEALTH_STRUCT = struct.Struct("<IIIIIIIIBBBBBBHBBBHIfB")

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
Expand Down
5 changes: 3 additions & 2 deletions tests/automated/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand Down
Binary file modified tests/automated/known_bootstub/bootstub.panda.bin
Binary file not shown.
Binary file modified tests/automated/known_bootstub/bootstub.panda_h7.bin
Binary file not shown.
2 changes: 1 addition & 1 deletion tests/canfd/test_canfd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"):
Expand Down
4 changes: 2 additions & 2 deletions tests/ci_reset_hw.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

pandas = PandaDFU.list()
print(pandas)
assert len(pandas) == 7
assert len(pandas) == 8

for serial in pandas:
p = PandaDFU(serial)
Expand All @@ -23,7 +23,7 @@

pandas = Panda.list()
print(pandas)
assert len(pandas) == 7
assert len(pandas) == 8

for serial in pandas:
pf = Panda(serial)
Expand Down

0 comments on commit ac21dbe

Please sign in to comment.