STMicroelectronics / stm32g4xx_hal_driver

Provides the STM32Cube MCU Component "hal_driver" of the STM32G4 series.
BSD 3-Clause "New" or "Revised" License
14 stars 9 forks source link

[HAL][FMAC] Implement missing DMA stop #12

Open hobby-pub opened 4 months ago

hobby-pub commented 4 months ago

Opened Issue HAL_FMAC_FilterStop does not terminate DMA transfer

Describe the bug A wrong behavior of subsequent HAL_FMAC_FilterStart() -> HAL_FMAC_FilterStop() -> HAL_FMAC_FilterStart().

How To Reproduce

  1. FMAC is configured as FIR with output buffer access mode DMA.
  2. The software periodically starts and stops FMAC, by calling HAL_FMAC_FilterStart() / HAL_FMAC_FilterStop().
  3. The second call of HAL_FMAC_FilterStart() fails with DMA related HAL error.

Additional context Follow the issue debugging, DMA transfer starts from within HAL_FMAC_FilterStart(). However, complementary DMA stop is missing in HAL_FMAC_FilterStop().

ALABSTM commented 4 months ago

Hi @hobby-pub,

Than you for this contribution. We will process it soon enough hopefully. By the way, thank you very much for the well formatted commit message.

With regards,

TOUNSTM commented 4 months ago

Hello @hobby-pub,

Thank you for your report. We have tried to reproduce the problem you described, without success. Could you please share the entire project you used to reproduce the problem to allow for a better analysis.

Best regards,

hobby-pub commented 4 months ago

Hello @TOUNSTM ,

Unfortunately, I cannot share the commercial project. However, I can send few lines of the related code. Please, let me know where to upload the code example.

Kindly regards,

TOUNSTM commented 4 months ago

Hello @hobby-pub,

To attach a file to your P-R, please drag-and-drop it into the comment box or you can click on the bar at the bottom of the comment box to add it from your computer and then wait for the upload process to finish.

With regards,

hobby-pub commented 4 months ago

Hello @TOUNSTM,

Attached the simple test example. Please note, that a lot of initializations are missing.

fmac_test.txt

TOUNSTM commented 3 months ago

ST Internal Reference: 177976

TOUNSTM commented 3 months ago

Hello @hobby-pub,

Upon further investigation, our development team have encountered a behavior that mirrors the issue described. It appears that during the second invocation of FilterStart, the DMAOut handle remains in a HAL_DMA_STATE_BUSY state. This is the underlying cause of the DMA error, as DMAOut must be in a HAL_DMA_STATE_READY state to initiate properly. I need further clarification from you for a better analysis:

  1. Can you confirm whether you have observed the same state when the DMA error occurs (DMAOut State == HAL_DMA_STATE_BUSY)?
  2. Is Stopping the filter before the end of calculus is an expected/authorized behavior by the program ?

There are two possible explanations for the HAL_DMA_BUSY state:

  1. Premature FilterStop: If FilterStop is called too early, and then all expected calculus are not completed on time. This reveal, perhaps, a timing issue in the program ?
  2. FMAC Configuration: The FMAC may not be configured correctly for the calculations required ?

However, It's also important to note that there is a missing step in the driver to halt the DMA in/out processes.

Thank you for your contribution. With regards,

hobby-pub commented 3 months ago

Hello, @TOUNSTM,

Please, see my answers below.

  1. Can you confirm whether you have observed the same state when the DMA error occurs (DMAOut State == HAL_DMA_STATE_BUSY)? Yes, as far as I remember.

  2. Is Stopping the filter before the end of calculus is an expected/authorized behavior by the program ? Yes, the program stops filter asynchronously regardless of the calculation state, and this is by design.

There are two more notes:

  1. It looks that HAL_DMA_Abort_IT() is the correct, complementary HAL function to stop DMA, and not HAL_DMA_Abort() which I committed in the patch.
  2. I did not use neither tested the input buffer in DMA mode.

Best regards,