cancel
Showing results for 
Search instead for 
Did you mean: 

Running HAL_SPI_TransmitReceive causes reset of the STM32L151RBT6A

DavidByrne
Associate II

Hi. First time I have posted here. This problem is driving me nuts, so hopefully someone might lead me to a solution. I am under extreme time pressure with this project and need to solve this very quickly. If anyone can help, it would be much appreciated and I'd owe you a beer at least.

I am using STM32cubeIDE ver 1.15.1, generating C code. Code for all I/O functions work fine, except the SPI. In fact, whenever I try to excercise the SPI, the CPU resets. The nRST line on the CPU glitches to 0V and then resets. Nothing Is driving that reset line, other than the S-LINK/V2, so the reset is happening within the STM32L151.

 

The application is driving on the SPI port two RF chips: the CC1120 and the SX1276. I have checked SPI various lines and there are no shorts and no obvious schematic errors. Both have independent SPI chip selects. Also the RF chips are not producing any RF - the digital signals are all clean. 

I was using the SPI nCS line (NSS), with software control from the .ioc file, and thinking there was an issue there for the CC1120, I cut a track and rerouted that signal to PB0. Still same bug.

I have read code examples and even used ChatPGT to generate code. Nothing fixes the issue. 

I have attached some screen shots of the schematic. The rail voltages are all 3.0V. Here is a test while(1) loop in main.c, simplified as to not cause confusion. As you can see, I have tried this with having the CC1120 and SX1276 stuck in reset, and only one in reset and none in reset - but no luck.

This is puzzling!

 

while (1)
  {
    /* USER CODE END WHILE */
 
    /* USER CODE BEGIN 3 */
 
if (button == YES)
{
HAL_Delay(500);
 
SwitchLedOn (LED1, GREEN);
 
HAL_GPIO_WritePin(nCS_SX1276,SET_PIN_HIGH);
HAL_GPIO_WritePin(nCS_CC1120,SET_PIN_LOW);
//HAL_GPIO_WritePin(nRESET_SX1276,SET_PIN_LOW);
//HAL_GPIO_WritePin(nRESET_CC1120,SET_PIN_LOW);
 
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0, GPIO_PIN_RESET); // Set CS low
 
data = 0x30;
 
if (HAL_SPI_TransmitReceive(&hspi1, &data, &receivedData, 1, HAL_MAX_DELAY) != HAL_OK) {
   Error_Handler();
}
 
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0, GPIO_PIN_SET); // Set CS high
 
}
else
{
SwitchLedOff(LED1);
 
SwitchLedOn (LED1, RED);
 
HAL_Delay(100);
 
HAL_GPIO_WritePin(nCS_SX1276,SET_PIN_HIGH);
HAL_GPIO_WritePin(nCS_CC1120,SET_PIN_HIGH);
}
  }
  /* USER CODE END 3 */
}

The SPI config is as such:

static void MX_SPI1_Init(void)
{

/* USER CODE BEGIN SPI1_Init 0 */

/* USER CODE END SPI1_Init 0 */

/* USER CODE BEGIN SPI1_Init 1 */

/* USER CODE END SPI1_Init 1 */
/* SPI1 parameter configuration*/
hspi1.Instance = SPI1;
hspi1.Init.Mode = SPI_MODE_MASTER;
hspi1.Init.Direction = SPI_DIRECTION_2LINES;
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_2;
hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
hspi1.Init.CRCPolynomial = 10;
if (HAL_SPI_Init(&hspi1) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN SPI1_Init 2 */

/* USER CODE END SPI1_Init 2 */

}

 

 

 

 

 

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions

I THINK I FOUND THE CAUSE!

It was that 10K resistor to VDDA. I only put it in there due to a legacy issue on an earlier design by an engineer who died suddenly last year, so I could not ask him why he put that in.

Chat GPT 4 actually say the voltage on the VDDA is important, and if it has the wrong voltage on it (eg: 10K will drop it), it will cause resets from the SPI! ChatGPT is remarkable.


View solution in original post

2 REPLIES 2
DavidByrne
Associate II

I found the line of code in stm32I1xx_hal_spi.c that crashed using debug, if that is any help...

 

{
if ((hspi->Init.Mode == SPI_MODE_SLAVE) || (initial_TxXferCount == 0x01U))
{
*((__IO uint8_t *)&hspi->Instance->DR) = (*hspi->pTxBuffPtr);  // CRASHES HERE!
hspi->pTxBuffPtr += sizeof(uint8_t);

I THINK I FOUND THE CAUSE!

It was that 10K resistor to VDDA. I only put it in there due to a legacy issue on an earlier design by an engineer who died suddenly last year, so I could not ask him why he put that in.

Chat GPT 4 actually say the voltage on the VDDA is important, and if it has the wrong voltage on it (eg: 10K will drop it), it will cause resets from the SPI! ChatGPT is remarkable.