Skip to content

Commit 190b4f6

Browse files
committedMar 10, 2018
start work on canflasher
1 parent 5c655c9 commit 190b4f6

File tree

5 files changed

+65
-1
lines changed

5 files changed

+65
-1
lines changed
 

‎board/bootstub.c

+6
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@
2424
#include "drivers/usb.h"
2525
//#include "drivers/uart.h"
2626

27+
#ifdef PEDAL
28+
#define CUSTOM_CAN_INTERRUPTS
29+
#include "safety.h"
30+
#include "drivers/can.h"
31+
#endif
32+
2733
int puts(const char *a) { return 0; }
2834
void puth(unsigned int i) {}
2935

‎board/pedal/Makefile

+3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ DFU_UTIL = "dfu-util"
1818
CERT = ../../certs/debug
1919
CFLAGS += "-DALLOW_DEBUG"
2020

21+
canflash: obj/$(PROJ_NAME).bin
22+
../../tests/pedal/enter_canloader.py $<
23+
2124
usbflash: obj/$(PROJ_NAME).bin
2225
../../tests/pedal/enter_canloader.py; sleep 0.5
2326
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)"

‎board/pedal/main.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ int main() {
264264

265265
// init can
266266
can_silent = ALL_CAN_LIVE;
267-
can_init_all();
267+
can_init(0);
268268

269269
// 48mhz / 65536 ~= 732
270270
timer_init(TIM3, 15);

‎board/spi_flasher.h

+48
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,35 @@ int spi_cb_rx(uint8_t *data, int len, uint8_t *data_out) {
130130
return resp_len;
131131
}
132132

133+
#ifdef PEDAL
134+
135+
#define CAN CAN1
136+
137+
#define CAN_BL_INPUT 0x1
138+
#define CAN_BL_OUTPUT 0x2
139+
140+
void CAN1_TX_IRQHandler() {
141+
// clear interrupt
142+
CAN->TSR |= CAN_TSR_RQCP0;
143+
}
144+
145+
void CAN1_RX0_IRQHandler() {
146+
while (CAN->RF0R & CAN_RF0R_FMP0) {
147+
if ((CAN->sFIFOMailBox[0].RIR>>21) == CAN_BL_INPUT) {
148+
CAN->sTxMailBox[0].TDLR = 0xAABBCCDD;
149+
CAN->sTxMailBox[0].TDHR = 0xAABBCCDD;
150+
CAN->sTxMailBox[0].TDTR = 8;
151+
CAN->sTxMailBox[0].TIR = (CAN_BL_OUTPUT << 21) | 1;
152+
}
153+
}
154+
}
155+
156+
void CAN1_SCE_IRQHandler() {
157+
can_sce(CAN);
158+
}
159+
160+
#endif
161+
133162
void soft_flasher_start() {
134163
puts("\n\n\n************************ FLASHER START ************************\n");
135164

@@ -140,6 +169,25 @@ void soft_flasher_start() {
140169
RCC->AHB2ENR |= RCC_AHB2ENR_OTGFSEN;
141170
RCC->APB1ENR |= RCC_APB1ENR_USART2EN;
142171

172+
// pedal has the canloader
173+
#ifdef PEDAL
174+
RCC->APB1ENR |= RCC_APB1ENR_CAN1EN;
175+
176+
// B8,B9: CAN 1
177+
set_gpio_alternate(GPIOB, 8, GPIO_AF9_CAN1);
178+
set_gpio_alternate(GPIOB, 9, GPIO_AF9_CAN1);
179+
set_can_enable(CAN1, 1);
180+
181+
// init can
182+
can_silent = ALL_CAN_LIVE;
183+
can_init(0);
184+
185+
// needed?
186+
NVIC_EnableIRQ(CAN1_TX_IRQn);
187+
NVIC_EnableIRQ(CAN1_RX0_IRQn);
188+
NVIC_EnableIRQ(CAN1_SCE_IRQn);
189+
#endif
190+
143191
// A4,A5,A6,A7: setup SPI
144192
set_gpio_alternate(GPIOA, 4, GPIO_AF5_SPI1);
145193
set_gpio_alternate(GPIOA, 5, GPIO_AF5_SPI1);

‎tests/pedal/enter_canloader.py

+7
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,20 @@
66
if __name__ == "__main__":
77
parser = argparse.ArgumentParser(description='Flash pedal over can')
88
parser.add_argument('--recover', action='store_true')
9+
parser.add_argument("fn", type=str, nargs='?', help="flash file")
910
args = parser.parse_args()
1011

1112
p = Panda()
1213
p.set_safety_mode(0x1337)
1314

1415
if args.recover:
1516
p.can_send(0x200, "\xce\xfa\xad\xde\x1e\x0b\xb0\x02", 0)
17+
exit(0)
1618
else:
1719
p.can_send(0x200, "\xce\xfa\xad\xde\x1e\x0b\xb0\x0a", 0)
1820

21+
if args.fn:
22+
print "flashing", args.fn
23+
24+
25+

0 commit comments

Comments
 (0)