@@ -134,6 +134,20 @@ void SerialUART::begin(unsigned long baud, uint16_t config) {
134134 _overflow = false ;
135135 _queue = new uint8_t [_fifoSize];
136136 _baud = baud;
137+
138+ _fcnTx = gpio_get_function (_tx);
139+ _fcnRx = gpio_get_function (_rx);
140+ gpio_set_function (_tx, GPIO_FUNC_UART);
141+ gpio_set_function (_rx, GPIO_FUNC_UART);
142+ if (_rts != UART_PIN_NOT_DEFINED) {
143+ _fcnRts = gpio_get_function (_rts);
144+ gpio_set_function (_rts, GPIO_FUNC_UART);
145+ }
146+ if (_cts != UART_PIN_NOT_DEFINED) {
147+ _fcnCts = gpio_get_function (_cts);
148+ gpio_set_function (_cts, GPIO_FUNC_UART);
149+ }
150+
137151 uart_init (_uart, baud);
138152 int bits, stop;
139153 uart_parity_t parity;
@@ -171,18 +185,6 @@ void SerialUART::begin(unsigned long baud, uint16_t config) {
171185 break ;
172186 }
173187 uart_set_format (_uart, bits, stop, parity);
174- _fcnTx = gpio_get_function (_tx);
175- _fcnRx = gpio_get_function (_rx);
176- gpio_set_function (_tx, GPIO_FUNC_UART);
177- gpio_set_function (_rx, GPIO_FUNC_UART);
178- if (_rts != UART_PIN_NOT_DEFINED) {
179- _fcnRts = gpio_get_function (_rts);
180- gpio_set_function (_rts, GPIO_FUNC_UART);
181- }
182- if (_cts != UART_PIN_NOT_DEFINED) {
183- _fcnCts = gpio_get_function (_cts);
184- gpio_set_function (_cts, GPIO_FUNC_UART);
185- }
186188 uart_set_hw_flow (_uart, _rts != UART_PIN_NOT_DEFINED, _cts != UART_PIN_NOT_DEFINED);
187189 _writer = 0 ;
188190 _reader = 0 ;
0 commit comments