2020-05-25 02:38 PM
Hello,
i was looking for some library to simulate UART on STM32 F4 MCU and i came across Application note AN4457. The note is clear in explaining how STSW-STM32156 firmware package provide such emulation and it looked really perfect for my case. Problem is that it's really difficult for me to understand how to implement such software in my project. Is there a way to import this middleware library inside CubeMX?
Thanks a lot
Filippo
2020-05-25 04:28 PM
HAL doesn't have software UART emulation built-in. You would need to import the code into your project and treat it as user code. There are instruction at the top of the source file as to how to use it.
==============================================================================
##### How to use this driver #####
==============================================================================
[..]
The UART Emulation HAL driver can be used as follows:
(#) Declare a UART_Emul_HandleTypeDef handle structure.
(#) Initialize the UART Emulation low level resources by implementing the HAL_UART_Emul_MspInit() API:
(##) Enable the UART_EMUL clock
(##) UART Emulation port declaration
(+++) UART pins configuration: TxPinNumber and RxPinNumber
(+++) Enable the clock for the GPIOs
(#) Program the Baud Rate, Word Length, Stop Bit, Parity,
and Mode(Receiver/Transmitter) in the huart Emul Init structure.
(#) Initialize the UART Emulation registers software by calling the HAL_UART_Emul_Init() API.
-@- The specific UART Emulaion Handle (Transmission complete, Reception complete
and Transfer Error) will be managed using the macros HAL_UART_Emul_TxCpltCallback(),
HAL_UART_Emul_RxCpltCallback() and __HAL_UART_Emul_TranferError() inside the transmit
and receive process.
-@- These API's(HAL_UART_Emul_Init() configures also the low level Hardware GPIO, CLOCK, CORTEX...etc)
by calling the customed HAL_UART_Emul_MspInit() API.
(#) Three modes of operations are available within this driver:
*** UART Emulation mode IO operation ***
===================================
[..]
(+) Send an amount of data in non blocking mode (DMA) using HAL_UART_Emul_Transmit_DMA()
(+) At transmission end of transfer HAL_UART_Emul_TxCpltCallback is executed and user can
add his own code by customization of function pointer HAL_UART_Emul_TxCpltCallback
(+) Receive an amount of data in non blocking mode (DMA) using HAL_UART_Emul_Receive_DMA()
(+) At reception end of transfer HAL_UART_Emul_RxCpltCallback is executed and user can
add his own code by customization of function pointer HAL_UART_Emul_RxCpltCallback
(+) In case of transfer Error, HAL_UART_ErrorCallback() function is executed and user can
add his own code by customization of function pointer HAL_UART_Emul_ErrorCallback
2020-05-26 02:42 PM
Thanks a lot TDK.
I seen indeed this explanation but here it's exactly where the problem come from for me.
In fact, although there are indications these are very fuzzy to my understanding.
For instance it says to implement HAL_UART_Emul_MspInit() in order to declare pin configuration and so on... point is that i have no idea where to declare this function and what is the configuration of such pins or timers or EXTI. Should i configure for instance PINs inside CubeMx, create macros to link them and try to report inside this function? or the function will configure everything simply passing port and pin number?
I checked the example and it's really hard to reverse engineering what is inside and find things described above.
Surely it's clear for eyes more into ST HAL framework, but not mines.
I'll try something and if i manage to make it working I'll try to describe a step by step for someone else convenience.
Meantime if someone have some indication or examples it will be more then welcome.
Thanks again,
Filippo
2024-03-25 11:57 PM
Hi,
How did you import these files with the STM32CubeMX generated files? and How did you manage the configurartion for emul_uart?
Could you please show me the sample code?