2025-08-09 6:41 AM
Hi,
I am using an STM32H523 MCU where I transmit some data via SPI (master tx only) in blocking mode.
In debug build the SPI behaves as it should be and everything is fine.
In release build the SPI CLK line remains high for too long, after the last bit of a transmission has been sent.
This results in the (software) CS line going high before the CLK returned to 0 (the DAC7562 slave does not like that)
How it looks like in Release:
How it looks like in Debug (correct):
My code for the transmits:
HAL_GPIO_WritePin(GPIOA, CS_Pin, GPIO_PIN_RESET);
hal_status = HAL_SPI_Transmit(spi_handle_, data, sizeof(data), HAL_MAX_DELAY);
HAL_GPIO_WritePin(GPIOA, CS_Pin, GPIO_PIN_SET);
CubeMX config code:
void MX_SPI1_Init(void)
{
hspi1.Instance = SPI1;
hspi1.Init.Mode = SPI_MODE_MASTER;
hspi1.Init.Direction = SPI_DIRECTION_2LINES_TXONLY;
hspi1.Init.DataSize = SPI_DATASIZE_8BIT;
hspi1.Init.CLKPolarity = SPI_POLARITY_LOW;
hspi1.Init.CLKPhase = SPI_PHASE_1EDGE;
hspi1.Init.NSS = SPI_NSS_SOFT;
hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_64;
hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
hspi1.Init.CRCPolynomial = 0x7;
hspi1.Init.NSSPMode = SPI_NSS_PULSE_DISABLE;
hspi1.Init.NSSPolarity = SPI_NSS_POLARITY_LOW;
hspi1.Init.FifoThreshold = SPI_FIFO_THRESHOLD_01DATA;
hspi1.Init.MasterSSIdleness = SPI_MASTER_SS_IDLENESS_00CYCLE;
hspi1.Init.MasterInterDataIdleness = SPI_MASTER_INTERDATA_IDLENESS_00CYCLE;
hspi1.Init.MasterReceiverAutoSusp = SPI_MASTER_RX_AUTOSUSP_DISABLE;
hspi1.Init.MasterKeepIOState = SPI_MASTER_KEEP_IO_STATE_DISABLE;
hspi1.Init.IOSwap = SPI_IO_SWAP_DISABLE;
hspi1.Init.ReadyMasterManagement = SPI_RDY_MASTER_MANAGEMENT_INTERNALLY;
hspi1.Init.ReadyPolarity = SPI_RDY_POLARITY_HIGH;
if (HAL_SPI_Init(&hspi1) != HAL_OK)
{
Error_Handler();
}
}
void HAL_SPI_MspInit(SPI_HandleTypeDef* spiHandle)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
if(spiHandle->Instance==SPI1)
{
/* USER CODE BEGIN SPI1_MspInit 0 */
/* USER CODE END SPI1_MspInit 0 */
/* SPI1 clock enable */
__HAL_RCC_SPI1_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
/**SPI1 GPIO Configuration
PA5 ------> SPI1_SCK
PA7 ------> SPI1_MOSI
*/
GPIO_InitStruct.Pin = GPIO_PIN_5|GPIO_PIN_7;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF5_SPI1;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
}
}
It's the first time I see this (also the first time I use an SPI on an H5 MCU)
Does anybody have a guess what causes this issue?
In the mean time I will try using the interrupt tx function and wait in a while loop for completion.
Thanks :)
Regards,
Howard
Solved! Go to Solution.
2025-08-09 6:44 AM
It's probably floating which would be apparent on an analog capture.
> SPI_MASTER_KEEP_IO_STATE_DISABLE
Set this enabled if you want the pins to keep their state.
2025-08-09 6:44 AM
It's probably floating which would be apparent on an analog capture.
> SPI_MASTER_KEEP_IO_STATE_DISABLE
Set this enabled if you want the pins to keep their state.
2025-08-09 7:08 AM
Yes, thanks! Have a nice weekend