stm32.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*
  2. * (C) Copyright 2011
  3. * Yuri Tikhonov, Emcraft Systems, yur@emcraft.com
  4. *
  5. * (C) Copyright 2015
  6. * Kamil Lulko, <kamil.lulko@gmail.com>
  7. *
  8. * Copyright 2015 ATS Advanced Telematics Systems GmbH
  9. * Copyright 2015 Konsulko Group, Matt Porter <mporter@konsulko.com>
  10. *
  11. * SPDX-License-Identifier: GPL-2.0+
  12. */
  13. #ifndef _MACH_STM32_H_
  14. #define _MACH_STM32_H_
  15. /*
  16. * Peripheral memory map
  17. */
  18. #define STM32_PERIPH_BASE 0x40000000
  19. #define STM32_APB1PERIPH_BASE (STM32_PERIPH_BASE + 0x00000000)
  20. #define STM32_APB2PERIPH_BASE (STM32_PERIPH_BASE + 0x00010000)
  21. #define STM32_AHB1PERIPH_BASE (STM32_PERIPH_BASE + 0x00018000)
  22. #define STM32_BUS_MASK 0xFFFF0000
  23. #define STM32_GPIOA_BASE (STM32_APB2PERIPH_BASE + 0x0800)
  24. #define STM32_GPIOB_BASE (STM32_APB2PERIPH_BASE + 0x0C00)
  25. #define STM32_GPIOC_BASE (STM32_APB2PERIPH_BASE + 0x1000)
  26. #define STM32_GPIOD_BASE (STM32_APB2PERIPH_BASE + 0x1400)
  27. #define STM32_GPIOE_BASE (STM32_APB2PERIPH_BASE + 0x1800)
  28. #define STM32_GPIOF_BASE (STM32_APB2PERIPH_BASE + 0x1C00)
  29. #define STM32_GPIOG_BASE (STM32_APB2PERIPH_BASE + 0x2000)
  30. /*
  31. * Register maps
  32. */
  33. struct stm32_des_regs {
  34. u16 flash_size;
  35. u16 pad1;
  36. u32 pad2;
  37. u32 uid0;
  38. u32 uid1;
  39. u32 uid2;
  40. };
  41. struct stm32_rcc_regs {
  42. u32 cr; /* RCC clock control */
  43. u32 cfgr; /* RCC clock configuration */
  44. u32 cir; /* RCC clock interrupt */
  45. u32 apb2rstr; /* RCC APB2 peripheral reset */
  46. u32 apb1rstr; /* RCC APB1 peripheral reset */
  47. u32 ahbenr; /* RCC AHB peripheral clock enable */
  48. u32 apb2enr; /* RCC APB2 peripheral clock enable */
  49. u32 apb1enr; /* RCC APB1 peripheral clock enable */
  50. u32 bdcr; /* RCC Backup domain control */
  51. u32 csr; /* RCC clock control & status */
  52. };
  53. struct stm32_pwr_regs {
  54. u32 cr;
  55. u32 csr;
  56. };
  57. struct stm32_flash_regs {
  58. u32 acr;
  59. u32 keyr;
  60. u32 optkeyr;
  61. u32 sr;
  62. u32 cr;
  63. u32 ar;
  64. u32 rsvd1; /* Reserved */
  65. u32 obr;
  66. u32 wrpr;
  67. u32 rsvd2[8]; /* Reserved */
  68. u32 keyr2;
  69. u32 rsvd3;
  70. u32 sr2;
  71. u32 cr2;
  72. u32 ar2;
  73. };
  74. /* Per bank register set for XL devices */
  75. struct stm32_flash_bank_regs {
  76. u32 keyr;
  77. u32 rsvd; /* Reserved */
  78. u32 sr;
  79. u32 cr;
  80. u32 ar;
  81. };
  82. /*
  83. * Registers access macros
  84. */
  85. #define STM32_DES_BASE (0x1ffff7e0)
  86. #define STM32_DES ((struct stm32_des_regs *)STM32_DES_BASE)
  87. #define STM32_RCC_BASE (STM32_AHB1PERIPH_BASE + 0x9000)
  88. #define STM32_RCC ((struct stm32_rcc_regs *)STM32_RCC_BASE)
  89. #define STM32_PWR_BASE (STM32_APB1PERIPH_BASE + 0x7000)
  90. #define STM32_PWR ((struct stm32_pwr_regs *)STM32_PWR_BASE)
  91. #define STM32_FLASH_BASE (STM32_AHB1PERIPH_BASE + 0xa000)
  92. #define STM32_FLASH ((struct stm32_flash_regs *)STM32_FLASH_BASE)
  93. #define STM32_FLASH_SR_BSY (1 << 0)
  94. #define STM32_FLASH_CR_PG (1 << 0)
  95. #define STM32_FLASH_CR_PER (1 << 1)
  96. #define STM32_FLASH_CR_STRT (1 << 6)
  97. #define STM32_FLASH_CR_LOCK (1 << 7)
  98. enum clock {
  99. CLOCK_CORE,
  100. CLOCK_AHB,
  101. CLOCK_APB1,
  102. CLOCK_APB2
  103. };
  104. int configure_clocks(void);
  105. unsigned long clock_get(enum clock clck);
  106. #endif /* _MACH_STM32_H_ */