How to design the communication between the external IO module and the HA

Hello everyone

I have been interested in smart homes for a long time and after many years I have installed HA again, I can see that currently HA is a leader in smart home solutions, so I am wondering whether to create a dedicated input and output module for HA.

The module will have about 40 digital 24v binary inputs, about 40 16A relay outputs and 12 PWM channels for LED strips. It will be controlled from STM32, additionally it plans extension modules with the same specificity. The modules are planned to be connected via CAN Bus.
However, I do not know how to connect them to the HA, I plan to put a Raspberry CM4 module on the main module, which will be connected to the STM via UART.
Is it possible to write a module for HA that will communicate directly with STM32 via UART or is it better to write a simple TCP server that will communicate with STM32 via UART and with HA via TCP?

Any idea ?

Have a look at ESPHome. Interfacing with HA will become a breeze.