board.c 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645
  1. /*
  2. * Copyright (c) 2006-2022, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2009-01-05 Bernard first implementation
  9. */
  10. #include <rthw.h>
  11. #include <rtthread.h>
  12. #include "board.h"
  13. #include "pin_mux.h"
  14. #include "fsl_iomuxc.h"
  15. #include "fsl_gpio.h"
  16. #ifdef BSP_USING_DMA
  17. #include "fsl_dmamux.h"
  18. #include "fsl_edma.h"
  19. #endif
  20. #define NVIC_PRIORITYGROUP_0 0x00000007U /*!< 0 bits for pre-emption priority
  21. 4 bits for subpriority */
  22. #define NVIC_PRIORITYGROUP_1 0x00000006U /*!< 1 bits for pre-emption priority
  23. 3 bits for subpriority */
  24. #define NVIC_PRIORITYGROUP_2 0x00000005U /*!< 2 bits for pre-emption priority
  25. 2 bits for subpriority */
  26. #define NVIC_PRIORITYGROUP_3 0x00000004U /*!< 3 bits for pre-emption priority
  27. 1 bits for subpriority */
  28. #define NVIC_PRIORITYGROUP_4 0x00000003U /*!< 4 bits for pre-emption priority
  29. 0 bits for subpriority */
  30. /* MPU configuration. */
  31. static void BOARD_ConfigMPU(void)
  32. {
  33. #if defined(__CC_ARM) || defined(__ARMCC_VERSION)
  34. extern uint32_t Image$$RW_m_ncache$$Base[];
  35. /* RW_m_ncache_unused is a auxiliary region which is used to get the whole size of noncache section */
  36. extern uint32_t Image$$RW_m_ncache_unused$$Base[];
  37. extern uint32_t Image$$RW_m_ncache_unused$$ZI$$Limit[];
  38. uint32_t nonCacheStart = (uint32_t)Image$$RW_m_ncache$$Base;
  39. uint32_t size = ((uint32_t)Image$$RW_m_ncache_unused$$Base == nonCacheStart) ?
  40. 0 :
  41. ((uint32_t)Image$$RW_m_ncache_unused$$ZI$$Limit - nonCacheStart);
  42. #elif defined(__MCUXPRESSO)
  43. #if defined(__USE_SHMEM)
  44. extern uint32_t __base_rpmsg_sh_mem;
  45. extern uint32_t __top_rpmsg_sh_mem;
  46. uint32_t nonCacheStart = (uint32_t)(&__base_rpmsg_sh_mem);
  47. uint32_t size = (uint32_t)(&__top_rpmsg_sh_mem) - nonCacheStart;
  48. #else
  49. extern uint32_t __base_NCACHE_REGION;
  50. extern uint32_t __top_NCACHE_REGION;
  51. uint32_t nonCacheStart = (uint32_t)(&__base_NCACHE_REGION);
  52. uint32_t size = (uint32_t)(&__top_NCACHE_REGION) - nonCacheStart;
  53. #endif
  54. #elif defined(__ICCARM__) || defined(__GNUC__)
  55. extern uint32_t __NCACHE_REGION_START[];
  56. extern uint32_t __NCACHE_REGION_SIZE[];
  57. uint32_t nonCacheStart = (uint32_t)__NCACHE_REGION_START;
  58. uint32_t size = (uint32_t)__NCACHE_REGION_SIZE;
  59. #endif
  60. volatile uint32_t i = 0;
  61. #if defined(__ICACHE_PRESENT) && __ICACHE_PRESENT
  62. /* Disable I cache and D cache */
  63. if (SCB_CCR_IC_Msk == (SCB_CCR_IC_Msk & SCB->CCR))
  64. {
  65. SCB_DisableICache();
  66. }
  67. #endif
  68. #if defined(__DCACHE_PRESENT) && __DCACHE_PRESENT
  69. if (SCB_CCR_DC_Msk == (SCB_CCR_DC_Msk & SCB->CCR))
  70. {
  71. SCB_DisableDCache();
  72. }
  73. #endif
  74. /* Disable MPU */
  75. ARM_MPU_Disable();
  76. /* MPU configure:
  77. * Use ARM_MPU_RASR(DisableExec, AccessPermission, TypeExtField, IsShareable, IsCacheable, IsBufferable,
  78. * SubRegionDisable, Size)
  79. * API in mpu_armv7.h.
  80. * param DisableExec Instruction access (XN) disable bit,0=instruction fetches enabled, 1=instruction fetches
  81. * disabled.
  82. * param AccessPermission Data access permissions, allows you to configure read/write access for User and
  83. * Privileged mode.
  84. * Use MACROS defined in mpu_armv7.h:
  85. * ARM_MPU_AP_NONE/ARM_MPU_AP_PRIV/ARM_MPU_AP_URO/ARM_MPU_AP_FULL/ARM_MPU_AP_PRO/ARM_MPU_AP_RO
  86. * Combine TypeExtField/IsShareable/IsCacheable/IsBufferable to configure MPU memory access attributes.
  87. * TypeExtField IsShareable IsCacheable IsBufferable Memory Attribtue Shareability Cache
  88. * 0 x 0 0 Strongly Ordered shareable
  89. * 0 x 0 1 Device shareable
  90. * 0 0 1 0 Normal not shareable Outer and inner write
  91. * through no write allocate
  92. * 0 0 1 1 Normal not shareable Outer and inner write
  93. * back no write allocate
  94. * 0 1 1 0 Normal shareable Outer and inner write
  95. * through no write allocate
  96. * 0 1 1 1 Normal shareable Outer and inner write
  97. * back no write allocate
  98. * 1 0 0 0 Normal not shareable outer and inner
  99. * noncache
  100. * 1 1 0 0 Normal shareable outer and inner
  101. * noncache
  102. * 1 0 1 1 Normal not shareable outer and inner write
  103. * back write/read acllocate
  104. * 1 1 1 1 Normal shareable outer and inner write
  105. * back write/read acllocate
  106. * 2 x 0 0 Device not shareable
  107. * Above are normal use settings, if your want to see more details or want to config different inner/outter cache
  108. * policy.
  109. * please refer to Table 4-55 /4-56 in arm cortex-M7 generic user guide <dui0646b_cortex_m7_dgug.pdf>
  110. * param SubRegionDisable Sub-region disable field. 0=sub-region is enabled, 1=sub-region is disabled.
  111. * param Size Region size of the region to be configured. use ARM_MPU_REGION_SIZE_xxx MACRO in
  112. * mpu_armv7.h.
  113. */
  114. /* Region 0 setting: Instruction access disabled, No data access permission. */
  115. MPU->RBAR = ARM_MPU_RBAR(0, 0x00000000U);
  116. MPU->RASR = ARM_MPU_RASR(1, ARM_MPU_AP_NONE, 2, 0, 0, 0, 0, ARM_MPU_REGION_SIZE_4GB);
  117. /* Region 1 setting: Memory with Device type, not shareable, non-cacheable. */
  118. MPU->RBAR = ARM_MPU_RBAR(1, 0x80000000U);
  119. MPU->RASR = ARM_MPU_RASR(0, ARM_MPU_AP_FULL, 2, 0, 0, 0, 0, ARM_MPU_REGION_SIZE_512MB);
  120. /* Region 2 setting: Memory with Device type, not shareable, non-cacheable. */
  121. MPU->RBAR = ARM_MPU_RBAR(2, 0x60000000U);
  122. MPU->RASR = ARM_MPU_RASR(0, ARM_MPU_AP_FULL, 2, 0, 0, 0, 0, ARM_MPU_REGION_SIZE_512MB);
  123. /* Region 3 setting: Memory with Device type, not shareable, non-cacheable. */
  124. MPU->RBAR = ARM_MPU_RBAR(3, 0x00000000U);
  125. MPU->RASR = ARM_MPU_RASR(0, ARM_MPU_AP_FULL, 2, 0, 0, 0, 0, ARM_MPU_REGION_SIZE_1GB);
  126. /* Region 4 setting: Memory with Normal type, not shareable, outer/inner write back */
  127. MPU->RBAR = ARM_MPU_RBAR(4, 0x00000000U);
  128. MPU->RASR = ARM_MPU_RASR(0, ARM_MPU_AP_FULL, 0, 0, 1, 1, 0, ARM_MPU_REGION_SIZE_256KB);
  129. /* Region 5 setting: Memory with Normal type, not shareable, outer/inner write back */
  130. MPU->RBAR = ARM_MPU_RBAR(5, 0x20000000U);
  131. MPU->RASR = ARM_MPU_RASR(0, ARM_MPU_AP_FULL, 0, 0, 1, 1, 0, ARM_MPU_REGION_SIZE_256KB);
  132. /* Region 6 setting: Memory with Normal type, not shareable, outer/inner write back */
  133. MPU->RBAR = ARM_MPU_RBAR(6, 0x20200000U);
  134. MPU->RASR = ARM_MPU_RASR(0, ARM_MPU_AP_FULL, 0, 0, 1, 1, 0, ARM_MPU_REGION_SIZE_1MB);
  135. /* Region 7 setting: Memory with Normal type, not shareable, outer/inner write back */
  136. MPU->RBAR = ARM_MPU_RBAR(7, 0x20300000U);
  137. MPU->RASR = ARM_MPU_RASR(0, ARM_MPU_AP_FULL, 0, 0, 1, 1, 0, ARM_MPU_REGION_SIZE_512KB);
  138. #if defined(XIP_EXTERNAL_FLASH) && (XIP_EXTERNAL_FLASH == 1)
  139. /* Region 8 setting: Memory with Normal type, not shareable, outer/inner write back. */
  140. MPU->RBAR = ARM_MPU_RBAR(8, 0x30000000U);
  141. MPU->RASR = ARM_MPU_RASR(0, ARM_MPU_AP_RO, 0, 0, 1, 1, 0, ARM_MPU_REGION_SIZE_16MB);
  142. #endif
  143. #ifdef USE_SDRAM
  144. /* Region 9 setting: Memory with Normal type, not shareable, outer/inner write back */
  145. MPU->RBAR = ARM_MPU_RBAR(9, 0x80000000U);
  146. MPU->RASR = ARM_MPU_RASR(0, ARM_MPU_AP_FULL, 0, 0, 1, 1, 0, ARM_MPU_REGION_SIZE_64MB);
  147. #endif
  148. while ((size >> i) > 0x1U)
  149. {
  150. i++;
  151. }
  152. if (i != 0)
  153. {
  154. /* The MPU region size should be 2^N, 5<=N<=32, region base should be multiples of size. */
  155. assert(!(nonCacheStart % size));
  156. assert(size == (uint32_t)(1 << i));
  157. assert(i >= 5);
  158. /* Region 10 setting: Memory with Normal type, not shareable, non-cacheable */
  159. MPU->RBAR = ARM_MPU_RBAR(10, nonCacheStart);
  160. MPU->RASR = ARM_MPU_RASR(0, ARM_MPU_AP_FULL, 1, 0, 0, 0, 0, i - 1);
  161. }
  162. /* Region 11 setting: Memory with Device type, not shareable, non-cacheable */
  163. MPU->RBAR = ARM_MPU_RBAR(11, 0x40000000);
  164. MPU->RASR = ARM_MPU_RASR(0, ARM_MPU_AP_FULL, 2, 0, 0, 0, 0, ARM_MPU_REGION_SIZE_16MB);
  165. /* Region 12 setting: Memory with Device type, not shareable, non-cacheable */
  166. MPU->RBAR = ARM_MPU_RBAR(12, 0x41000000);
  167. MPU->RASR = ARM_MPU_RASR(0, ARM_MPU_AP_FULL, 2, 0, 0, 0, 0, ARM_MPU_REGION_SIZE_2MB);
  168. /* Region 13 setting: Memory with Device type, not shareable, non-cacheable */
  169. MPU->RBAR = ARM_MPU_RBAR(13, 0x41400000);
  170. MPU->RASR = ARM_MPU_RASR(0, ARM_MPU_AP_FULL, 2, 0, 0, 0, 0, ARM_MPU_REGION_SIZE_1MB);
  171. /* Region 14 setting: Memory with Device type, not shareable, non-cacheable */
  172. MPU->RBAR = ARM_MPU_RBAR(14, 0x41800000);
  173. MPU->RASR = ARM_MPU_RASR(0, ARM_MPU_AP_FULL, 2, 0, 0, 0, 0, ARM_MPU_REGION_SIZE_2MB);
  174. /* Region 15 setting: Memory with Device type, not shareable, non-cacheable */
  175. MPU->RBAR = ARM_MPU_RBAR(15, 0x42000000);
  176. MPU->RASR = ARM_MPU_RASR(0, ARM_MPU_AP_FULL, 2, 0, 0, 0, 0, ARM_MPU_REGION_SIZE_1MB);
  177. /* Enable MPU */
  178. ARM_MPU_Enable(MPU_CTRL_PRIVDEFENA_Msk);
  179. /* Enable I cache and D cache */
  180. #if defined(__DCACHE_PRESENT) && __DCACHE_PRESENT
  181. SCB_EnableDCache();
  182. #endif
  183. #if defined(__ICACHE_PRESENT) && __ICACHE_PRESENT
  184. SCB_EnableICache();
  185. #endif
  186. }
  187. /* This is the timer interrupt service routine. */
  188. void SysTick_Handler(void)
  189. {
  190. /* enter interrupt */
  191. rt_interrupt_enter();
  192. rt_tick_increase();
  193. /* leave interrupt */
  194. rt_interrupt_leave();
  195. }
  196. #ifdef BSP_USING_LPUART
  197. void imxrt_uart_pins_init(void)
  198. {
  199. #ifdef BSP_USING_LPUART1
  200. IOMUXC_SetPinMux(
  201. IOMUXC_GPIO_AD_24_LPUART1_TXD, /* GPIO_AD_B0_12 is configured as LPUART1_TX */
  202. 0U); /* Software Input On Field: Input Path is determined by functionality */
  203. IOMUXC_SetPinMux(
  204. IOMUXC_GPIO_AD_25_LPUART1_RXD, /* GPIO_AD_B0_13 is configured as LPUART1_RX */
  205. 0U); /* Software Input On Field: Input Path is determined by functionality */
  206. IOMUXC_SetPinConfig(
  207. IOMUXC_GPIO_AD_24_LPUART1_TXD, /* GPIO_AD_B0_12 PAD functional properties : */
  208. 0x10B0u); /* Slew Rate Field: Slow Slew Rate
  209. Drive Strength Field: R0/6
  210. Speed Field: medium(100MHz)
  211. Open Drain Enable Field: Open Drain Disabled
  212. Pull / Keep Enable Field: Pull/Keeper Enabled
  213. Pull / Keep Select Field: Keeper
  214. Pull Up / Down Config. Field: 100K Ohm Pull Down
  215. Hyst. Enable Field: Hysteresis Disabled */
  216. IOMUXC_SetPinConfig(
  217. IOMUXC_GPIO_AD_25_LPUART1_RXD, /* GPIO_AD_B0_13 PAD functional properties : */
  218. 0x10B0u); /* Slew Rate Field: Slow Slew Rate
  219. Drive Strength Field: R0/6
  220. Speed Field: medium(100MHz)
  221. Open Drain Enable Field: Open Drain Disabled
  222. Pull / Keep Enable Field: Pull/Keeper Enabled
  223. Pull / Keep Select Field: Keeper
  224. Pull Up / Down Config. Field: 100K Ohm Pull Down
  225. Hyst. Enable Field: Hysteresis Disabled */
  226. #endif
  227. #ifdef BSP_USING_LPUART2
  228. IOMUXC_SetPinMux(
  229. IOMUXC_GPIO_AD_B1_02_LPUART2_TX,
  230. 0U);
  231. IOMUXC_SetPinMux(
  232. IOMUXC_GPIO_AD_B1_03_LPUART2_RX,
  233. 0U);
  234. IOMUXC_SetPinConfig(
  235. IOMUXC_GPIO_AD_B1_02_LPUART2_TX,
  236. 0x10B0u);
  237. IOMUXC_SetPinConfig(
  238. IOMUXC_GPIO_AD_B1_03_LPUART2_RX,
  239. 0x10B0u);
  240. #endif
  241. #ifdef BSP_USING_LPUART3
  242. IOMUXC_SetPinMux(
  243. IOMUXC_GPIO_AD_B1_06_LPUART3_TX,
  244. 0U);
  245. IOMUXC_SetPinMux(
  246. IOMUXC_GPIO_AD_B1_07_LPUART3_RX,
  247. 0U);
  248. IOMUXC_SetPinConfig(
  249. IOMUXC_GPIO_AD_B1_06_LPUART3_TX,
  250. 0x10B0u);
  251. IOMUXC_SetPinConfig(
  252. IOMUXC_GPIO_AD_B1_07_LPUART3_RX,
  253. 0x10B0u);
  254. #endif
  255. #ifdef BSP_USING_LPUART4
  256. IOMUXC_SetPinMux(
  257. IOMUXC_GPIO_B1_00_LPUART4_TX,
  258. 0U);
  259. IOMUXC_SetPinMux(
  260. IOMUXC_GPIO_B1_01_LPUART4_RX,
  261. 0U);
  262. IOMUXC_SetPinConfig(
  263. IOMUXC_GPIO_B1_00_LPUART4_TX,
  264. 0x10B0u);
  265. IOMUXC_SetPinConfig(
  266. IOMUXC_GPIO_B1_01_LPUART4_RX,
  267. 0x10B0u);
  268. #endif
  269. #ifdef BSP_USING_LPUART5
  270. IOMUXC_SetPinMux(
  271. IOMUXC_GPIO_B1_12_LPUART5_TX,
  272. 0U);
  273. IOMUXC_SetPinMux(
  274. IOMUXC_GPIO_B1_13_LPUART5_RX,
  275. 0U);
  276. IOMUXC_SetPinConfig(
  277. IOMUXC_GPIO_B1_12_LPUART5_TX,
  278. 0x10B0u);
  279. IOMUXC_SetPinConfig(
  280. IOMUXC_GPIO_B1_13_LPUART5_RX,
  281. 0x10B0u);
  282. #endif
  283. #ifdef BSP_USING_LPUART6
  284. IOMUXC_SetPinMux(
  285. IOMUXC_GPIO_AD_B0_02_LPUART6_TX,
  286. 0U);
  287. IOMUXC_SetPinMux(
  288. IOMUXC_GPIO_AD_B0_03_LPUART6_RX,
  289. 0U);
  290. IOMUXC_SetPinConfig(
  291. IOMUXC_GPIO_AD_B0_02_LPUART6_TX,
  292. 0x10B0u);
  293. IOMUXC_SetPinConfig(
  294. IOMUXC_GPIO_AD_B0_03_LPUART6_RX,
  295. 0x10B0u);
  296. #endif
  297. #ifdef BSP_USING_LPUART7
  298. IOMUXC_SetPinMux(
  299. IOMUXC_GPIO_EMC_31_LPUART7_TX,
  300. 0U);
  301. IOMUXC_SetPinMux(
  302. IOMUXC_GPIO_EMC_32_LPUART7_RX,
  303. 0U);
  304. IOMUXC_SetPinConfig(
  305. IOMUXC_GPIO_EMC_31_LPUART7_TX,
  306. 0x10B0u);
  307. IOMUXC_SetPinConfig(
  308. IOMUXC_GPIO_EMC_32_LPUART7_RX,
  309. 0x10B0u);
  310. #endif
  311. #ifdef BSP_USING_LPUART8
  312. IOMUXC_SetPinMux(
  313. IOMUXC_GPIO_AD_B1_10_LPUART8_TX,
  314. 0U);
  315. IOMUXC_SetPinMux(
  316. IOMUXC_GPIO_AD_B1_11_LPUART8_RX,
  317. 0U);
  318. IOMUXC_SetPinConfig(
  319. IOMUXC_GPIO_AD_B1_10_LPUART8_TX,
  320. 0x10B0u);
  321. IOMUXC_SetPinConfig(
  322. IOMUXC_GPIO_AD_B1_11_LPUART8_RX,
  323. 0x10B0u);
  324. #endif
  325. }
  326. #endif /* BSP_USING_LPUART */
  327. #ifdef BSP_USING_SDIO
  328. void imxrt_SDcard_pins_init(void)
  329. {
  330. CLOCK_EnableClock(kCLOCK_Iomuxc); /* LPCG on: LPCG is ON. */
  331. IOMUXC_SetPinMux(
  332. IOMUXC_GPIO_AD_34_USDHC1_VSELECT, /* GPIO_AD_34 is configured as USDHC1_VSELECT */
  333. 0U); /* Software Input On Field: Input Path is determined by functionality */
  334. IOMUXC_SetPinMux(
  335. IOMUXC_GPIO_AD_35_GPIO10_IO02, /* GPIO_AD_35 is configured as GPIO10_IO02 */
  336. 0U); /* Software Input On Field: Input Path is determined by functionality */
  337. IOMUXC_SetPinMux(
  338. IOMUXC_GPIO_SD_B1_00_USDHC1_CMD, /* GPIO_SD_B1_00 is configured as USDHC1_CMD */
  339. 1U); /* Software Input On Field: Force input path of pad GPIO_SD_B1_00 */
  340. IOMUXC_SetPinMux(
  341. IOMUXC_GPIO_SD_B1_01_USDHC1_CLK, /* GPIO_SD_B1_01 is configured as USDHC1_CLK */
  342. 1U); /* Software Input On Field: Force input path of pad GPIO_SD_B1_01 */
  343. IOMUXC_SetPinMux(
  344. IOMUXC_GPIO_SD_B1_02_USDHC1_DATA0, /* GPIO_SD_B1_02 is configured as USDHC1_DATA0 */
  345. 1U); /* Software Input On Field: Force input path of pad GPIO_SD_B1_02 */
  346. IOMUXC_SetPinMux(
  347. IOMUXC_GPIO_SD_B1_03_USDHC1_DATA1, /* GPIO_SD_B1_03 is configured as USDHC1_DATA1 */
  348. 1U); /* Software Input On Field: Force input path of pad GPIO_SD_B1_03 */
  349. IOMUXC_SetPinMux(
  350. IOMUXC_GPIO_SD_B1_04_USDHC1_DATA2, /* GPIO_SD_B1_04 is configured as USDHC1_DATA2 */
  351. 1U); /* Software Input On Field: Force input path of pad GPIO_SD_B1_04 */
  352. IOMUXC_SetPinMux(
  353. IOMUXC_GPIO_SD_B1_05_USDHC1_DATA3, /* GPIO_SD_B1_05 is configured as USDHC1_DATA3 */
  354. 1U); /* Software Input On Field: Force input path of pad GPIO_SD_B1_05 */
  355. IOMUXC_GPR->GPR43 = ((IOMUXC_GPR->GPR43 &
  356. (~(IOMUXC_GPR_GPR43_GPIO_MUX3_GPIO_SEL_HIGH_MASK))) /* Mask bits to zero which are setting */
  357. | IOMUXC_GPR_GPR43_GPIO_MUX3_GPIO_SEL_HIGH(0x8000U) /* GPIO3 and CM7_GPIO3 share same IO MUX function, GPIO_MUX3 selects one GPIO function: 0x8000U */
  358. );
  359. IOMUXC_SetPinConfig(
  360. IOMUXC_GPIO_SD_B1_00_USDHC1_CMD, /* GPIO_SD_B1_00 PAD functional properties : */
  361. 0x04U); /* PDRV Field: high drive strength
  362. Pull Down Pull Up Field: Internal pullup resistor enabled
  363. Open Drain Field: Disabled
  364. Domain write protection: Both cores are allowed
  365. Domain write protection lock: Neither of DWP bits is locked */
  366. IOMUXC_SetPinConfig(
  367. IOMUXC_GPIO_SD_B1_01_USDHC1_CLK, /* GPIO_SD_B1_01 PAD functional properties : */
  368. 0x0CU); /* PDRV Field: high drive strength
  369. Pull Down Pull Up Field: No Pull
  370. Open Drain Field: Disabled
  371. Domain write protection: Both cores are allowed
  372. Domain write protection lock: Neither of DWP bits is locked */
  373. IOMUXC_SetPinConfig(
  374. IOMUXC_GPIO_SD_B1_02_USDHC1_DATA0, /* GPIO_SD_B1_02 PAD functional properties : */
  375. 0x04U); /* PDRV Field: high drive strength
  376. Pull Down Pull Up Field: Internal pullup resistor enabled
  377. Open Drain Field: Disabled
  378. Domain write protection: Both cores are allowed
  379. Domain write protection lock: Neither of DWP bits is locked */
  380. IOMUXC_SetPinConfig(
  381. IOMUXC_GPIO_SD_B1_03_USDHC1_DATA1, /* GPIO_SD_B1_03 PAD functional properties : */
  382. 0x04U); /* PDRV Field: high drive strength
  383. Pull Down Pull Up Field: Internal pullup resistor enabled
  384. Open Drain Field: Disabled
  385. Domain write protection: Both cores are allowed
  386. Domain write protection lock: Neither of DWP bits is locked */
  387. IOMUXC_SetPinConfig(
  388. IOMUXC_GPIO_SD_B1_04_USDHC1_DATA2, /* GPIO_SD_B1_04 PAD functional properties : */
  389. 0x04U); /* PDRV Field: high drive strength
  390. Pull Down Pull Up Field: Internal pullup resistor enabled
  391. Open Drain Field: Disabled
  392. Domain write protection: Both cores are allowed
  393. Domain write protection lock: Neither of DWP bits is locked */
  394. IOMUXC_SetPinConfig(
  395. IOMUXC_GPIO_SD_B1_05_USDHC1_DATA3, /* GPIO_SD_B1_05 PAD functional properties : */
  396. 0x04U); /* PDRV Field: high drive strength
  397. Pull Down Pull Up Field: Internal pullup resistor enabled
  398. Open Drain Field: Disabled
  399. Domain write protection: Both cores are allowed
  400. Domain write protection lock: Neither of DWP bits is locked */
  401. }
  402. #endif
  403. #ifdef BSP_USING_ETH
  404. void imxrt_eth_pins_init(void) {
  405. CLOCK_EnableClock(kCLOCK_Iomuxc); /* LPCG on: LPCG is ON. */
  406. CLOCK_EnableClock(kCLOCK_Iomuxc_Lpsr); /* LPCG on: LPCG is ON. */
  407. IOMUXC_SetPinMux(
  408. IOMUXC_GPIO_AD_12_GPIO9_IO11, /* GPIO_AD_12 is configured as GPIO9_IO11 */
  409. 0U); /* Software Input On Field: Input Path is determined by functionality */
  410. IOMUXC_SetPinMux(
  411. IOMUXC_GPIO_AD_24_LPUART1_TXD, /* GPIO_AD_24 is configured as LPUART1_TXD */
  412. 0U); /* Software Input On Field: Input Path is determined by functionality */
  413. IOMUXC_SetPinMux(
  414. IOMUXC_GPIO_AD_25_LPUART1_RXD, /* GPIO_AD_25 is configured as LPUART1_RXD */
  415. 1U); /* Software Input On Field: Force input path of pad GPIO_AD_25 */
  416. IOMUXC_SetPinMux(
  417. IOMUXC_GPIO_AD_32_ENET_MDC, /* GPIO_AD_32 is configured as ENET_MDC */
  418. 0U); /* Software Input On Field: Input Path is determined by functionality */
  419. IOMUXC_SetPinMux(
  420. IOMUXC_GPIO_AD_33_ENET_MDIO, /* GPIO_AD_33 is configured as ENET_MDIO */
  421. 0U); /* Software Input On Field: Input Path is determined by functionality */
  422. IOMUXC_SetPinMux(
  423. IOMUXC_GPIO_DISP_B2_02_ENET_TX_DATA00, /* GPIO_DISP_B2_02 is configured as ENET_TX_DATA00 */
  424. 0U); /* Software Input On Field: Input Path is determined by functionality */
  425. IOMUXC_SetPinMux(
  426. IOMUXC_GPIO_DISP_B2_03_ENET_TX_DATA01, /* GPIO_DISP_B2_03 is configured as ENET_TX_DATA01 */
  427. 0U); /* Software Input On Field: Input Path is determined by functionality */
  428. IOMUXC_SetPinMux(
  429. IOMUXC_GPIO_DISP_B2_04_ENET_TX_EN, /* GPIO_DISP_B2_04 is configured as ENET_TX_EN */
  430. 0U); /* Software Input On Field: Input Path is determined by functionality */
  431. IOMUXC_SetPinMux(
  432. IOMUXC_GPIO_DISP_B2_05_ENET_REF_CLK, /* GPIO_DISP_B2_05 is configured as ENET_REF_CLK */
  433. 1U); /* Software Input On Field: Force input path of pad GPIO_DISP_B2_05 */
  434. IOMUXC_SetPinMux(
  435. IOMUXC_GPIO_DISP_B2_06_ENET_RX_DATA00, /* GPIO_DISP_B2_06 is configured as ENET_RX_DATA00 */
  436. 1U); /* Software Input On Field: Force input path of pad GPIO_DISP_B2_06 */
  437. IOMUXC_SetPinMux(
  438. IOMUXC_GPIO_DISP_B2_07_ENET_RX_DATA01, /* GPIO_DISP_B2_07 is configured as ENET_RX_DATA01 */
  439. 1U); /* Software Input On Field: Force input path of pad GPIO_DISP_B2_07 */
  440. IOMUXC_SetPinMux(
  441. IOMUXC_GPIO_DISP_B2_08_ENET_RX_EN, /* GPIO_DISP_B2_08 is configured as ENET_RX_EN */
  442. 0U); /* Software Input On Field: Input Path is determined by functionality */
  443. IOMUXC_SetPinMux(
  444. IOMUXC_GPIO_DISP_B2_09_ENET_RX_ER, /* GPIO_DISP_B2_09 is configured as ENET_RX_ER */
  445. 0U); /* Software Input On Field: Input Path is determined by functionality */
  446. IOMUXC_GPR->GPR4 = ((IOMUXC_GPR->GPR4 &
  447. (~(IOMUXC_GPR_GPR4_ENET_REF_CLK_DIR_MASK))) /* Mask bits to zero which are setting */
  448. | IOMUXC_GPR_GPR4_ENET_REF_CLK_DIR(0x01U) /* ENET_REF_CLK direction control: 0x01U */
  449. );
  450. IOMUXC_SetPinMux(
  451. IOMUXC_GPIO_LPSR_12_GPIO12_IO12, /* GPIO_LPSR_12 is configured as GPIO12_IO12 */
  452. 0U); /* Software Input On Field: Input Path is determined by functionality */
  453. IOMUXC_SetPinConfig(
  454. IOMUXC_GPIO_AD_12_GPIO9_IO11, /* GPIO_AD_12 PAD functional properties : */
  455. 0x06U); /* Slew Rate Field: Slow Slew Rate
  456. Drive Strength Field: high drive strength
  457. Pull / Keep Select Field: Pull Enable
  458. Pull Up / Down Config. Field: Weak pull down
  459. Open Drain Field: Disabled
  460. Domain write protection: Both cores are allowed
  461. Domain write protection lock: Neither of DWP bits is locked */
  462. IOMUXC_SetPinConfig(
  463. IOMUXC_GPIO_AD_24_LPUART1_TXD, /* GPIO_AD_24 PAD functional properties : */
  464. 0x06U); /* Slew Rate Field: Slow Slew Rate
  465. Drive Strength Field: high drive strength
  466. Pull / Keep Select Field: Pull Enable
  467. Pull Up / Down Config. Field: Weak pull down
  468. Open Drain Field: Disabled
  469. Domain write protection: Both cores are allowed
  470. Domain write protection lock: Neither of DWP bits is locked */
  471. IOMUXC_SetPinConfig(
  472. IOMUXC_GPIO_AD_25_LPUART1_RXD, /* GPIO_AD_25 PAD functional properties : */
  473. 0x06U); /* Slew Rate Field: Slow Slew Rate
  474. Drive Strength Field: high drive strength
  475. Pull / Keep Select Field: Pull Enable
  476. Pull Up / Down Config. Field: Weak pull down
  477. Open Drain Field: Disabled
  478. Domain write protection: Both cores are allowed
  479. Domain write protection lock: Neither of DWP bits is locked */
  480. IOMUXC_SetPinConfig(
  481. IOMUXC_GPIO_DISP_B2_02_ENET_TX_DATA00, /* GPIO_DISP_B2_02 PAD functional properties : */
  482. 0x02U); /* Slew Rate Field: Slow Slew Rate
  483. Drive Strength Field: high drive strength
  484. Pull / Keep Select Field: Pull Disable, Highz
  485. Pull Up / Down Config. Field: Weak pull down
  486. Open Drain Field: Disabled
  487. Domain write protection: Both cores are allowed
  488. Domain write protection lock: Neither of DWP bits is locked */
  489. IOMUXC_SetPinConfig(
  490. IOMUXC_GPIO_DISP_B2_03_ENET_TX_DATA01, /* GPIO_DISP_B2_03 PAD functional properties : */
  491. 0x02U); /* Slew Rate Field: Slow Slew Rate
  492. Drive Strength Field: high drive strength
  493. Pull / Keep Select Field: Pull Disable, Highz
  494. Pull Up / Down Config. Field: Weak pull down
  495. Open Drain Field: Disabled
  496. Domain write protection: Both cores are allowed
  497. Domain write protection lock: Neither of DWP bits is locked */
  498. IOMUXC_SetPinConfig(
  499. IOMUXC_GPIO_DISP_B2_04_ENET_TX_EN, /* GPIO_DISP_B2_04 PAD functional properties : */
  500. 0x02U); /* Slew Rate Field: Slow Slew Rate
  501. Drive Strength Field: high drive strength
  502. Pull / Keep Select Field: Pull Disable, Highz
  503. Pull Up / Down Config. Field: Weak pull down
  504. Open Drain Field: Disabled
  505. Domain write protection: Both cores are allowed
  506. Domain write protection lock: Neither of DWP bits is locked */
  507. IOMUXC_SetPinConfig(
  508. IOMUXC_GPIO_DISP_B2_05_ENET_REF_CLK, /* GPIO_DISP_B2_05 PAD functional properties : */
  509. 0x03U); /* Slew Rate Field: Fast Slew Rate
  510. Drive Strength Field: high drive strength
  511. Pull / Keep Select Field: Pull Disable, Highz
  512. Pull Up / Down Config. Field: Weak pull down
  513. Open Drain Field: Disabled
  514. Domain write protection: Both cores are allowed
  515. Domain write protection lock: Neither of DWP bits is locked */
  516. IOMUXC_SetPinConfig(
  517. IOMUXC_GPIO_DISP_B2_06_ENET_RX_DATA00, /* GPIO_DISP_B2_06 PAD functional properties : */
  518. 0x06U); /* Slew Rate Field: Slow Slew Rate
  519. Drive Strength Field: high drive strength
  520. Pull / Keep Select Field: Pull Enable
  521. Pull Up / Down Config. Field: Weak pull down
  522. Open Drain Field: Disabled
  523. Domain write protection: Both cores are allowed
  524. Domain write protection lock: Neither of DWP bits is locked */
  525. IOMUXC_SetPinConfig(
  526. IOMUXC_GPIO_DISP_B2_07_ENET_RX_DATA01, /* GPIO_DISP_B2_07 PAD functional properties : */
  527. 0x06U); /* Slew Rate Field: Slow Slew Rate
  528. Drive Strength Field: high drive strength
  529. Pull / Keep Select Field: Pull Enable
  530. Pull Up / Down Config. Field: Weak pull down
  531. Open Drain Field: Disabled
  532. Domain write protection: Both cores are allowed
  533. Domain write protection lock: Neither of DWP bits is locked */
  534. IOMUXC_SetPinConfig(
  535. IOMUXC_GPIO_DISP_B2_08_ENET_RX_EN, /* GPIO_DISP_B2_08 PAD functional properties : */
  536. 0x06U); /* Slew Rate Field: Slow Slew Rate
  537. Drive Strength Field: high drive strength
  538. Pull / Keep Select Field: Pull Enable
  539. Pull Up / Down Config. Field: Weak pull down
  540. Open Drain Field: Disabled
  541. Domain write protection: Both cores are allowed
  542. Domain write protection lock: Neither of DWP bits is locked */
  543. IOMUXC_SetPinConfig(
  544. IOMUXC_GPIO_DISP_B2_09_ENET_RX_ER, /* GPIO_DISP_B2_09 PAD functional properties : */
  545. 0x06U); /* Slew Rate Field: Slow Slew Rate
  546. Drive Strength Field: high drive strength
  547. Pull / Keep Select Field: Pull Enable
  548. Pull Up / Down Config. Field: Weak pull down
  549. Open Drain Field: Disabled
  550. Domain write protection: Both cores are allowed
  551. Domain write protection lock: Neither of DWP bits is locked */
  552. IOMUXC_SetPinConfig(
  553. IOMUXC_GPIO_LPSR_12_GPIO12_IO12, /* GPIO_LPSR_12 PAD functional properties : */
  554. 0x0EU); /* Slew Rate Field: Slow Slew Rate
  555. Drive Strength Field: high driver
  556. Pull / Keep Select Field: Pull Enable
  557. Pull Up / Down Config. Field: Weak pull up
  558. Open Drain LPSR Field: Disabled
  559. Domain write protection: Both cores are allowed
  560. Domain write protection lock: Neither of DWP bits is locked */
  561. }
  562. #endif
  563. void rt_hw_us_delay(rt_uint32_t us)
  564. {
  565. }
  566. void rt_hw_board_init()
  567. {
  568. BOARD_ConfigMPU();
  569. BOARD_InitPins();
  570. BOARD_BootClockRUN();
  571. NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_4);
  572. SysTick_Config(SystemCoreClock / RT_TICK_PER_SECOND);
  573. #ifdef BSP_USING_LPUART
  574. imxrt_uart_pins_init();
  575. #endif
  576. #ifdef RT_USING_HEAP
  577. rt_system_heap_init((void *)HEAP_BEGIN, (void *)HEAP_END);
  578. #endif
  579. #ifdef RT_USING_COMPONENTS_INIT
  580. rt_components_board_init();
  581. #endif
  582. #ifdef RT_USING_CONSOLE
  583. rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
  584. #endif
  585. #ifdef BSP_USING_SDIO
  586. imxrt_SDcard_pins_init();
  587. #endif
  588. #ifdef BSP_USING_ETH
  589. imxrt_eth_pins_init();
  590. #endif
  591. }