mpconfigboard_common.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. /*
  2. * This file is part of the MicroPython project, http://micropython.org/
  3. *
  4. * The MIT License (MIT)
  5. *
  6. * Copyright (c) 2018 Damien P. George
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a copy
  9. * of this software and associated documentation files (the "Software"), to deal
  10. * in the Software without restriction, including without limitation the rights
  11. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  12. * copies of the Software, and to permit persons to whom the Software is
  13. * furnished to do so, subject to the following conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be included in
  16. * all copies or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  21. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  22. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  23. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  24. * THE SOFTWARE.
  25. */
  26. // Common settings and defaults for board configuration.
  27. // The defaults here should be overridden in mpconfigboard.h.
  28. #include STM32_HAL_H
  29. /*****************************************************************************/
  30. // Feature settings with defaults
  31. // Whether to include the stm module, with peripheral register constants
  32. #ifndef MICROPY_PY_STM
  33. #define MICROPY_PY_STM (1)
  34. #endif
  35. // Whether to include legacy functions and classes in the pyb module
  36. #ifndef MICROPY_PY_PYB_LEGACY
  37. #define MICROPY_PY_PYB_LEGACY (1)
  38. #endif
  39. // Whether to enable storage on the internal flash of the MCU
  40. #ifndef MICROPY_HW_ENABLE_INTERNAL_FLASH_STORAGE
  41. #define MICROPY_HW_ENABLE_INTERNAL_FLASH_STORAGE (1)
  42. #endif
  43. // Whether to enable the RTC, exposed as pyb.RTC
  44. #ifndef MICROPY_HW_ENABLE_RTC
  45. #define MICROPY_HW_ENABLE_RTC (0)
  46. #endif
  47. // Whether to enable the hardware RNG peripheral, exposed as pyb.rng()
  48. #ifndef MICROPY_HW_ENABLE_RNG
  49. #define MICROPY_HW_ENABLE_RNG (0)
  50. #endif
  51. // Whether to enable the ADC peripheral, exposed as pyb.ADC and pyb.ADCAll
  52. #ifndef MICROPY_HW_ENABLE_ADC
  53. #define MICROPY_HW_ENABLE_ADC (1)
  54. #endif
  55. // Whether to enable the DAC peripheral, exposed as pyb.DAC
  56. #ifndef MICROPY_HW_ENABLE_DAC
  57. #define MICROPY_HW_ENABLE_DAC (0)
  58. #endif
  59. // Whether to enable USB support
  60. #ifndef MICROPY_HW_ENABLE_USB
  61. #define MICROPY_HW_ENABLE_USB (0)
  62. #endif
  63. // Whether to enable the PA0-PA3 servo driver, exposed as pyb.Servo
  64. #ifndef MICROPY_HW_ENABLE_SERVO
  65. #define MICROPY_HW_ENABLE_SERVO (0)
  66. #endif
  67. // Whether to enable a USR switch, exposed as pyb.Switch
  68. #ifndef MICROPY_HW_HAS_SWITCH
  69. #define MICROPY_HW_HAS_SWITCH (0)
  70. #endif
  71. // Whether to expose internal flash storage as pyb.Flash
  72. #ifndef MICROPY_HW_HAS_FLASH
  73. #define MICROPY_HW_HAS_FLASH (0)
  74. #endif
  75. // Whether to enable the SD card interface, exposed as pyb.SDCard
  76. #ifndef MICROPY_HW_HAS_SDCARD
  77. #define MICROPY_HW_HAS_SDCARD (0)
  78. #endif
  79. // Whether to enable the MMA7660 driver, exposed as pyb.Accel
  80. #ifndef MICROPY_HW_HAS_MMA7660
  81. #define MICROPY_HW_HAS_MMA7660 (0)
  82. #endif
  83. // Whether to enable the LCD32MK driver, exposed as pyb.LCD
  84. #ifndef MICROPY_HW_HAS_LCD
  85. #define MICROPY_HW_HAS_LCD (0)
  86. #endif
  87. // The volume label used when creating the flash filesystem
  88. #ifndef MICROPY_HW_FLASH_FS_LABEL
  89. #define MICROPY_HW_FLASH_FS_LABEL "pybflash"
  90. #endif
  91. /*****************************************************************************/
  92. // General configuration
  93. // Configuration for STM32F0 series
  94. #if defined(STM32F0)
  95. #define MP_HAL_UNIQUE_ID_ADDRESS (0x1ffff7ac)
  96. #define PYB_EXTI_NUM_VECTORS (23)
  97. #define MICROPY_HW_MAX_TIMER (17)
  98. #define MICROPY_HW_MAX_UART (8)
  99. // Configuration for STM32F4 series
  100. #elif defined(STM32F4)
  101. #define MP_HAL_UNIQUE_ID_ADDRESS (0x1fff7a10)
  102. #define PYB_EXTI_NUM_VECTORS (23)
  103. #define MICROPY_HW_MAX_TIMER (14)
  104. #ifdef UART8
  105. #define MICROPY_HW_MAX_UART (8)
  106. #else
  107. #define MICROPY_HW_MAX_UART (6)
  108. #endif
  109. // Configuration for STM32F7 series
  110. #elif defined(STM32F7)
  111. #if defined(STM32F722xx) || defined(STM32F723xx) || defined(STM32F732xx) || defined(STM32F733xx)
  112. #define MP_HAL_UNIQUE_ID_ADDRESS (0x1ff07a10)
  113. #else
  114. #define MP_HAL_UNIQUE_ID_ADDRESS (0x1ff0f420)
  115. #endif
  116. #define PYB_EXTI_NUM_VECTORS (24)
  117. #define MICROPY_HW_MAX_TIMER (17)
  118. #define MICROPY_HW_MAX_UART (8)
  119. // Configuration for STM32H7 series
  120. #elif defined(STM32H7)
  121. #define MP_HAL_UNIQUE_ID_ADDRESS (0x1ff1e800)
  122. #define PYB_EXTI_NUM_VECTORS (24)
  123. #define MICROPY_HW_MAX_TIMER (17)
  124. #define MICROPY_HW_MAX_UART (8)
  125. // Configuration for STM32L4 series
  126. #elif defined(STM32L4)
  127. #define MP_HAL_UNIQUE_ID_ADDRESS (0x1fff7590)
  128. #define PYB_EXTI_NUM_VECTORS (23)
  129. #define MICROPY_HW_MAX_TIMER (17)
  130. #define MICROPY_HW_MAX_UART (6)
  131. #else
  132. #error Unsupported MCU series
  133. #endif
  134. // Configure HSE for bypass or oscillator
  135. #if MICROPY_HW_CLK_USE_BYPASS
  136. #define MICROPY_HW_CLK_HSE_STATE (RCC_HSE_BYPASS)
  137. #else
  138. #define MICROPY_HW_CLK_HSE_STATE (RCC_HSE_ON)
  139. #endif
  140. #if MICROPY_HW_ENABLE_INTERNAL_FLASH_STORAGE
  141. // Provide block device macros if internal flash storage is enabled
  142. #define MICROPY_HW_BDEV_IOCTL flash_bdev_ioctl
  143. #define MICROPY_HW_BDEV_READBLOCK flash_bdev_readblock
  144. #define MICROPY_HW_BDEV_WRITEBLOCK flash_bdev_writeblock
  145. #endif
  146. // Enable the storage sub-system if a block device is defined
  147. #if defined(MICROPY_HW_BDEV_IOCTL)
  148. #define MICROPY_HW_ENABLE_STORAGE (1)
  149. #else
  150. #define MICROPY_HW_ENABLE_STORAGE (0)
  151. #endif
  152. // Enable hardware I2C if there are any peripherals defined
  153. #if defined(MICROPY_HW_I2C1_SCL) || defined(MICROPY_HW_I2C2_SCL) \
  154. || defined(MICROPY_HW_I2C3_SCL) || defined(MICROPY_HW_I2C4_SCL)
  155. #define MICROPY_HW_ENABLE_HW_I2C (1)
  156. #else
  157. #define MICROPY_HW_ENABLE_HW_I2C (0)
  158. #endif
  159. // Enable CAN if there are any peripherals defined
  160. #if defined(MICROPY_HW_CAN1_TX) || defined(MICROPY_HW_CAN2_TX)
  161. #define MICROPY_HW_ENABLE_CAN (1)
  162. #else
  163. #define MICROPY_HW_ENABLE_CAN (0)
  164. #endif
  165. // Pin definition header file
  166. #define MICROPY_PIN_DEFS_PORT_H "pin_defs_stm32.h"
  167. // D-cache clean/invalidate helpers
  168. #if __DCACHE_PRESENT == 1
  169. #define MP_HAL_CLEANINVALIDATE_DCACHE(addr, size) \
  170. (SCB_CleanInvalidateDCache_by_Addr((uint32_t*)((uint32_t)addr & ~0x1f), \
  171. ((uint32_t)((uint8_t*)addr + size + 0x1f) & ~0x1f) - ((uint32_t)addr & ~0x1f)))
  172. #define MP_HAL_CLEAN_DCACHE(addr, size) \
  173. (SCB_CleanDCache_by_Addr((uint32_t*)((uint32_t)addr & ~0x1f), \
  174. ((uint32_t)((uint8_t*)addr + size + 0x1f) & ~0x1f) - ((uint32_t)addr & ~0x1f)))
  175. #else
  176. #define MP_HAL_CLEANINVALIDATE_DCACHE(addr, size)
  177. #define MP_HAL_CLEAN_DCACHE(addr, size)
  178. #endif
  179. #define MICROPY_HW_USES_BOOTLOADER (MICROPY_HW_VTOR != 0x08000000)