code powering the comma.ai panda
Go to file
Ruben Medina 229e8bb3a5
enable misra-c2012-12.2 (#1824)
* enable misra-c2012-12.2

* refactor: use 1UL in all FAULT defs
2024-01-20 16:19:34 -08:00
.github/workflows Add more MISRA mutation tests (#1818) 2024-01-20 15:52:38 -08:00
board enable misra-c2012-12.2 (#1824) 2024-01-20 16:19:34 -08:00
certs
crypto CI: set PYTHONWARNINGS=error (#1323) 2023-04-02 09:33:35 -07:00
docs move this to commaai/neo 2023-12-09 14:54:16 -08:00
drivers remove windows driver (#1793) 2024-01-13 14:05:10 -08:00
examples Sort output of can_bit_transition script numerically (#1785) 2023-12-29 11:32:37 -08:00
python pre-commit: autoupdate hooks (#1789) 2024-01-17 11:35:20 -08:00
release cleanup fw filename conventions (#1434) 2023-05-21 21:19:19 -07:00
tests enable misra-c2012-12.2 (#1824) 2024-01-20 16:19:34 -08:00
.gitignore safety: coverage report (#1696) 2023-10-25 22:01:01 -07:00
.pre-commit-config.yaml pre-commit: autoupdate hooks (#1789) 2024-01-17 11:35:20 -08:00
Dockerfile Subaru: cruise_rpm and cruise_throttle are 13 bits (#1786) 2023-12-29 19:25:02 -05:00
Jenkinsfile jenkins: run bootkick tests (#1688) 2023-10-09 21:52:15 -07:00
LICENSE
README.md remove windows driver (#1793) 2024-01-13 14:05:10 -08:00
SConscript CI: Translate abspath to relpath for build. (#1783) 2023-12-22 10:16:09 -08:00
SConstruct Rename safety coverage flag 2023-10-30 11:43:56 -07:00
__init__.py Remove flash logging (#1674) 2023-09-30 12:49:46 -07:00
mypy.ini Same mypy checks as openpilot (#1233) 2023-02-11 12:25:13 -08:00
panda.png
pyproject.toml Ruff: propgate config from OP (#1579) 2023-08-14 12:52:02 -07:00
requirements.txt Add more MISRA mutation tests (#1818) 2024-01-20 15:52:38 -08:00
setup.cfg
setup.py

README.md

Welcome to panda

panda tests panda drivers

panda speaks CAN and CAN FD, and it runs on STM32F205, STM32F413, and STM32H725.

Directory structure

.
├── board           # Code that runs on the STM32
├── drivers         # Drivers (not needed for use with Python)
├── python          # Python userspace library for interfacing with the panda
├── tests           # Tests and helper programs for panda

Safety Model

When a panda powers up, by default it's in SAFETY_SILENT mode. While in SAFETY_SILENT mode, the CAN buses are forced to be silent. In order to send messages, you have to select a safety mode. Some of safety modes (for example SAFETY_ALLOUTPUT) are disabled in release firmwares. In order to use them, compile and flash your own build.

Safety modes optionally support controls_allowed, which allows or blocks a subset of messages based on a customizable state in the board.

Code Rigor

The panda firmware is written for its use in conjuction with openpilot. The panda firmware, through its safety model, provides and enforces the openpilot safety. Due to its critical function, it's important that the application code rigor within the board folder is held to high standards.

These are the CI regression tests we have in place:

  • A generic static code analysis is performed by cppcheck.
  • In addition, cppcheck has a specific addon to check for MISRA C:2012 violations. See current coverage.
  • Compiler options are relatively strict: the flags -Wall -Wextra -Wstrict-prototypes -Werror are enforced.
  • The safety logic is tested and verified by unit tests for each supported car variant. to ensure that the behavior remains unchanged.
  • A hardware-in-the-loop test verifies panda's functionalities on all active panda variants, including:
    • additional safety model checks
    • compiling and flashing the bootstub and app code
    • receiving, sending, and forwarding CAN messages on all buses
    • CAN loopback and latency tests through USB and SPI

The above tests are themselves tested by:

  • a mutation test on the MISRA coverage
  • 100% line coverage enforced on the safety unit tests

In addition, we run the ruff linter and mypy on panda's Python library.

Usage

Setup dependencies:

# Ubuntu
sudo apt-get install dfu-util gcc-arm-none-eabi python3-pip libffi-dev git

# macOS
brew install --cask gcc-arm-embedded
brew install python3 dfu-util gcc@13

Clone panda repository and install:

git clone https://github.com/commaai/panda.git
cd panda

# install dependencies
pip install -r requirements.txt

# install panda
python setup.py install

See the Panda class for how to interact with the panda.

For example, to receive CAN messages:

>>> from panda import Panda
>>> panda = Panda()
>>> panda.can_recv()

And to send one on bus 0:

>>> panda.can_send(0x1aa, "message", 0)

Note that you may have to setup udev rules for Linux, such as

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"
EOF
sudo udevadm control --reload-rules && sudo udevadm trigger

The panda jungle uses different udev rules. See the repo for instructions.

Software interface support

As a universal car interface, it should support every reasonable software interface.

Licensing

panda software is released under the MIT license unless otherwise specified.