I get a hardfault ( unaligned ) using an app based on combining 1024 samples lwip_httpsrv_freertos and host_msd_fatfs_freertos. Newbie attempt on 1024 eval board.
Deviations from the samples:
1) heap4 model , ucHeap
2) No off chip RAM used; 192K DTC used
3) code added to align ( 8 ) the source for memcpy in ENET_SendFrame() . This can avoid the hardfault here but same issue arises elsewhere.
4) xTaskCreate(USB_HostTask) and xTaskCreate(USB_HostApplicationTask) both commented out.
Symptom: Enet runs fine unless I invoke this function within USB_HostApplicationInit:
status = USB_HostInit(CONTROLLER_ID, &g_HostHandle, USB_HostEvent); // <== Problematic?
Would highly welcome questions, feedback on specific issues, and general input as to how to debug and/or fix this. Attached are linker, memory and hardfault screenshots. Thanks, dB
Hi
Try a USB + ENET reference from here too:
https://www.utasker.com/iMX/RT1024.html
If you are sure it is alignment you could try adding -mno-unaligned-access to the compiler flag settings. This will ensure GCC doesn't generate mis-aligned addresses (which it does frequently when max. optimisation is used) in packed structs or when generally optimising.
If that doesn't help you can easily identify the cause of such faults if you modify the hard fault handler to be an empty interrupt
void hardfault(void)
{
// optionally add a counter and set a break point on it
volatile static int iCnt = 0;
iCnt++;
}
When it hits just switch to disassembler mode and step out of the hard fault which will return to the instruction that caused it. Then see the instruction (probably a pointer it is using is not aligned), where it was set and why it is not as it should be.
Regards
Mark
i.MX and Kinetis stock available at https://www.utasker.com/Shop/semi.html
I switched to NewlibNano ( nohost ) and it worked. Optimization was at zero all along.