Skip to main content
Visitor II
November 19, 2024
Solved

Hard Fault

  • November 19, 2024
  • 3 replies
  • 784 views

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.
    Best answer by STea

    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

    3 replies

    Technical Moderator
    November 19, 2024

    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.

    STeaAnswer
    ST Employee
    November 19, 2024

    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

    Super User
    November 19, 2024

    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 ??)