Skip to content
Merged
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
2 changes: 2 additions & 0 deletions board/crc.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#if defined(ENABLE_SPI) || defined(BOOTSTUB)
uint8_t crc_checksum(const uint8_t *dat, int len, const uint8_t poly) {
uint8_t crc = 0xFFU;
int i;
Expand All @@ -17,3 +18,4 @@ uint8_t crc_checksum(const uint8_t *dat, int len, const uint8_t poly) {
}
return crc;
}
#endif
12 changes: 7 additions & 5 deletions board/drivers/gpio.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@
#define OUTPUT_TYPE_PUSH_PULL 0U
#define OUTPUT_TYPE_OPEN_DRAIN 1U

typedef struct {
GPIO_TypeDef * const bank;
uint8_t pin;
} gpio_t;

void set_gpio_mode(GPIO_TypeDef *GPIO, unsigned int pin, unsigned int mode) {
ENTER_CRITICAL();
uint32_t tmp = GPIO->MODER;
Expand Down Expand Up @@ -68,6 +63,12 @@ int get_gpio_input(const GPIO_TypeDef *GPIO, unsigned int pin) {
return (GPIO->IDR & (1UL << pin)) == (1UL << pin);
}

#ifdef PANDA_JUNGLE
typedef struct {
GPIO_TypeDef * const bank;
uint8_t pin;
} gpio_t;

void gpio_set_all_output(gpio_t *pins, uint8_t num_pins, bool enabled) {
for (uint8_t i = 0; i < num_pins; i++) {
set_gpio_output(pins[i].bank, pins[i].pin, enabled);
Expand All @@ -79,6 +80,7 @@ void gpio_set_bitmask(gpio_t *pins, uint8_t num_pins, uint32_t bitmask) {
set_gpio_output(pins[i].bank, pins[i].pin, (bitmask >> i) & 1U);
}
}
#endif

// Detection with internal pullup
#define PULL_EFFECTIVE_DELAY 4096
Expand Down
3 changes: 2 additions & 1 deletion board/flasher.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,12 @@ void soft_flasher_start(void) {
// enable USB
usb_init();

// enable SPI
#ifdef ENABLE_SPI
if (current_board->has_spi) {
gpio_spi_init();
spi_init();
}
#endif

// green LED on for flashing
led_set(LED_GREEN, 1);
Expand Down
6 changes: 6 additions & 0 deletions board/stm32f4/peripherals.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ static void gpio_usb_init(void) {
GPIOA->OSPEEDR = GPIO_OSPEEDER_OSPEEDR11 | GPIO_OSPEEDER_OSPEEDR12;
}

#ifdef ENABLE_SPI
void gpio_spi_init(void) {
// A4-A7: SPI
set_gpio_alternate(GPIOA, 4, GPIO_AF5_SPI1);
Expand All @@ -17,12 +18,15 @@ void gpio_spi_init(void) {
set_gpio_alternate(GPIOA, 7, GPIO_AF5_SPI1);
register_set_bits(&(GPIOA->OSPEEDR), GPIO_OSPEEDER_OSPEEDR4 | GPIO_OSPEEDER_OSPEEDR5 | GPIO_OSPEEDER_OSPEEDR6 | GPIO_OSPEEDER_OSPEEDR7);
}
#endif

#ifdef BOOTSTUB
void gpio_usart2_init(void) {
// A2,A3: USART 2 for debugging
set_gpio_alternate(GPIOA, 2, GPIO_AF7_USART2);
set_gpio_alternate(GPIOA, 3, GPIO_AF7_USART2);
}
#endif

// Common GPIO initialization
void common_init_gpio(void) {
Expand All @@ -45,12 +49,14 @@ void common_init_gpio(void) {
set_gpio_alternate(GPIOB, 9, GPIO_AF8_CAN1);
}

#ifdef BOOTSTUB
void flasher_peripherals_init(void) {
RCC->AHB1ENR |= RCC_AHB1ENR_DMA2EN;
RCC->APB2ENR |= RCC_APB2ENR_SPI1EN;
RCC->AHB2ENR |= RCC_AHB2ENR_OTGFSEN;
RCC->APB1ENR |= RCC_APB1ENR_USART2EN;
}
#endif

// Peripheral initialization
void peripherals_init(void) {
Expand Down
6 changes: 6 additions & 0 deletions board/stm32h7/peripherals.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,23 @@ static void gpio_usb_init(void) {
GPIOA->OSPEEDR = GPIO_OSPEEDR_OSPEED11 | GPIO_OSPEEDR_OSPEED12;
}

#ifdef ENABLE_SPI
void gpio_spi_init(void) {
set_gpio_alternate(GPIOE, 11, GPIO_AF5_SPI4);
set_gpio_alternate(GPIOE, 12, GPIO_AF5_SPI4);
set_gpio_alternate(GPIOE, 13, GPIO_AF5_SPI4);
set_gpio_alternate(GPIOE, 14, GPIO_AF5_SPI4);
register_set_bits(&(GPIOE->OSPEEDR), GPIO_OSPEEDR_OSPEED11 | GPIO_OSPEEDR_OSPEED12 | GPIO_OSPEEDR_OSPEED13 | GPIO_OSPEEDR_OSPEED14);
}
#endif

#ifdef BOOTSTUB
void gpio_usart2_init(void) {
// A2,A3: USART 2 for debugging
set_gpio_alternate(GPIOA, 2, GPIO_AF7_USART2);
set_gpio_alternate(GPIOA, 3, GPIO_AF7_USART2);
}
#endif

void gpio_uart7_init(void) {
// E7,E8: UART 7 for debugging
Expand Down Expand Up @@ -62,13 +66,15 @@ void common_init_gpio(void) {
set_gpio_alternate(GPIOG, 10, GPIO_AF2_FDCAN3);
}

#ifdef BOOTSTUB
void flasher_peripherals_init(void) {
RCC->AHB1ENR |= RCC_AHB1ENR_USB1OTGHSEN;

// SPI + DMA
RCC->APB2ENR |= RCC_APB2ENR_SPI4EN;
RCC->AHB1ENR |= RCC_AHB1ENR_DMA2EN;
}
#endif

// Peripheral initialization
void peripherals_init(void) {
Expand Down
Loading