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

Change DMA2 to DMA1 for FSMC TFT on STM32F1xx #27385

Merged
merged 3 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Marlin/src/HAL/STM32/sdio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ void HAL_SD_MspInit(SD_HandleTypeDef *hsd) {
hdma_sdio.Init.MemInc = DMA_MINC_ENABLE;
hdma_sdio.Init.PeriphDataAlignment = DMA_PDATAALIGN_WORD;
hdma_sdio.Init.MemDataAlignment = DMA_MDATAALIGN_WORD;
hdma_sdio.Init.Priority = DMA_PRIORITY_LOW;
hdma_sdio.Init.Priority = DMA_PRIORITY_MEDIUM;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rhapsodyv — Is there any reason you can think of that we should not do this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing defaults are always prone to break someone’s setup…
And if you take a look in the history, you will see that it’s no the first time this same line change between dma channels.

In this case, I think the best would add to the board pin file the right dma to use, or at least allow it be overwritten by the env build flags… so Marlin doesn’t need to back and forth changing dma channels in the code each time it doesn’t work for someone.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your comments!

Changing defaults are always prone to break someone’s setup…

It's definitely possible that this could break something for someone, so this change is definitely a tenuous one that we want to keep an eye on. Most advice I found in searches pointed to using a slightly higher priority for SDIO or a slightly lower priority for FSMC. If we haven't gotten any definitive feedback about this change before 2.1.3-beta1 is ready, I'll mark it as an important bullet point for testers.

For testing purposes it would be best to get feedback from those who were definitely affected by the DMA contention issue, but I do have a small pile of STM32-based boards, a few with FSMC, and some are inside printers. If I have one of the specifically affected boards or printers I can also try to make SDIO break and see what happens when priorities are adjusted.

best would add to the board pin file the right dma to use

Some boards do specify FSMC_DMA_DEV and FSMC_DMA_CHANNEL. (For example Mingda D2 has DMA1 and DMA_CH4) but these only seem to apply to our deprecated Maple environments. For others the DMA is based on the HAL, but that follows from the ports and interrupts specified by the boards/variants.

So, I'll have to do a board-by-board audit to see which DMA they use. I should also make a big Google spreadsheet with all our board information laid out for easy reference. (I'll ask an LLM to help with that.) Most boards are based on a generic STM32 layout but we can look at each one and make sure that the DMA we've picked is correct, and if there is a need to add overrides on a per-board basis we'll also add that capability. I hope we can automatically figure out most of these things on the users' behalf from things like pins and header defines so they don't have to think about it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll gather our board / environment info in this here spreadsheet…. A single board may have more than one environment with different DMA settings, and that's what we'll discover from populating this sheet.

https://docs.google.com/spreadsheets/d/10Wsch_IduVArjNApnnBtpQlc1-TRjwyaRo6-FanhCYI/edit?usp=sharing

__HAL_LINKDMA(&hsd, hdmarx, hdma_sdio);
__HAL_LINKDMA(&hsd, hdmatx, hdma_sdio);

Expand Down
7 changes: 4 additions & 3 deletions Marlin/src/HAL/STM32/tft/tft_fsmc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,11 @@ void TFT_FSMC::init() {

HAL_SRAM_Init(&SRAMx, &timing, &extTiming);

__HAL_RCC_DMA2_CLK_ENABLE();

#ifdef STM32F1xx
DMAtx.Instance = DMA2_Channel1;
__HAL_RCC_DMA1_CLK_ENABLE();
DMAtx.Instance = DMA1_Channel1;
#elif defined(STM32F4xx)
__HAL_RCC_DMA2_CLK_ENABLE();
DMAtx.Instance = DMA2_Stream0;
DMAtx.Init.Channel = DMA_CHANNEL_0;
DMAtx.Init.FIFOMode = DMA_FIFOMODE_ENABLE;
Expand Down Expand Up @@ -182,6 +182,7 @@ void TFT_FSMC::transmitDMA(uint32_t memoryIncrease, uint16_t *data, uint16_t cou
DMAtx.Init.PeriphInc = memoryIncrease;
HAL_DMA_Init(&DMAtx);
HAL_DMA_Start(&DMAtx, (uint32_t)data, (uint32_t)&(LCD->RAM), count);
TERN_(TFT_SHARED_IO, while (isBusy()));
}

void TFT_FSMC::transmit(uint32_t memoryIncrease, uint16_t *data, uint16_t count) {
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/HAL/STM32/tft/tft_spi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ void TFT_SPI::transmitDMA(uint32_t memoryIncrease, uint16_t *data, uint16_t coun
SET_BIT(SPIx.Instance->CR2, SPI_CR2_TXDMAEN); // Enable Tx DMA Request
#endif

TERN_(TFT_SHARED_IO, while (isBusy()) { /* nada */ });
TERN_(TFT_SHARED_IO, while (isBusy()));
}

void TFT_SPI::transmit(uint32_t memoryIncrease, uint16_t *data, uint16_t count) {
Expand Down
Loading