Skip to content

Commit

Permalink
Merge remote-tracking branch 'commaai/panda/master' into camera-scc-long
Browse files Browse the repository at this point in the history
  • Loading branch information
sunnyhaibin committed Apr 25, 2023
2 parents d7e3f16 + b342c2d commit dfc38c1
Show file tree
Hide file tree
Showing 85 changed files with 1,324 additions and 692 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/repo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: repo

on:
schedule:
- cron: "0 15 * * 2"
workflow_dispatch:

jobs:
pre-commit-autoupdate:
name: pre-commit autoupdate
runs-on: ubuntu-20.04
container:
image: ghcr.io/commaai/panda:latest
steps:
- uses: actions/checkout@v3
- name: pre-commit autoupdate
run: |
git config --global --add safe.directory '*'
pre-commit autoupdate
- name: Create Pull Request
uses: peter-evans/create-pull-request@5b4a9f6a9e2af26e5f02351490b90d01eb8ec1e5
with:
token: ${{ secrets.ACTIONS_CREATE_PR_PAT }}
commit-message: Update pre-commit hook versions
title: 'pre-commit: autoupdate hooks'
branch: pre-commit-updates
base: master
delete-branch: true
4 changes: 3 additions & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ env:
export DOCKER_BUILDKIT=1
docker build --pull --build-arg BUILDKIT_INLINE_CACHE=1 --cache-from ghcr.io/commaai/panda:latest -t panda -f Dockerfile .
PYTHONWARNINGS: "error"

jobs:
docker_push:
name: docker push
Expand Down Expand Up @@ -67,7 +69,7 @@ jobs:
- name: Build Docker image
run: eval "$BUILD"
- name: Run safety tests
timeout-minutes: 4
timeout-minutes: 3
run: |
${{ env.RUN }} "cd .. && \
scons -c && \
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ ENV PATH="/root/.pyenv/bin:/root/.pyenv/shims:${PATH}"

ENV PANDA_PATH=/tmp/openpilot/panda
ENV OPENPILOT_REF="ee0dd36a3c775dbd82493c84f4e7272c1eb3fcbd"
ENV OPENDBC_REF="e8e97fcf00be9a696be009aa37ca13c55b9f632c"
ENV OPENDBC_REF="342c0320dd271fb585db3cced397c5122078af85"

COPY requirements.txt /tmp/
RUN pyenv install 3.8.10 && \
Expand Down Expand Up @@ -83,7 +83,7 @@ RUN cd /tmp/openpilot && \
git clone https://github.com/commaai/panda_jungle.git && \
cd panda_jungle && \
git fetch && \
git checkout 7b7197c605915ac34f3d62f314edd84e2e78a759 && \
git checkout 3a791be1f1877a69cf45de16a670992380622297 && \
rm -rf .git/

RUN cd /tmp/openpilot && \
Expand Down
141 changes: 109 additions & 32 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ def docker_run(String step_label, int timeout_mins, String cmd) {
timeout(time: timeout_mins, unit: 'MINUTES') {
sh script: "docker run --rm --privileged \
--env PARTIAL_TESTS=${env.PARTIAL_TESTS} \
--env PYTHONWARNINGS=error \
--volume /dev/bus/usb:/dev/bus/usb \
--volume /var/run/dbus:/var/run/dbus \
--workdir /tmp/openpilot/panda \
Expand All @@ -12,58 +13,134 @@ def docker_run(String step_label, int timeout_mins, String cmd) {
}
}


def phone(String ip, String step_label, String cmd) {
withCredentials([file(credentialsId: 'id_rsa', variable: 'key_file')]) {
def ssh_cmd = """
ssh -tt -o StrictHostKeyChecking=no -i ${key_file} 'comma@${ip}' /usr/bin/bash <<'END'
set -e
source ~/.bash_profile
if [ -f /etc/profile ]; then
source /etc/profile
fi
export CI=1
export TEST_DIR=${env.TEST_DIR}
export SOURCE_DIR=${env.SOURCE_DIR}
export GIT_BRANCH=${env.GIT_BRANCH}
export GIT_COMMIT=${env.GIT_COMMIT}
export PYTHONPATH=${env.TEST_DIR}/../
export PYTHONWARNINGS=error
cd ${env.TEST_DIR} || true
${cmd}
exit 0
END"""

sh script: ssh_cmd, label: step_label
}
}

def phone_steps(String device_type, steps) {
lock(resource: "", label: device_type, inversePrecedence: true, variable: 'device_ip', quantity: 1) {
timeout(time: 20, unit: 'MINUTES') {
phone(device_ip, "git checkout", readFile("tests/setup_device_ci.sh"),)
steps.each { item ->
phone(device_ip, item[0], item[1])
}
}
}
}



pipeline {
agent any
environment {
CI = "1"
PARTIAL_TESTS = "${env.BRANCH_NAME == 'master' ? ' ' : '1'}"
PYTHONWARNINGS= "error"
DOCKER_IMAGE_TAG = "panda:build-${env.GIT_COMMIT}"

TEST_DIR = "/data/panda"
SOURCE_DIR = "/data/panda_source/"
}
options {
timeout(time: 3, unit: 'HOURS')
disableConcurrentBuilds(abortPrevious: env.BRANCH_NAME != 'master')
}

stages {
stage ('Acquire resource locks') {
options {
lock(resource: "pandas")
}
stages {
stage('Build Docker Image') {
stage('panda tests') {
parallel {
stage('test dos') {
agent { docker { image 'ghcr.io/commaai/alpine-ssh'; args '--user=root' } }
steps {
timeout(time: 20, unit: 'MINUTES') {
script {
sh 'git archive -v -o panda.tar.gz --format=tar.gz HEAD'
dockerImage = docker.build("${env.DOCKER_IMAGE_TAG}")
}
}
phone_steps("panda-dos", [
["build", "scons -j4"],
["flash", "cd tests/ && ./ci_reset_internal_hw.py"],
["test", "cd tests/hitl && HW_TYPES=6 pytest --durations=0 [2-7]*.py -k 'not test_send_recv'"],
])
}
}
stage('prep') {

stage('test tres') {
agent { docker { image 'ghcr.io/commaai/alpine-ssh'; args '--user=root' } }
steps {
script {
docker_run("reset hardware", 3, "python ./tests/ci_reset_hw.py")
}
phone_steps("panda-tres", [
["build", "scons -j4"],
["flash", "cd tests/ && ./ci_reset_internal_hw.py"],
["test", "cd tests/hitl && HW_TYPES=9 pytest --durations=0 2*.py [5-7]*.py -k 'not test_fan_controller and not test_fan_overshoot'"],
])
}
}
stage('pedal tests') {
steps {
script {
docker_run("test pedal", 1, "PEDAL_JUNGLE=058010800f51363038363036 python ./tests/pedal/test_pedal.py")
}

stage ('Acquire resource locks') {
options {
lock(resource: "pandas")
}
}
stage('HITL tests') {
steps {
script {
docker_run("HITL tests", 35, 'PANDAS_JUNGLE=23002d000851393038373731 PANDAS_EXCLUDE="1d0002000c51303136383232 2f002e000c51303136383232" ./tests/hitl/test.sh')
stages {
stage('Build Docker Image') {
steps {
timeout(time: 20, unit: 'MINUTES') {
script {
sh 'git archive -v -o panda.tar.gz --format=tar.gz HEAD'
dockerImage = docker.build("${env.DOCKER_IMAGE_TAG}")
}
}
}
}
}
}
stage('CANFD tests') {
steps {
script {
docker_run("CANFD tets", 6, 'JUNGLE=058010800f51363038363036 H7_PANDAS_EXCLUDE="080021000c51303136383232 33000e001051393133353939" ./tests/canfd/test_canfd.py')
stage('prep') {
steps {
script {
docker_run("reset hardware", 3, "python ./tests/ci_reset_hw.py")
}
}
}
stage('pedal tests') {
steps {
script {
docker_run("test pedal", 1, "PEDAL_JUNGLE=058010800f51363038363036 python ./tests/pedal/test_pedal.py")
}
}
}
stage('HITL tests') {
steps {
script {
docker_run("HITL tests", 35, 'PANDAS_JUNGLE=23002d000851393038373731 PANDAS_EXCLUDE="1d0002000c51303136383232 2f002e000c51303136383232" ./tests/hitl/test.sh')
}
}
}
stage('CANFD tests') {
steps {
script {
docker_run("CANFD tets", 6, 'JUNGLE=058010800f51363038363036 H7_PANDAS_EXCLUDE="080021000c51303136383232 33000e001051393133353939" ./tests/canfd/test_canfd.py')
}
}
}
}
}
Expand Down
23 changes: 14 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,30 @@ It uses an [STM32F413](http://www.st.com/en/microcontrollers/stm32f413-423.html?

## Usage

Setup your dependencies:

Setup dependencies:
```bash
# Ubuntu
sudo apt-get install dfu-util gcc-arm-none-eabi python3-pip
pip install -r requirements.txt

sudo apt-get install dfu-util gcc-arm-none-eabi python3-pip libffi-dev git
```
```bash
# macOS
brew tap ArmMbed/homebrew-formulae
brew install python dfu-util arm-none-eabi-gcc gcc@12
pip install -r requirements.txt
```

### Python

To install the library:
Clone panda repository:
``` bash
git clone https://github.com/commaai/panda.git
cd panda
```

Install requirements:
```bash
pip install -r requirements.txt
```

Install library:
``` bash
python setup.py install
```

Expand Down
11 changes: 4 additions & 7 deletions board/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,15 @@ Programming
**Panda**

```
./recover.sh # flash bootstub
```

```
./flash.sh # flash application
./recover.py # flash bootstub
./flash.py # flash application
```

Troubleshooting
----

If your panda will not flash and green LED is on, use `recover.sh`.
If panda is blinking fast with green LED, use `flash.sh`.
If your panda will not flash and green LED is on, use `recover.py`.
If panda is blinking fast with green LED, use `flash.py`.
Otherwise if LED is off and panda can't be seen with `lsusb` command, use [panda paw](https://comma.ai/shop/products/panda-paw) to go into DFU mode.


Expand Down
3 changes: 2 additions & 1 deletion board/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ def get_key_header(name):
from Crypto.PublicKey import RSA

public_fn = File(f'../certs/{name}.pub').srcnode().abspath
rsa = RSA.importKey(open(public_fn).read())
with open(public_fn) as f:
rsa = RSA.importKey(f.read())
assert(rsa.size_in_bits() == 1024)

rr = pow(2**1024, 2, rsa.n)
Expand Down
2 changes: 1 addition & 1 deletion board/boards/dos.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ const board board_dos = {
.fan_max_rpm = 6500U,
.adc_scale = 8862U,
.fan_stall_recovery = true,
.fan_enable_cooldown_time = 0U,
.fan_enable_cooldown_time = 3U,
.init = dos_init,
.enable_can_transceiver = dos_enable_can_transceiver,
.enable_can_transceivers = dos_enable_can_transceivers,
Expand Down
1 change: 1 addition & 0 deletions board/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
//#define DEBUG_SPI
//#define DEBUG_FAULTS
//#define DEBUG_COMMS
//#define DEBUG_FAN

#define CAN_INIT_TIMEOUT_MS 500U
#define DEEPSLEEP_WAKEUP_DELAY 3U
Expand Down
2 changes: 1 addition & 1 deletion board/drivers/bxcan.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ void can_rx(uint8_t can_number) {
can_set_checksum(&to_push);

// forwarding (panda only)
int bus_fwd_num = safety_fwd_hook(bus_number, &to_push);
int bus_fwd_num = safety_fwd_hook(bus_number, to_push.addr);
if (bus_fwd_num != -1) {
CANPacket_t to_send;

Expand Down
1 change: 1 addition & 0 deletions board/drivers/can_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ void can_send(CANPacket_t *to_push, uint8_t bus_number, bool skip_tx_hook) {
}
} else {
safety_tx_blocked += 1U;
to_push->returned = 0U;
to_push->rejected = 1U;

// data changed
Expand Down
10 changes: 6 additions & 4 deletions board/drivers/fake_siren.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
#include "stm32h7/lli2c.h"

#define CODEC_I2C_ADDR 0x10

// 1Vpp sine wave with 1V offset
const uint8_t fake_siren_lut[360] = { 134U, 135U, 137U, 138U, 139U, 140U, 141U, 143U, 144U, 145U, 146U, 148U, 149U, 150U, 151U, 152U, 154U, 155U, 156U, 157U, 158U, 159U, 160U, 162U, 163U, 164U, 165U, 166U, 167U, 168U, 169U, 170U, 171U, 172U, 174U, 175U, 176U, 177U, 177U, 178U, 179U, 180U, 181U, 182U, 183U, 184U, 185U, 186U, 186U, 187U, 188U, 189U, 190U, 190U, 191U, 192U, 193U, 193U, 194U, 195U, 195U, 196U, 196U, 197U, 197U, 198U, 199U, 199U, 199U, 200U, 200U, 201U, 201U, 202U, 202U, 202U, 203U, 203U, 203U, 203U, 204U, 204U, 204U, 204U, 204U, 204U, 204U, 205U, 205U, 205U, 205U, 205U, 205U, 205U, 204U, 204U, 204U, 204U, 204U, 204U, 204U, 203U, 203U, 203U, 203U, 202U, 202U, 202U, 201U, 201U, 200U, 200U, 199U, 199U, 199U, 198U, 197U, 197U, 196U, 196U, 195U, 195U, 194U, 193U, 193U, 192U, 191U, 190U, 190U, 189U, 188U, 187U, 186U, 186U, 185U, 184U, 183U, 182U, 181U, 180U, 179U, 178U, 177U, 177U, 176U, 175U, 174U, 172U, 171U, 170U, 169U, 168U, 167U, 166U, 165U, 164U, 163U, 162U, 160U, 159U, 158U, 157U, 156U, 155U, 154U, 152U, 151U, 150U, 149U, 148U, 146U, 145U, 144U, 143U, 141U, 140U, 139U, 138U, 137U, 135U, 134U, 133U, 132U, 130U, 129U, 128U, 127U, 125U, 124U, 123U, 122U, 121U, 119U, 118U, 117U, 116U, 115U, 113U, 112U, 111U, 110U, 109U, 108U, 106U, 105U, 104U, 103U, 102U, 101U, 100U, 99U, 98U, 97U, 96U, 95U, 94U, 93U, 92U, 91U, 90U, 89U, 88U, 87U, 86U, 85U, 84U, 83U, 82U, 82U, 81U, 80U, 79U, 78U, 78U, 77U, 76U, 76U, 75U, 74U, 74U, 73U, 72U, 72U, 71U, 71U, 70U, 70U, 69U, 69U, 68U, 68U, 67U, 67U, 67U, 66U, 66U, 66U, 65U, 65U, 65U, 65U, 64U, 64U, 64U, 64U, 64U, 64U, 64U, 64U, 64U, 63U, 64U, 64U, 64U, 64U, 64U, 64U, 64U, 64U, 64U, 65U, 65U, 65U, 65U, 66U, 66U, 66U, 67U, 67U, 67U, 68U, 68U, 69U, 69U, 70U, 70U, 71U, 71U, 72U, 72U, 73U, 74U, 74U, 75U, 76U, 76U, 77U, 78U, 78U, 79U, 80U, 81U, 82U, 82U, 83U, 84U, 85U, 86U, 87U, 88U, 89U, 90U, 91U, 92U, 93U, 94U, 95U, 96U, 97U, 98U, 99U, 100U, 101U, 102U, 103U, 104U, 105U, 106U, 108U, 109U, 110U, 111U, 112U, 113U, 115U, 116U, 117U, 118U, 119U, 121U, 122U, 123U, 124U, 125U, 127U, 128U, 129U, 130U, 132U, 133U };

bool fake_siren_enabled = false;

void fake_siren_codec_enable(bool enabled) {
if(enabled) {
bool success = false;
if (enabled) {
bool success = true;
success &= i2c_set_reg_bits(I2C5, CODEC_I2C_ADDR, 0x2B, (1U << 1)); // Left speaker mix from INA1
success &= i2c_set_reg_bits(I2C5, CODEC_I2C_ADDR, 0x2C, (1U << 1)); // Right speaker mix from INA1
success &= i2c_set_reg_mask(I2C5, CODEC_I2C_ADDR, 0x3D, 0x17, 0b11111); // Left speaker volume
Expand All @@ -17,11 +18,12 @@ void fake_siren_codec_enable(bool enabled) {
success &= i2c_set_reg_bits(I2C5, CODEC_I2C_ADDR, 0x4C, (1U << 7)); // Enable INA
success &= i2c_set_reg_bits(I2C5, CODEC_I2C_ADDR, 0x51, (1U << 7)); // Disable global shutdown
if (!success) {
print("Failed to setup the codec for fake siren\n");
print("Siren codec enable failed\n");
fault_occurred(FAULT_SIREN_MALFUNCTION);
}
} else {
// Disable INA input. Make sure to retry a few times if the I2C bus is busy.
for(uint8_t i=0U; i<10U; i++) {
for (uint8_t i=0U; i<10U; i++) {
if (i2c_clear_reg_bits(I2C5, CODEC_I2C_ADDR, 0x4C, (1U << 7))) {
break;
}
Expand Down
Loading

0 comments on commit dfc38c1

Please sign in to comment.