Skip to content

Commit

Permalink
stm32f0: fixed bug in uart implementation
Browse files Browse the repository at this point in the history
alternate function register was written incorrectly for pin numbers > 8
+ cpu/stm32f0: fixed possible null-ptr deref
  • Loading branch information
michz committed Mar 2, 2016
1 parent 94c287c commit dfe5c27
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions cpu/stm32f0/periph/uart.c
Expand Up @@ -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 */
Expand Down

0 comments on commit dfe5c27

Please sign in to comment.