From dfe5c273d1bbe767c023af4eb20caa64aa39b925 Mon Sep 17 00:00:00 2001 From: Michael Zapf Date: Sat, 12 Sep 2015 18:51:23 +0200 Subject: [PATCH] stm32f0: fixed bug in uart implementation alternate function register was written incorrectly for pin numbers > 8 + cpu/stm32f0: fixed possible null-ptr deref --- cpu/stm32f0/periph/uart.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cpu/stm32f0/periph/uart.c b/cpu/stm32f0/periph/uart.c index cd1772a973..1343680d7c 100644 --- a/cpu/stm32f0/periph/uart.c +++ b/cpu/stm32f0/periph/uart.c @@ -122,16 +122,16 @@ int init_base(uart_t uart, uint32_t baudrate) port->AFR[0] |= af << (rx_pin * 4); } else { - port->AFR[1] &= ~(0xf << ((rx_pin - 16) * 4)); - port->AFR[1] |= af << ((rx_pin - 16) * 4); + port->AFR[1] &= ~(0xf << ((rx_pin - 8) * 4)); + port->AFR[1] |= af << ((rx_pin - 8) * 4); } if (tx_pin < 8) { port->AFR[0] &= ~(0xf << (tx_pin * 4)); port->AFR[0] |= af << (tx_pin * 4); } else { - port->AFR[1] &= ~(0xf << ((tx_pin - 16) * 4)); - port->AFR[1] |= af << ((tx_pin - 16) * 4); + port->AFR[1] &= ~(0xf << ((tx_pin - 8) * 4)); + port->AFR[1] |= af << ((tx_pin - 8) * 4); } /* configure UART to mode 8N1 with given baudrate */