Skip to main content
Associate
Solved

Hard Fault

Hello all ,

I am facing a issue of hard fault because of some reason however after analyzing issue I  suspect this could be due to  use of structure having uint64_t variable having bit fielding. I have also attached snapshot of issue which I am facing(Precise data access violation).

devendra_0-1732019755800.jpeg

 

typedef struct _st_device_info_payload

{

 uint64_t IMEI : 50;

 uint64_t BLE_MAC_ID : 48;

 uint64_t WiFi_MAC_ID : 48;

 uint16_t Server_Port;

 uint64_t SIM_ICCID_1 :6;

 uint64_t SIM_ICCID_2 :64;

 char Server_Domain_Name[20];

 char APN[20];

}st_device_info_payload;

Please confirm these few points.

1. Can I use uint64_t for STM32H7 MCU.

2. Can we use bit fielding for uint64_t variable for stm32h7. 

 

 

    This topic has been closed for replies.
    STeaBest answer
    ST Employee

    Hello @devendra ,

    answering your questions:

    1. yes, you can use type uint64 with STM32H7.
    2. use bit fielding for uint64_t variable for any 32 bit device is risky as it can lead to unaligned access which could cause a Hardfault and most probably it's you case.

    you need to further pinpoint the exact instruction which lead to the Hardfault to make sure it is a problem of memory alignment so my recommendation is to take a look at this article which will help you debug the Hardfault.
    Regards

    In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

    3 replies

    mƎALLEm
    ST Technical Moderator

    Hello @devendra ,

    Please review how to post a thread in this community: https://community.st.com/t5/community-guidelines/how-to-write-your-question-to-maximize-your-chances-to-find-a/ta-p/575228

    This is mainly regarding the title, share a better image resolution, and how to share the code, MCU part number..

    Thank you for your understanding.

    To give better visibility on the answered topics, please click "Best answer" on the reply which solved your issue or answered your question.
    STeaBest answer
    ST Employee

    Hello @devendra ,

    answering your questions:

    1. yes, you can use type uint64 with STM32H7.
    2. use bit fielding for uint64_t variable for any 32 bit device is risky as it can lead to unaligned access which could cause a Hardfault and most probably it's you case.

    you need to further pinpoint the exact instruction which lead to the Hardfault to make sure it is a problem of memory alignment so my recommendation is to take a look at this article which will help you debug the Hardfault.
    Regards

    In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
    Pavel A.

    > structure having uint64_t variable having bit fielding

    This immediately hints to alignment requirements. 64-bit variables should be aligned on 64 bit even on Cortex-M7. 

    Bit fields wider than 32 bits ... not sure. Use disassembly view to see how it compiles with your compiler (gcc or IAR or Keil or ??)