Skip to content

Commit

Permalink
Merge branch 'commaai:master' into secoc-long
Browse files Browse the repository at this point in the history
  • Loading branch information
chrispypatt authored Jan 24, 2025
2 parents c2f73e3 + 1290588 commit f061123
Show file tree
Hide file tree
Showing 20 changed files with 63 additions and 1,021 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ RUN pip3 install --break-system-packages --no-cache-dir $PYTHONPATH/panda/[dev]

# TODO: this should be a "pip install" or not even in this repo at all
RUN git config --global --add safe.directory $PYTHONPATH/panda
ENV OPENDBC_REF="b89fe79950121ca93d8a1f0d3fd17df31703be2a"
ENV OPENDBC_REF="7af6f3885dc43be8ecf331df1f0914cf3338de50"
RUN cd /tmp/ && \
git clone --depth 1 https://github.com/commaai/opendbc opendbc_repo && \
cd opendbc_repo && git fetch origin $OPENDBC_REF && git checkout FETCH_HEAD && rm -rf .git/ && \
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ And to send one on bus 0:
Note that you may have to setup [udev rules](https://github.com/commaai/panda/tree/master/drivers/linux) for Linux, such as
``` bash
sudo tee /etc/udev/rules.d/11-panda.rules <<EOF
SUBSYSTEM=="usb", ATTRS{idVendor}=="bbaa", ATTRS{idProduct}=="ddcc", MODE="0666"
SUBSYSTEM=="usb", ATTRS{idVendor}=="bbaa", ATTRS{idProduct}=="ddee", MODE="0666"
SUBSYSTEM=="usb", ATTRS{idVendor}=="3801", ATTRS{idProduct}=="ddcc", MODE="0666"
SUBSYSTEM=="usb", ATTRS{idVendor}=="3801", ATTRS{idProduct}=="ddee", MODE="0666"
EOF
sudo udevadm control --reload-rules && sudo udevadm trigger
```
Expand Down
2 changes: 1 addition & 1 deletion __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from .python.serial import PandaSerial # noqa: F401
from .python.canhandle import CanHandle # noqa: F401
from .python.utils import logger # noqa: F401
from .python import (Panda, PandaDFU, uds, isotp, # noqa: F401
from .python import (Panda, PandaDFU, isotp, # noqa: F401
pack_can_buffer, unpack_can_buffer, calculate_checksum,
DLC_TO_LEN, LEN_TO_DLC, ALTERNATIVE_EXPERIENCE, CANPACKET_HEAD_SIZE)

Expand Down
4 changes: 2 additions & 2 deletions board/boards/cuatro.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ static void cuatro_set_fan_enabled(bool enabled) {

static void cuatro_set_bootkick(BootState state) {
set_gpio_output(GPIOA, 0, state != BOOT_BOOTKICK);
// only use if we have to
//set_gpio_output(GPIOC, 12, state != BOOT_RESET);
// TODO: confirm we need this
set_gpio_output(GPIOC, 12, state != BOOT_RESET);
}

static void cuatro_set_amp_enabled(bool enabled){
Expand Down
2 changes: 1 addition & 1 deletion board/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#define MAX_CAN_MSGS_PER_SPI_BULK_TRANSFER 170U

// USB definitions
#define USB_VID 0xBBAAU
#define USB_VID 0x3801U

#ifdef PANDA_JUNGLE
#ifdef BOOTSTUB
Expand Down
4 changes: 2 additions & 2 deletions board/jungle/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ To make the jungle usable without root permissions, you might need to setup udev
On ubuntu, this should do the trick:
``` bash
sudo tee /etc/udev/rules.d/12-panda_jungle.rules <<EOF
SUBSYSTEM=="usb", ATTRS{idVendor}=="bbaa", ATTRS{idProduct}=="ddcf", MODE="0666"
SUBSYSTEM=="usb", ATTRS{idVendor}=="bbaa", ATTRS{idProduct}=="ddef", MODE="0666"
SUBSYSTEM=="usb", ATTRS{idVendor}=="3801", ATTRS{idProduct}=="ddcf", MODE="0666"
SUBSYSTEM=="usb", ATTRS{idVendor}=="3801", ATTRS{idProduct}=="ddef", MODE="0666"
EOF
sudo udevadm control --reload-rules && sudo udevadm trigger
```
Expand Down
2 changes: 1 addition & 1 deletion board/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ static void tick_handler(void) {
}

if (controls_allowed || heartbeat_engaged) {
controls_allowed_countdown = 30U;
controls_allowed_countdown = 5U;
} else if (controls_allowed_countdown > 0U) {
controls_allowed_countdown -= 1U;
} else {
Expand Down
35 changes: 15 additions & 20 deletions board/safety/safety_ford.h
Original file line number Diff line number Diff line change
Expand Up @@ -363,42 +363,33 @@ static safety_config ford_init(uint16_t param) {
{.msg = {{FORD_DesiredTorqBrk, 0, 8, .frequency = 50U}, { 0 }, { 0 }}},
};

#define FORD_COMMON_TX_MSGS \
{FORD_Steering_Data_FD1, 0, 8}, \
{FORD_Steering_Data_FD1, 2, 8}, \
{FORD_ACCDATA_3, 0, 8}, \
{FORD_Lane_Assist_Data1, 0, 8}, \
{FORD_IPMA_Data, 0, 8}, \

static const CanMsg FORD_CANFD_LONG_TX_MSGS[] = {
{FORD_Steering_Data_FD1, 0, 8},
{FORD_Steering_Data_FD1, 2, 8},
FORD_COMMON_TX_MSGS
{FORD_ACCDATA, 0, 8},
{FORD_ACCDATA_3, 0, 8},
{FORD_Lane_Assist_Data1, 0, 8},
{FORD_LateralMotionControl2, 0, 8},
{FORD_IPMA_Data, 0, 8},
};

static const CanMsg FORD_CANFD_STOCK_TX_MSGS[] = {
{FORD_Steering_Data_FD1, 0, 8},
{FORD_Steering_Data_FD1, 2, 8},
{FORD_ACCDATA_3, 0, 8},
{FORD_Lane_Assist_Data1, 0, 8},
FORD_COMMON_TX_MSGS
{FORD_LateralMotionControl2, 0, 8},
{FORD_IPMA_Data, 0, 8},
};

static const CanMsg FORD_STOCK_TX_MSGS[] = {
{FORD_Steering_Data_FD1, 0, 8},
{FORD_Steering_Data_FD1, 2, 8},
{FORD_ACCDATA_3, 0, 8},
{FORD_Lane_Assist_Data1, 0, 8},
FORD_COMMON_TX_MSGS
{FORD_LateralMotionControl, 0, 8},
{FORD_IPMA_Data, 0, 8},
};

static const CanMsg FORD_LONG_TX_MSGS[] = {
{FORD_Steering_Data_FD1, 0, 8},
{FORD_Steering_Data_FD1, 2, 8},
FORD_COMMON_TX_MSGS
{FORD_ACCDATA, 0, 8},
{FORD_ACCDATA_3, 0, 8},
{FORD_Lane_Assist_Data1, 0, 8},
{FORD_LateralMotionControl, 0, 8},
{FORD_IPMA_Data, 0, 8},
};

UNUSED(param);
Expand All @@ -409,6 +400,9 @@ static safety_config ford_init(uint16_t param) {
ford_canfd = GET_FLAG(param, FORD_PARAM_CANFD);
#endif

// Longitudinal is the default for CAN, and optional for CAN FD w/ ALLOW_DEBUG
ford_longitudinal = !ford_canfd || ford_longitudinal;

safety_config ret;
// FIXME: cppcheck thinks that ford_canfd is always false. This is not true
// if ALLOW_DEBUG is defined but cppcheck is run without ALLOW_DEBUG
Expand All @@ -417,6 +411,7 @@ static safety_config ford_init(uint16_t param) {
ret = ford_longitudinal ? BUILD_SAFETY_CFG(ford_rx_checks, FORD_CANFD_LONG_TX_MSGS) : \
BUILD_SAFETY_CFG(ford_rx_checks, FORD_CANFD_STOCK_TX_MSGS);
} else {
// cppcheck-suppress knownConditionTrueFalse
ret = ford_longitudinal ? BUILD_SAFETY_CFG(ford_rx_checks, FORD_LONG_TX_MSGS) : \
BUILD_SAFETY_CFG(ford_rx_checks, FORD_STOCK_TX_MSGS);
}
Expand Down
2 changes: 1 addition & 1 deletion board/safety/safety_subaru_preglobal.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ static safety_config subaru_preglobal_init(uint16_t param) {
{.msg = {{MSG_SUBARU_PG_CruiseControl, SUBARU_PG_MAIN_BUS, 8, .frequency = 20U}, { 0 }, { 0 }}},
};

const int SUBARU_PG_PARAM_REVERSED_DRIVER_TORQUE = 1;
const int SUBARU_PG_PARAM_REVERSED_DRIVER_TORQUE = 4;

subaru_pg_reversed_driver_torque = GET_FLAG(param, SUBARU_PG_PARAM_REVERSED_DRIVER_TORQUE);
return BUILD_SAFETY_CFG(subaru_preglobal_rx_checks, SUBARU_PG_TX_MSGS);
Expand Down
4 changes: 2 additions & 2 deletions board/stm32h7/lladc.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ static uint16_t adc_get_raw(uint8_t channel) {
ADC1->SQR1 &= ~(ADC_SQR1_L);
ADC1->SQR1 = (uint32_t)channel << 6U;

ADC1->SMPR1 = 0x2UL << (channel * 3UL);
ADC1->SMPR1 = 0x4UL << (channel * 3UL);
ADC1->PCSEL_RES0 = (0x1UL << channel);
ADC1->CFGR2 = (127UL << ADC_CFGR2_OVSR_Pos) | (0x7U << ADC_CFGR2_OVSS_Pos) | ADC_CFGR2_ROVSE;
ADC1->CFGR2 = (63UL << ADC_CFGR2_OVSR_Pos) | (0x6U << ADC_CFGR2_OVSS_Pos) | ADC_CFGR2_ROVSE;

ADC1->CR |= ADC_CR_ADSTART;
while (!(ADC1->ISR & ADC_ISR_EOC));
Expand Down
29 changes: 17 additions & 12 deletions board/stm32h7/sound.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define SOUND_TX_BUF_SIZE (SOUND_RX_BUF_SIZE/2U)

__attribute__((section(".sram4"))) static uint16_t sound_rx_buf[2][SOUND_RX_BUF_SIZE];
__attribute__((section(".sram4"))) static uint16_t sound_tx_buf[2][SOUND_TX_BUF_SIZE];

static uint8_t sound_idle_count;

Expand All @@ -10,24 +11,24 @@ void sound_tick(void) {
sound_idle_count--;
if (sound_idle_count == 0U) {
current_board->set_amp_enabled(false);
register_clear_bits(&DMA1_Stream1->CR, DMA_SxCR_EN);
}
}
}

// Playback processing
static void BDMA_Channel0_IRQ_Handler(void) {
__attribute__((section(".sram4"))) static uint16_t tx_buf[SOUND_TX_BUF_SIZE];

BDMA->IFCR |= BDMA_IFCR_CGIF0; // clear flag

uint8_t buf_idx = (((BDMA_Channel0->CCR & BDMA_CCR_CT) >> BDMA_CCR_CT_Pos) == 1U) ? 0U : 1U;
uint8_t rx_buf_idx = (((BDMA_Channel0->CCR & BDMA_CCR_CT) >> BDMA_CCR_CT_Pos) == 1U) ? 0U : 1U;
uint8_t tx_buf_idx = (((DMA1_Stream1->CR & DMA_SxCR_CT) >> DMA_SxCR_CT_Pos) == 1U) ? 0U : 1U;

// process samples (shift to 12b and bias to be unsigned)
bool sound_playing = false;
for (uint16_t i=0U; i < SOUND_RX_BUF_SIZE; i += 2U) {
// since we are playing mono and receiving stereo, we take every other sample
tx_buf[i/2U] = ((sound_rx_buf[buf_idx][i] + (1UL << 14)) >> 3);
if (sound_rx_buf[buf_idx][i] > 0U) {
sound_tx_buf[tx_buf_idx][i/2U] = ((sound_rx_buf[rx_buf_idx][i] + (1UL << 14)) >> 3);
if (sound_rx_buf[rx_buf_idx][i] > 0U) {
sound_playing = true;
}
}
Expand All @@ -36,16 +37,17 @@ static void BDMA_Channel0_IRQ_Handler(void) {
if (sound_playing) {
if (sound_idle_count == 0U) {
current_board->set_amp_enabled(true);

// empty the other buf and start playing that
for (uint16_t i=0U; i < SOUND_TX_BUF_SIZE; i++) {
sound_tx_buf[1U - tx_buf_idx][i] = (1UL << 11);
}
register_set(&DMA1_Stream1->CR, (1UL - tx_buf_idx) << DMA_SxCR_CT_Pos, DMA_SxCR_CT_Msk);
register_set_bits(&DMA1_Stream1->CR, DMA_SxCR_EN);
}
sound_idle_count = 4U;
}
sound_tick();

DMA1->LIFCR |= 0xF40;
DMA1_Stream1->CR &= ~DMA_SxCR_EN;
register_set(&DMA1_Stream1->M0AR, (uint32_t) tx_buf, 0xFFFFFFFFU);
DMA1_Stream1->NDTR = SOUND_TX_BUF_SIZE;
DMA1_Stream1->CR |= DMA_SxCR_EN;
}

void sound_init(void) {
Expand All @@ -61,8 +63,11 @@ void sound_init(void) {

// Setup DMA
register_set(&DMA1_Stream1->PAR, (uint32_t) &(DAC1->DHR12R1), 0xFFFFFFFFU);
register_set(&DMA1_Stream1->M0AR, (uint32_t) sound_tx_buf[0], 0xFFFFFFFFU);
register_set(&DMA1_Stream1->M1AR, (uint32_t) sound_tx_buf[1], 0xFFFFFFFFU);
register_set(&DMA1_Stream1->FCR, 0U, 0x00000083U);
DMA1_Stream1->CR = (0b11UL << DMA_SxCR_PL_Pos) | (0b01UL << DMA_SxCR_MSIZE_Pos) | (0b01UL << DMA_SxCR_PSIZE_Pos) | DMA_SxCR_MINC | (1U << DMA_SxCR_DIR_Pos);
DMA1_Stream1->NDTR = SOUND_TX_BUF_SIZE;
DMA1_Stream1->CR = DMA_SxCR_DBM | (0b11UL << DMA_SxCR_PL_Pos) | (0b01UL << DMA_SxCR_MSIZE_Pos) | (0b01UL << DMA_SxCR_PSIZE_Pos) | DMA_SxCR_MINC | (1U << DMA_SxCR_DIR_Pos);

// Init trigger timer (little slower than 48kHz, pulled in sync by SAI4_FS_B)
register_set(&TIM5->PSC, 2600U, 0xFFFFU);
Expand Down
4 changes: 2 additions & 2 deletions drivers/linux/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ You will need to bring it up using `sudo ifconfig can0 up` or
Note that you may have to setup udev rules for Linux
``` bash
sudo tee /etc/udev/rules.d/11-panda.rules <<EOF
SUBSYSTEM=="usb", ATTRS{idVendor}=="bbaa", ATTRS{idProduct}=="ddcc", MODE="0666"
SUBSYSTEM=="usb", ATTRS{idVendor}=="bbaa", ATTRS{idProduct}=="ddee", MODE="0666"
SUBSYSTEM=="usb", ATTRS{idVendor}=="3801", ATTRS{idProduct}=="ddcc", MODE="0666"
SUBSYSTEM=="usb", ATTRS{idVendor}=="3801", ATTRS{idProduct}=="ddee", MODE="0666"
EOF
sudo udevadm control --reload-rules && sudo udevadm trigger
```
2 changes: 1 addition & 1 deletion drivers/linux/panda.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

/* vendor and product id */
#define PANDA_MODULE_NAME "panda"
#define PANDA_VENDOR_ID 0XBBAA
#define PANDA_VENDOR_ID 0X3801
#define PANDA_PRODUCT_ID 0XDDCC

#define PANDA_MAX_TX_URBS 20
Expand Down
6 changes: 3 additions & 3 deletions examples/query_fw_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import argparse
from tqdm import tqdm
from panda import Panda
from panda.python.uds import UdsClient, MessageTimeoutError, NegativeResponseError, InvalidSubAddressError, \
SESSION_TYPE, DATA_IDENTIFIER_TYPE
from opendbc.car.uds import UdsClient, MessageTimeoutError, NegativeResponseError, InvalidSubAddressError, \
SESSION_TYPE, DATA_IDENTIFIER_TYPE

if __name__ == "__main__":
parser = argparse.ArgumentParser()
Expand Down Expand Up @@ -97,7 +97,7 @@
resp = {}
for uds_data_id in sorted(uds_data_ids):
try:
data = uds_client.read_data_by_identifier(uds_data_id) # type: ignore
data = uds_client.read_data_by_identifier(DATA_IDENTIFIER_TYPE(uds_data_id))
if data:
resp[uds_data_id] = data
except (NegativeResponseError, MessageTimeoutError, InvalidSubAddressError):
Expand Down
8 changes: 4 additions & 4 deletions python/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ class Panda:
SERIAL_LIN2 = 3
SERIAL_SOM_DEBUG = 4

USB_VIDS = (0xbbaa, 0x3801) # 0x3801 is comma's registered VID
USB_PIDS = (0xddee, 0xddcc)
REQUEST_IN = usb1.ENDPOINT_IN | usb1.TYPE_VENDOR | usb1.RECIPIENT_DEVICE
REQUEST_OUT = usb1.ENDPOINT_OUT | usb1.TYPE_VENDOR | usb1.RECIPIENT_DEVICE
Expand Down Expand Up @@ -214,8 +215,7 @@ class Panda:

FLAG_SUBARU_GEN2 = 1
FLAG_SUBARU_LONG = 2

FLAG_SUBARU_PREGLOBAL_REVERSED_DRIVER_TORQUE = 1
FLAG_SUBARU_PREGLOBAL_REVERSED_DRIVER_TORQUE = 4

FLAG_NISSAN_ALT_EPS_BUS = 1

Expand Down Expand Up @@ -385,7 +385,7 @@ def usb_connect(cls, serial, claim=True, no_error=False):
context.open()
try:
for device in context.getDeviceList(skip_on_error=True):
if device.getVendorID() == 0xbbaa and device.getProductID() in cls.USB_PIDS:
if device.getVendorID() in cls.USB_VIDS and device.getProductID() in cls.USB_PIDS:
try:
this_serial = device.getSerialNumber()
except Exception:
Expand Down Expand Up @@ -441,7 +441,7 @@ def usb_list(cls):
try:
with usb1.USBContext() as context:
for device in context.getDeviceList(skip_on_error=True):
if device.getVendorID() == 0xbbaa and device.getProductID() in cls.USB_PIDS:
if device.getVendorID() in cls.USB_VIDS and device.getProductID() in cls.USB_PIDS:
try:
serial = device.getSerialNumber()
if len(serial) == 24:
Expand Down
Loading

0 comments on commit f061123

Please sign in to comment.