1 /* 2 * Copyright (C) 2016 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef _HWR_H_ 18 #define _HWR_H_ 19 20 #ifdef __cplusplus 21 extern "C" { 22 #endif 23 24 #include <stdint.h> 25 #include <stdbool.h> 26 #include <plat/inc/rtc.h> 27 28 /* busses */ 29 #define PERIPH_BUS_AHB1 0 30 #define PERIPH_BUS_AHB2 1 31 #define PERIPH_BUS_AHB3 2 32 #define PERIPH_BUS_APB1 3 33 #define PERIPH_BUS_APB2 4 34 35 36 /* AHB 1 peripherals */ 37 #define PERIPH_AHB1_GPIOA 0x00000001UL 38 #define PERIPH_AHB1_GPIOB 0x00000002UL 39 #define PERIPH_AHB1_GPIOC 0x00000004UL 40 #define PERIPH_AHB1_GPIOD 0x00000008UL 41 #define PERIPH_AHB1_GPIOE 0x00000010UL 42 #define PERIPH_AHB1_GPIOF 0x00000020UL 43 #define PERIPH_AHB1_GPIOG 0x00000040UL 44 #define PERIPH_AHB1_GPIOH 0x00000080UL 45 #define PERIPH_AHB1_GPIOI 0x00000100UL 46 #define PERIPH_AHB1_CRC 0x00001000UL 47 #define PERIPH_AHB1_FLITF 0x00008000UL 48 #define PERIPH_AHB1_SRAM1 0x00010000UL 49 #define PERIPH_AHB1_SRAM2 0x00020000UL 50 #define PERIPH_AHB1_BKPSRAM 0x00040000UL 51 #define PERIPH_AHB1_SRAM3 0x00080000UL 52 #define PERIPH_AHB1_CCMDATARAMEN 0x00100000UL 53 #define PERIPH_AHB1_DMA1 0x00200000UL 54 #define PERIPH_AHB1_DMA2 0x00400000UL 55 #define PERIPH_AHB1_ETH_MAC 0x02000000UL 56 #define PERIPH_AHB1_ETH_MAC_TX 0x04000000UL 57 #define PERIPH_AHB1_ETH_MAC_RX 0x08000000UL 58 #define PERIPH_AHB1_ETH_MAC_PTP 0x10000000UL 59 #define PERIPH_AHB1_OTG_HS 0x20000000UL 60 #define PERIPH_AHB1_OTG_HS_ULPI 0x40000000UL 61 62 /* AHB 2 peripherals */ 63 #define PERIPH_AHB2_DCMI 0x00000001UL 64 #define PERIPH_AHB2_CRYP 0x00000010UL 65 #define PERIPH_AHB2_HASH 0x00000020UL 66 #define PERIPH_AHB2_RNG 0x00000040UL 67 #define PERIPH_AHB2_OTG_FS 0x00000080UL 68 69 /* AHB 3 peripherals */ 70 #define PERIPH_AHB3_FSMC 0x00000001UL 71 72 /* APB 1 peripherals */ 73 #define PERIPH_APB1_TIM2 0x00000001UL 74 #define PERIPH_APB1_TIM3 0x00000002UL 75 #define PERIPH_APB1_TIM4 0x00000004UL 76 #define PERIPH_APB1_TIM5 0x00000008UL 77 #define PERIPH_APB1_TIM6 0x00000010UL 78 #define PERIPH_APB1_TIM7 0x00000020UL 79 #define PERIPH_APB1_TIM12 0x00000040UL 80 #define PERIPH_APB1_TIM13 0x00000080UL 81 #define PERIPH_APB1_TIM14 0x00000100UL 82 #define PERIPH_APB1_WWDG 0x00000800UL 83 #define PERIPH_APB1_SPI2 0x00004000UL 84 #define PERIPH_APB1_SPI3 0x00008000UL 85 #define PERIPH_APB1_USART2 0x00020000UL 86 #define PERIPH_APB1_USART3 0x00040000UL 87 #define PERIPH_APB1_UART4 0x00080000UL 88 #define PERIPH_APB1_UART5 0x00100000UL 89 #define PERIPH_APB1_I2C1 0x00200000UL 90 #define PERIPH_APB1_I2C2 0x00400000UL 91 #define PERIPH_APB1_I2C3 0x00800000UL 92 #define PERIPH_APB1_CAN1 0x02000000UL 93 #define PERIPH_APB1_CAN2 0x04000000UL 94 #define PERIPH_APB1_PWR 0x10000000UL 95 #define PERIPH_APB1_DAC 0x20000000UL 96 #define PERIPH_APB1_UART7 0x40000000UL 97 #define PERIPH_APB1_UART8 0x80000000UL 98 99 /* APB 2 peripherals */ 100 #define PERIPH_APB2_TIM1 0x00000001UL 101 #define PERIPH_APB2_TIM8 0x00000002UL 102 #define PERIPH_APB2_USART1 0x00000010UL 103 #define PERIPH_APB2_USART6 0x00000020UL 104 #define PERIPH_APB2_ADC 0x00000100UL 105 #define PERIPH_APB2_ADC1 0x00000100UL 106 #define PERIPH_APB2_ADC2 0x00000200UL 107 #define PERIPH_APB2_ADC3 0x00000400UL 108 #define PERIPH_APB2_SDIO 0x00000800UL 109 #define PERIPH_APB2_SPI1 0x00001000UL 110 #define PERIPH_APB2_SPI4 0x00002000UL 111 #define PERIPH_APB2_SYSCFG 0x00004000UL 112 #define PERIPH_APB2_TIM9 0x00010000UL 113 #define PERIPH_APB2_TIM10 0x00020000UL 114 #define PERIPH_APB2_TIM11 0x00040000UL 115 #define PERIPH_APB2_SPI5 0x00100000UL 116 #define PERIPH_APB2_SPI6 0x00200000UL 117 118 119 120 121 /* base addrs */ 122 #define UDID_BASE 0x1FFF7A10UL 123 #define TIM2_BASE 0x40000000UL 124 #define TIM3_BASE 0x40000400UL 125 #define TIM4_BASE 0x40000800UL 126 #define TIM5_BASE 0x40000C00UL 127 #define RTC_BASE 0x40002800UL 128 #define SPI2_BASE 0x40003800UL 129 #define SPI3_BASE 0x40003C00UL 130 #define USART2_BASE 0x40004400UL 131 #define USART3_BASE 0x40004800UL 132 #define UART4_BASE 0x40004C00UL 133 #define UART5_BASE 0x40005000UL 134 #define I2C1_BASE 0x40005400UL 135 #define I2C2_BASE 0x40005800UL 136 #define I2C3_BASE 0x40005C00UL 137 #define PWR_BASE 0x40007000UL 138 #define TIM1_BASE 0x40010000UL 139 #define USART1_BASE 0x40011000UL 140 #define USART6_BASE 0x40011400UL 141 #define SPI1_BASE 0x40013000UL 142 #define SPI4_BASE 0x40013400UL 143 #define SYSCFG_BASE 0x40013800UL 144 #define EXTI_BASE 0x40013C00UL 145 #define TIM9_BASE 0x40014000UL 146 #define TIM10_BASE 0x40014400UL 147 #define TIM11_BASE 0x40014800UL 148 #define SPI5_BASE 0x40015000UL 149 #define SPI6_BASE 0x40015400UL 150 #define GPIOA_BASE 0x40020000UL 151 #define GPIOB_BASE 0x40020400UL 152 #define GPIOC_BASE 0x40020800UL 153 #define GPIOD_BASE 0x40020C00UL 154 #define GPIOE_BASE 0x40021000UL 155 #define GPIOF_BASE 0x40021400UL 156 #define GPIOG_BASE 0x40021800UL 157 #define GPIOH_BASE 0x40021C00UL 158 #define GPIOI_BASE 0x40022000UL 159 #define CRC_BASE 0x40023000UL 160 #define RCC_BASE 0x40023800UL 161 #define FLASH_BASE 0x40023C00UL 162 #define DMA1_BASE 0x40026000UL 163 #define DMA2_BASE 0x40026400UL 164 #define DBG_BASE 0xE0042000UL 165 166 167 enum Stm32F4xxSleepType { //current power wkup way wkup speed (typ/max) 168 stm32f411SleepModeSleep, //2.7-5.9mA all-core interrupt 1 cy 169 stm32f144SleepModeStopMR, //111uA RTC,flash,reg EXTI 13.5/14.5us 170 stm32f144SleepModeStopMRFPD,// 73uA RTC,reg EXTI 105/111us 171 stm32f411SleepModeStopLPFD, // 42uA RTC,lpreg EXTI 113/130us 172 stm32f411SleepModeStopLPLV, // 10uA RTC EXTT 314/407us (actually lower, but not quoted) 173 }; 174 175 /* funcs */ 176 void pwrSystemInit(void); 177 uint32_t pwrResetReason(void); 178 void pwrUnitClock(uint32_t bus, uint32_t unit, bool on); 179 void pwrUnitReset(uint32_t bus, uint32_t unit, bool on); 180 uint32_t pwrGetBusSpeed(uint32_t bus); 181 void pwrEnableAndClockRtc(enum RtcClock); 182 void pwrEnableWriteBackupDomainRegs(void); 183 184 185 /* internal to platform */ 186 void pwrSetSleepType(enum Stm32F4xxSleepType sleepType); 187 188 #ifdef __cplusplus 189 } 190 #endif 191 192 #endif 193 194