Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DMA2D_IRQHandler called with empty ISR register #31

Open
davidev94 opened this issue Oct 4, 2022 · 4 comments
Open

DMA2D_IRQHandler called with empty ISR register #31

davidev94 opened this issue Oct 4, 2022 · 4 comments
Assignees
Labels
hal HAL-LL driver-related issue or pull-request.

Comments

@davidev94
Copy link

I'm using a custom board with STM32H723 (144pin), 5inch display (LTDC), external SRAM (FMC), external NOR flash (OSPI) with Touchgfx and DMA2D (double buffer strategy). No OS.

I experimented random stucks of the touchgfx like described in this thread. After struggling I found out that the problem was caused by DMA2D_IRQHandler called with empty ISR register. In fact, the touchgfx was expecting a call to XferErrorCallback(hdma2d) that never happened and so hanged on.

For what I've seen when this empty call is triggered the DMA2D_FLAG_TC should be HIGH, but actually this sometimes doesn't happens.

I do not know why this happens (silicon bug? touchgfx clean the flag in particular moment?), but for sure the HAL library doesn't manage this case.

So to solve my issue I changed in void HAL_DMA2D_IRQHandler(DMA2D_HandleTypeDef *hdma2d){...} of stm32h7xx_hal_dma2d.c the following line:
if ((isrflags & DMA2D_FLAG_TC) != 0U)
in
if ((isrflags & DMA2D_FLAG_TC) != 0U || isrflags == 0U)

@taltenbach
Copy link

taltenbach commented Nov 15, 2022

I am encountering the exact same issue with a STM32H753XL MCU using TouchGFX 4.20.0. After some investigation, it seems that the DMA2D_FLAG_TC interrupt flag is cleared in STM32DMA::tearDown before the ISR is executed:

void tearDown()
{
    /* Wait for DMA2D to finish last run */
    while ((READ_REG(DMA2D->CR) & DMA2D_CR_START) != 0U);
    
    /* Clear transfer flags */
    WRITE_REG(DMA2D->IFCR, DMA2D_FLAG_TC|DMA2D_FLAG_CE|DMA2D_FLAG_TE);
}

After the while loop is exited, there is no guarantee that the DMA2D ISR is entered before the write to DMA2D_IFCR is performed. I added the following check as a workaround and the issue doesn't seem to happen anymore:

void tearDown()
{
    /* Wait for DMA2D to finish last run */
    while ((READ_REG(DMA2D->CR) & DMA2D_CR_START) != 0U);
    
    if (DMA2D->CR & DMA2D_CR_TCIE) {
        /* DMA2D interrupt enabled, wait until ISR has been executed, flags are cleared by the ISR */
        while ((DMA2D->ISR & DMA2D_CR_TCIE) != 0u);
    } else {
        /* DMA2D interrupt disabled, manually clear transfer flags */
        WRITE_REG(DMA2D->IFCR, DMA2D_FLAG_TC|DMA2D_FLAG_CE|DMA2D_FLAG_TE);
    }
}

Not sure that's the proper way to fix the issue but hopefully this will be helpful

@TOUNSTM TOUNSTM added the hal HAL-LL driver-related issue or pull-request. label Jun 21, 2023
@paulflory
Copy link

@taltenbach
Did you override the tearDown() function so this would be overwritten with code generation?
I assume you would create another STM32DMA_user.cpp with the overriden tearDown() function right? Would this go in the TouchGFX->target directory above the generated folder with the STM32DMA.cpp function that has the base tearDown() function?
Do you have the entire fill you used to share as an example? I'm having a very similar issue on a STM32H743 using TouchGFX 4.20 but only happens occasionally so very difficult to reproduce.

@TOUNSTM
Has ST addressed this in a later version of TouchGFX?

@cdesjardins
Copy link

Just a note on this patch:
while ((DMA2D->ISR & DMA2D_CR_TCIE) != 0u);

appears to be incorrect, I believe the proper bit is:
while ((DMA2D->ISR & DMA2D_ISR_TCIF) != 0u);

@WaseemTamboli
Copy link

Thanks for the workaround , It works for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hal HAL-LL driver-related issue or pull-request.
Projects
None yet
Development

No branches or pull requests

6 participants