Files
root ca13734bf0 Add full automotive RTOS project
Add kernel (Cortex-M0/M3/M4, Tricore, S32K, RISC-V ports), drivers,
middleware (CAN stack, diagnostics, safety), applications, board
support, build/test tooling, and documentation.
2026-08-23 03:35:29 -04:00

221 lines
7.1 KiB
C

/**
* @file mcu_config.h
* @brief MCU-specific configuration
*/
#ifndef MCU_CONFIG_H
#define MCU_CONFIG_H
/* ============================================================================
* MCU Selection
* ============================================================================ */
/* Select target MCU */
#define MCU_STM32F407VG 1
#define MCU_NXP_S32K144 0
#define MCU_INFINEON_TC397 0
#if (MCU_STM32F407VG + MCU_NXP_S32K144 + MCU_INFINEON_TC397) != 1
#error "Exactly one MCU must be selected"
#endif
/* ============================================================================
* Clock Configuration
* ============================================================================ */
#if MCU_STM32F407VG
/* STM32F407VG clock configuration */
#define HSE_VALUE 8000000U /* External crystal */
#define HSI_VALUE 16000000U /* Internal oscillator */
#define LSE_VALUE 32768U /* Low speed external */
#define LSI_VALUE 32000U /* Low speed internal */
#define SYSTEM_CLOCK 168000000U /* 168 MHz */
#define AHB_CLOCK 168000000U /* 168 MHz */
#define APB1_CLOCK 42000000U /* 42 MHz */
#define APB2_CLOCK 84000000U /* 84 MHz */
/* PLL configuration */
#define PLL_M 8
#define PLL_N 336
#define PLL_P 2
#define PLL_Q 7
#elif MCU_NXP_S32K144
/* NXP S32K144 clock configuration */
#define SOSC_FREQUENCY 8000000U /* System oscillator */
#define SPLL_FREQUENCY 160000000U /* System PLL */
#define FIRC_FREQUENCY 48000000U /* Fast IRC */
#define SIRC_FREQUENCY 8000000U /* Slow IRC */
#define SYSTEM_CLOCK 160000000U /* 160 MHz */
#define BUS_CLOCK 40000000U /* 40 MHz */
#define FLASH_CLOCK 20000000U /* 20 MHz */
/* PLL configuration */
#define PLL_MULT 20
#define PLL_DIV 1
#elif MCU_INFINEON_TC397
/* Infineon TC397 clock configuration */
#define F_OSC 20000000U /* External oscillator */
#define F_PLL 300000000U /* PLL frequency */
#define SYSTEM_CLOCK 300000000U /* 300 MHz */
#define PERIPHERAL_CLOCK 150000000U /* 150 MHz */
#define STM_CLOCK 100000000U /* 100 MHz */
/* PLL configuration */
#define PLL_N 30
#define PLL_P 2
#define PLL_K2 1
#endif
/* ============================================================================
* Peripheral Configuration
* ============================================================================ */
#if MCU_STM32F407VG
/* STM32F407VG peripherals */
#define GPIO_PORT_COUNT 6
#define UART_COUNT 6
#define SPI_COUNT 3
#define I2C_COUNT 3
#define CAN_COUNT 2
#define ADC_COUNT 3
#define TIMER_COUNT 14
#define DMA_STREAM_COUNT 16
/* GPIO ports */
#define GPIOA_ENABLE 1
#define GPIOB_ENABLE 1
#define GPIOC_ENABLE 1
#define GPIOD_ENABLE 1
#define GPIOE_ENABLE 1
#define GPIOF_ENABLE 0
#define GPIOG_ENABLE 0
/* UART configuration */
#define UART1_ENABLE 1
#define UART2_ENABLE 1
#define UART3_ENABLE 0
#define UART4_ENABLE 0
#define UART5_ENABLE 0
#define UART6_ENABLE 0
/* SPI configuration */
#define SPI1_ENABLE 1
#define SPI2_ENABLE 1
#define SPI3_ENABLE 0
/* I2C configuration */
#define I2C1_ENABLE 1
#define I2C2_ENABLE 0
#define I2C3_ENABLE 0
/* CAN configuration */
#define CAN1_ENABLE 1
#define CAN2_ENABLE 1
/* ADC configuration */
#define ADC1_ENABLE 1
#define ADC2_ENABLE 0
#define ADC3_ENABLE 0
#elif MCU_NXP_S32K144
/* NXP S32K144 peripherals */
#define GPIO_PORT_COUNT 5
#define UART_COUNT 3
#define SPI_COUNT 3
#define I2C_COUNT 2
#define CAN_COUNT 3
#define ADC_COUNT 2
#define TIMER_COUNT 5
/* GPIO ports */
#define GPIOA_ENABLE 1
#define GPIOB_ENABLE 1
#define GPIOC_ENABLE 1
#define GPIOD_ENABLE 1
#define GPIOE_ENABLE 1
/* UART configuration */
#define UART0_ENABLE 1
#define UART1_ENABLE 1
#define UART2_ENABLE 0
/* SPI configuration */
#define SPI0_ENABLE 1
#define SPI1_ENABLE 1
#define SPI2_ENABLE 0
/* I2C configuration */
#define I2C0_ENABLE 1
#define I2C1_ENABLE 0
/* CAN configuration */
#define CAN0_ENABLE 1
#define CAN1_ENABLE 1
#define CAN2_ENABLE 0
/* ADC configuration */
#define ADC0_ENABLE 1
#define ADC1_ENABLE 1
#elif MCU_INFINEON_TC397
/* Infineon TC397 peripherals */
#define GPIO_PORT_COUNT 16
#define UART_COUNT 4
#define SPI_COUNT 4
#define I2C_COUNT 2
#define CAN_COUNT 4
#define ADC_COUNT 8
#define TIMER_COUNT 20
#endif
/* ============================================================================
* Interrupt Configuration
* ============================================================================ */
/* NVIC priority grouping */
#define NVIC_PRIORITY_GROUPING 4 /* 4 bits preemption, 0 bits sub-priority */
/* Maximum interrupt priority */
#define MAX_INTERRUPT_PRIORITY 15
/* ============================================================================
* Power Configuration
* ============================================================================ */
/* Voltage monitoring */
#define ENABLE_VOLTAGE_MONITORING 1
#define VOLTAGE_MONITOR_THRESHOLD 2.7f /* Volts */
/* Temperature monitoring */
#define ENABLE_TEMP_MONITORING 1
#define TEMP_MONITOR_THRESHOLD 125 /* °C */
/* Brown-out reset */
#define ENABLE_BROWN_OUT_RESET 1
#define BROWN_OUT_THRESHOLD 2.7f /* Volts */
/* ============================================================================
* Safety Configuration
* ============================================================================ */
/* Watchdog */
#define WATCHDOG_ENABLED 1
#define WATCHDOG_TIMEOUT 100 /* ms */
#define WATCHDOG_WINDOW 50 /* ms */
/* Clock security system */
#define ENABLE_CLOCK_SECURITY 1
/* Memory protection */
#define ENABLE_MPU 1
/* ECC */
#define ENABLE_ECC 1
#endif /* MCU_CONFIG_H */