@@ -171,12 +171,16 @@ void SerialUART::begin(unsigned long baud, uint16_t config) {
171171 break ;
172172 }
173173 uart_set_format (_uart, bits, stop, parity);
174+ _fcnTx = gpio_get_function (_tx);
175+ _fcnRx = gpio_get_function (_rx);
174176 gpio_set_function (_tx, GPIO_FUNC_UART);
175177 gpio_set_function (_rx, GPIO_FUNC_UART);
176178 if (_rts != UART_PIN_NOT_DEFINED) {
179+ _fcnRts = gpio_get_function (_rts);
177180 gpio_set_function (_rts, GPIO_FUNC_UART);
178181 }
179182 if (_cts != UART_PIN_NOT_DEFINED) {
183+ _fcnCts = gpio_get_function (_cts);
180184 gpio_set_function (_cts, GPIO_FUNC_UART);
181185 }
182186 uart_set_hw_flow (_uart, _rts != UART_PIN_NOT_DEFINED, _cts != UART_PIN_NOT_DEFINED);
@@ -211,6 +215,7 @@ void SerialUART::end() {
211215 irq_set_enabled (UART1_IRQ, false );
212216 }
213217 }
218+
214219 // Paranoia - ensure nobody else is using anything here at the same time
215220 mutex_enter_blocking (&_mutex);
216221 mutex_enter_blocking (&_fifoMutex);
@@ -219,6 +224,16 @@ void SerialUART::end() {
219224 // Reset the mutexes once all is off/cleaned up
220225 mutex_exit (&_fifoMutex);
221226 mutex_exit (&_mutex);
227+
228+ // Restore pin functions
229+ gpio_set_function (_tx, _fcnTx);
230+ gpio_set_function (_rx, _fcnRx);
231+ if (_rts != UART_PIN_NOT_DEFINED) {
232+ gpio_set_function (_rts, _fcnRts);
233+ }
234+ if (_cts != UART_PIN_NOT_DEFINED) {
235+ gpio_set_function (_cts, _fcnCts);
236+ }
222237}
223238
224239void SerialUART::_pumpFIFO () {
0 commit comments