Skip to content

Commit

Permalink
enable unusedFunction for whole project and Panda program separately
Browse files Browse the repository at this point in the history
  • Loading branch information
dzid26 committed Jun 8, 2024
1 parent e787ad5 commit 07ff61a
Show file tree
Hide file tree
Showing 10 changed files with 479 additions and 19 deletions.
4 changes: 2 additions & 2 deletions SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ def build_project(project_name, project, extra_flags):

# 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")
env.Object(f"bootstub-rsa-{project_name}", f"{panda_root}/crypto/rsa.c"),
env.Object(f"bootstub-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",
Expand Down
6 changes: 6 additions & 0 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@ env = Environment(
)

if GetOption('compile_db'):
# whole project compilation database
env.CompilationDatabase("compile_commands.json")

# Panda compilation database
env_p = env.Clone()
env_p["COMPILATIONDB_PATH_FILTER"] = '*board/[!jungle/][!bootstub]*'
env_p.CompilationDatabase("compile_commands_panda.json")

# panda fw & test files
SConscript('SConscript')
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
2 changes: 0 additions & 2 deletions board/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -353,11 +353,9 @@ int main(void) {
// enable USB (right before interrupts or enum can fail!)
usb_init();

#ifdef ENABLE_SPI
if (current_board->has_spi) {
spi_init();
}
#endif

current_board->set_led(LED_RED, false);
current_board->set_led(LED_GREEN, false);
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
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
Loading

0 comments on commit 07ff61a

Please sign in to comment.