2025-07-19 21:58:58 -07:00
|
|
|
#include "stm32f4xx.h"
|
|
|
|
|
#include "stm32f4xx_hal_gpio_ex.h"
|
2024-02-16 22:58:01 -08:00
|
|
|
#define MCU_IDCODE 0x463U
|
|
|
|
|
|
2023-02-14 12:16:15 +01:00
|
|
|
#define CORE_FREQ 96U // in MHz
|
|
|
|
|
#define APB1_FREQ (CORE_FREQ/2U)
|
|
|
|
|
#define APB1_TIMER_FREQ (APB1_FREQ*2U) // APB1 is multiplied by 2 for the timer peripherals
|
|
|
|
|
#define APB2_FREQ (CORE_FREQ/2U)
|
|
|
|
|
#define APB2_TIMER_FREQ (APB2_FREQ*2U) // APB2 is multiplied by 2 for the timer peripherals
|
2021-07-02 18:25:35 -07:00
|
|
|
|
2021-07-14 10:30:02 -07:00
|
|
|
#define BOOTLOADER_ADDRESS 0x1FFF0004U
|
2021-07-02 18:25:35 -07:00
|
|
|
|
|
|
|
|
// Around (1Mbps / 8 bits/byte / 12 bytes per message)
|
|
|
|
|
#define CAN_INTERRUPT_RATE 12000U
|
|
|
|
|
|
|
|
|
|
#define MAX_LED_FADE 8192U
|
|
|
|
|
|
|
|
|
|
#define NUM_INTERRUPTS 102U // There are 102 external interrupt sources (see stm32f413.h)
|
|
|
|
|
|
|
|
|
|
#define TICK_TIMER_IRQ TIM1_BRK_TIM9_IRQn
|
|
|
|
|
#define TICK_TIMER TIM9
|
|
|
|
|
|
|
|
|
|
#define MICROSECOND_TIMER TIM2
|
|
|
|
|
|
|
|
|
|
#define INTERRUPT_TIMER_IRQ TIM6_DAC_IRQn
|
|
|
|
|
#define INTERRUPT_TIMER TIM6
|
|
|
|
|
|
2023-05-05 16:46:38 -07:00
|
|
|
#define IND_WDG IWDG
|
|
|
|
|
|
2021-07-14 10:30:02 -07:00
|
|
|
#define PROVISION_CHUNK_ADDRESS 0x1FFF79E0U
|
|
|
|
|
#define DEVICE_SERIAL_NUMBER_ADDRESS 0x1FFF79C0U
|
2021-07-02 18:25:35 -07:00
|
|
|
|
2025-07-19 21:58:58 -07:00
|
|
|
#include "board/can.h"
|
|
|
|
|
#include "board/comms_definitions.h"
|
CAN_FIFOMailBox to CANPacket struct + USB dynamic packet size (#739)
* Squashed commits, no cleanup
* Few fixes
* No init = garbage
* Only receive with new canpacket
* Add send with canpacket
* Revert "Add send with canpacket"
This reverts commit 7d06686ddd6d447c714b5289d31af24403d36931.
* Packet must be aligned to word, or bad performance
* Cleaner
* Fix tests
* Tests...
* MISRA 10.4
* More MISRA
* libpandasafety_py
* cffi
* even more tests...
* typo
* ...
* ...
* ...
* Slight cleanup
* MISRA 6.1
* MISRA 17.7
* Bug in bxcan + even style
* MISRA 10.1
* Revert "MISRA 10.1"
This reverts commit 404ae7fcc39556f80f528de9015702e69f4ea0a5.
* ...
* MISRA 10.1 and 10.4 suppress until next PR
* MISRA 20.1
* ...
* test_honda
* ...
* ...
* test_toyota
* test_volkswagen_mqb
* test_volkswagen_pq
* Sketchy thing...
* Revert "Sketchy thing..."
This reverts commit 3b2e5715bdc1954f7b7b3b7469ba3d0eaa06bdf9.
* remove comment
* bxcan extended address bug
* Concept, experimental dynamic usb packet size
* increase each buffer to 10240 bytes
* raise python bulk read/write limits
* ...
* Move packet size to start
* Experimental send, stream-like
* New receive test, stream-like
* cleanup
* cleanup + rebase fixes
* MISRA
* Extra receive method, stream-like, commented out
* type change
* Revert back to buffer for send, stream commented
* forgot ZLP
* lower buffer, add rx failsafe
* ... remove ZLP
* return ZLP back
* Add tx checks to panda fw
* TX stream with counter
* fix counter overflow
* 13 free slots should be enough
* limit tx usb packet
* ...
* Revert max_bulk_msg doubling
* python lib improve speed
* Stream with counter for RX, dirty, needs cleanup
* Increase chunk length to 4096 bytes
* cleanup fdcan.h
* cleanup __init__.py
* MISRA 12.1
* MISRA 10.8
* remove non-streaming usb functions
* more main.c cleanup
* MISRA 15.6
* MISRA 15.5
* MISRA 18.4 and suppress objectIndex
* handling usb pakcets > 63bytes, naming and cleanup
* Cleanup old from tests and update CANPacket_t struct
* Switch to 4 bit DLC instead of 6 bit length
* ops)
* ...
* pylint
* receive python buffer increase
* USB increase receive packet len
* tweak buffers
* No need for so high limits
* MISRA 20.1 workaround
* performance tweaks
* cleanup, dlc to data_len_code naming
* main.c naming
* comments and cleanup for main.c usb
* clean py lib
* pylint
* do not discard good rx messages on stream fail
* cleanups
* naming
* remove bitstruct lib and lower tx limit
* bitstruct lefovers
* fix bug in VW test
* remove adjusting data size and assert on wrong len
* ...
* test new memcpy before merging
* Revert "test new memcpy before merging"
This reverts commit 399465a264835061adabdd785718c4b6fc18c267.
* macros for to/fromuint8_t array
* MISRA hates me!
* tests.c include macros instead
* move CANPacket to can_definitions.h
* vw_pq python test fix
* new memcpy test, REMOVE
* check without alignment
* revert macros for uint8 arrays
* Revert "revert macros for uint8 arrays"
This reverts commit 581a9db735a42d0d68200bd270d87a8fd34e43fe.
* check assert
* Revert "check assert"
This reverts commit 9e970d029a50597a1718b2bb0260196c050fd77f.
* one more variation
* Revert "one more variation"
This reverts commit f6c0528b7ac7e125750dc0d9445c7ce97f6954b5.
* what about read performance
* Revert "what about read performance"
This reverts commit d2610f90958a816fe7f1822157a84f85e97d9249.
* check struct alignment to word
* check for aligned memcpy again
* cleanup
* add CANPacket structure diagram
* update CANPacket and add USB packet struct
* bugfix + refactoring of EP1
* move dlc_to_len to header
* missed include
* typo...
* MISRA
* fk
* lower MAX_CAN_MSGS_PER_BULK_TRANSFER
* bump CAN_PACKET_VERSION to 2
* bump python lib CAN_PACKET_VERSION to 2
* rename parse_can_buffer to unpack_can_buffer
* CANPacket_t const fields
* Revert "CANPacket_t const fields"
This reverts commit cf91c035b7706a14e317550c5f0501ae3fce7c70.
* test.c relative path
* cleanup
* move macros to safety_declarations
* Refactor pack/unpack funcs and add unittest
* usb_protocol.h
* oops
* Update .github/workflows/test.yaml
Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com>
* remove print from unittest
Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com>
2021-11-12 16:36:34 -08:00
|
|
|
|
2021-07-02 18:25:35 -07:00
|
|
|
#ifndef BOOTSTUB
|
2025-07-19 21:58:58 -07:00
|
|
|
#include "board/main_definitions.h"
|
2021-07-02 18:25:35 -07:00
|
|
|
#else
|
2025-07-19 21:58:58 -07:00
|
|
|
#include "board/bootstub_declarations.h"
|
2021-07-02 18:25:35 -07:00
|
|
|
#endif
|
|
|
|
|
|
2025-07-19 21:58:58 -07:00
|
|
|
#include "board/libc.h"
|
|
|
|
|
#include "board/critical.h"
|
|
|
|
|
#include "board/faults.h"
|
|
|
|
|
#include "board/utils.h"
|
2021-07-02 18:25:35 -07:00
|
|
|
|
2025-07-19 21:58:58 -07:00
|
|
|
#include "board/drivers/registers.h"
|
|
|
|
|
#include "board/drivers/interrupts.h"
|
|
|
|
|
#include "board/drivers/gpio.h"
|
|
|
|
|
#include "board/stm32f4/peripherals.h"
|
|
|
|
|
#include "board/stm32f4/interrupt_handlers.h"
|
|
|
|
|
#include "board/drivers/timers.h"
|
|
|
|
|
#include "board/stm32f4/board.h"
|
|
|
|
|
#include "board/stm32f4/clock.h"
|
2021-07-13 14:12:07 -07:00
|
|
|
|
2024-02-16 22:58:01 -08:00
|
|
|
#if !defined(BOOTSTUB)
|
2025-07-19 21:58:58 -07:00
|
|
|
#include "board/drivers/uart.h"
|
|
|
|
|
#include "board/stm32f4/lluart.h"
|
2021-07-13 14:12:07 -07:00
|
|
|
#endif
|
2021-07-02 18:25:35 -07:00
|
|
|
|
2023-09-30 12:49:46 -07:00
|
|
|
#ifdef BOOTSTUB
|
2025-07-19 21:58:58 -07:00
|
|
|
#include "board/stm32f4/llflash.h"
|
2023-09-30 12:49:46 -07:00
|
|
|
#else
|
2025-07-19 21:58:58 -07:00
|
|
|
#include "board/stm32f4/llbxcan.h"
|
2021-07-02 18:25:35 -07:00
|
|
|
#endif
|
|
|
|
|
|
2025-07-19 21:58:58 -07:00
|
|
|
#include "board/stm32f4/llusb.h"
|
2021-07-14 10:31:11 -07:00
|
|
|
|
2025-07-19 21:05:12 -07:00
|
|
|
// unused
|
|
|
|
|
void spi_init(void) {};
|
|
|
|
|
void sound_tick(void) {};
|
|
|
|
|
void can_tx_comms_resume_spi(void) {};
|
|
|
|
|
|
2021-07-02 18:25:35 -07:00
|
|
|
void early_gpio_float(void) {
|
|
|
|
|
RCC->AHB1ENR = RCC_AHB1ENR_GPIOAEN | RCC_AHB1ENR_GPIOBEN | RCC_AHB1ENR_GPIOCEN;
|
|
|
|
|
|
2025-03-12 17:26:07 +01:00
|
|
|
GPIOB->MODER = 0; GPIOC->MODER = 0;
|
2021-07-02 18:25:35 -07:00
|
|
|
GPIOA->ODR = 0; GPIOB->ODR = 0; GPIOC->ODR = 0;
|
|
|
|
|
GPIOA->PUPDR = 0; GPIOB->PUPDR = 0; GPIOC->PUPDR = 0;
|
|
|
|
|
}
|