Skip to main content
angeliran
Associate III
March 21, 2022
Question

I made a vga signal, trough the spi as pixel sending, can you suggest a faster op?

  • March 21, 2022
  • 2 replies
  • 921 views

I use this:

void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef * htim)

{

if (htim->Instance==TIM2) // Tarda 2.17 us en llegar aqui, AQUI DIBUJO EL BUFFER, EN HSYNC

{

if((m<56))

{

for (h=0;h<16;h++){} //10 ORIG, AQUI DAMOS ESPACIO PARA FONT PORCH

HAL_SPI_Transmit_DMA_MIA(&hspi1,pointer_Data,Data_size);

pointer_Data[0]=fb[m][0];  

pointer_Data[1]=fb[m][1];

pointer_Data[2]=fb[m][2];

.......

m++;

Where my function is:

void HAL_SPI_Transmit_DMA_MIA(SPI_HandleTypeDef *hspi, uint8_t *pData, uint16_t Size)

{ /*  

 HAL_StatusTypeDef errorcode = HAL_OK;

 assert_param(IS_SPI_DIRECTION_2LINES_OR_1LINE(hspi->Init.Direction));

 */

 hspi->pTxBuffPtr = pData;

 hspi->TxXferSize = Size;

 hspi->TxXferCount = Size;/*

 hspi->pRxBuffPtr = (uint8_t*)NULL;

 hspi->RxXferSize = 0;

 hspi->RxXferCount = 0;*/

 /* Enable the Tx DMA channel */

 HAL_DMA_Start_IT(hspi->hdmatx, (uint32_t)hspi->pTxBuffPtr, (uint32_t)&hspi->Instance->DR, hspi->TxXferCount);

 /* Check if the SPI is already enabled */

 // if((hspi->Instance->CR1 &SPI_CR1_SPE) != SPI_CR1_SPE)

 //{

  /* Enable SPI peripheral */   

  __HAL_SPI_ENABLE(hspi);

 // }

 /* Enable Tx DMA Request */

 SET_BIT(hspi->Instance->CR2, SPI_CR2_TXDMAEN);

}

    This topic has been closed for replies.

    2 replies

    KnarfB
    Super User
    March 21, 2022

    Copying the pixels from fb row m to pointer_Data seems time consuming and should be avoided.

    > can you suggest a faster op

    Where else do you see room for improvements?

    hth

    KnarfB

    angeliran
    angeliranAuthor
    Associate III
    March 21, 2022

    Thx for answer me @KnarfB​ ! =(. In some examples I've seen, they use something like:

     SET_BIT(hspi->Instance->CR2, SPI_CR2_TXDMAEN);

    And with only one instruction they begin to draw, but they uses standard libraries, i'm using hal libraries...

    Tesla DeLorean
    Guru
    March 22, 2022

    The MCU and the underlying registers and bits, are the same between HAL and SPL implementations.

    SPI2->CR2 will work on all CMSIS based implementations.

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    angeliran
    angeliranAuthor
    Associate III
    March 22, 2022

    It´s just an example, =(...

    This is what artekit uses:

    1. //*****************************************************************************
    2. // This irq is generated at the end of the horizontal back porch.
    3. // Test if inside a valid vertical start frame (vflag variable), 
    4. // and start the DMA to output a single frame buffer line through the SPI device.
    5. //*****************************************************************************
    6. void TIM1_CC_IRQHandler(void)
    7. {
    8. if (vflag)
    9. {
    10. // VIDEO_DMA->LIFCR = 0x003d0000; // hard-coded clear of all DMA2 interrupt flags
    11. DMA_STREAM->CR |= DMA_SxCR_EN; // set the EN bit to enable the stream
    12. // LED_ON(RED); // debug
    13. // LED_OFF(ORANGE); // debug
    14. }
    15. TIM1->SR &= ~TIM_IT_CC2; // 0xFFFB; //~TIM_IT_CC2;
    16. }