Skip to main content
gaojian
Associate II
April 11, 2013
Question

HardFault Handler occurs with the memcpy function

  • April 11, 2013
  • 7 replies
  • 1780 views
Posted on April 11, 2013 at 10:52

void DMA2_Stream2_Rx(void)

{

  USART_ITConfig(USART1,USART_IT_RXNE,ENABLE);

  USART_ITConfig(USART1,USART_IT_ORE_RX,ENABLE);

  USART_DMACmd(USART1,USART_DMAReq_Rx,DISABLE);                    

  memcpy(&mbdCurRxDNode->c->rxBuf[1], &stm32f4_mbus_drv_rx_buf[1],7);

  STM32F4_ENDRX_RxInt();

}

This is the DMA interrupter function,when the program excutes memcpy function,the HardFault Hander occurs. The destination buffer and the source buffer are global!
    This topic has been closed for replies.

    7 replies

    frankmeyer9
    Associate III
    April 11, 2013
    Posted on April 11, 2013 at 11:34

      memcpy(&mbdCurRxDNode->c->rxBuf[

    1

    ], &stm32f4_mbus_drv_rx_buf[

    1

    ],7);

     

    In C, arrays ALWAYS start at index 0. So your memcpy() parameters are very likely to be odd addresses, which is only supported by certain instructions.(

    http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0553a/BABFAIGG.html

    )

    And the library code for memcpy() may not use them (assuming you have picked the correct library at all).

    Why use clib at all ?

    A simple for loop might do as well.

    gaojian
    gaojianAuthor
    Associate II
    April 11, 2013
    Posted on April 11, 2013 at 11:36

    And it just occurs when booting from flash!

    Can anybody resolve this issue? Thanks

    gaojian
    gaojianAuthor
    Associate II
    April 11, 2013
    Posted on April 11, 2013 at 11:41

    • Thanks for your answer. I use the array from xx[1] because I don't want for xx[0].
    • And I use a ''for'' loop to do the copy, but the Hardfualt still occurs. 

    frankmeyer9
    Associate III
    April 11, 2013
    Posted on April 11, 2013 at 12:00

    Did you check that your address parameters point to the actual addresses upon entering memcpy ?

      memcpy(&mbdCurRxDNode->c->rxBuf[1], &stm32f4_mbus_drv_rx_buf[1],7);

     

    I find the suspicious. Adding braces could help to explain what you mean.

    &mbdCurRxDNode->c->rxBuf[1],  -> &

    (

    mbdCurRxDNode->c->rxBuf[1]

    )

    Tesla DeLorean
    Guru
    April 11, 2013
    Posted on April 11, 2013 at 13:41

    One, or both addresses are bad, determine which, determine why.

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    gaojian
    gaojianAuthor
    Associate II
    April 11, 2013
    Posted on April 11, 2013 at 14:16

    I checked the address when Hardfault occurs. The destinaton buffer address(mbdCurRxDNode->c->rxBuf[0]) is 0x01478048 and it is not an effective memory address.

    But I don't know why.

    Tesla DeLorean
    Guru
    April 11, 2013
    Posted on April 11, 2013 at 15:51

    Your job will be to figure that out, one of the structures/unions along that chain  (pointers to pointers) has bogus content. Understand how the structures in the chain were built and filled.

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