cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F103C8T6 SPI DMA hardfault

external2
Associate
Posted on December 24, 2015 at 08:31

Hello All,

I try to send an uint8_t array over SPI with DMA, but the microcontroller going to hard fault handler. The C code is generated by STM32cubeMX.

My source code is:

/* USER CODE BEGIN 0 */

&sharpdefine meret 100

uint8_t spitx[meret];

/* USER CODE END 0 */

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();

  /* Configure the system clock */

  SystemClock_Config();

  /* Initialize all configured peripherals */

  MX_GPIO_Init();

  MX_DMA_Init();

  MX_SPI1_Init();

  /* USER CODE BEGIN 2 */

for(uint16_t i=0;i<meret;i++)

{

spitx[i]=127;

}

HAL_SPI_Transmit_DMA(&hspi1,spitx,meret);

  /* USER CODE END 2 */

  /* Infinite loop */

  /* USER CODE BEGIN WHILE */

  while (1)

  {

  /* USER CODE END WHILE */

  /* USER CODE BEGIN 3 */

  }

  /* USER CODE END 3 */

}

Can someone help to me?

#dma #spi #hardfault
3 REPLIES 3
Posted on December 24, 2015 at 16:46

You'll need to analyze the faulting state, and look at the processor context and register states.

Look at implementing a proper Hard Fault Handler, and examining the instruction that is actually faulting.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
matic
Associate III
Posted on December 24, 2015 at 17:03

As Clive said, step through your code and watch where it goes to HardFault. These HAL functions are quite enormous and it is hard to say what should go wrong.