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

DMA Mode not working #2

Closed
cider101 opened this issue Feb 17, 2023 · 7 comments
Closed

DMA Mode not working #2

cider101 opened this issue Feb 17, 2023 · 7 comments

Comments

@cider101
Copy link

cider101 commented Feb 17, 2023

This is a great little library/driver - thx for your great work!

I'm having trouble to get the DMA mode to work. It "hangs" in the Displ_Transmit() function on line 77.

while (!Displ_SpiAvailable) {};

It looks like there there is never a transfer-complete interrupt received - though both, the global SPI1 and DMA2 TX interrupts are enabled. I'v never worked with DMA before - do I need to configure something "special" except enabling the DMA TX ?
Btw: it works in "normal" Interrupt-Mode - just not in DMA mode....

@maudeve-it
Copy link
Owner

Hi cider101,
yes, it seems that DMA doesn't signal transfer-complete.
Which uC are you using?
Have you enabled SPI interrupt? ("SPIx global interrupt" enabled, on "NVIC settings", in the SPIx "Configuration" page)
That has to be enabled together with the SPIx_TX settings.
Let me know.

Bye

@cider101
Copy link
Author

Thx for your quick response.
I'm using an SMT32F401 Weact Blackpill and yes, both, SPI1_TX and SPI1 global interrupt are enabled...
As mentioned before, I haven't used DMA yet - so please forgive my ignorance. From the HAL code I understood, that the DMATransferCompleted-IRQ/Event ist routed by HAL from the DMA-IRQ-Handle to the to the SPI-IRQ-Handler which then will finally call the function HAL_SPI_TxCpltCallback() from your library - right ?

image

image

@maudeve-it
Copy link
Owner

Hi Cider101
3 more questions:

  • can you tell me the display you are using?
  • can you tell me the configuration in z_displ_ILI9XXX.h? I mean the values enabled in STEP1 to STEP6
  • can you also show me lines in "main.c" between /* USER CODE END SysInit / and / USER CODE BEGIN 2 */
    thet means the initialization sequence set by CubeMX?

Thank you

@cider101
Copy link
Author

Good Morning Mauro

I'm using a ILI9488 Display with an FT6236 touch controller

this is my configuration for the display in the z_displ_ILI9XXX.h

0. //#define DISPLAY_USING_TOUCHGFX

1. #define ILI9488_V1 (this display seems only to work with rgb666)

2. #define DISPL_SPI_PORT 	hspi1
    #define DISPL_SPI 		SPI1

3. #define DISPL_PRESCALER SPI_BAUDRATEPRESCALER_2     //prescaler assigned to display SPI port
   #define TOUCH_PRESCALER SPI_BAUDRATEPRESCALER_256	//prescaler assigned to touch device SPI port

4. //#define DISPLAY_SPI_POLLING_MODE
   //#define DISPLAY_SPI_INTERRUPT_MODE
    #define DISPLAY_SPI_DMA_MODE // (mixed: polling/DMA, see below)

5. //#define DISPLAY_DIMMING_MODE 

6. #define BUFLEVEL 12

and that's my main.c

MX_GPIO_Init();
MX_SPI1_Init();
MX_I2C1_Init();
MX_TIM2_Init();
MX_DMA_Init();

/* USER CODE BEGIN 2 */
Displ_Init(Displ_Orientat_0);
Displ_CLS(BLUE);
//Displ_BackLight('I');  			//currently hard-wired to 3v3 
/* USER CODE END 2 */

/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
  /* USER CODE END WHILE */

  /* USER CODE BEGIN 3 */
    Displ_PerfTest();
}
/* USER CODE END 3 */

thx again for your help! have a nice weekend
Marco

@maudeve-it
Copy link
Owner

maudeve-it commented Feb 18, 2023

Hi Cider101,
can you do these tests, changing the initialization order?

test 1:
MX_GPIO_Init();
MX_I2C1_Init();
MX_TIM2_Init();
MX_DMA_Init();
MX_SPI1_Init();

test 2:
MX_GPIO_Init();
MX_DMA_Init();
MX_I2C1_Init();
MX_TIM2_Init();
MX_SPI1_Init();

Do not enter in CubeMX, saving configuration after the above changes. Just change the order in your main.c file as above and run the project.

And let me know what happens?

@cider101
Copy link
Author

cider101 commented Feb 18, 2023

That worked - both of your suggested changes!! thx a lot! And hell, what a performance-difference :)

looks like the DMA needs to be initialized before the SPI is initialized. Seems this is a bug/issue with the Stm32CubeIDE since that code is generated by the IDE.

btw:did you ever figure out, what the difference between board version 1.0 and 2.0 is ? Maybe a different chip or firmware version/revision of the Ili9488 ?

thx again end enjoy the weekend
best regards
Marco

@maudeve-it
Copy link
Owner

maudeve-it commented Feb 18, 2023

Yes,
it seems (to me) that when you create a new project, CubeMX sets the right initialization order. Ever.
But, if you start to "play" with your SPI configuration: enabling DMA (saving configuration), then disabling it, then changing its setup, many times... CubeMX can fall into a wrong sequence and it is not able to set it back to the right one.
You could set the initialization sequence into CubeMX -> Project Manager -> Advanced Settings but some sequences (including DMA) are protected (against your mistakes but not against CubeMX mistakes).

STM guys know this problem, but it seems thay aren't able to find a stable solution:
https://community.st.com/s/question/0D50X0000Bmob3uSQA/dma-not-working-in-cubemx-generated-code-order-of-initialization

About your project: from now on, if you make any changing in configuration, CubeMX will set back the wrong order. The only way (I found) avoiding it, is to create a new project

Bye

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants