stm32f303xc/
lib.rs

1// Licensed under the Apache License, Version 2.0 or the MIT License.
2// SPDX-License-Identifier: Apache-2.0 OR MIT
3// Copyright Tock Contributors 2022.
4
5//! Peripheral implementations for the STM32F3xx MCU.
6//!
7//! STM32F303: <https://www.st.com/en/microcontrollers-microprocessors/stm32f303.html>
8
9#![crate_name = "stm32f303xc"]
10#![crate_type = "rlib"]
11#![no_std]
12
13pub mod chip;
14pub mod nvic;
15
16// Peripherals
17pub mod adc;
18pub mod dma;
19pub mod exti;
20pub mod flash;
21pub mod gpio;
22pub mod i2c;
23pub mod rcc;
24pub mod spi;
25pub mod syscfg;
26pub mod tim2;
27pub mod usart;
28pub mod wdt;
29
30use cortexm4f::{initialize_ram_jump_to_main, unhandled_interrupt, CortexM4F, CortexMVariant};
31
32extern "C" {
33    // _estack is not really a function, but it makes the types work
34    // You should never actually invoke it!!
35    fn _estack();
36}
37
38#[cfg_attr(
39    all(target_arch = "arm", target_os = "none"),
40    link_section = ".vectors"
41)]
42// used Ensures that the symbol is kept until the final binary
43#[cfg_attr(all(target_arch = "arm", target_os = "none"), used)]
44pub static BASE_VECTORS: [unsafe extern "C" fn(); 16] = [
45    _estack,
46    initialize_ram_jump_to_main,
47    unhandled_interrupt,           // NMI
48    CortexM4F::HARD_FAULT_HANDLER, // Hard Fault
49    unhandled_interrupt,           // MemManage
50    unhandled_interrupt,           // BusFault
51    unhandled_interrupt,           // UsageFault
52    unhandled_interrupt,
53    unhandled_interrupt,
54    unhandled_interrupt,
55    unhandled_interrupt,
56    CortexM4F::SVC_HANDLER, // SVC
57    unhandled_interrupt,    // DebugMon
58    unhandled_interrupt,
59    unhandled_interrupt,        // PendSV
60    CortexM4F::SYSTICK_HANDLER, // SysTick
61];
62
63// STM32F303VCT6 has total of 82 interrupts
64// Extracted from `CMSIS/Device/ST/STM32F3xx/Include/stm32f303xc.h`
65// NOTE: There are missing IRQn between 0 and 81
66#[cfg_attr(all(target_arch = "arm", target_os = "none"), link_section = ".irqs")]
67// used Ensures that the symbol is kept until the final binary
68#[cfg_attr(all(target_arch = "arm", target_os = "none"), used)]
69pub static IRQS: [unsafe extern "C" fn(); 82] = [
70    CortexM4F::GENERIC_ISR, // WWDG (0)
71    CortexM4F::GENERIC_ISR, // PVD (1)
72    CortexM4F::GENERIC_ISR, // TAMP_STAMP (2)
73    CortexM4F::GENERIC_ISR, // RTC_WKUP (3)
74    CortexM4F::GENERIC_ISR, // FLASH (4)
75    CortexM4F::GENERIC_ISR, // RCC (5)
76    CortexM4F::GENERIC_ISR, // EXTI0 (6)
77    CortexM4F::GENERIC_ISR, // EXTI1 (7)
78    CortexM4F::GENERIC_ISR, // EXTI2 (8)
79    CortexM4F::GENERIC_ISR, // EXTI3 (9)
80    CortexM4F::GENERIC_ISR, // EXTI4 (10)
81    CortexM4F::GENERIC_ISR, // DMA1_Stream0 (11)
82    CortexM4F::GENERIC_ISR, // DMA1_Stream1 (12)
83    CortexM4F::GENERIC_ISR, // DMA1_Stream2 (13)
84    CortexM4F::GENERIC_ISR, // DMA1_Stream3 (14)
85    CortexM4F::GENERIC_ISR, // DMA1_Stream4 (15)
86    CortexM4F::GENERIC_ISR, // DMA1_Stream5 (16)
87    CortexM4F::GENERIC_ISR, // DMA1_Stream6 (17)
88    CortexM4F::GENERIC_ISR, // ADC1_2 (18)
89    CortexM4F::GENERIC_ISR, // HP_USB or CAN1_TX (19)
90    CortexM4F::GENERIC_ISR, // LP_USB or CAN1_RX0 (20)
91    CortexM4F::GENERIC_ISR, // CAN1_RX1 (21)
92    CortexM4F::GENERIC_ISR, // CAN1_SCE (22)
93    CortexM4F::GENERIC_ISR, // EXTI9_5 (23)
94    CortexM4F::GENERIC_ISR, // TIM1_BRK_TIM9 (24)
95    CortexM4F::GENERIC_ISR, // TIM1_UP_TIM10 (25)
96    CortexM4F::GENERIC_ISR, // TIM1_TRG_COM_TIM11 (26)
97    CortexM4F::GENERIC_ISR, // TIM1_CC (27)
98    CortexM4F::GENERIC_ISR, // TIM2 (28)
99    CortexM4F::GENERIC_ISR, // TIM3 (29)
100    CortexM4F::GENERIC_ISR, // TIM4 (30)
101    CortexM4F::GENERIC_ISR, // I2C1_EV (31)
102    CortexM4F::GENERIC_ISR, // I2C1_ER (32)
103    CortexM4F::GENERIC_ISR, // I2C2_EV (33)
104    CortexM4F::GENERIC_ISR, // I2C2_ER (34)
105    CortexM4F::GENERIC_ISR, // SPI1 (35)
106    CortexM4F::GENERIC_ISR, // SPI2 (36)
107    CortexM4F::GENERIC_ISR, // USART1 (37)
108    CortexM4F::GENERIC_ISR, // USART2 (38)
109    CortexM4F::GENERIC_ISR, // USART3 (39)
110    CortexM4F::GENERIC_ISR, // EXTI15_10 (40)
111    CortexM4F::GENERIC_ISR, // RTC_Alarm (41)
112    CortexM4F::GENERIC_ISR, // USB_WKUP (42)
113    CortexM4F::GENERIC_ISR, // TIM8_BRK_TIM12 (43)
114    CortexM4F::GENERIC_ISR, // TIM8_UP_TIM13 (44)
115    CortexM4F::GENERIC_ISR, // TIM8_TRG_COM_TIM14 (45)
116    CortexM4F::GENERIC_ISR, // TIM8_CC (46)
117    CortexM4F::GENERIC_ISR, // ADC3 (47)
118    unhandled_interrupt,    // (48)
119    unhandled_interrupt,    // (49)
120    unhandled_interrupt,    // (50)
121    CortexM4F::GENERIC_ISR, // SPI3 (51)
122    CortexM4F::GENERIC_ISR, // UART4 (52)
123    CortexM4F::GENERIC_ISR, // UART5 (53)
124    CortexM4F::GENERIC_ISR, // TIM6_DAC (54)
125    CortexM4F::GENERIC_ISR, // TIM7 (55)
126    CortexM4F::GENERIC_ISR, // DMA2_Stream0 (56)
127    CortexM4F::GENERIC_ISR, // DMA2_Stream1 (57)
128    CortexM4F::GENERIC_ISR, // DMA2_Stream2 (58)
129    CortexM4F::GENERIC_ISR, // DMA2_Stream3 (59)
130    CortexM4F::GENERIC_ISR, // DMA2_Stream4 (60)
131    CortexM4F::GENERIC_ISR, // ADC4 (61)
132    unhandled_interrupt,    // (62)
133    unhandled_interrupt,    // (63)
134    CortexM4F::GENERIC_ISR, // COMP1_2_3 (64)
135    CortexM4F::GENERIC_ISR, // COMP4_5_6 (65)
136    CortexM4F::GENERIC_ISR, // COMP7 (66)
137    unhandled_interrupt,    //(67)
138    unhandled_interrupt,    //(68)
139    unhandled_interrupt,    //(69)
140    unhandled_interrupt,    //(70)
141    unhandled_interrupt,    //(71)
142    unhandled_interrupt,    //(72)
143    unhandled_interrupt,    //(73)
144    CortexM4F::GENERIC_ISR, // USB_HP (74)
145    CortexM4F::GENERIC_ISR, // USB_LP (75)
146    CortexM4F::GENERIC_ISR, // USB_RMP_WKUP (76)
147    unhandled_interrupt,    // (77)
148    unhandled_interrupt,    // (78)
149    unhandled_interrupt,    // (79)
150    unhandled_interrupt,    // (80)
151    CortexM4F::GENERIC_ISR, // FPU (81)
152];
153
154pub unsafe fn init() {
155    cortexm4f::nvic::disable_all();
156    cortexm4f::nvic::clear_all_pending();
157    cortexm4f::nvic::enable_all();
158}