MCPcopy Create free account
hub / github.com/kiibohd/controller / uart_serial_setup

Function uart_serial_setup

Bootloader/debug.c:94–166  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

92// ----- Functions -----
93
94void uart_serial_setup()
95{
96#if defined(_kinetis_)
97 // Setup the the UART interface for keyboard data input
98 SIM_SCGC4 |= SIM_SCGC4_UART; // Disable clock gating
99
100// Kiibohd-dfu
101#if defined(_kii_v2_)
102 // Pin Setup for UART2
103 PORTD_PCR3 = PORT_PCR_DSE | PORT_PCR_SRE | PORT_PCR_MUX(3); // TX Pin
104#elif defined(_kii_v1_)
105 // Pin Setup for UART0
106 PORTA_PCR2 = PORT_PCR_DSE | PORT_PCR_SRE | PORT_PCR_MUX(3); // TX Pin
107#endif
108
109
110#if defined(_kii_v2_) // UART2 Debug
111 // Setup baud rate - 115200 Baud
112 // Uses Bus Clock
113 // 36 MHz / ( 16 * Baud ) = BDH/L
114 // Baud: 115200 -> 36 MHz / ( 16 * 115200 ) = 19.53125
115 // Thus baud setting = 19
116 // NOTE: If finer baud adjustment is needed see UARTx_C4 -> BRFA in the datasheet
117 uint16_t baud = 19; // Max setting of 8191
118 UART_BDH = (uint8_t)(baud >> 8);
119 UART_BDL = (uint8_t)baud;
120 UART_C4 = 0x11;
121
122#elif defined(_kii_v1_)
123 // Setup baud rate - 115200 Baud
124 // 48 MHz / ( 16 * Baud ) = BDH/L
125 // Baud: 115200 -> 48 MHz / ( 16 * 115200 ) = 26.0416667
126 // Thus baud setting = 26
127 // NOTE: If finer baud adjustment is needed see UARTx_C4 -> BRFA in the datasheet
128 uint16_t baud = 26; // Max setting of 8191
129 UART_BDH = (uint8_t)(baud >> 8);
130 UART_BDL = (uint8_t)baud;
131 UART_C4 = 0x02;
132
133#endif
134
135 // 8 bit, No Parity, Idle Character bit after stop
136 UART_C1 = UART_C1_ILT;
137
138 // TX FIFO Enabled, TX FIFO Size 1 (Max 8 datawords)
139 // TX/RX FIFO Size:
140 // 0x0 - 1 dataword
141 // 0x1 - 4 dataword
142 // 0x2 - 8 dataword
143 UART_PFIFO = UART_PFIFO_TXFE;
144
145 // TX Enabled, RX Enabled, RX Interrupt Enabled, Generate idles
146 // UART_C2_TE UART_C2_RE UART_C2_RIE UART_C2_ILIE
147 UART_C2 = UART_C2_TE | UART_C2_ILIE;
148
149#elif defined(_sam_)
150 //Select Peripheral A for UART pins
151 UART_PIO->PIO_ABCDSR[0] &= ~((1 << UART_RX_PIN) | (1 << UART_TX_PIN));

Callers 1

mainFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…