Skip to content

Commit

Permalink
enable unusedFunction per build - Panda
Browse files Browse the repository at this point in the history
  • Loading branch information
dzid26 committed Jun 4, 2024
1 parent c86dd6f commit d6c6ab8
Show file tree
Hide file tree
Showing 16 changed files with 67 additions and 276 deletions.
14 changes: 8 additions & 6 deletions SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ def build_project(project_name, project, extra_flags):

includes = [
'.',
'..',
panda_root,
f"{panda_root}/board/",
]
Expand All @@ -105,15 +104,18 @@ def build_project(project_name, project, extra_flags):

startup = env.Object(f"obj/startup_{project_name}", project["STARTUP_FILE"])

bootstub_env = env.Clone()
bootstub_env.Append(CPPDEFINES=['ENABLE_SPI'])

# Bootstub
crypto_obj = [
env.Object(f"rsa-{project_name}", f"{panda_root}/crypto/rsa.c"),
env.Object(f"sha-{project_name}", f"{panda_root}/crypto/sha.c")
bootstub_env.Object(f"rsa-{project_name}", f"{panda_root}/crypto/rsa.c"),
bootstub_env.Object(f"sha-{project_name}", f"{panda_root}/crypto/sha.c")
]
bootstub_obj = env.Object(f"bootstub-{project_name}", File(project.get("BOOTSTUB", f"{panda_root}/board/bootstub.c")))
bootstub_elf = env.Program(f"obj/bootstub.{project_name}.elf",
bootstub_obj = bootstub_env.Object(f"bootstub-{project_name}", File(project.get("BOOTSTUB", f"{panda_root}/board/bootstub.c")))
bootstub_elf = bootstub_env.Program(f"obj/bootstub.{project_name}.elf",
[startup] + crypto_obj + [bootstub_obj])
env.Objcopy(f"obj/bootstub.{project_name}.bin", bootstub_elf)
bootstub_env.Objcopy(f"obj/bootstub.{project_name}.bin", bootstub_elf)

# Build main
main_obj = env.Object(f"main-{project_name}", project["MAIN"])
Expand Down
2 changes: 0 additions & 2 deletions board/bootstub_declarations.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
void print(const char *a){ UNUSED(a); }
void puth(uint8_t i){ UNUSED(i); }
void puth2(uint8_t i){ UNUSED(i); }
void puth4(uint8_t i){ UNUSED(i); }
void hexdump(const void *a, int l){ UNUSED(a); UNUSED(l); }
typedef struct board board;
typedef struct harness_configuration harness_configuration;
void pwm_init(TIM_TypeDef *TIM, uint8_t channel);
Expand Down
2 changes: 2 additions & 0 deletions board/can_comms.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@ void refresh_can_tx_slots_available(void) {
if (can_tx_check_min_slots_free(MAX_CAN_MSGS_PER_USB_BULK_TRANSFER)) {
can_tx_comms_resume_usb();
}
#ifdef ENABLE_SPI
if (can_tx_check_min_slots_free(MAX_CAN_MSGS_PER_SPI_BULK_TRANSFER)) {
can_tx_comms_resume_spi();
}
#endif
}
2 changes: 2 additions & 0 deletions board/drivers/can_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,11 @@ void can_set_orientation(bool flipped) {
bus_config[2].can_num_lookup = flipped ? 0U : 2U;
}

#ifdef FINAL_PROVISIONING // only used in jungle final provisioning
void can_set_forwarding(uint8_t from, uint8_t to) {
bus_config[from].forwarding_bus = to;
}
#endif

void ignition_can_hook(CANPacket_t *to_push) {
int bus = GET_BUS(to_push);
Expand Down
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
11 changes: 8 additions & 3 deletions board/drivers/spi.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,10 @@ void spi_rx_done(void) {
response_len = 1U;
} else {
// response: NACK and reset state machine
print("- incorrect header sync or checksum "); hexdump(spi_buf_rx, SPI_HEADER_SIZE);
print("- incorrect header sync or checksum ");
#ifdef DEBUG_SPI
hexdump(spi_buf_rx, SPI_HEADER_SIZE);
#endif
spi_buf_tx[0] = SPI_NACK;
next_rx_state = SPI_STATE_HEADER_NACK;
response_len = 1U;
Expand Down Expand Up @@ -192,12 +195,14 @@ void spi_rx_done(void) {
} else {
// Checksum was incorrect
response_ack = false;
print("- incorrect data checksum ");
puth4(spi_data_len_mosi);
print("SPI: incorrect data checksum ");
#ifdef DEBUG_SPI
PUTH(spi_data_len_mosi);
print("\n");
hexdump(spi_buf_rx, SPI_HEADER_SIZE);
hexdump(&(spi_buf_rx[SPI_HEADER_SIZE]), MIN(spi_data_len_mosi, 64));
print("\n");
#endif
}

if (!response_ack) {
Expand Down
2 changes: 2 additions & 0 deletions board/drivers/uart.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ void puth2(unsigned int i) {
puthx(i, 2U);
}

#ifdef DEBUG
void puth4(unsigned int i) {
puthx(i, 4U);
}
Expand All @@ -179,3 +180,4 @@ void hexdump(const void *a, int l) {
}
print("\n");
}
#endif
3 changes: 3 additions & 0 deletions board/main_comms.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ int get_health_pkt(void *dat) {
health->heartbeat_lost_pkt = heartbeat_lost;
health->safety_rx_checks_invalid_pkt = safety_rx_checks_invalid;

#ifndef ENABLE_SPI
uint16_t spi_checksum_error_count = 0;
#endif
health->spi_checksum_error_count_pkt = spi_checksum_error_count;

health->fault_status_pkt = fault_status;
Expand Down
5 changes: 5 additions & 0 deletions board/stm32f4/peripherals.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ void gpio_spi_init(void) {
register_set_bits(&(GPIOA->OSPEEDR), GPIO_OSPEEDER_OSPEEDR4 | GPIO_OSPEEDER_OSPEEDR5 | GPIO_OSPEEDER_OSPEEDR6 | GPIO_OSPEEDER_OSPEEDR7);
}

#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 @@ -41,12 +43,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;
}
#else

// Peripheral initialization
void peripherals_init(void) {
Expand Down Expand Up @@ -84,6 +88,7 @@ void peripherals_init(void) {
RCC->APB1ENR |= RCC_APB1ENR_TIM6EN; // interrupt timer
RCC->APB2ENR |= RCC_APB2ENR_TIM9EN; // slow loop
}
#endif

void enable_interrupt_timer(void) {
register_set_bits(&(RCC->APB1ENR), RCC_APB1ENR_TIM6EN); // Enable interrupt timer peripheral
Expand Down
6 changes: 4 additions & 2 deletions board/stm32f4/stm32f4_config.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "stm32f4/inc/stm32f4xx.h"
#include "stm32f4/inc/stm32f4xx_hal_gpio_ex.h"
#include "stm32f4xx.h"
#include "stm32f4xx_hal_gpio_ex.h"
#define MCU_IDCODE 0x463U

// from the linker script
Expand Down Expand Up @@ -56,8 +56,10 @@
#include "stm32f4/board.h"
#include "stm32f4/clock.h"

#ifdef ENABLE_SPI
#include "drivers/spi.h"
#include "stm32f4/llspi.h"
#endif

#if !defined(BOOTSTUB)
#include "drivers/uart.h"
Expand Down
2 changes: 2 additions & 0 deletions board/stm32h7/llspi.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ void llspi_miso_dma(uint8_t *addr, int len) {
register_set_bits(&(SPI4->CR1), SPI_CR1_SPE);
}

#ifdef ENABLE_SPI
// master -> panda DMA finished
void DMA2_Stream2_IRQ_Handler(void) {
// Clear interrupt flag
Expand Down Expand Up @@ -104,3 +105,4 @@ void llspi_init(void) {
NVIC_EnableIRQ(DMA2_Stream3_IRQn);
NVIC_EnableIRQ(SPI4_IRQn);
}
#endif
11 changes: 7 additions & 4 deletions board/stm32h7/peripherals.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ void gpio_spi_init(void) {
register_set_bits(&(GPIOE->OSPEEDR), GPIO_OSPEEDR_OSPEED11 | GPIO_OSPEEDR_OSPEED12 | GPIO_OSPEEDR_OSPEED13 | GPIO_OSPEEDR_OSPEED14);
}

#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 @@ -78,14 +80,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;
}

#else
// Peripheral initialization
void peripherals_init(void) {
// enable GPIO(A,B,C,D,E,F,G,H)
Expand Down Expand Up @@ -126,12 +129,12 @@ void peripherals_init(void) {
RCC->APB1LENR |= RCC_APB1LENR_TIM7EN; // DMA trigger timer
RCC->APB2ENR |= RCC_APB2ENR_TIM8EN; // tick timer
RCC->APB1LENR |= RCC_APB1LENR_TIM12EN; // slow loop

#ifdef PANDA_JUNGLE
#ifdef PANDA_JUNGLE
RCC->AHB3ENR |= RCC_AHB3ENR_SDMMC1EN; // SDMMC
RCC->AHB4ENR |= RCC_AHB4ENR_ADC3EN; // Enable ADC3 clocks
#endif
#endif
}
#endif

void enable_interrupt_timer(void) {
register_set_bits(&(RCC->APB1LENR), RCC_APB1LENR_TIM6EN); // Enable interrupt timer peripheral
Expand Down
6 changes: 4 additions & 2 deletions board/stm32h7/stm32h7_config.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "stm32h7/inc/stm32h7xx.h"
#include "stm32h7/inc/stm32h7xx_hal_gpio_ex.h"
#include "stm32h7xx.h"
#include "stm32h7xx_hal_gpio_ex.h"
#define MCU_IDCODE 0x483U

// from the linker script
Expand Down Expand Up @@ -83,8 +83,10 @@ separate IRQs for RX and TX.

#include "stm32h7/llusb.h"

#ifdef ENABLE_SPI
#include "drivers/spi.h"
#include "stm32h7/llspi.h"
#endif

void early_gpio_float(void) {
RCC->AHB4ENR = RCC_AHB4ENR_GPIOAEN | RCC_AHB4ENR_GPIOBEN | RCC_AHB4ENR_GPIOCEN | RCC_AHB4ENR_GPIODEN | RCC_AHB4ENR_GPIOEEN | RCC_AHB4ENR_GPIOFEN | RCC_AHB4ENR_GPIOGEN | RCC_AHB4ENR_GPIOHEN;
Expand Down
2 changes: 1 addition & 1 deletion crypto/hash-internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#ifndef SYSTEM_CORE_INCLUDE_MINCRYPT_HASH_INTERNAL_H_
#define SYSTEM_CORE_INCLUDE_MINCRYPT_HASH_INTERNAL_H_

#include "stdint.h"
#include <stdint.h>

#ifdef __cplusplus
extern "C" {
Expand Down
Loading

0 comments on commit d6c6ab8

Please sign in to comment.