2025-06-07 9:43 AM - edited 2025-06-07 9:46 AM
I'm about to program a continously running DMA stream (using GPDMA1 (circularly)) in an STM32H503CBU6. But the start already fails.
during the setup of the i2s->hdmatx pointer is zero causing the crash when it wants to get initialized.
I'm in need of a running example with an I2S device configured with a continously running DMA write stream
with a length of 1 (32 word) to the I2S device. Help urgently needed, please.
int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_GPDMA1_Init();
MX_ICACHE_Init();
MX_I2C1_Init();
MX_I2S2_Init();
MX_TIM1_Init();
/* USER CODE BEGIN 2 */
//HAL_I2S_Transmit_IT(&hi2s2, ram_loc, 1);
HAL_I2S_Transmit_DMA(&hi2s2, ram_loc,1);
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
HAL_Delay(10);
ram_loc[0]++,ram_loc[1]++;
//HAL_I2S_Transmit_DMA(&hi2s2, ram_loc,1);
//HAL_I2S_Transmit_IT(&hi2s2, ram_loc, 1);
//HAL_I2S_Transmit(&hi2s2, sine_amplitudes, size,5000);
//HAL_I2S_Transmit(&hi2s2, test_amplitudes, 4 ,5000);
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
}
DMA
2025-06-07 9:50 AM
Please include your IOC file. The DMA pointer should get initialized in the mspinit function. Needs to be enabled in the IOC.
2025-06-07 9:54 AM
2025-06-07 11:46 AM
Set up a GPDMA channel to service I2S2_TX requests. You don't have one assigned.
2025-06-07 12:40 PM - edited 2025-06-07 12:49 PM
Ah, thanks. I see "Request configuration", there is SPI2_TX/I2S2_TX !
I'll try to get further. Only about the mode I'm not sure. Wouldn't I have to choose circular mode when the DMA should keep itself ongoing?
2025-06-07 12:56 PM
Yes, if you want it to continue forever you will need to enable circular mode.
2025-06-07 1:27 PM
This is the code in main.c I'm using now:
uint16_t ram_loc[2] = {0,0};
//HAL_I2S_Transmit_IT(&hi2s2, ram_loc, 1);
HAL_I2S_Transmit_DMA(&hi2s2, ram_loc,1); // since circular is configured,
// am I right that the DMA keeps alive itself?
/* Infinite loop */
while (1)
{
// for testing, increment ram_loc (L+R) by one every 10ms
// which should produce a (sawtooth) ramp.
//
HAL_Delay(10);
ram_loc[0]++,ram_loc[1]++;
if(ram_loc[0] == 65535)
ram_loc[0]=ram_loc[1]=0;
}
I don't see any data out though at the moment.