This commit is contained in:
Comma Device 2024-11-17 00:02:44 +00:00
parent 465a1bb8c5
commit 68e3aee3e3
6 changed files with 25 additions and 147 deletions

View File

@ -4,7 +4,7 @@ import copy
Import('build_project', 'base_project_f4', 'base_project_h7')
build_projects = {
"panda": base_project_f4,
#"panda": base_project_f4,
"panda_h7": base_project_h7,
}

View File

@ -83,67 +83,9 @@ static void cuatro_set_amp_enabled(bool enabled){
static void cuatro_init(void) {
red_chiplet_init();
// init LEDs as open drain
set_gpio_output_type(GPIOE, 2, OUTPUT_TYPE_OPEN_DRAIN);
set_gpio_output_type(GPIOB, 2, OUTPUT_TYPE_OPEN_DRAIN);
set_gpio_output_type(GPIOD, 15, OUTPUT_TYPE_OPEN_DRAIN);
// Power readout
set_gpio_mode(GPIOC, 5, MODE_ANALOG);
set_gpio_mode(GPIOA, 6, MODE_ANALOG);
// CAN transceiver enables
set_gpio_pullup(GPIOB, 7, PULL_NONE);
set_gpio_mode(GPIOB, 7, MODE_OUTPUT);
set_gpio_pullup(GPIOD, 8, PULL_NONE);
set_gpio_mode(GPIOD, 8, MODE_OUTPUT);
// FDCAN3, different pins on this package than the rest of the reds
set_gpio_pullup(GPIOD, 12, PULL_NONE);
set_gpio_alternate(GPIOD, 12, GPIO_AF5_FDCAN3);
set_gpio_pullup(GPIOD, 13, PULL_NONE);
set_gpio_alternate(GPIOD, 13, GPIO_AF5_FDCAN3);
// C2: SOM GPIO used as input (fan control at boot)
set_gpio_mode(GPIOC, 2, MODE_INPUT);
set_gpio_pullup(GPIOC, 2, PULL_DOWN);
// SOM bootkick + reset lines
cuatro_set_bootkick(BOOT_BOOTKICK);
// SOM debugging UART
gpio_uart7_init();
uart_init(&uart_ring_som_debug, 115200);
// SPI init
gpio_spi_init();
// fan setup
set_gpio_alternate(GPIOC, 8, GPIO_AF2_TIM3);
register_set_bits(&(GPIOC->OTYPER), GPIO_OTYPER_OT8); // open drain
// Initialize IR PWM and set to 0%
set_gpio_alternate(GPIOC, 9, GPIO_AF2_TIM3);
pwm_init(TIM3, 4);
tres_set_ir_power(0U);
// Clock source
clock_source_init();
// Beeper
set_gpio_alternate(GPIOD, 14, GPIO_AF2_TIM4);
beeper_init();
// Sound codec
cuatro_set_amp_enabled(false);
set_gpio_alternate(GPIOA, 2, GPIO_AF8_SAI4); // SAI4_SCK_B
set_gpio_alternate(GPIOC, 0, GPIO_AF8_SAI4); // SAI4_FS_B
set_gpio_alternate(GPIOD, 11, GPIO_AF10_SAI4); // SAI4_SD_A
set_gpio_alternate(GPIOE, 3, GPIO_AF8_SAI4); // SAI4_SD_B
set_gpio_alternate(GPIOE, 4, GPIO_AF2_SAI1); // SAI1_D2
set_gpio_alternate(GPIOE, 5, GPIO_AF2_SAI1); // SAI1_CK2
set_gpio_alternate(GPIOE, 6, GPIO_AF10_SAI4); // SAI4_MCLK_B
sound_init();
}
board board_cuatro = {

View File

@ -86,54 +86,6 @@ static void red_chiplet_set_fan_or_usb_load_switch(bool enabled) {
}
static void red_chiplet_init(void) {
common_init_gpio();
// A8, A3: OBD_SBU1_RELAY, OBD_SBU2_RELAY
set_gpio_output_type(GPIOA, 8, OUTPUT_TYPE_OPEN_DRAIN);
set_gpio_pullup(GPIOA, 8, PULL_NONE);
set_gpio_output(GPIOA, 8, 1);
set_gpio_mode(GPIOA, 8, MODE_OUTPUT);
set_gpio_output_type(GPIOA, 3, OUTPUT_TYPE_OPEN_DRAIN);
set_gpio_pullup(GPIOA, 3, PULL_NONE);
set_gpio_output(GPIOA, 3, 1);
set_gpio_mode(GPIOA, 3, MODE_OUTPUT);
// G11,B10,D7,B11: transceiver enable
set_gpio_pullup(GPIOG, 11, PULL_NONE);
set_gpio_mode(GPIOG, 11, MODE_OUTPUT);
set_gpio_pullup(GPIOB, 10, PULL_NONE);
set_gpio_mode(GPIOB, 10, MODE_OUTPUT);
set_gpio_pullup(GPIOD, 7, PULL_NONE);
set_gpio_mode(GPIOD, 7, MODE_OUTPUT);
set_gpio_pullup(GPIOB, 11, PULL_NONE);
set_gpio_mode(GPIOB, 11, MODE_OUTPUT);
// D3: usb load switch
set_gpio_pullup(GPIOD, 3, PULL_NONE);
set_gpio_mode(GPIOD, 3, MODE_OUTPUT);
// B0: 5VOUT_S
set_gpio_pullup(GPIOB, 0, PULL_NONE);
set_gpio_mode(GPIOB, 0, MODE_ANALOG);
// Initialize harness
harness_init();
// Enable CAN transceivers
red_chiplet_enable_can_transceivers(true);
// Disable LEDs
red_set_led(LED_RED, false);
red_set_led(LED_GREEN, false);
red_set_led(LED_BLUE, false);
// Set normal CAN mode
red_chiplet_set_can_mode(CAN_MODE_NORMAL);
}
static harness_configuration red_chiplet_harness_config = {

View File

@ -30,19 +30,20 @@
#ifdef STM32H7
void LPTIM1_IRQHandler(void) {
static uint8_t cnt = 0;
//static uint8_t cnt = 0;
static bool on = true;
if (LPTIM1->ISR & LPTIM_ISR_ARRM) {
uptime_cnt++;
LPTIM1->ICR |= LPTIM_ICR_ARRMCF;
current_board->set_siren((cnt++ % 2 == 0U));
//uptime_cnt++;
on = !on;
//current_board->set_siren(on);
} else {
//assert_fatal(false, "shouldn't happen");
}
}
#endif
// ********************* Serial debugging *********************
static bool check_started(void) {
@ -322,10 +323,6 @@ int main(void) {
clock_init();
peripherals_init();
detect_board_type();
// red+green leds enabled until succesful USB/SPI init, as a debug indicator
current_board->set_led(LED_RED, true);
current_board->set_led(LED_GREEN, true);
adc_init();
// print hello
print("\n\n\n************************ MAIN START ************************\n");
@ -337,7 +334,21 @@ int main(void) {
print(" Board type: 0x"); puth(hw_type); print("\n");
// init board
current_board->init();
//enable_interrupts();
//NVIC_EnableIRQ(LPTIM1_IRQn);
while (true) {
current_board->set_siren(true);
delay(512000U);
current_board->set_siren(false);
delay(512000U);
continue;
//SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
__WFI();
SCB->SCR &= ~SCB_SCR_SLEEPDEEP_Msk;
}
// panda has an FPU, let's use it!
enable_fpu();
@ -383,10 +394,10 @@ int main(void) {
// LED should keep on blinking all the time
NVIC_DisableIRQ(TICK_TIMER_IRQ);
while (true) {
//SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
__WFI();
SCB->SCR &= ~SCB_SCR_SLEEPDEEP_Msk;
/*
SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
*/
continue;

View File

@ -102,40 +102,14 @@ void peripherals_init(void) {
RCC->AHB4ENR |= RCC_AHB4ENR_GPIOGEN;
// Enable CPU access to SRAMs for DMA
RCC->AHB2ENR |= RCC_AHB2ENR_SRAM1EN | RCC_AHB2ENR_SRAM2EN;
//RCC->AHB2ENR |= RCC_AHB2ENR_SRAM1EN | RCC_AHB2ENR_SRAM2EN;
// Supplemental
RCC->AHB1ENR |= RCC_AHB1ENR_DMA1EN; // DAC DMA
RCC->AHB1ENR |= RCC_AHB1ENR_DMA2EN; // SPI DMA
RCC->APB4ENR |= RCC_APB4ENR_SYSCFGEN;
RCC->AHB4ENR |= RCC_AHB4ENR_BDMAEN; // Audio DMA
// Connectivity
RCC->APB2ENR |= RCC_APB2ENR_SPI4EN; // SPI
RCC->APB1LENR |= RCC_APB1LENR_I2C5EN; // codec I2C
RCC->AHB1ENR |= RCC_AHB1ENR_USB1OTGHSEN; // USB
RCC->AHB1LPENR |= RCC_AHB1LPENR_USB1OTGHSLPEN; // USB LP needed for CSleep state(__WFI())
RCC->AHB1LPENR &= ~(RCC_AHB1LPENR_USB1OTGHSULPILPEN); // disable USB ULPI
RCC->APB1LENR |= RCC_APB1LENR_UART7EN; // SOM uart
RCC->APB1HENR |= RCC_APB1HENR_FDCANEN; // FDCAN core enable
// Analog
RCC->AHB1ENR |= RCC_AHB1ENR_ADC12EN; // Enable ADC12 clocks
RCC->APB1LENR |= RCC_APB1LENR_DAC12EN; // DAC
// Audio
RCC->APB4ENR |= RCC_APB4ENR_SAI4EN; // SAI4
// Timers
RCC->APB2ENR |= RCC_APB2ENR_TIM1EN; // clock source timer
RCC->APB1LENR |= RCC_APB1LENR_LPTIM1EN; // low power siren timer
RCC->APB1LENR |= RCC_APB1LENR_TIM2EN; // main counter
RCC->APB1LENR |= RCC_APB1LENR_TIM3EN; // fan pwm
RCC->APB1LENR |= RCC_APB1LENR_TIM4EN; // beeper source
RCC->APB1LENR |= RCC_APB1LENR_TIM6EN; // interrupt timer
RCC->APB1LENR |= RCC_APB1LENR_TIM7EN; // DMA trigger timer
RCC->APB2ENR |= RCC_APB2ENR_TIM8EN; // tick timer
RCC->APB1LENR |= RCC_APB1LENR_TIM12EN; // slow loop
RCC->APB1LENR |= RCC_APB1LENR_TIM4EN;
// *** LPTIM ***
RCC->CSR |= RCC_CSR_LSION;
@ -153,7 +127,6 @@ void peripherals_init(void) {
LPTIM1->CR |= LPTIM_CR_CNTSTRT;
LPTIM1->IER |= LPTIM_IER_ARRMIE;
NVIC_EnableIRQ(LPTIM1_IRQn);
#ifdef PANDA_JUNGLE
RCC->AHB3ENR |= RCC_AHB3ENR_SDMMC1EN; // SDMMC

View File

@ -33,7 +33,7 @@ if __name__ == "__main__":
time.sleep(1)
gpio_set(GPIO.STM_RST_N, 0)
gpio_set(GPIO.STM_BOOT0, 0)
time.sleep(1)
time.sleep(0.2)
print("flashing bootstub")
PandaDFU(None).recover()