STM32 USART, UART and LPUART Referencing

This blog entry discusses way that the various UART types and their channels are referenced in the µTasker project.

The STM32 parts have various UART types as illustrated from the following comparison of four chips:
STM32F405: USART1, USART2, USART3, UART4, UART5, USART6, UART7, UART8
STM32L451: USART1, USART2, USART3, UART4, LPUART1
STM32L071: USART1, USART2, USART4, USART5, LPUART1
STM32L031: USART2, LPUART1

The first thing that is seen that the UARTs count for 1 upwards, which is typical of the referencing to channels as done by ST-Micro, whereas most manufacturers count peripheral instances from 0 upwards - which is also how they are refenced in µTasker project code.

USART and UART types are generally counted as a single type (notice that STM32F405 and STM32L451 have a UART4 whereby STM32L071 has a USART4 and also notice that the STM32F405 has 4 UARTs [4, 5, 6 and 7] add 4 USARTs [1, 2 3 and 6]) but LPUARTs are counted as a different type starting at LPUART1.

The referencing of these in the µTasker project start at 0 to keep global compatibility [µTasker UART channel 0 thus corresponds to USART1]. It keeps the same ordering as USART and UARTs and so the referencing of the STM32F405 U(S)ARTs are µTasker UART channels 0, 1, 2, 3, 4, 5, 6 and 7. LPUARTs, if present, are then attached to the end of these, which means that µTasker UART 4 corresponds to LPUART1 in the STM32L451.

The STM32L031 has a single USART but starts at USART2 (without there being a USART1 available). In such a case the micro;Tasker UART channels are counted 0, 1, 2 as follows: 0 is a dummy channel that can't be used (it doesn't occupy and code space and an attempt to use it will result in an exception in the micro;Tasker simulator or no operation on the HW target), 1 is USART2 and 2 is LPUART1. This results in more consistency as referencing USART2 and channel 0.

Similarly, the STM32L071 UARTs are counted 0 [USART1], 1 [USART2], 2 [dummy that can't be used], 3 [USART4], 4 [USART5], 5 [LPUART1]












Return to the STM32 landing page



µTasker STM32 Development. Copyright (c) 2004..2018 M.J.Butcher Consulting