cancel
Showing results for 
Search instead for 
Did you mean: 

DMA giving hardfault in STM32F4 Nucleo @84Mhz

darla14
Senior
Posted on February 02, 2016 at 14:20

I have modified an STM32F4 example and developed a windows application to interact with it for sending data continuously.I am reading a file on PC line by line and sending continuously each line on a serial port (COM9) to which STM32F4Nucleo board is connected.

STM324 is running @84Mhz and UART is configured at 921600 Baudrate.

Host code : 

loop : 

while(1)

//being while loop

//read a line from a text file

 if(line == ''EOF'')

   break

else

{ send a line to COM Port 

   delay 500 ms

}

 //End while loop

 

on STM32 : 

int main(void)

{

  

 HAL_Init();

  

  /* Configure the System clock to 84 MHz */

  SystemClock_Config();

  

/* Initialize UART */

USARTConfig();

        

  /* Infinite loop */

  while (1)

  {

    

if (UART_ReceivedMSG((TMsg*) &Msg)) {

 //do the processing of the MSg data

                   printf(Msg.Data);

}

attached is the file where UART_ReceivedMSG is defined.

So here I am able to see the data coming (on console I/O of the IDE I am using - IAR)

but at times I am getting a hardfault at 

Get_DMA_Flag_Status > 

uint32_t Get_DMA_Flag_Status(DMA_HandleTypeDef *handle_dma)

{

  return (__HAL_DMA_GET_FLAG(handle_dma, __HAL_DMA_GET_FE_FLAG_INDEX(handle_dma)));

}

What could be the cause for this?

Is it some sort of non atomic operation happening at the handle_dma.How can I avoid it.

Thanks in advance !

#hardfault #hardfault #hardfault #uart #dma #dma #dma #stm32f4 #!stm32f4-!stm32f401
11 REPLIES 11
darla14
Senior
Posted on March 09, 2016 at 12:38

And what are the contents of R0 before executing this instruction ?

Or, in other words, which address you try to access when hardfaulting ?

I think above two Qs are different(one is before executing the instruction .what was the content of R0 and second is what was the content at the time of access which gives HF).Answer for the second is in the snapshot I have attahced in previous post.

Correct me if I am wrong !

How can I find what you asked in 1st Qs?

There is while loop where this code is running and it is coming after some 10-15 minutes of run.I may have to debug step in and out to find this.I can do that and paste the result here if you want it.

Posted on March 09, 2016 at 13:53

Well it is pretty clear that R0 is gettin corrupted, itcontains some ASCII values like 0x312D.... which is not a valid or readable address, and bang it Hard Faults.

You NEED to sanity  check the address of the handle and its internal references BEFORE you hand it down to the HAL code so you can identify WHEN this is first occuring. Check it frequently at key points in your code.

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