2018-05-09 05:37 AM
Hi!
in my program i am using the 'HAL_UART_Receive_IT' function, it is first called when i initialize my app.
There comes a moment during the run of the program when the pointer to buffer given to the function expires and is no longer valid, this is when i want to call this function again with new parameters.
The problem is that the operation doesnt succeed and the HAL_BUSY retval is returned.
please advise on how to restart this function properly after it has already been used.
thanks alot!
2018-05-09 05:50 AM
Hi
yuri.cherniakov
,Please have a look to this example it may help you :
STM32Cube_FW_L4_V1.0\Projects\STM32L476G-EVAL\Examples\I2C\I2C_TwoBoards_RestartComIT:
This example describes how to perform a single I2C data buffer transmission/reception
between two boards in Interrupt mode and with a restart condition.-Nesrine-
2018-05-09 06:18 AM
Hi Nesrine,
Thanks for responding. unfortunetly this doesnt help since i'm using UART communication.
2018-05-09 06:35 AM
Reflect on the library code provided, and write something better. There is no value to building a fine house on a poor foundation. I prefer a clean/elegant approach over an abstracted/obtuse one.
With the HAL you'd likely need to transition the object's buffer state in the IRQ Handler prior to calling into the HAL layer, or lock down the interrupt/structure to reconfigure it.
2018-05-09 06:53 AM
this seems to be the problem:
'There comes a moment during the run of the program when the pointer to buffer given to the function expires'
this is an architectural issue. imho
2018-05-09 09:07 AM
Yeah, I don't like the use of auto/local variable for DMA or IRQ buffers.
If the scope is finite, manage it with a timeout. As I've observed before the HAL often get's in its own way, and has a paradigm that frequently doesn't fit what people are used to, or is 95% complete.
2018-05-09 05:59 PM
This is likely because the HAL function checks 'busy' flag set by it's previous call.
If the flag is set it immediately fails.
.So you need to let the HAL function complete, or call
.-- pa
2018-05-11 03:08 PM
You should either use a statically or dynamically allocated buffer for the UART or use an automatic (stack allocation) buffer that is declared at a scope that does not 'expire'. Static allocation of buffers is easier to debug, though other schemes are possible. Stack allocation is particularly hard to debug because the interrupt callback functions don't have the stack variables from the non-interrupt thread in their scope. The buffer is still there, but there's no really good way to get the address of it using the array name for the buffer.
In any case, I recommend not calling the 'HAL_UART_Receive_IT()' function in your initialization routine. You can set up the interface there without calling the receive function. Instead, make the receive call at the top of a main loop where the buffer does not go out of scope until the program exits. You can cancel any pending IO on the way out. Having the input pending before you are prepared to process the data then switching to a new buffer will cause any data received up to that point to be lost anyway, so it's best to wait to make the receieve call until you're ready to process the data.
2018-05-12 10:18 PM
Thaks everyone for your responses,
I understand that the 'expiration' of the pointer to the buffer is an architechtural issue that has to be dealt with.
unfortunetly, i have inhereted some code that can not be changed at this part of the project.
I am particularly intrested in the HAL_UART_Abort function, this would help me solve the probem, i was unable to find it in the HAL functions.
i am working on the STM32F7 , is the set of the abort commands is not yet implemented for the F7?
2018-05-13 07:05 PM
>
i am working on the STM32F7 , is the set of the abort commands is not yet implemented for the F7?
Have you looked? Have you downloaded the F7 libraries?
-- pa