您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

HardwareSerial.cpp 16KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582
  1. #include "HardwareSerial.h"
  2. #include "core_pins.h"
  3. #include "Arduino.h"
  4. //#include "debug/printf.h"
  5. /*typedef struct {
  6. const uint32_t VERID;
  7. const uint32_t PARAM;
  8. volatile uint32_t GLOBAL;
  9. volatile uint32_t PINCFG;
  10. volatile uint32_t BAUD;
  11. volatile uint32_t STAT;
  12. volatile uint32_t CTRL;
  13. volatile uint32_t DATA;
  14. volatile uint32_t MATCH;
  15. volatile uint32_t MODIR;
  16. volatile uint32_t FIFO;
  17. volatile uint32_t WATER;
  18. } IMXRT_LPUART_t; */
  19. //. From Onewire utility files
  20. #define PIN_TO_BASEREG(pin) (portOutputRegister(pin))
  21. #define PIN_TO_BITMASK(pin) (digitalPinToBitMask(pin))
  22. #define IO_REG_TYPE uint32_t
  23. #define IO_REG_BASE_ATTR
  24. #define IO_REG_MASK_ATTR
  25. #define DIRECT_READ(base, mask) ((*((base)+2) & (mask)) ? 1 : 0)
  26. #define DIRECT_MODE_INPUT(base, mask) (*((base)+1) &= ~(mask))
  27. #define DIRECT_MODE_OUTPUT(base, mask) (*((base)+1) |= (mask))
  28. #define DIRECT_WRITE_LOW(base, mask) (*((base)+34) = (mask))
  29. #define DIRECT_WRITE_HIGH(base, mask) (*((base)+33) = (mask))
  30. #define UART_CLOCK 24000000
  31. #ifndef SERIAL1_TX_BUFFER_SIZE
  32. #define SERIAL1_TX_BUFFER_SIZE 64 // number of outgoing bytes to buffer
  33. #endif
  34. #ifndef SERIAL1_RX_BUFFER_SIZE
  35. #define SERIAL1_RX_BUFFER_SIZE 64 // number of incoming bytes to buffer
  36. #endif
  37. #ifndef SERIAL2_TX_BUFFER_SIZE
  38. #define SERIAL2_TX_BUFFER_SIZE 40 // number of outgoing bytes to buffer
  39. #endif
  40. #ifndef SERIAL2_RX_BUFFER_SIZE
  41. #define SERIAL2_RX_BUFFER_SIZE 64 // number of incoming bytes to buffer
  42. #endif
  43. #ifndef SERIAL3_TX_BUFFER_SIZE
  44. #define SERIAL3_TX_BUFFER_SIZE 40 // number of outgoing bytes to buffer
  45. #endif
  46. #ifndef SERIAL3_RX_BUFFER_SIZE
  47. #define SERIAL3_RX_BUFFER_SIZE 64 // number of incoming bytes to buffer
  48. #endif
  49. #ifndef SERIAL4_TX_BUFFER_SIZE
  50. #define SERIAL4_TX_BUFFER_SIZE 40 // number of outgoing bytes to buffer
  51. #endif
  52. #ifndef SERIAL4_RX_BUFFER_SIZE
  53. #define SERIAL4_RX_BUFFER_SIZE 64 // number of incoming bytes to buffer
  54. #endif
  55. #ifndef SERIAL5_TX_BUFFER_SIZE
  56. #define SERIAL5_TX_BUFFER_SIZE 40 // number of outgoing bytes to buffer
  57. #endif
  58. #ifndef SERIAL5_RX_BUFFER_SIZE
  59. #define SERIAL5_RX_BUFFER_SIZE 64 // number of incoming bytes to buffer
  60. #endif
  61. #ifndef SERIAL6_TX_BUFFER_SIZE
  62. #define SERIAL6_TX_BUFFER_SIZE 40 // number of outgoing bytes to buffer
  63. #endif
  64. #ifndef SERIAL6_RX_BUFFER_SIZE
  65. #define SERIAL6_RX_BUFFER_SIZE 64 // number of incoming bytes to buffer
  66. #endif
  67. #ifndef SERIAL7_TX_BUFFER_SIZE
  68. #define SERIAL7_TX_BUFFER_SIZE 40 // number of outgoing bytes to buffer
  69. #endif
  70. #ifndef SERIAL7_RX_BUFFER_SIZE
  71. #define SERIAL7_RX_BUFFER_SIZE 64 // number of incoming bytes to buffer
  72. #endif
  73. #ifndef SERIAL8_TX_BUFFER_SIZE
  74. #define SERIAL8_TX_BUFFER_SIZE 40 // number of outgoing bytes to buffer
  75. #endif
  76. #ifndef SERIAL8_RX_BUFFER_SIZE
  77. #define SERIAL8_RX_BUFFER_SIZE 64 // number of incoming bytes to buffer
  78. #endif
  79. #define IRQ_PRIORITY 64 // 0 = highest priority, 255 = lowest
  80. #define CTRL_ENABLE (LPUART_CTRL_TE | LPUART_CTRL_RE | LPUART_CTRL_RIE | LPUART_CTRL_ILIE)
  81. #define CTRL_TX_ACTIVE (CTRL_ENABLE | LPUART_CTRL_TIE)
  82. #define CTRL_TX_COMPLETING (CTRL_ENABLE | LPUART_CTRL_TCIE)
  83. #define CTRL_TX_INACTIVE CTRL_ENABLE
  84. void HardwareSerial::begin(uint32_t baud, uint8_t format)
  85. {
  86. //printf("HardwareSerial begin\n");
  87. float base = (float)UART_CLOCK / (float)baud;
  88. float besterr = 1e20;
  89. int bestdiv = 1;
  90. int bestosr = 4;
  91. for (int osr=4; osr <= 32; osr++) {
  92. float div = base / (float)osr;
  93. int divint = (int)(div + 0.5f);
  94. if (divint < 1) divint = 1;
  95. else if (divint > 8191) divint = 8191;
  96. float err = ((float)divint - div) / div;
  97. if (err < 0.0f) err = -err;
  98. if (err <= besterr) {
  99. besterr = err;
  100. bestdiv = divint;
  101. bestosr = osr;
  102. }
  103. }
  104. //printf(" baud %d: osr=%d, div=%d\n", baud, bestosr, bestdiv);
  105. rx_buffer_head_ = 0;
  106. rx_buffer_tail_ = 0;
  107. tx_buffer_head_ = 0;
  108. tx_buffer_tail_ = 0;
  109. transmitting_ = 0;
  110. hardware->ccm_register |= hardware->ccm_value;
  111. uint32_t fastio = IOMUXC_PAD_SRE | IOMUXC_PAD_DSE(3) | IOMUXC_PAD_SPEED(3);
  112. *(portControlRegister(hardware->rx_pin)) = fastio;
  113. *(portControlRegister(hardware->tx_pin)) = fastio;
  114. *(portConfigRegister(hardware->rx_pin)) = hardware->rx_mux_val;
  115. *(portConfigRegister(hardware->tx_pin)) = hardware->tx_mux_val;
  116. //hardware->rx_mux_register = hardware->rx_mux_val;
  117. //hardware->tx_mux_register = hardware->tx_mux_val;
  118. hardware->rx_select_input_register = hardware->rx_select_val;
  119. port->BAUD = LPUART_BAUD_OSR(bestosr - 1) | LPUART_BAUD_SBR(bestdiv);
  120. port->PINCFG = 0;
  121. // Enable the transmitter, receiver and enable receiver interrupt
  122. attachInterruptVector(hardware->irq, hardware->irq_handler);
  123. NVIC_SET_PRIORITY(hardware->irq, IRQ_PRIORITY); // maybe should put into hardware...
  124. NVIC_ENABLE_IRQ(hardware->irq);
  125. uint16_t tx_fifo_size = (((port->FIFO >> 4) & 0x7) << 2);
  126. uint8_t tx_water = (tx_fifo_size < 16) ? tx_fifo_size >> 1 : 7;
  127. uint16_t rx_fifo_size = (((port->FIFO >> 0) & 0x7) << 2);
  128. uint8_t rx_water = (rx_fifo_size < 16) ? rx_fifo_size >> 1 : 7;
  129. /*
  130. Serial.printf("SerialX::begin stat:%x ctrl:%x fifo:%x water:%x\n", port->STAT, port->CTRL, port->FIFO, port->WATER );
  131. Serial.printf(" FIFO sizes: tx:%d rx:%d\n",tx_fifo_size, rx_fifo_size);
  132. Serial.printf(" Watermark tx:%d, rx: %d\n", tx_water, rx_water);
  133. */
  134. port->WATER = LPUART_WATER_RXWATER(rx_water) | LPUART_WATER_TXWATER(tx_water);
  135. port->FIFO |= LPUART_FIFO_TXFE | LPUART_FIFO_RXFE;
  136. port->CTRL = CTRL_TX_INACTIVE;
  137. //Serial.printf(" stat:%x ctrl:%x fifo:%x water:%x\n", port->STAT, port->CTRL, port->FIFO, port->WATER );
  138. };
  139. void HardwareSerial::end(void)
  140. {
  141. }
  142. void HardwareSerial::transmitterEnable(uint8_t pin)
  143. {
  144. while (transmitting_) ;
  145. pinMode(pin, OUTPUT);
  146. transmit_pin_baseReg_ = PIN_TO_BASEREG(pin);
  147. transmit_pin_bitmask_ = PIN_TO_BITMASK(pin);
  148. DIRECT_WRITE_LOW(transmit_pin_baseReg_, transmit_pin_bitmask_);
  149. }
  150. void HardwareSerial::setRX(uint8_t pin)
  151. {
  152. // BUGBUG Implement
  153. //Serial.printf("SerialX TX(%d) param:%x stat:%x ctrl:%x fifo:%x water:%x\n", hardware->tx_pin, port->PARAM, port->STAT, port->CTRL, port->FIFO, port->WATER );
  154. }
  155. void HardwareSerial::setTX(uint8_t pin, bool opendrain)
  156. {
  157. // BUGBUG Implement
  158. }
  159. bool HardwareSerial::attachRts(uint8_t pin)
  160. {
  161. // BUGBUG Implement
  162. return false;
  163. }
  164. bool HardwareSerial::attachCts(uint8_t pin)
  165. {
  166. // BUGBUG Implement
  167. return false;
  168. }
  169. void HardwareSerial::clear(void)
  170. {
  171. // BUGBUG:: deal with FIFO
  172. rx_buffer_head_ = rx_buffer_tail_;
  173. //if (rts_pin_) rts_assert();
  174. }
  175. int HardwareSerial::availableForWrite(void)
  176. {
  177. uint32_t head, tail;
  178. head = tx_buffer_head_;
  179. tail = tx_buffer_tail_;
  180. if (head >= tail) return tx_buffer_total_size_ - 1 - head + tail;
  181. return tail - head - 1;
  182. }
  183. size_t HardwareSerial::write9bit(uint32_t c)
  184. {
  185. return 0;
  186. }
  187. int HardwareSerial::available(void)
  188. {
  189. uint32_t head, tail;
  190. head = rx_buffer_head_;
  191. tail = rx_buffer_tail_;
  192. if (head >= tail) return head - tail;
  193. return rx_buffer_total_size_ + head - tail;
  194. }
  195. int HardwareSerial::peek(void)
  196. {
  197. uint32_t head, tail;
  198. head = rx_buffer_head_;
  199. tail = rx_buffer_tail_;
  200. if (head == tail) return -1;
  201. if (++tail >= rx_buffer_total_size_) tail = 0;
  202. if (tail < rx_buffer_size_) {
  203. return rx_buffer_[tail];
  204. } else {
  205. return rx_buffer_storage_[tail-rx_buffer_size_];
  206. }
  207. }
  208. int HardwareSerial::read(void)
  209. {
  210. uint32_t head, tail;
  211. int c;
  212. head = rx_buffer_head_;
  213. tail = rx_buffer_tail_;
  214. if (head == tail) return -1;
  215. if (++tail >= rx_buffer_total_size_) tail = 0;
  216. if (tail < rx_buffer_size_) {
  217. c = rx_buffer_[tail];
  218. } else {
  219. c = rx_buffer_storage_[tail-rx_buffer_size_];
  220. }
  221. rx_buffer_tail_ = tail;
  222. if (rts_pin_) {
  223. uint32_t avail;
  224. if (head >= tail) avail = head - tail;
  225. else avail = rx_buffer_total_size_ + head - tail;
  226. /*
  227. if (avail <= rts_low_watermark_) rts_assert();
  228. */
  229. }
  230. return c;
  231. }
  232. void HardwareSerial::flush(void)
  233. {
  234. while (transmitting_) yield(); // wait
  235. }
  236. size_t HardwareSerial::write(uint8_t c)
  237. {
  238. uint32_t head, n;
  239. //digitalWrite(3, HIGH);
  240. //digitalWrite(5, HIGH);
  241. if (transmit_pin_baseReg_) DIRECT_WRITE_HIGH(transmit_pin_baseReg_, transmit_pin_bitmask_);
  242. head = tx_buffer_head_;
  243. if (++head >= tx_buffer_total_size_) head = 0;
  244. while (tx_buffer_tail_ == head) {
  245. /*
  246. int priority = nvic_execution_priority();
  247. if (priority <= IRQ_PRIORITY) {
  248. if ((port->STAT & LPUART_STAT_TDRE)) {
  249. uint32_t tail = tx_buffer_tail_;
  250. if (++tail >= tx_buffer_total_size_) tail = 0;
  251. if (tail < tx_buffer_size_) {
  252. n = tx_buffer_[tail];
  253. } else {
  254. n = tx_buffer_storage_[tail-tx_buffer_size_];
  255. }
  256. port->DATA = n;
  257. tx_buffer_tail_ = tail;
  258. }
  259. } else if (priority >= 256)
  260. */
  261. {
  262. yield(); // wait
  263. }
  264. }
  265. //digitalWrite(5, LOW);
  266. //Serial.printf("WR %x %d %d %d %x %x\n", c, head, tx_buffer_size_, tx_buffer_total_size_, (uint32_t)tx_buffer_, (uint32_t)tx_buffer_storage_);
  267. if (head < tx_buffer_size_) {
  268. tx_buffer_[head] = c;
  269. } else {
  270. tx_buffer_storage_[head - tx_buffer_size_] = c;
  271. }
  272. transmitting_ = 1;
  273. tx_buffer_head_ = head;
  274. port->CTRL |= LPUART_CTRL_TIE; // (may need to handle this issue)BITBAND_SET_BIT(LPUART0_CTRL, TIE_BIT);
  275. //digitalWrite(3, LOW);
  276. return 1;
  277. }
  278. void HardwareSerial::IRQHandler()
  279. {
  280. //digitalWrite(4, HIGH);
  281. uint32_t head, tail, n;
  282. uint32_t ctrl;
  283. // See if we have stuff to read in.
  284. // Todo - Check idle.
  285. if (port->STAT & (LPUART_STAT_RDRF | LPUART_STAT_IDLE)) {
  286. // See how many bytes or pending.
  287. //digitalWrite(5, HIGH);
  288. uint8_t avail = (port->WATER >> 24) & 0x7;
  289. if (avail) {
  290. uint32_t newhead;
  291. head = rx_buffer_head_;
  292. tail = rx_buffer_tail_;
  293. do {
  294. #if 1
  295. n = port->DATA; // get the byte...
  296. #else
  297. if (use9Bits_ && (port().C3 & 0x80)) {
  298. n = port().D | 0x100;
  299. } else {
  300. n = port().D;
  301. }
  302. #endif
  303. newhead = head + 1;
  304. if (newhead >= rx_buffer_total_size_) newhead = 0;
  305. if (newhead != rx_buffer_tail_) {
  306. head = newhead;
  307. if (newhead < rx_buffer_size_) {
  308. rx_buffer_[head] = n;
  309. } else {
  310. rx_buffer_storage_[head-rx_buffer_size_] = n;
  311. }
  312. }
  313. } while (--avail > 0) ;
  314. rx_buffer_head_ = head;
  315. }
  316. // If it was an idle status clear the idle
  317. if (port->STAT & LPUART_STAT_IDLE) {
  318. port->STAT |= LPUART_STAT_IDLE; // writing a 1 to idle should clear it.
  319. }
  320. //digitalWrite(5, LOW);
  321. }
  322. // See if we are transmitting and room in buffer.
  323. ctrl = port->CTRL;
  324. if ((ctrl & LPUART_CTRL_TIE) && (port->STAT & LPUART_STAT_TDRE))
  325. {
  326. //digitalWrite(3, HIGH);
  327. head = tx_buffer_head_;
  328. tail = tx_buffer_tail_;
  329. do {
  330. if (head == tail) break;
  331. if (++tail >= tx_buffer_total_size_) tail = 0;
  332. if (tail < tx_buffer_size_) {
  333. n = tx_buffer_[tail];
  334. } else {
  335. n = tx_buffer_storage_[tail-tx_buffer_size_];
  336. }
  337. //if (use9Bits_) port().C3 = (port().C3 & ~0x40) | ((n & 0x100) >> 2);
  338. port->DATA = n;
  339. } while (((port->WATER >> 8) & 0x7) < 4); // need to computer properly
  340. tx_buffer_tail_ = tail;
  341. if (head == tail) port->CTRL = CTRL_TX_COMPLETING;
  342. //digitalWrite(3, LOW);
  343. }
  344. if ((ctrl & LPUART_CTRL_TCIE) && (port->STAT & LPUART_STAT_TC))
  345. {
  346. transmitting_ = 0;
  347. if (transmit_pin_baseReg_) DIRECT_WRITE_LOW(transmit_pin_baseReg_, transmit_pin_bitmask_);
  348. port->CTRL = CTRL_TX_INACTIVE;
  349. }
  350. //digitalWrite(4, LOW);
  351. }
  352. void IRQHandler_Serial1()
  353. {
  354. Serial1.IRQHandler();
  355. }
  356. void IRQHandler_Serial2()
  357. {
  358. Serial2.IRQHandler();
  359. }
  360. void IRQHandler_Serial3()
  361. {
  362. Serial3.IRQHandler();
  363. }
  364. void IRQHandler_Serial4()
  365. {
  366. Serial4.IRQHandler();
  367. }
  368. void IRQHandler_Serial5()
  369. {
  370. Serial5.IRQHandler();
  371. }
  372. void IRQHandler_Serial6()
  373. {
  374. Serial6.IRQHandler();
  375. }
  376. void IRQHandler_Serial7()
  377. {
  378. Serial7.IRQHandler();
  379. }
  380. void IRQHandler_Serial8()
  381. {
  382. Serial8.IRQHandler();
  383. }
  384. // Serial1
  385. static BUFTYPE tx_buffer1[SERIAL1_TX_BUFFER_SIZE];
  386. static BUFTYPE rx_buffer1[SERIAL1_RX_BUFFER_SIZE];
  387. const HardwareSerial::hardware_t UART6_Hardware = {
  388. IRQ_LPUART6, &IRQHandler_Serial1,
  389. CCM_CCGR3, CCM_CCGR3_LPUART6(CCM_CCGR_ON),
  390. 0, //IOMUXC_SW_MUX_CTL_PAD_GPIO_AD_B0_03, // pin 0
  391. 1, //IOMUXC_SW_MUX_CTL_PAD_GPIO_AD_B0_02, // pin 1
  392. IOMUXC_LPUART6_RX_SELECT_INPUT,
  393. 2, // page 473
  394. 2, // page 472
  395. 1, // page 861
  396. };
  397. HardwareSerial Serial1(&IMXRT_LPUART6, &UART6_Hardware, tx_buffer1, SERIAL1_TX_BUFFER_SIZE,
  398. rx_buffer1, SERIAL1_RX_BUFFER_SIZE);
  399. // Serial2
  400. static BUFTYPE tx_buffer2[SERIAL2_TX_BUFFER_SIZE];
  401. static BUFTYPE rx_buffer2[SERIAL2_RX_BUFFER_SIZE];
  402. static HardwareSerial::hardware_t UART4_Hardware = {
  403. IRQ_LPUART4, &IRQHandler_Serial2,
  404. CCM_CCGR1, CCM_CCGR1_LPUART4(CCM_CCGR_ON),
  405. 6, //IOMUXC_SW_MUX_CTL_PAD_GPIO_B1_01, // pin 6
  406. 7, // IOMUXC_SW_MUX_CTL_PAD_GPIO_B1_00, // pin 7
  407. IOMUXC_LPUART4_RX_SELECT_INPUT,
  408. 2, // page 521
  409. 2, // page 520
  410. 2, // page 858
  411. };
  412. HardwareSerial Serial2(&IMXRT_LPUART4, &UART4_Hardware, tx_buffer2, SERIAL2_TX_BUFFER_SIZE,
  413. rx_buffer2, SERIAL2_RX_BUFFER_SIZE);
  414. // Serial3
  415. static BUFTYPE tx_buffer3[SERIAL3_TX_BUFFER_SIZE];
  416. static BUFTYPE rx_buffer3[SERIAL3_RX_BUFFER_SIZE];
  417. static HardwareSerial::hardware_t UART2_Hardware = {
  418. IRQ_LPUART2, &IRQHandler_Serial3,
  419. CCM_CCGR0, CCM_CCGR0_LPUART2(CCM_CCGR_ON),
  420. 15, //IOMUXC_SW_MUX_CTL_PAD_GPIO_AD_B1_03, // pin 15
  421. 14, //IOMUXC_SW_MUX_CTL_PAD_GPIO_AD_B1_02, // pin 14
  422. IOMUXC_LPUART2_RX_SELECT_INPUT,
  423. 2, // page 491
  424. 2, // page 490
  425. 1, // Page 855
  426. };
  427. HardwareSerial Serial3(&IMXRT_LPUART2, &UART2_Hardware,tx_buffer3, SERIAL3_TX_BUFFER_SIZE,
  428. rx_buffer3, SERIAL3_RX_BUFFER_SIZE);
  429. // Serial4
  430. static BUFTYPE tx_buffer4[SERIAL4_TX_BUFFER_SIZE];
  431. static BUFTYPE rx_buffer4[SERIAL4_RX_BUFFER_SIZE];
  432. static HardwareSerial::hardware_t UART3_Hardware = {
  433. IRQ_LPUART3, &IRQHandler_Serial4,
  434. CCM_CCGR0, CCM_CCGR0_LPUART3(CCM_CCGR_ON),
  435. 16, //IOMUXC_SW_MUX_CTL_PAD_GPIO_AD_B1_07, // pin 16
  436. 17, //IOMUXC_SW_MUX_CTL_PAD_GPIO_AD_B1_06, // pin 17
  437. IOMUXC_LPUART3_RX_SELECT_INPUT,
  438. 2, // page 495
  439. 2, // page 494
  440. 0, // Page 857
  441. };
  442. HardwareSerial Serial4(&IMXRT_LPUART3, &UART3_Hardware, tx_buffer4, SERIAL4_TX_BUFFER_SIZE,
  443. rx_buffer4, SERIAL4_RX_BUFFER_SIZE);
  444. // Serial5
  445. static BUFTYPE tx_buffer5[SERIAL5_TX_BUFFER_SIZE];
  446. static BUFTYPE rx_buffer5[SERIAL5_RX_BUFFER_SIZE];
  447. static HardwareSerial::hardware_t UART8_Hardware = {
  448. IRQ_LPUART8, &IRQHandler_Serial5,
  449. CCM_CCGR6, CCM_CCGR6_LPUART8(CCM_CCGR_ON),
  450. 21, //IOMUXC_SW_MUX_CTL_PAD_GPIO_AD_B1_11, // pin 21
  451. 20, //IOMUXC_SW_MUX_CTL_PAD_GPIO_AD_B1_10, // pin 20
  452. IOMUXC_LPUART8_RX_SELECT_INPUT,
  453. 2, // page 499
  454. 2, // page 498
  455. 1, // Page 864-5
  456. };
  457. HardwareSerial Serial5(&IMXRT_LPUART8, &UART8_Hardware, tx_buffer5, SERIAL5_TX_BUFFER_SIZE,
  458. rx_buffer5, SERIAL5_RX_BUFFER_SIZE);
  459. // Serial6
  460. static BUFTYPE tx_buffer6[SERIAL6_TX_BUFFER_SIZE];
  461. static BUFTYPE rx_buffer6[SERIAL6_RX_BUFFER_SIZE];
  462. uint32_t IOMUXC_LPUART1_RX_SELECT_INPUT; // bugbug - does not exist so hack
  463. static HardwareSerial::hardware_t UART1_Hardware = {
  464. IRQ_LPUART1, &IRQHandler_Serial6,
  465. CCM_CCGR5, CCM_CCGR5_LPUART1(CCM_CCGR_ON),
  466. 25, //IOMUXC_SW_MUX_CTL_PAD_GPIO_AD_B0_13, // pin 25
  467. 24, //IOMUXC_SW_MUX_CTL_PAD_GPIO_AD_B0_12, // pin 24
  468. IOMUXC_LPUART1_RX_SELECT_INPUT,
  469. 2, // page 486
  470. 2, // page 485
  471. 0, // ??? Does not have one ???
  472. };
  473. HardwareSerial Serial6(&IMXRT_LPUART1, &UART1_Hardware, tx_buffer6, SERIAL6_TX_BUFFER_SIZE,
  474. rx_buffer6, SERIAL6_RX_BUFFER_SIZE);
  475. // Serial7
  476. static BUFTYPE tx_buffer7[SERIAL7_TX_BUFFER_SIZE];
  477. static BUFTYPE rx_buffer7[SERIAL7_RX_BUFFER_SIZE];
  478. static HardwareSerial::hardware_t UART7_Hardware = {
  479. IRQ_LPUART7, &IRQHandler_Serial7,
  480. CCM_CCGR5, CCM_CCGR5_LPUART7(CCM_CCGR_ON),
  481. 28, //IOMUXC_SW_MUX_CTL_PAD_GPIO_EMC_32, // pin 28
  482. 29, //IOMUXC_SW_MUX_CTL_PAD_GPIO_EMC_31, // pin 29
  483. IOMUXC_LPUART7_RX_SELECT_INPUT,
  484. 2, // page 458
  485. 2, // page 457
  486. 1, // Page 863
  487. };
  488. HardwareSerial Serial7(&IMXRT_LPUART7, &UART7_Hardware, tx_buffer7, SERIAL7_TX_BUFFER_SIZE,
  489. rx_buffer7, SERIAL7_RX_BUFFER_SIZE);
  490. // Serial8
  491. static BUFTYPE tx_buffer8[SERIAL8_TX_BUFFER_SIZE];
  492. static BUFTYPE rx_buffer8[SERIAL8_RX_BUFFER_SIZE];
  493. static HardwareSerial::hardware_t UART5_Hardware = {
  494. IRQ_LPUART5, &IRQHandler_Serial8,
  495. CCM_CCGR3, CCM_CCGR3_LPUART5(CCM_CCGR_ON),
  496. 30, //IOMUXC_SW_MUX_CTL_PAD_GPIO_EMC_24, // pin 30
  497. 31, // IOMUXC_SW_MUX_CTL_PAD_GPIO_EMC_23, // pin 31
  498. IOMUXC_LPUART5_RX_SELECT_INPUT,
  499. 2, // page 450
  500. 2, // page 449
  501. 0,
  502. };
  503. HardwareSerial Serial8(&IMXRT_LPUART5, &UART5_Hardware, tx_buffer8, SERIAL8_TX_BUFFER_SIZE,
  504. rx_buffer8, SERIAL8_RX_BUFFER_SIZE);