Merge pull request #1543 from dhalbert/atmel-uart-fix

Fix atmel UART after ASF4 pruning.
This commit is contained in:
Scott Shawcroft 2019-02-13 10:22:09 -08:00 committed by GitHub
commit 78f51792a7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 19 additions and 8 deletions

View File

@ -169,17 +169,28 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
// 0x1: RX pad 1 // 0x1: RX pad 1
// 0x2: RX pad 2 // 0x2: RX pad 2
// 0x3: RX pad 3 // 0x3: RX pad 3
sercom->USART.CTRLA.reg = SERCOM_USART_CTRLA_TXPO(tx_pad / 2) |
SERCOM_USART_CTRLA_RXPO(rx_pad) | // Doing a group mask and set of the registers saves 60 bytes over setting the bitfields individually.
(parity == PARITY_NONE ? 0 : SERCOM_USART_CTRLA_FORM(1));
sercom->USART.CTRLA.reg &= ~(SERCOM_USART_CTRLA_TXPO_Msk |
SERCOM_USART_CTRLA_RXPO_Msk |
SERCOM_USART_CTRLA_FORM_Msk);
sercom->USART.CTRLA.reg |= SERCOM_USART_CTRLA_TXPO(tx_pad / 2) |
SERCOM_USART_CTRLA_RXPO(rx_pad) |
(parity == PARITY_NONE ? 0 : SERCOM_USART_CTRLA_FORM(1));
// Enable tx and/or rx based on whether the pins were specified. // Enable tx and/or rx based on whether the pins were specified.
// CHSIZE is 0 for 8 bits, 5, 6, 7 for 5, 6, 7 bits. 1 for 9 bits, but we don't support that. // CHSIZE is 0 for 8 bits, 5, 6, 7 for 5, 6, 7 bits. 1 for 9 bits, but we don't support that.
sercom->USART.CTRLB.reg = (have_tx ? SERCOM_USART_CTRLB_TXEN : 0) | sercom->USART.CTRLB.reg &= ~(SERCOM_USART_CTRLB_TXEN |
(have_rx ? SERCOM_USART_CTRLB_RXEN : 0) | SERCOM_USART_CTRLB_RXEN |
(parity == PARITY_ODD ? SERCOM_USART_CTRLB_PMODE : 0) | SERCOM_USART_CTRLB_PMODE |
(stop > 1 ? SERCOM_USART_CTRLB_SBMODE : 0) | SERCOM_USART_CTRLB_SBMODE |
SERCOM_USART_CTRLB_CHSIZE(bits % 8); SERCOM_USART_CTRLB_CHSIZE_Msk);
sercom->USART.CTRLB.reg |= (have_tx ? SERCOM_USART_CTRLB_TXEN : 0) |
(have_rx ? SERCOM_USART_CTRLB_RXEN : 0) |
(parity == PARITY_ODD ? SERCOM_USART_CTRLB_PMODE : 0) |
(stop > 1 ? SERCOM_USART_CTRLB_SBMODE : 0) |
SERCOM_USART_CTRLB_CHSIZE(bits % 8);
// Set baud rate // Set baud rate
common_hal_busio_uart_set_baudrate(self, baudrate); common_hal_busio_uart_set_baudrate(self, baudrate);