Skip to content

Commit

Permalink
Add smart roadster interceptor
Browse files Browse the repository at this point in the history
  • Loading branch information
ReFil committed Nov 17, 2023
1 parent 0b6eaae commit cfb6b67
Show file tree
Hide file tree
Showing 7 changed files with 1,023 additions and 0 deletions.
8 changes: 8 additions & 0 deletions board/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
#ifdef IBST
#include "boards/ibst.h"
#endif
#ifdef KOMBI
#include "boards/kombi.h"
#endif

void detect_board_type(void) {
#ifdef PANDA
Expand Down Expand Up @@ -56,13 +59,18 @@ void detect_board_type(void) {
#ifdef IBST
hw_type = HW_TYPE_IBST;
current_board = &board_ibst;
#else
#ifdef KOMBI
hw_type = HW_TYPE_KOMBI;
current_board = &board_kombi;
#else
hw_type = HW_TYPE_UNKNOWN;
puts("Hardware type is UNKNOWN!\n");
#endif
#endif
#endif
#endif
#endif
}


Expand Down
125 changes: 125 additions & 0 deletions board/boards/kombi.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
// /////////// //
// KOMBI gateway //
// /////////// //

void kombi_enable_can_transceiver(uint8_t transceiver, bool enabled) {
switch (transceiver){
case 1U:
set_gpio_output(GPIOC, 1, !enabled);
break;
case 2U:
set_gpio_output(GPIOC, 13, !enabled);
break;
case 3U:
set_gpio_output(GPIOA, 0, !enabled);
break;
default:
puts("Invalid CAN transceiver ("); puth(transceiver); puts("): enabling failed\n");
break;
}
}

void kombi_enable_can_transceivers(bool enabled) {
uint8_t t1 = enabled ? 1U : 2U; // leave transceiver 1 enabled to detect CAN ignition
for(uint8_t i=t1; i<=3U; i++) {
kombi_enable_can_transceiver(i, enabled);
}
}

void kombi_set_led(uint8_t color, bool enabled) {
UNUSED(color);
UNUSED(enabled);
}

void kombi_set_usb_power_mode(uint8_t mode){
UNUSED(mode);
}

void kombi_set_gps_mode(uint8_t mode) {
UNUSED(mode);
}

void kombi_set_can_mode(uint8_t mode){
switch (mode) {
case CAN_MODE_NORMAL:
set_gpio_alternate(GPIOB, 8, GPIO_AF8_CAN1);
set_gpio_alternate(GPIOB, 9, GPIO_AF8_CAN1);
// B5,B6: normal CAN2 mode
set_gpio_alternate(GPIOB, 5, GPIO_AF9_CAN2);
set_gpio_alternate(GPIOB, 6, GPIO_AF9_CAN2);

// A8,A15: normal CAN3 mode
set_gpio_alternate(GPIOA, 8, GPIO_AF11_CAN3);
set_gpio_alternate(GPIOA, 15, GPIO_AF11_CAN3);
break;
default:
puts("Tried to set unsupported CAN mode: "); puth(mode); puts("\n");
break;
}
}

uint32_t kombi_read_current(void){
return 0U;
}

void kombi_usb_power_mode_tick(uint32_t uptime){
UNUSED(uptime);
}

void kombi_set_ir_power(uint8_t percentage){
UNUSED(percentage);
}

void kombi_set_fan_power(uint8_t percentage){
UNUSED(percentage);
}

bool kombi_check_ignition(void){
// ignition is on PA1
return 0U;
}

void kombi_set_phone_power(bool enabled){
UNUSED(enabled);
}

void kombi_set_clock_source_mode(uint8_t mode){
UNUSED(mode);
}

void kombi_set_siren(bool enabled){
UNUSED(enabled);
}

void kombi_init(void) {
common_init_gpio();

// Enable CAN transceivers
kombi_enable_can_transceivers(true);
// Set normal CAN mode
kombi_set_can_mode(CAN_MODE_NORMAL);
}

const harness_configuration kombi_harness_config = {
.has_harness = false
};

const board board_kombi = {
.board_type = "White",
.harness_config = &kombi_harness_config,
.init = kombi_init,
.enable_can_transceiver = kombi_enable_can_transceiver,
.enable_can_transceivers = kombi_enable_can_transceivers,
.set_led = kombi_set_led,
.set_usb_power_mode = kombi_set_usb_power_mode,
.set_gps_mode = kombi_set_gps_mode,
.set_can_mode = kombi_set_can_mode,
.usb_power_mode_tick = kombi_usb_power_mode_tick,
.check_ignition = kombi_check_ignition,
.read_current = kombi_read_current,
.set_fan_power = kombi_set_fan_power,
.set_ir_power = kombi_set_ir_power,
.set_phone_power = kombi_set_phone_power,
.set_clock_source_mode = kombi_set_clock_source_mode,
.set_siren = kombi_set_siren
};
1 change: 1 addition & 0 deletions board/kombi/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
obj/*
81 changes: 81 additions & 0 deletions board/kombi/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
PROJ_NAME = panda
CFLAGS = -g -Wall -Wextra -Wstrict-prototypes -Werror

CFLAGS += -mlittle-endian -mthumb -mcpu=cortex-m4
CFLAGS += -mhard-float -DSTM32F4 -DSTM32F413xx -mfpu=fpv4-sp-d16 -fsingle-precision-constant -DIBST
STARTUP_FILE = startup_stm32f413xx

CFLAGS += -I ../inc -I ../ -I ../../ -nostdlib -fno-builtin -std=gnu11 -Os

CFLAGS += -T../stm32_flash.ld

DFU_UTIL = "dfu-util"

#COMPILER_PATH = /home/batman/Downloads/gcc-arm-none-eabi-9-2020-q2-update/bin/
CC = $(COMPILER_PATH)arm-none-eabi-gcc
OBJCOPY = $(COMPILER_PATH)arm-none-eabi-objcopy
OBJDUMP = $(COMPILER_PATH)arm-none-eabi-objdump

CERT = ../../certs/debug
CFLAGS += "-DALLOW_DEBUG"



DEPDIR = ../generated_dependencies
$(shell mkdir -p -m 777 $(DEPDIR) >/dev/null)
DEPFLAGS = -MT $@ -MMD -MP -MF $(DEPDIR)/$*.Td
POSTCOMPILE = @mv -f $(DEPDIR)/$*.Td $(DEPDIR)/$*.d && touch $@

# this no longer pushes the bootstub
canflash: obj/$(PROJ_NAME).bin
../../tests/ctrls/enter_canloader.py $<

usbflash: obj/$(PROJ_NAME).bin
../../tests/ibst/enter_canloader.py; sleep 0.5
PYTHONPATH=../../ python -c "from python import Panda; p = [x for x in [Panda(x) for x in Panda.list()] if x.bootstub]; assert(len(p)==1); p[0].flash('obj/$(PROJ_NAME).bin', reconnect=False)"

recover: obj/bootstub.bin obj/$(PROJ_NAME).bin
../tools/enter_download_mode.py $<
sleep 1.0
$(DFU_UTIL) -d 0483:df11 -a 0 -s 0x08004000 -D obj/$(PROJ_NAME).bin
$(DFU_UTIL) -d 0483:df11 -a 0 -s 0x08000000:leave -D obj/bootstub.bin

recover_can: obj/bootstub.bin obj/$(PROJ_NAME).bin
../../tests/ibst/enter_canloader.py --recover; sleep 0.5
$(DFU_UTIL) -d 0483:df11 -a 0 -s 0x08004000 -D obj/$(PROJ_NAME).bin
$(DFU_UTIL) -d 0483:df11 -a 0 -s 0x08000000:leave -D obj/bootstub.bin

include ../../common/version.mk

obj/cert.h: ../../crypto/getcertheader.py
../../crypto/getcertheader.py ../../certs/debug.pub ../../certs/release.pub > $@

obj/main.o: main.c ../*.h
mkdir -p obj
$(CC) $(CFLAGS) -o $@ -c $<

obj/bootstub.o: ../bootstub.c ../*.h obj/gitversion.h obj/cert.h
mkdir -p obj
mkdir -p ../obj
cp obj/gitversion.h ../obj/gitversion.h
cp obj/cert.h ../obj/cert.h
$(CC) $(CFLAGS) -o $@ -c $<

obj/$(STARTUP_FILE).o: ../$(STARTUP_FILE).s
$(CC) $(CFLAGS) -o $@ -c $<

obj/%.o: ../../crypto/%.c
$(CC) $(CFLAGS) -o $@ -c $<

obj/$(PROJ_NAME).bin: obj/$(STARTUP_FILE).o obj/main.o
# hack
$(CC) -Wl,--section-start,.isr_vector=0x8004000 $(CFLAGS) -o obj/$(PROJ_NAME).elf $^
$(OBJCOPY) -v -O binary obj/$(PROJ_NAME).elf obj/code.bin
SETLEN=1 ../../crypto/sign.py obj/code.bin $@ $(CERT)

obj/bootstub.bin: obj/$(STARTUP_FILE).o obj/bootstub.o obj/sha.o obj/rsa.o
$(CC) $(CFLAGS) -o obj/bootstub.$(PROJ_NAME).elf $^
$(OBJCOPY) -v -O binary obj/bootstub.$(PROJ_NAME).elf $@

clean:
rm -f obj/*
Loading

0 comments on commit cfb6b67

Please sign in to comment.