Enable Advanced UART Features (Swap, RXInvert, TXInvert)

Dear forum,
is there any way to enable advanced UART features e.g., (SwapTXRX, RXInvert, TXInvert) from within micropython or by changing certain flags in the source code (and then cross-compile and flash new firmware). Board OpenMV3 (STM32F7xxxx). I’ve seen that these flags are available in the HAL definitions, but I don’t know how to activate them. In previous firmware versions it seems that the MAPPING of UART3_TX to GPIO_10 was hard coded in some config file and was now refactored.

Kind regards
Chris

Yes, use the stm.mem32[] feature. This lets you read/write SRAM memory locations directly.

e.g.

Many thanks. That is helpful. It seems that I can’t write these registers. Is there something I need to enable first?

Test-Code:

def print_uart_registers(label):
    print(label,
          " CR1: ", stm.mem32[stm.USART3 + stm.USART_CR1],
          " CR2: ", stm.mem32[stm.USART3 + stm.USART_CR2],
          " BRR: ", stm.mem32[stm.USART3 + stm.USART_BRR])

def set_TXRX_swap():
    stm.mem32[stm.USART3 + stm.USART_CR2] = stm.mem32[stm.USART3 + stm.USART_CR2] | (1 << 15)

print_uart_registers("UART not created     ")
set_TXRX_swap()
print_uart_registers("VerifySetSwap        ")
baud = 115200
uart = machine.UART(3, baud)
print_uart_registers("UART instance 115200 ")
set_TXRX_swap()
print_uart_registers("VerifySetSwap        ")
uart.init(9600, timeout_char=100, rxbuf=2500, parity=None)
print_uart_registers("UART initialized 9600")
set_TXRX_swap()
print_uart_registers("VerifySetSwap        ")

UART not created CR1: 0 CR2: 0 BRR: 0
VerifySetSwap CR1: 0 CR2: 0 BRR: 0
UART instance 115200 CR1: 45 CR2: 0 BRR: 469
VerifySetSwap CR1: 45 CR2: 0 BRR: 469
UART initialized 9600 CR1: 45 CR2: 0 BRR: 5625
VerifySetSwap CR1: 45 CR2: 0 BRR: 5625

No matter, when I set the register CR2, it keeps being at 0

I mean one could hard code this into:

But I would rather have it on micropython level and not “fork” the firmware

You need to enable the UART via the RCC reg.

I’d import the module first, init it, and then apply your custom changes. There are a lot of other registers you have to setup first.

Many thanks. Activating the register did the trick.

def set_TXRX_swap():
    stm.mem32[stm.RCC + stm.RCC_APB1ENR]  |= 0x00040000
    stm.mem32[stm.USART3 + stm.USART_CR2] |= (1 << 15)