Skip to content

Conversation

@chrismas9
Copy link
Contributor

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

@chrismas9
Copy link
Contributor Author

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.

@chrismas9
Copy link
Contributor Author

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.

@dpgeorge
Copy link
Member

dpgeorge commented Dec 9, 2019

Thanks for this.

LPUART1 is enabled as the next available UART after the standard U(S)ARTs.

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 machine.LPUART class because it's very stm32-specific. Maybe something like machine.UART('LP1') to select the low-power peripherals? Also need to think how the low-power functionality would be exposed, possibly just additional keyword args to .init().

@chrismas9
Copy link
Contributor Author

I don't think it makes sense to have a machine.LPUART class

I agree, I didn't want to make any changes to the UART class, that's why I did it this way.

Maybe something like machine.UART('LP1')

Good idea. Done

Also need to think how the low-power functionality would be exposed, possibly just additional keyword args to .init().

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.

mp_printf(print, "UART(%u)", self->uart_id);
#ifdef LPUART1
if (self->uart_id == PYB_LPUART_1) {
mp_printf(print, "UART('MP1')");
Copy link
Contributor

@H-Grobben H-Grobben Feb 1, 2021

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?

Copy link
Contributor Author

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

@H-Grobben
Copy link
Contributor

I will merge this with my G4 setup ( #6808 ), and also with our custom WB board, and try testing later this week.

@dpgeorge dpgeorge mentioned this pull request Feb 1, 2021
@dpgeorge
Copy link
Member

dpgeorge commented Feb 1, 2021

I still think naming the UART with "LP1" and "LP2" etc is the right approach (rather than numbering them after all other UARTs).

H-Grobben added a commit to AEMICS/micropython that referenced this pull request Feb 1, 2021
… 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
@H-Grobben
Copy link
Contributor

Tested succesfully it in our repo, only for G4 series Nucleo board:
AEMICS@ba929ae
(and some more commits for the checks for code formatting etc)
With this pull request, we don't need the additional wires on the Nucleo board!

@chrismas9
Copy link
Contributor Author

I still think naming the UART with "LP1" and "LP2" etc is the right approach (rather than numbering them after all other UARTs).

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 uart.h so the next number is used in the driver with 'LP1' handled as a special case. Implementing LPUART without using the next number would need more driver changes than I could do.

@chrismas9 chrismas9 force-pushed the LPUART branch 2 times, most recently from acd1f46 to d086bba Compare February 2, 2021 12:43
@chrismas9
Copy link
Contributor Author

Rebased, fixed typo 'MP1' -> 'LP1', updated code formatting

if (self->uart_id == PYB_LPUART_1) {
mp_printf(print, "UART('LP1')");
} else {
#endif
Copy link
Member

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(...);
}

#define MICROPY_HW_MAX_I2C (4)
#define MICROPY_HW_MAX_TIMER (17)
#define MICROPY_HW_MAX_UART (8)
#define MICROPY_HW_MAX_UART (9)
Copy link
Member

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]; \

PYB_LPUART_1 = 9,
#else
PYB_UART_9 = 9,
#endif
Copy link
Member

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

@chrismas9
Copy link
Contributor Author

Thanks for the review and suggestions. Once this is cleaned up I can add LPUART1 to mpconfigboard.h for some boards and update the docs.

@dpgeorge
Copy link
Member

@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.

@H-Grobben
Copy link
Contributor

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>
@dpgeorge
Copy link
Member

Thanks for updating the PR. Merged in 9d674cf with some minor changes:

  • fixed so it raises an exception creating an LP1 UART (without specifying a baudrate or any other params) if the TX/RX pins are not defined
  • reverted stray changes to some config values in mpconfigboard_common.h
  • made AF_FN_LPUART distinct from AF_FN_UART to avoid changing mp_hal_pin_config_alt

I also enabled LPUART1 on NUCLEO_WB55 in a separate commit, 03a64f2

@dpgeorge dpgeorge closed this Feb 21, 2021
@chrismas9 chrismas9 deleted the LPUART branch February 24, 2021 14:06
tannewt pushed a commit to tannewt/circuitpython that referenced this pull request Oct 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants