This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CC1312R7: IRQ Hard Fault: FORCED: USAGE: UNALIGNED in macAllocTxBuffer from WiSun Fan code SDK 6.40.00.13

Part Number: CC1312R7
Other Parts Discussed in Thread: SYSBIOS, WI-SUN,

Hi

UPDATE to update: Previous statement was wrong. It crashes with security disabled. However the exception *only* occurs if there is a running WiSun network with a border router. So if the network code does not see a network in the air, no exception occurs.

We are getting HWI exception in the above function (accordingt to the SP,LR,PC registers in the exceptionInfo)

How do we fix this?

Stack trace according to debugger:

Texas Instruments XDS110 USB Debug Probe/Cortex_M4_0 (Suspended)    
    macAllocTxBuffer() at mac_hl_patch.c:1 690 0x00048A76    
    macBuildCommonReq() at mac_hl_patch.c:2 739 0x00033B1E    
    macRadioSendEnhAck() at mac_radio_tx.c:1 179 0x0007B402    
    rxFcsIsr() at mac_rx.c:1 331 0x0001524A    
    rxPayloadIsr() at mac_rx.c:1 052 0x00015024    
    rxStartIsr() at mac_rx.c:0 0x0000B590    
    macRxFrameIsr() at mac_rx.c:400 0x0000B2FE    
    macRxCbSubG() at mac.c:0 0x00021E3C    
    macRxCb() at mac.c:546 0x00021E1C    
    RF_radioOpDoneCb() at RFCC26X2_multiMode.c:2 947 0x00039496    
    RF_fsmActiveState() at List.h:155 0x0000E9AC    
    ti_sysbios_knl_Swi_run() at Swi.c:185 0x0006994A    
    ti_sysbios_knl_Swi_restoreHwi() at Swi.c:440 0x0005538A    
    ti_sysbios_family_arm_m3_Hwi_doSwiRestore() at Hwi.c:1 754 0x0008A7FA    
    ti_sysbios_family_arm_m3_Hwi_dispatch + 0xb0 ()

  • Hi os,

    Which project are you basing your project on? Is this in the out of the box Wi-SUN projects?

    Please explain the where you are using this function? 

    Regards,

    Sid 

  • Yes, it based on the ns_coap_node_src_LP_CC1312R7_tirtos7_ticlang from the SDK.
    We are not using the function, it is part of network stack and is called from an IRQ.

  • Also, there are a number of inconsistencies in the mbed port:

    in mbed_config.h we have
    #define MBED_CONF_NANOSTACK_HAL_CRITICAL_SECTION_USABLE_FROM_INTERRUPT        0
    which presumably should tell the code that the critical section is *not* usable from interrupt.

    However, arm_hal_timer.c only checks that the MBED_CONF_NANOSTACK_HAL_CRITICAL_SECTION_USABLE_FROM_INTERRUPT is defined, not what it is set to.
    Does this generate incorrect code?

    I have tried undefining MBED_CONF_NANOSTACK_HAL_CRITICAL_SECTION_USABLE_FROM_INTERRUPT  but we still get the same exception.

    There are also two different conflicting settings for MBED_CONF_NANOSTACK_HAL_EVENT_LOOP_THREAD_STACK_SIZE
    In mbed_config.h it is set to 6144, in mbed_config_app.h it is set to 3800. It is tha last definition that the build uses.

    Which is the correct statck size for the stack event loop?

  • Ok, we

    typedef struct {
        const char *uri;
        uint8_t methods;
        coap_service_request_recv_cb *callback;
    } servicetable_t;
    
    #define NUMBEROFSERVICES 6
    
    servicetable_t servicetable[NUMBEROFSERVICES ] =
    {
     { "option"
       , COAP_SERVICE_ACCESS_GET_ALLOWED | COAP_SERVICE_ACCESS_PUT_ALLOWED | COAP_SERVICE_ACCESS_DELETE_ALLOWED
       , node_option_cb
     }
     ,{ "group"
        , COAP_SERVICE_ACCESS_GET_ALLOWED | COAP_SERVICE_ACCESS_PUT_ALLOWED | COAP_SERVICE_ACCESS_DELETE_ALLOWED
        , group_option_cb
     }
     ,{ "trig"
        , COAP_SERVICE_ACCESS_PUT_ALLOWED
        , trig_cb
     }
     ,{ "ping"
        , COAP_SERVICE_ACCESS_PUT_ALLOWED
        , dummy_cb
     }
     ,{ "req"                          
        , COAP_SERVICE_ACCESS_PUT_ALLOWED
        , req_cb
     }
     ,{ "Dummy"                          // TODO: Remove
        , COAP_SERVICE_ACCESS_GET_ALLOWED | COAP_SERVICE_ACCESS_PUT_ALLOWED | COAP_SERVICE_ACCESS_DELETE_ALLOWED
        , dummy_cb
     }
    
    // ,{ "cal"
    //    , COAP_SERVICE_ACCESS_GET_ALLOWED
    //        | COAP_SERVICE_ACCESS_PUT_ALLOWED
    //        | COAP_SERVICE_ACCESS_DELETE_ALLOWED
    //        | COAP_SERVICE_ACCESS_POST_ALLOWED
    //    , cal_cb
    // }
    // ,{ "reboot"
    //    , COAP_SERVICE_ACCESS_PUT_ALLOWED
    //    , reboot_cb
    // }
    // ,{ "debug"
    //    , COAP_SERVICE_ACCESS_GET_ALLOWED | COAP_SERVICE_ACCESS_PUT_ALLOWED
    //    , debug_cb
    // }
    //
    };
    
    have found what triggers the network stack exception. It seems that having too large table initialization causes the corruption. So the firmware with the below code works perfectly with the array size set to 6. If we increase the array size to 7 we get the exception in macAllocTxBuffer.

    Note that the exception occures *before* the table is touched, macAllocTxBuffer causes exception before the WiSun-network has connected, and before any of the coap callbacks are registred.

    So I have no idea why the network stack gets corrupted by this. Does the compiler generate incorrect structure inits that overwrite nanostack data structures?
    Any suggestions?

  • You could diff the two map files generated with array size 6 and an array size 7 to see if there is any obvious change. Is there an easy way to reproduce this issue from the OOB example? 

  • I found what generates the error. Having a static buffer inside a function causes the TI radio stack to crash with the above exception.
    This definitely looks lika a code generation or linker error. Maybe it is time to escalte this to engineering?

    //The follwing code causes the TI radio stack to crash.
    // Note that the stack crashes before this code runs, or the buffer is touched in any way.
    // The exceptiopn occures before any coap handler have been registered
    int cal_cb         (int8_t service_id, uint8_t source_address[static 16], uint16_t source_port, sn_coap_hdr_s *request_ptr) {
        DebugWriteUart0 ("\r\ncal_cb: ");
        DebugPrintCoap (request_ptr);
    
        const char *reply= NULL;    // NULL indicates no error message
        coapQuery_t optionQuery;
        int numberOfQueryOptions=0;
    
    #define CALOUTBUFSIZE   255
        static unsigned char buf[CALOUTBUFSIZE];  // TODO: Is this the thing that crashes TIs stack when static?
    
    //////////////////////////////////////////////////////////////////////////
    // The following code *works* flawlessly. No other changes whatsoever:
    int cal_cb         (int8_t service_id, uint8_t source_address[static 16], uint16_t source_port, sn_coap_hdr_s *request_ptr) {
        DebugWriteUart0 ("\r\ncal_cb: ");
        DebugPrintCoap (request_ptr);
    
        const char *reply= NULL;    // NULL indicates no error message
        coapQuery_t optionQuery;
        int numberOfQueryOptions=0;
    
    #define CALOUTBUFSIZE   255
        unsigned char buf[CALOUTBUFSIZE];  
    

  • Update: see separate comment to your previous question for the real cause.
    It is not the coap method table that is the problem, it is the static allocation keyword inside a function, that causes the compiler and/or linker to generate incorrect code (or possible some unforeseen interaction in the TI radio stack). The reason the crash occurs if we change service table is that the linker will not link the cal_cb function if it is not refered to in the table.

    Here is the start of the diff, and the wisun parts. Left is map for working firmware, right is from firmware that casues the hardware exception.
    So what can you tell from this?

    4c4
    < >> Linked Mon Apr 17 09:56:49 2023
    ---
    > >> Linked Mon Apr 17 11:17:45 2023
    7c7
    < ENTRY POINT SYMBOL: "ResetISR"  address: 0008e31b
    ---
    > ENTRY POINT SYMBOL: "ResetISR"  address: 0008e633
    14c14
    <   FLASH                 00000000   000ae000  00092a20  0001b5e0  R  X
    ---
    >   FLASH                 00000000   000ae000  00092d54  0001b2ac  R  X
    16c16
    <   SRAM                  20000000   00024000  0001100e  00012ff2  RW X
    ---
    >   SRAM                  20000000   00024000  00011125  00012edb  RW X
    23c23
    < 00000000    00000000    0008e52c   0008e52c    r-x
    ---
    > 00000000    00000000    0008e848   0008e848    r-x
    25,30c25,30
    <   00000040    00000040    00006474   00006474    r-- .rodata
    <   000064b8    000064b8    00088074   00088074    r-x .text.1
    < 0008e52c    0008e52c    00000008   00000008    rw-
    <   0008e52c    0008e52c    00000008   00000008    rw- .args
    < 0008e534    0008e534    000004f4   000004f4    r--
    <   0008e534    0008e534    000004f4   000004f4    r-- .cinit
    ---
    >   00000040    00000040    000064a4   000064a4    r-- .rodata
    >   000064e8    000064e8    00088360   00088360    r-x .text.1
    > 0008e848    0008e848    00000008   00000008    rw-
    >   0008e848    0008e848    00000008   00000008    rw- .args
    > 0008e850    0008e850    0000050c   0000050c    r--
    >   0008e850    0008e850    0000050c   0000050c    r-- .cinit
    47c47
    < 20001860    20001860    0000f173   00000000    rw-
    ---
    > 20001860    20001860    0000f28b   00000000    rw-
    49,50c49,50
    <   20001870    20001870    0000df73   00000000    rw- .bss.3
    <   2000f7e8    2000f7e8    000011eb   00000000    rw- .data
    ---
    >   20001870    20001870    0000e072   00000000    rw- .bss.3
    >   2000f8e8    2000f8e8    00001203   00000000    rw- .data
    67c67
    < .rodata    0    00000040    00006474
    ---
    > .rodata    0    00000040    000064a4
    72,363c72,363
    [non wisun deleted]
    <                   00002eda    00000237     wisun_tasklet.o (.rodata.WISUN_CLIENT_CERTIFICATE)
    <                   00003561    000001e1     wisun_tasklet.o (.rodata.WISUN_ROOT_CERTIFICATE)
    <                   00003f81    00000003     kde_helper.o (.rodata.wisun_oui)
    <                   0000436c    000000e7     wisun_tasklet.o (.rodata.WISUN_CLIENT_KEY)
    <                   0000628c    0000000f     wisun_tasklet.o (.rodata.str1.1)
    <                   000062b4    0000000c     wisun_tasklet.o (.rodata..L__const.wisun_tasklet_configure_and_connect_to_network.own_cert)
    <                   000062c0    0000000c     wisun_tasklet.o (.rodata..L__const.wisun_tasklet_configure_and_connect_to_network.trusted_cert)
    >                   00002f0a    00000237     wisun_tasklet.o (.rodata.WISUN_CLIENT_CERTIFICATE)
    >                   00003591    000001e1     wisun_tasklet.o (.rodata.WISUN_ROOT_CERTIFICATE)
    >                   00003fb1    00000003     kde_helper.o (.rodata.wisun_oui)
    >                   0000439c    000000e7     wisun_tasklet.o (.rodata.WISUN_CLIENT_KEY)
    >                   000062bc    0000000f     wisun_tasklet.o (.rodata.str1.1)
    >                   000062e4    0000000c     wisun_tasklet.o (.rodata..L__const.wisun_tasklet_configure_and_connect_to_network.own_cert)
    >                   000062f0    0000000c     wisun_tasklet.o (.rodata..L__const.wisun_tasklet_configure_and_connect_to_network.trusted_cert)
    <                   0002b7e0    000001c6     wisun_tasklet.o (.text.wisun_tasklet_configure_and_connect_to_network)
    <                   0003f20a    0000012a     application.o (.text.nanostack_wisunInterface_configure)
    <                   00043824    00000112     wisun_tasklet.o (.text.wisun_tasklet_clear_stored_certificates)
    <                   000477ee    000000fe     wisun_tasklet.o (.text.wisun_tasklet_add_stored_certificates)
    <                   00049638    000000f6     wisun_tasklet.o (.text.wisun_tasklet_parse_network_event)
    <                   0004a292    000000f2     wisun_tasklet.o (.text.wisun_tasklet_connect)
    <                   00069924    0000007e     wisun_tasklet.o (.text.wisun_tasklet_main)
    <                   000699a2    0000007e     wisun_tasklet.o (.text.wisun_tasklet_statistics_do_start)
    <                   0007217c    00000066     wisun_tasklet.o (.text.wisun_tasklet_statistics_start)
    <                   000731e0    00000062     icmpv6.o (.text.icmpv6_na_wisun_aro_handler)
    <                   000739ea    00000062     wisun_tasklet.o (.text.wisun_tasklet_network_init)
    <                   000762fe    0000005a     application.o (.text.nanostack_wisunInterface_connect)
    <                   0007b192    0000004e     application.o (.text.nanostack_wisunInterface_bringup)
    <                   00082bc8    0000003c     wisun_tasklet.o (.text.wisun_tasklet_init)
    <                   000862ac    00000030     wisun_tasklet.o (.text.wisun_tasklet_network_state_changed)
    >                   0002ba00    000001c6     wisun_tasklet.o (.text.wisun_tasklet_configure_and_connect_to_network)
    >                   0003f42a    0000012a     application.o (.text.nanostack_wisunInterface_configure)
    >                   00043a44    00000112     wisun_tasklet.o (.text.wisun_tasklet_clear_stored_certificates)
    >                   00047a0e    000000fe     wisun_tasklet.o (.text.wisun_tasklet_add_stored_certificates)
    >                   00049858    000000f6     wisun_tasklet.o (.text.wisun_tasklet_parse_network_event)
    >                   0004a4b2    000000f2     wisun_tasklet.o (.text.wisun_tasklet_connect)
    >                   00069bfc    0000007e     wisun_tasklet.o (.text.wisun_tasklet_main)
    >                   00069c7a    0000007e     wisun_tasklet.o (.text.wisun_tasklet_statistics_do_start)
    >                   00072454    00000066     wisun_tasklet.o (.text.wisun_tasklet_statistics_start)
    >                   000734b8    00000062     icmpv6.o (.text.icmpv6_na_wisun_aro_handler)
    >                   00073cc2    00000062     wisun_tasklet.o (.text.wisun_tasklet_network_init)
    >                   000765d6    0000005a     application.o (.text.nanostack_wisunInterface_connect)
    >                   0007b46a    0000004e     application.o (.text.nanostack_wisunInterface_bringup)
    >                   00082ea0    0000003c     wisun_tasklet.o (.text.wisun_tasklet_init)
    >                   00086584    00000030     wisun_tasklet.o (.text.wisun_tasklet_network_state_changed)
    <                   200108ec    00000004     wisun_tasklet.o (.data.mac_api)
    <                   20010950    00000004     wisun_tasklet.o (.data.statistics)
    <                   20010960    00000004     wisun_tasklet.o (.data.wisun_certificates_ptr)
    <                   20010964    00000004     wisun_tasklet.o (.data.wisun_tasklet_data_ptr)
    <                   200109c6    00000001     wisun_tasklet.o (.data.statistics_started)
    >                   20010a04    00000004     wisun_tasklet.o (.data.mac_api)
    >                   20010a68    00000004     wisun_tasklet.o (.data.statistics)
    >                   20010a78    00000004     wisun_tasklet.o (.data.wisun_certificates_ptr)
    >                   20010a7c    00000004     wisun_tasklet.o (.data.wisun_tasklet_data_ptr)
    >                   20010ade    00000001     wisun_tasklet.o (.data.statistics_started)
    < 00002eda  WISUN_CLIENT_CERTIFICATE
    < 0000436c  WISUN_CLIENT_KEY
    < 00003561  WISUN_ROOT_CERTIFICATE
    > 00002f0a  WISUN_CLIENT_CERTIFICATE
    > 0000439c  WISUN_CLIENT_KEY
    > 00003591  WISUN_ROOT_CERTIFICATE
    < 0007b193  nanostack_wisunInterface_bringup
    < 0003f20b  nanostack_wisunInterface_configure
    < 000762ff  nanostack_wisunInterface_connect
    > 0007b46b  nanostack_wisunInterface_bringup
    > 0003f42b  nanostack_wisunInterface_configure
    > 000765d7  nanostack_wisunInterface_connect
    < 00003f81  wisun_oui
    < 0004a293  wisun_tasklet_connect
    < 00082bc9  wisun_tasklet_init
    < 000739eb  wisun_tasklet_network_init
    < 0007217d  wisun_tasklet_statistics_start
    > 00003fb1  wisun_oui
    > 0004a4b3  wisun_tasklet_connect
    > 00082ea1  wisun_tasklet_init
    > 00073cc3  wisun_tasklet_network_init
    > 00072455  wisun_tasklet_statistics_start
    < 00002eda  WISUN_CLIENT_CERTIFICATE
    < 00003561  WISUN_ROOT_CERTIFICATE
    < 00003f81  wisun_oui
    < 0000436c  WISUN_CLIENT_KEY
    < 0003f20b  nanostack_wisunInterface_configure
    < 0004a293  wisun_tasklet_connect
    < 0007217d  wisun_tasklet_statistics_start
    < 000739eb  wisun_tasklet_network_init
    < 000762ff  nanostack_wisunInterface_connect
    < 0007b193  nanostack_wisunInterface_bringup