Skip to content

Commit 5f50c3b

Browse files
committed
machine/samd51: add UART hardware flow control support
Signed-off-by: deadprogram <ron@hybridgroup.com>
1 parent 8858d49 commit 5f50c3b

File tree

1 file changed

+26
-6
lines changed

1 file changed

+26
-6
lines changed

src/machine/machine_atsamd51.go

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,14 +1015,14 @@ func (uart *UART) Configure(config UARTConfig) error {
10151015
if !ok {
10161016
return ErrInvalidOutputPin
10171017
}
1018-
var txPinOut uint32
1018+
var txPadOut uint32
10191019
// See CTRLA.RXPO bits of the SERCOM USART peripheral (page 945-946) for how
10201020
// pads are mapped to pinout values.
10211021
switch txPad {
10221022
case 0:
1023-
txPinOut = 0
1023+
txPadOut = 0
10241024
default:
1025-
// TODO: flow control (RTS/CTS)
1025+
// should be flow control (RTS/CTS) pin
10261026
return ErrInvalidOutputPin
10271027
}
10281028

@@ -1033,12 +1033,32 @@ func (uart *UART) Configure(config UARTConfig) error {
10331033
}
10341034
// As you can see in the CTRLA.RXPO bits of the SERCOM USART peripheral
10351035
// (page 945), input pins are mapped directly.
1036-
rxPinOut := rxPad
1036+
rxPadOut := rxPad
10371037

10381038
// configure pins
10391039
config.TX.Configure(PinConfig{Mode: txPinMode})
10401040
config.RX.Configure(PinConfig{Mode: rxPinMode})
10411041

1042+
// configure RTS/CTS pins if provided
1043+
if config.RTS != 0 && config.CTS != 0 {
1044+
rtsPinMode, _, ok := findPinPadMapping(uart.SERCOM, config.RTS)
1045+
if !ok {
1046+
return ErrInvalidOutputPin
1047+
}
1048+
1049+
ctsPinMode, _, ok := findPinPadMapping(uart.SERCOM, config.CTS)
1050+
if !ok {
1051+
return ErrInvalidInputPin
1052+
}
1053+
1054+
// See CTRLA.RXPO bits of the SERCOM USART peripheral (page 945-946) for how
1055+
// pads are mapped to pinout values.
1056+
txPadOut = 2
1057+
1058+
config.RTS.Configure(PinConfig{Mode: rtsPinMode})
1059+
config.CTS.Configure(PinConfig{Mode: ctsPinMode})
1060+
}
1061+
10421062
// reset SERCOM
10431063
uart.Bus.CTRLA.SetBits(sam.SERCOM_USART_INT_CTRLA_SWRST)
10441064
for uart.Bus.CTRLA.HasBits(sam.SERCOM_USART_INT_CTRLA_SWRST) ||
@@ -1075,8 +1095,8 @@ func (uart *UART) Configure(config UARTConfig) error {
10751095
// set UART pads. This is not same as pins...
10761096
// SERCOM_USART_CTRLA_TXPO(txPad) |
10771097
// SERCOM_USART_CTRLA_RXPO(rxPad);
1078-
uart.Bus.CTRLA.SetBits((txPinOut << sam.SERCOM_USART_INT_CTRLA_TXPO_Pos) |
1079-
(rxPinOut << sam.SERCOM_USART_INT_CTRLA_RXPO_Pos))
1098+
uart.Bus.CTRLA.SetBits((txPadOut << sam.SERCOM_USART_INT_CTRLA_TXPO_Pos) |
1099+
(rxPadOut << sam.SERCOM_USART_INT_CTRLA_RXPO_Pos))
10801100

10811101
// Enable Transceiver and Receiver
10821102
//sercom->USART.CTRLB.reg |= SERCOM_USART_CTRLB_TXEN | SERCOM_USART_CTRLB_RXEN ;

0 commit comments

Comments
 (0)