|
| 1 | +/* Copyright 2017 Pete Warden. All Rights Reserved. |
| 2 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 3 | +you may not use this file except in compliance with the License. |
| 4 | +You may obtain a copy of the License at |
| 5 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 6 | +Unless required by applicable law or agreed to in writing, software |
| 7 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 8 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 9 | +See the License for the specific language governing permissions and |
| 10 | +limitations under the License. |
| 11 | +==============================================================================*/ |
| 12 | + |
| 13 | +// Provides useful definitions for processor-specific parts of the STM32 |
| 14 | +// platform, such as device register locations. |
| 15 | + |
| 16 | +#ifndef INCLUDE_CORE_STM32_H |
| 17 | +#define INCLUDE_CORE_STM32_H |
| 18 | + |
| 19 | +// We need a couple of STM32-specific definitions before we include the main M3 |
| 20 | +// header file. |
| 21 | +typedef enum IRQn { |
| 22 | + NonMaskableInt_IRQn = -14, |
| 23 | + MemoryManagement_IRQn = -12, |
| 24 | + BusFault_IRQn = -11, |
| 25 | + UsageFault_IRQn = -10, |
| 26 | + SVCall_IRQn = -5, |
| 27 | + DebugMonitor_IRQn = -4, |
| 28 | + PendSV_IRQn = -2, |
| 29 | + SysTick_IRQn = -1, |
| 30 | + WWDG_IRQn = 0, |
| 31 | + PVD_IRQn = 1, |
| 32 | + TAMPER_IRQn = 2, |
| 33 | + RTC_IRQn = 3, |
| 34 | + FLASH_IRQn = 4, |
| 35 | + RCC_IRQn = 5, |
| 36 | + EXTI0_IRQn = 6, |
| 37 | + EXTI1_IRQn = 7, |
| 38 | + EXTI2_IRQn = 8, |
| 39 | + EXTI3_IRQn = 9, |
| 40 | + EXTI4_IRQn = 10, |
| 41 | + DMA1_Channel1_IRQn = 11, |
| 42 | + DMA1_Channel2_IRQn = 12, |
| 43 | + DMA1_Channel3_IRQn = 13, |
| 44 | + DMA1_Channel4_IRQn = 14, |
| 45 | + DMA1_Channel5_IRQn = 15, |
| 46 | + DMA1_Channel6_IRQn = 16, |
| 47 | + DMA1_Channel7_IRQn = 17, |
| 48 | +} IRQn_Type; |
| 49 | +#define __NVIC_PRIO_BITS 4 |
| 50 | + |
| 51 | +// This include relies on CMSIS being downloaded. See README for details. |
| 52 | +#include <core_cm3.h> |
| 53 | + |
| 54 | +// Now define some device-specific structures. For more information, see |
| 55 | +// http://www.st.com/content/ccc/resource/technical/document/reference_manual/59/b9/ba/7f/11/af/43/d5/CD00171190.pdf/files/CD00171190.pdf/jcr:content/translations/en.CD00171190.pdf |
| 56 | + |
| 57 | +// Reset and Clock Control Layout. |
| 58 | +typedef struct { |
| 59 | + __IO uint32_t CR; // Clock Control. |
| 60 | + __IO uint32_t CFGR; // Clock Configuration #1. |
| 61 | + __IO uint32_t CIR; // Clock Interrupt. |
| 62 | + __IO uint32_t APB2RSTR; // APB2 Peripheral Reset. |
| 63 | + __IO uint32_t APB1RSTR; // APB1 Peripheral Reset. |
| 64 | + __IO uint32_t AHBENR; // AHB Peripheral Clock. |
| 65 | + __IO uint32_t APB2ENR; // APB2 Peripheral Clock Enable. |
| 66 | + __IO uint32_t APB1ENR; // APB1 Peripheral Clock Enable. |
| 67 | + __IO uint32_t BDCR; // Backup Domain Control. |
| 68 | + __IO uint32_t CSR; // Clock Control and status. |
| 69 | + __IO uint32_t AHBRSTR; // AHB Peripheral Reset. |
| 70 | + __IO uint32_t CFGR2; // Clock Configuration #2. |
| 71 | + __IO uint32_t CFGR3; // Clock Configuration #3. |
| 72 | +} RCC_t; |
| 73 | + |
| 74 | +// GPIO Control Layout. |
| 75 | +typedef struct { |
| 76 | + __IO uint32_t CRL; // Control Low. |
| 77 | + __IO uint32_t CRH; // Control High. |
| 78 | + __IO uint16_t IDR; // Port Input Data. |
| 79 | + __IO uint16_t UNUSED1; // Unused. |
| 80 | + __IO uint16_t ODR; // Output data register. |
| 81 | + __IO uint16_t UNUSED2; // Unused. |
| 82 | + __IO uint32_t BSRR; // Port Bit Set/Reset. |
| 83 | + __IO uint16_t BRR; // Bit Reset. |
| 84 | + __IO uint16_t UNUSED3; // Unused. |
| 85 | + __IO uint32_t LCKR; // Port Configuration Lock. |
| 86 | +} GPIO_t; |
| 87 | + |
| 88 | +// Addresses of peripherals. |
| 89 | +#define RCC_BASE ((uint32_t)0x40021000) |
| 90 | +#define GPIOA_BASE ((uint32_t)0x40010800) |
| 91 | +#define GPIOB_BASE ((uint32_t)0x40010C00) |
| 92 | +#define GPIOC_BASE ((uint32_t)0x40011000) |
| 93 | + |
| 94 | +// Globals for accessing peripherals. |
| 95 | +#define RCC ((RCC_t*)RCC_BASE) |
| 96 | +#define GPIOA ((GPIO_t*)GPIOA_BASE) |
| 97 | +#define GPIOB ((GPIO_t*)GPIOB_BASE) |
| 98 | +#define GPIOC ((GPIO_t*)GPIOC_BASE) |
| 99 | + |
| 100 | +// Register access values. |
| 101 | +#define RCC_GPIOA_ENABLE (0x04) |
| 102 | +#define RCC_GPIOB_ENABLE (0x08) |
| 103 | +#define RCC_GPIOC_ENABLE (0x10) |
| 104 | + |
| 105 | +#define GPIO_MODE_OUT_2 (0x02) |
| 106 | +#define GPIO_CONF_GP_UD (0x0) |
| 107 | +#define GPIO_CONF_GP_OD (0x4) |
| 108 | + |
| 109 | +#endif // INCLUDE_CORE_STM32_H |
0 commit comments