cancel
Showing results for 
Search instead for 
Did you mean: 

Which STM32 has a total of 12 or more UART + USARTS? My STM32F4 only has a total of 10, two short of what I need. Thanks.

JPhil.1
Associate
 
6 REPLIES 6
chaaalyy
Senior II

ST´s sales manager would say: buy two or more of them, connect them via SPI or USB to each other and you have as many ports, as you want ;)

Or bitbang them.

Btw. which F4 has 10 UARTs?

JW

TDK
Guru

The STM32F413/423 has 10 UARTs and that's the most you can get on any STM32. STM32CubeMX has a MPU selection tool that you can use to sort chips by the number of peripherals they have. You could use SPI to mimic UART, but it's a bit more work.

If you feel a post has answered your question, please click "Accept as Solution".
berendi
Principal

Some STM32H7{A,B} MCUs e.g. STM32H7B0VB have 5 UARTs, 5 USARTs and 1 LPUART. Still one less than 12, but it means that only one has to be bitbanged or hacked otherwise.

What kind of peripherals would be connected to these ports?

Is there one which is transmitting only and one which is receiving only? You could handle both with one UART as long as the baud rate is the same.

Receiving peripherals (i.e. where the MCU only transmits data and RX is not used) are easier to bitbang, or possible to emulate with SPI. Receiving would need either somewhat complex timer/dma arrangements or a lot of time spent in interrupt handlers.

Are there peripherals which need only periodic attention, answering only to queries from the MCU? Your program could serve them in turns, reconfiguring GPIO pin mappings dynamically.

Thanks, TDK. I was offline, and always took the "lower-end" 'F4 s as stripped-down versions of 'F407.

An interesting idea, to use SPI for UART emulation. Fullduplex would be slightly tricky, though. I generally consider SPI as a more valuable resource than UART - in many project I use USARTs in synchronous mode just for lack of enough SPIs - but that of course depends on appication.

There's an appnote, AN4457, as a clue how to use timer-driven-DMA for bit-banging UARTs.

JW

I'm trying to elaborate on TDK's idea to use SPI for UART emulation, achieving fullduplex while trying to avoid the TIM/DMA complex.

Maybe it would be possible to use SPI running at 8x/16x UART baudrate*, fullduplex, with circular DMA on both directions, dual-buffer, having NDTR worth 1 UART frame and interrupting on the transfer complete (buffer can be longer, in the multiple of frames, if higher latencies are acceptable, of course; and buffers for both directions can have different size - but those are details left to the implementation).

Tx, as berendi said, is trivial, simply direct the currently-inactive memory pointer of DMA to the required Tx pattern for the next frame to be transmitted, these may come pre-chewed in FLASH.

Rx is not necessarily prohibitively complex and/or slow either - seeking for start-bit is simply seeking for a non-all-ones word in the buffer; IIRC there's a CLZ instruction in the M4 to find out the bitshift, and the rest is a basic exercise in state machines. Triple-sampling would be possible but definitively more processing.

Could be a fun project indeed.

JW

* Given the inflexible clocking scheme of the STM32 SPIs (timer-clocking of SPI/other peripherals ought to go to the hardware-part of wishlist) this may turn out to be the tricky part. It may turn out that timer is still needed to generate clock, SPI being slave and clock to timer connected externally. Note, that given how it's implemented, STM32 SPI Rx can not be used without an explicit clock pin, even if the clock signal is not needed (one of my friend has experienced a painful encounter with this pitfall).