cancel
Showing results for 
Search instead for 
Did you mean: 

The data is not coming on MOSI line when using the DMA forSTM32H7

MDeva.1
Associate II

Hello,

I am trying to transmit data to DAC using SPI DMA method on STM32h745 I tried all the methods that mentioned on forum. But i did not get the data on MOSI pin, when I use the polling method the data is successfully transmit .

const uint16_t addr[]={0x0000,0x0001,0x0002,0x0003,0x0004,0x0005,0x0006,0x0007,0x0008,0x0009,0x000A,0x000B,0x000C,0x000D,0x000E,0x001F,0x0020,0x0022,0x0023,0x0024,0x0025,0x0026,0x0027,0x0028,0x0029,0x002A,0x002B,0x002C,0x002D,0x002E,0x002F,0x0030,0x0031,0x0032,0x0033,0x0034,0x0035,0x0036,0x0037,0x003E,0x003F,0x0040,0x0041,0x0042,0x0043,0x0044,0x0045,0x0046,0x0047,0x0050,0x0051,0x0052,0x0053,0x0054,0x0055,0x0056,0x0057,0x0058,0x0059,0x005A,0x005B,0x005C,0x005D,0x005E,0x005F,0x0060,0x001D,0x001E};

const uint16_t Valu[]={0x0000,0x0E00,0x0000,0x0000,0x4000,0x4000,0x4000,0x4000,0x0000,0x1F00,0x1F00,0x1F00,0x1F00,0x0000,0x0000,0x0000,0x000E,0x0000,0x0000,0x0000,0x0000,0x0101,0x0101,0x0111,0xFFFF,0x0101,0x0101,0x0003,0x0000,0x7FFC,0x7FFC,0x7FFC,0x7FFC,0x4000,0x4000,0x4000,0x4000,0x0001,0x0200,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x07D0,0x0000,0x0000,0x0000,0x03E8,0x0000,0x0000,0x0000,0x0BB8,0x0000,0x0000,0x0000,0x0FA0,0x0000,0x0000,0x0000,0x0004,0x0001,0x0001};

void HAL_SPI_TxCpltCallback(SPI_HandleTypeDef *hspi)

{

HAL_GPIO_WritePin(LED3_GPIO_Port, LED3_Pin, GPIO_PIN_SET);

}

while (1)

{

  /* USER CODE END WHILE */

  /* USER CODE BEGIN 3 */

printf("=================1====================================\n\r");

for(i=0,j=0;i<69;i++,j++)

{

SCB_CleanDCache_by_Addr((uint32_t*)(((uint32_t)addr[i]) & ~(uint32_t)0x1F), BUFSIZE+32);

HAL_GPIO_WritePin(CS1_GPIO_Port, CS1_Pin, GPIO_PIN_RESET);

HAL_SPI_Transmit_DMA(&hspi4, (uint8_t*)&addr[i], 1);

while(s==0){

s=HAL_DMA_GetState(&hdma_spi4_tx);

printf("s=%d\n\r",s);

}

while(HAL_SPI_GetState(&hspi4)!=HAL_SPI_STATE_READY);

HAL_GPIO_WritePin(LED3_GPIO_Port, LED3_Pin, GPIO_PIN_RESET);

SCB_CleanDCache_by_Addr((uint32_t*)(((uint32_t)Valu[j]) & ~(uint32_t)0x1F), BUFSIZE+32);

HAL_SPI_Transmit_DMA(&hspi4, (uint8_t*)&Valu[j],1);

while(s1==0)

{

printf("s1=%d\n\r",s1);

s1=HAL_DMA_GetState(&hdma_spi4_tx);

}

while(HAL_SPI_GetState(&hspi4)!=HAL_SPI_STATE_READY);

HAL_GPIO_WritePin(CS1_GPIO_Port, CS1_Pin, GPIO_PIN_SET);

HAL_Delay(50);

printf("W- ADDR=%x, Value=%x\n\r",addr[i],Valu[j]);

HAL_GPIO_WritePin(LED3_GPIO_Port, LED3_Pin, GPIO_PIN_RESET);

}

HAL_GPIO_WritePin(GPIOH, Trigger1_Pin, GPIO_PIN_RESET);

HAL_Delay(1);

HAL_GPIO_WritePin(GPIOH, Trigger1_Pin, GPIO_PIN_SET);

printf("==========================2=========================\n\r");

HAL_Delay(1000);

}

 /* USER CODE END 3 */

}

What I am mistaken here. What is these meaning "Make sure the address is 32-byte aligned and add 32-bytes to length, in case it overlaps cacheline"

In DMA transmission first I need to transfer 16 bit address and then 16bit value then I need to HIGH the CS pin. In DMA transfer function what length I need to mentioned . Can you please help me. When I disable the cache the function gets stucks, What I need to do?

2 REPLIES 2

What would be the point of doing DMA on single bytes?​

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..