Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ def to_c_uint32(x):
return "{" + 'U,'.join(map(str, nums)) + "U}"


def build_project(project_name, project, extra_flags):
def build_project(project_name, project, extra_flags, cppdefines=None):
cppdefines = cppdefines or []
print(f"{project_name} -> CPPDEFINES [{', '.join(cppdefines)}]")
linkerscript_fn = File(project["LINKER_SCRIPT"]).srcnode().relpath

flags = project["PROJECT_FLAGS"] + extra_flags + common_flags + [
Expand Down Expand Up @@ -101,6 +103,7 @@ def build_project(project_name, project, extra_flags):
'Objcopy': Builder(generator=objcopy, suffix='.bin', src_suffix='.elf')
},
tools=["default", "compilation_db"],
CPPDEFINES=cppdefines,
)

startup = env.Object(f"obj/startup_{project_name}", project["STARTUP_FILE"])
Expand Down Expand Up @@ -179,12 +182,15 @@ with open("board/obj/cert.h", "w") as f:
for cert in certs:
f.write("\n".join(cert) + "\n")

# panda fw
SConscript('board/SConscript')

# panda jungle fw
SConscript('board/jungle/SConscript')

# test files
if GetOption('extras'):
SConscript('tests/libpanda/SConscript')
if not GetOption('escc'): # if we are building ESCC, we don't build anything else
# panda fw
SConscript('board/SConscript')

# panda jungle fw
SConscript('board/jungle/SConscript')

# test files
if GetOption('extras'):
SConscript('tests/libpanda/SConscript')
else:
SConscript('board/escc/SConscript')
4 changes: 4 additions & 0 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ AddOption('--mutation',
action='store_true',
help='generate mutation-ready code')

AddOption('--escc',
action='store_true',
help='build escc firmware')

env = Environment(
COMPILATIONDB_USE_ABSPATH=True,
tools=["default", "compilation_db"],
Expand Down
2 changes: 2 additions & 0 deletions board/drivers/can_common_declarations.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include "health.h"

typedef struct {
volatile uint32_t w_ptr;
volatile uint32_t r_ptr;
Expand Down
1 change: 1 addition & 0 deletions board/escc/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
obj/*
81 changes: 81 additions & 0 deletions board/escc/README.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
## Documentation
[see more](https://github.com/sunnypilot/sunnypilot/blob/5d754169a6285e88e755ff9a592a851cb92b0abc/docs/escc/ESCC%20IONIQ%20PHEV%20Guide.md)

### Detailed Connection List

#### Molex 5018762640 Pinout:

- Pin 1: GND
- Pin 2: IGN
- Pin 3: internal 120 Ohm Resistor, simply bridge to Pin 5
- Pin 4: C-CAN HIGH
- Pin 5: internal 120 Ohm Resistor, simply bridge to Pin 3
- Pin 6: C-CAN LOW
- Pin 8: L-CAN HIGH
- Pin 10: L-CAN LOW
- Pin 12: 12v
- Pin 14: 12v
- Pin 16: IGN
- Pin 18: L-CAN HIGH
- Pin 20: L-CAN LOW
- Pin 22: C-CAN HIGH
- Pin 24: C-CAN LOW
- Pin 26: GND

#### **IONIQ 2203663 (Car Harness, Female):**

- Pin 1: 12v -> Molex Pin 12
- Pin 4: GND -> Molex Pin 1
- Pin 7: C-CAN LOW -> Molex Pin 6
- Pin 8: C-CAN HIGH -> Molex Pin 4
- Pin 9: L-CAN LOW -> Molex Pin 10
- Pin 10: IGPM (IGN) -> Molex Pin 2
- Pin 18: L-CAN HIGH -> Molex Pin 8

#### **IONIQ 2203663 (Car Radar, Male):**

- Molex Pin: 14 -> Pin 1: 12v
- Molex Pin: 26 -> Pin 4: GND
- Molex Pin: 24 -> Pin 7: C-CAN LOW
- Molex Pin: 22 -> Pin 8: C-CAN HIGH
- Molex Pin: 20 -> Pin 9: L-CAN LOW
- Molex Pin: 16 -> Pin 10: IGN
- Molex Pin: 18 -> Pin 18: L-CAN HIGH


```
IONIQ 2203663 Molex 5018762640 IONIQ 2203663
Car Harness (Female) Car Radar (Male)
+-----+-----+ +-----+-----+ +-----+-----+
| 18 | 9 | | 2 | 1 | | 10 | 1 |
| 17 | 8 | | 4 | 3 | | 11 | 2 |
| 16 | 7 | | 6 | 5 | | 12 | 3 |
| 15 | 6 | | 8 | 7 | | 13 | 4 |
| 14 | 5 | NOTCH | 10 | 9 | | 14 | 5 | NOTCH
| 13 | 4 | | 12 | 11 | | 15 | 6 |
| 12 | 3 | | 14 | 13 | NOTCH | 16 | 7 |
| 11 | 2 | | 16 | 15 | | 17 | 8 |
| 10 | 1 | | 18 | 17 | | 18 | 9 |
+-----+-----+ | 20 | 19 | +-----+-----+
| 22 | 21 |
| 24 | 23 |
| 26 | 25 |
+-----+-----+

Connections:
Molex Pin 3 (120 Ohm) <--> Molex Pin 5 (120 Ohm)
Harness Pin 1 (12V) <--> Molex Pin 12 (12V)
Harness Pin 4 (GND) <--> Molex Pin 1 (GND)
Harness Pin 10 (IGN) <--> Molex Pin 2 (IGN)
Harness Pin 8 (C-CAN H) <--> Molex Pin 4 (C-CAN H)
Harness Pin 7 (C-CAN L) <--> Molex Pin 6 (C-CAN L)
Harness Pin 18 (L-CAN H) <--> Molex Pin 8 (L-CAN H)
Harness Pin 9 (L-CAN L) <--> Molex Pin 10 (L-CAN L)
Molex Pin 20 (L-CAN L) <--> Radar Pin 9 (L-CAN L)
Molex Pin 18 (L-CAN H) <--> Radar Pin 18 (L-CAN H)
Molex Pin 24 (C-CAN L) <--> Radar Pin 7 (C-CAN L)
Molex Pin 22 (C-CAN H) <--> Radar Pin 8 (C-CAN H)
Molex Pin 16 (IGN) <--> Radar Pin 10 (IGN)
Molex Pin 14 (12V) <--> Radar Pin 1 (12V)
Molex Pin 26 (GND) <--> Radar Pin 4 (GND)
```
39 changes: 39 additions & 0 deletions board/escc/SConscript
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import os
import copy

Import('build_project', 'base_project_h7')

build_projects = {}

# RENAMED from "escc" to "panda"
build_projects["panda"] = {
"MAIN": "../main.c",
"BOOTSTUB": "../bootstub.c",
"STARTUP_FILE": File("../stm32f4/startup_stm32f413xx.s"),
"LINKER_SCRIPT": File("../stm32f4/stm32f4_flash.ld"),
"APP_START_ADDRESS": "0x8004000",
"PROJECT_FLAGS": [
"-mcpu=cortex-m4",
"-mhard-float",
"-DSTM32F4",
"-DSTM32F413xx",
"-mfpu=fpv4-sp-d16",
"-fsingle-precision-constant",
"-Os",
"-g",
],
}

# RENAMED from "escc_h7" to "panda_h7"
build_projects["panda_h7"] = copy.deepcopy(base_project_h7)
build_projects["panda_h7"]["MAIN"] = "../main.c"

for project_name, project in build_projects.items():
flags = [
"-DPANDA",
"-DESCC",
]
if ("ENABLE_SPI" in os.environ or "h7" in project_name) and not project_name.startswith('pedal'):
flags.append('-DENABLE_SPI')

build_project(project_name, project, flags, ["ESCC"])
39 changes: 39 additions & 0 deletions board/escc/flash.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env python3
import os
import subprocess
import argparse
import shutil # Don't forget to import shutil here too!

from panda import Panda

board_path = os.path.dirname(os.path.realpath(__file__))

if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--all", action="store_true", help="Recover all Panda devices")
args = parser.parse_args()

# Note the ../.. and the --escc flag!
subprocess.check_call(f"scons -C {board_path}/../.. -j$(nproc) {board_path} --escc", shell=True)

# --- HACK: SCons outputs our localized ESCC builds to 'board/escc/obj/'.
# However, the upstream Panda Python library (PandaDFU / p.flash) hardcodes
# its search path to the root 'board/obj/' directory. We copy the compiled
# binaries there so the hardware auto-picker can find them without us
# needing to modify and cause merge conflicts in the upstream library. ---
os.makedirs(f"{board_path}/../obj", exist_ok=True)
for f in os.listdir(f"{board_path}/obj"):
shutil.copy(os.path.join(f"{board_path}/obj", f), f"{board_path}/../obj")

if args.all:
serials = Panda.list()
print(f"found {len(serials)} panda(s) - {serials}")
else:
serials = [None]

for s in serials:
with Panda(serial=s) as p:
print("flashing", p.get_usb_serial())
# p.flash() auto-detects H7/F4 and picks the matching binary!
p.flash()
exit(1 if len(serials) == 0 else 0)
8 changes: 8 additions & 0 deletions board/escc/flash_can.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env sh
set -e

cd ..
scons -u -j$(nproc) --escc
cd escc

../../tests/escc/enter_canloader.py obj/panda_h7.bin.signed
36 changes: 36 additions & 0 deletions board/escc/recover.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env python3
import os
import time
import subprocess
import shutil

from panda import Panda, PandaDFU

board_path = os.path.dirname(os.path.realpath(__file__))

if __name__ == "__main__":
subprocess.check_call(f"scons -C {board_path}/../.. -j$(nproc) {board_path} --escc", shell=True)

# --- HACK: SCons outputs our localized ESCC builds to 'board/escc/obj/'.
# However, the upstream Panda Python library (PandaDFU / p.flash) hardcodes
# its search path to the root 'board/obj/' directory. We copy the compiled
# binaries there so the hardware auto-picker can find them without us
# needing to modify and cause merge conflicts in the upstream library. ---
os.makedirs(f"{board_path}/../obj", exist_ok=True)
for f in os.listdir(f"{board_path}/obj"):
shutil.copy(os.path.join(f"{board_path}/obj", f), f"{board_path}/../obj")

for s in Panda.list():
with Panda(serial=s) as p:
print(f"putting {p.get_usb_serial()} in DFU mode")
p.reset(enter_bootstub=True)
p.reset(enter_bootloader=True)

time.sleep(1)

dfu_serials = PandaDFU.list()
print(f"found {len(dfu_serials)} panda(s) in DFU - {dfu_serials}")
for s in dfu_serials:
print("flashing", s)
PandaDFU(s).recover()
exit(1 if len(dfu_serials) == 0 else 0)
11 changes: 11 additions & 0 deletions board/escc/recover.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env sh
set -e

DFU_UTIL="dfu-util"

cd ..
scons -u -j$(nproc) --escc
cd escc

$DFU_UTIL -d 0483:df11 -a 0 -s 0x08020000 -D obj/escc_h7.bin.signed
$DFU_UTIL -d 0483:df11 -a 0 -s 0x08000000:leave -D obj/bootstub.escc_h7.bin
2 changes: 2 additions & 0 deletions board/health.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#pragma once

// When changing these structs, python/__init__.py needs to be kept up to date!

#define HEALTH_PACKET_VERSION 16
Expand Down
Loading