-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
stm32/uart: Add support for LPUART1 on L0, L4, H7 and WB MCUs. #5396
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Motivation for this PR was changing from F030 to L073 to get EEPROM. L073 does not have USART3, but has LPUART1 on same pin (PB10/11). It also adds a user UART to NUCLEO_WB55 which uses its only USART for REPL. Gives more pin choices for UART when normal UARTS unavailable due to other use of pins for I2C, ADC, Eth, etc. Testing: LPUART1 as UART(6) tested with external loopbak and baud rate check on NUCLEO_L073RZ and NUCLEO_L452RE. Flow control not tested. I don't have hardware to test WB55 or H7. Checked UASART6 as UART(6) on PYBV3. NUCLEO_WB55 and NUCLEO_H743ZI ports compile with LPUART1 enabled. PYBV3 and NUCLEO_F767ZI compile without error. Review of all register differences between U(S)ART and LPUART. Code inspection of all direct access to STM32 registers. Handle difference in buadrate (BRR register). There are several interrupt enables in CR1 and CR2 not implemented in LPUART. These must be kept at reset state (0). They are defined, but only cleared, so have not changed the code. |
|
I have another PR coming to reduce size of L073 port. Then I will update mpconfigport.h for various boards to enable the extra UARTs - LPUART1 and UASART4/5 on L0. |
|
Thanks for this.
I'm not sure this is the right approach because it could get confusing with what the last normal UART number is (the STM32's have a big range in available UARTs). I don't think it makes sense to have a |
I agree, I didn't want to make any changes to the UART class, that's why I did it this way.
Good idea. Done
I think the only low power feature that would be useful is to set the clock to 32kHz (9600 buad max) and enable wake on interrupt. I don't have a need of this and I don't know how popular it would be. I am not sure I would be confident implementing this. |
ports/stm32/machine_uart.c
Outdated
| mp_printf(print, "UART(%u)", self->uart_id); | ||
| #ifdef LPUART1 | ||
| if (self->uart_id == PYB_LPUART_1) { | ||
| mp_printf(print, "UART('MP1')"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be LP1, or LPUART1?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it should be 'LP1", also line 182. I will review, rebase and retest this week
|
I will merge this with my G4 setup ( #6808 ), and also with our custom WB board, and try testing later this week. |
|
I still think naming the UART with |
… micopython specifies MICROPY_HW_MAX_UART in mpconfigboard_common.h (is max also max number of uarts, or is it related to internal UART numbering (e.g. [UART1, UART2, UART3, UART6] -> max = 6?) All credits go to @christmas9 for pull request micropython#5396
|
Tested succesfully it in our repo, only for G4 series Nucleo board: |
Yes, I agree now, especially if low power features are added later, in which case 'LP1', etc identify that these UARTs are different. The UARTs are enumerated in |
acd1f46 to
d086bba
Compare
|
Rebased, fixed typo 'MP1' -> 'LP1', updated code formatting |
| if (self->uart_id == PYB_LPUART_1) { | ||
| mp_printf(print, "UART('LP1')"); | ||
| } else { | ||
| #endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
simpler to use the following pattern:
#ifdef LPUART1
if (...) {
} else
#endif
{
mp_printf(...);
}
ports/stm32/mpconfigboard_common.h
Outdated
| #define MICROPY_HW_MAX_I2C (4) | ||
| #define MICROPY_HW_MAX_TIMER (17) | ||
| #define MICROPY_HW_MAX_UART (8) | ||
| #define MICROPY_HW_MAX_UART (9) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
might be clearer to do something like this:
#define MICROPY_HW_MAX_LPUART (1)
#define MICROPY_HW_MAX_UART (8)(ie last line there unchanged), and then in mpconfigport.h:
struct _pyb_uart_obj_t *pyb_uart_obj_all[MICROPY_HW_MAX_UART + MICROPY_HW_MAX_LPUART]; \
ports/stm32/uart.h
Outdated
| PYB_LPUART_1 = 9, | ||
| #else | ||
| PYB_UART_9 = 9, | ||
| #endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all this could be simplified to:
#ifdef LPUART1
PYB_LPUART_1 = MICROPY_HW_MAX_UART,
#endif|
Thanks for the review and suggestions. Once this is cleaned up I can add LPUART1 to |
|
@chrismas9 I'd like to merge this before the STM32G4 addition. If you can't get to updating the PR just let me know and I can do it. |
|
I've added this into the STM32G4 (#6911), but it would also apply to other families of the STM32, just didn't test it, as I don't have the hardware to test it. I did build all STM32 families (ci script nucleo and pyb boards) |
Add LPUART1 as a standard UART. No low power features are supported.
LPUART1 is enabled as the next available UART after the standard U(S)ARTs.
STM32WB: LPUART1 = UART(2)
STM32L0: LPUART1 = UART(6)
STM32L4: LPUART1 = UART(6)
STM32H7: LPUART1 = UART(9)
or all ports: LPUART1 = UART('LP1')
LPUART1 is enabled by defining MICROPY_HW_LPUART1_TX
and MICROPY_HW_LPUART1_RX in mpconfigboard.h
Signed-off-by: Chris Mason <c.mason@inchipdesign.com.au>
|
Thanks for updating the PR. Merged in 9d674cf with some minor changes:
I also enabled LPUART1 on NUCLEO_WB55 in a separate commit, 03a64f2 |
Fix a critical "typo"
Add LPUART1 as a standard UART. No low power features are supported.
LPUART1 is enabled as the next available UART after the standard U(S)ARTs.
STM32WB: LPUART1 = UART(2)
STM32L0: LPUART1 = UART(6)
STM32L4: LPUART1 = UART(6)
STM32H7: LPUART1 = UART(9)
LPUART1 is enabled by defining MICROPY_HW_LPUART1_TX and MICROPY_HW_LPUART1_RX in mpconfigboard.h