Skip to content

Commit

Permalink
Merge branch 'commaai:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
rav4kumar authored Feb 2, 2024
2 parents ddb422a + bca1162 commit a49803d
Show file tree
Hide file tree
Showing 26 changed files with 149 additions and 72 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.13
rev: v0.1.15
hooks:
- id: ruff
3 changes: 3 additions & 0 deletions board/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@ for project_name, project in build_projects.items():
if ("ENABLE_SPI" in os.environ or "h7" in project_name) and not project_name.startswith('pedal'):
flags.append('-DENABLE_SPI')

if "H723" in os.environ:
flags.append('-DSTM32H723')

build_project(project_name, project, flags)
1 change: 0 additions & 1 deletion board/boards/black.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ const harness_configuration black_harness_config = {
};

const board board_black = {
.board_type = "Black",
.set_bootkick = unused_set_bootkick,
.harness_config = &black_harness_config,
.has_hw_gmlan = false,
Expand Down
2 changes: 1 addition & 1 deletion board/boards/board_declarations.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ typedef void (*board_set_bootkick)(BootState state);
typedef bool (*board_read_som_gpio)(void);

struct board {
const char *board_type;
const harness_configuration *harness_config;
const bool has_hw_gmlan;
const bool has_obd;
Expand Down Expand Up @@ -58,6 +57,7 @@ struct board {
#define HW_TYPE_RED_PANDA 7U
#define HW_TYPE_RED_PANDA_V2 8U
#define HW_TYPE_TRES 9U
#define HW_TYPE_CUATRO 10U

// LED colors
#define LED_RED 0U
Expand Down
86 changes: 86 additions & 0 deletions board/boards/cuatro.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
void cuatro_set_led(uint8_t color, bool enabled) {
switch (color) {
case LED_RED:
set_gpio_output(GPIOD, 15, !enabled);
break;
case LED_GREEN:
set_gpio_output(GPIOD, 14, !enabled);
break;
case LED_BLUE:
set_gpio_output(GPIOE, 2, !enabled);
break;
default:
break;
}
}

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);

// SOM bootkick + reset lines
set_gpio_mode(GPIOC, 12, MODE_OUTPUT);
tres_set_bootkick(BOOT_BOOTKICK);

// SOM debugging UART
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);

// Initialize IR PWM and set to 0%
set_gpio_alternate(GPIOC, 9, GPIO_AF2_TIM3);
pwm_init(TIM3, 4);
tres_set_ir_power(0U);

// Clock source
clock_source_init();
}

const board board_cuatro = {
.harness_config = &red_chiplet_harness_config,
.has_hw_gmlan = false,
.has_obd = true,
.has_spi = true,
.has_canfd = true,
.has_rtc_battery = true,
.fan_max_rpm = 6600U,
.avdd_mV = 1800U,
.fan_stall_recovery = false,
.fan_enable_cooldown_time = 3U,
.init = cuatro_init,
.init_bootloader = unused_init_bootloader,
.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,
.read_current = unused_read_current,
.set_fan_enabled = tres_set_fan_enabled,
.set_ir_power = tres_set_ir_power,
.set_siren = unused_set_siren,
.set_bootkick = tres_set_bootkick,
.read_som_gpio = tres_read_som_gpio
};
1 change: 0 additions & 1 deletion board/boards/dos.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ const harness_configuration dos_harness_config = {
};

const board board_dos = {
.board_type = "Dos",
.harness_config = &dos_harness_config,
.has_hw_gmlan = false,
.has_obd = true,
Expand Down
1 change: 0 additions & 1 deletion board/boards/grey.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
// Most hardware functionality is similar to white panda

const board board_grey = {
.board_type = "Grey",
.set_bootkick = unused_set_bootkick,
.harness_config = &white_harness_config,
.has_hw_gmlan = true,
Expand Down
1 change: 0 additions & 1 deletion board/boards/pedal.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ const harness_configuration pedal_harness_config = {
};

const board board_pedal = {
.board_type = "Pedal",
.set_bootkick = unused_set_bootkick,
.harness_config = &pedal_harness_config,
.has_hw_gmlan = false,
Expand Down
1 change: 0 additions & 1 deletion board/boards/red.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ const harness_configuration red_harness_config = {
};

const board board_red = {
.board_type = "Red",
.set_bootkick = unused_set_bootkick,
.harness_config = &red_harness_config,
.has_hw_gmlan = false,
Expand Down
38 changes: 0 additions & 38 deletions board/boards/red_v2.h

This file was deleted.

2 changes: 0 additions & 2 deletions board/boards/tres.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ void tres_init(void) {
}

const board board_tres = {
.board_type = "Tres",
.harness_config = &red_chiplet_harness_config,
.has_hw_gmlan = false,
.has_obd = true,
Expand All @@ -84,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,
Expand Down
1 change: 0 additions & 1 deletion board/boards/uno.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,6 @@ const harness_configuration uno_harness_config = {
};

const board board_uno = {
.board_type = "Uno",
.harness_config = &uno_harness_config,
.has_hw_gmlan = false,
.has_obd = true,
Expand Down
1 change: 0 additions & 1 deletion board/boards/white.h
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,6 @@ const harness_configuration white_harness_config = {
};

const board board_white = {
.board_type = "White",
.set_bootkick = unused_set_bootkick,
.harness_config = &white_harness_config,
.has_hw_gmlan = true,
Expand Down
1 change: 0 additions & 1 deletion board/jungle/boards/board_declarations.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ typedef float (*board_get_channel_power)(uint8_t channel);
typedef uint16_t (*board_get_sbu_mV)(uint8_t channel, uint8_t sbu);

struct board {
const char *board_type;
const bool has_canfd;
const bool has_sbu_sense;
const uint16_t avdd_mV;
Expand Down
1 change: 0 additions & 1 deletion board/jungle/boards/board_v1.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ void board_v1_init(void) {
void board_v1_tick(void) {}

const board board_v1 = {
.board_type = "V1",
.has_canfd = false,
.has_sbu_sense = false,
.avdd_mV = 3300U,
Expand Down
1 change: 0 additions & 1 deletion board/jungle/boards/board_v2.h
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,6 @@ void board_v2_init(void) {
void board_v2_tick(void) {}

const board board_v2 = {
.board_type = "V2",
.has_canfd = true,
.has_sbu_sense = true,
.avdd_mV = 3300U,
Expand Down
2 changes: 1 addition & 1 deletion board/jungle/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ int main(void) {
}

print("Config:\n");
print(" Board type: "); print(current_board->board_type); print("\n");
print(" Board type: 0x"); puth(hw_type); print("\n");

// init board
current_board->init();
Expand Down
2 changes: 1 addition & 1 deletion board/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ int main(void) {
}

print("Config:\n");
print(" Board type: "); print(current_board->board_type); print("\n");
print(" Board type: 0x"); puth(hw_type); print("\n");

// init board
current_board->init();
Expand Down
13 changes: 12 additions & 1 deletion board/safety/safety_elm327.h
Original file line number Diff line number Diff line change
@@ -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);
Expand All @@ -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;
}

Expand Down
15 changes: 12 additions & 3 deletions board/stm32h7/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
#include "drivers/clock_source.h"
#include "boards/red.h"
#include "boards/red_chiplet.h"
#include "boards/red_v2.h"
#include "boards/tres.h"
#include "boards/cuatro.h"


uint8_t get_board_id(void) {
Expand All @@ -34,13 +34,22 @@ void detect_board_type(void) {
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;
// deprecated
//hw_type = HW_TYPE_RED_PANDA_V2;
} else if (board_id == 2U) {
hw_type = HW_TYPE_TRES;
current_board = &board_tres;
} else if (board_id == 3U) {
hw_type = HW_TYPE_CUATRO;
current_board = &board_tres;
} else {
hw_type = HW_TYPE_UNKNOWN;
print("Hardware type is UNKNOWN!\n");
}

// TODO: detect this live
#ifdef STM32H723
hw_type = HW_TYPE_CUATRO;
current_board = &board_cuatro;
#endif
}
6 changes: 4 additions & 2 deletions board/stm32h7/clock.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ PCLK1: 60MHz (for USART2,3,4,5,7,8)
*/

void clock_init(void) {
//Set power mode to direct SMPS power supply(depends on the board layout)
// Set power mode to direct SMPS power supply(depends on the board layout)
#ifndef STM32H723
register_set(&(PWR->CR3), PWR_CR3_SMPSEN, 0xFU); // powered only by SMPS
//Set VOS level (VOS3 to 170Mhz, VOS2 to 300Mhz, VOS1 to 400Mhz, VOS0 to 550Mhz)
// Set VOS level (VOS3 to 170Mhz, VOS2 to 300Mhz, VOS1 to 400Mhz, VOS0 to 550Mhz)
register_set(&(PWR->D3CR), PWR_D3CR_VOS_1 | PWR_D3CR_VOS_0, 0xC000U); //VOS1, needed for 80Mhz CAN FD
while ((PWR->CSR1 & PWR_CSR1_ACTVOSRDY) == 0);
while ((PWR->CSR1 & PWR_CSR1_ACTVOS) != (PWR->D3CR & PWR_D3CR_VOS)); // check that VOS level was actually set
#endif
// Configure Flash ACR register LATENCY and WRHIGHFREQ (VOS0 range!)
register_set(&(FLASH->ACR), FLASH_ACR_LATENCY_2WS | 0x20U, 0x3FU); // VOS2, AXI 100MHz-150MHz
// enable external oscillator HSE
Expand Down
Loading

0 comments on commit a49803d

Please sign in to comment.