Hi Folks,
I started porting USB Mass Storage library for STM32F107 and I am hitting with an issue… I am hitting with a hardFault in the library when the data into incoming EP(EP1) is copied into it’s FIFO. OTGD_FS_WritePacket is called from ISR. Not sure why i am getting hit with the ASSERT at the step that I have highlighted in the below code.
USB_OTG_WRITE_REG32( fifo, *((__packed uint32_t *)src) );
Did any one hit with such an issue? This issue is blocking me. Any one please help with this?
USB_OTG_Status OTGD_FS_WritePacket(uint8_t *src, uint8_t ep_num, uint16_t bytes)
{
USB_OTG_Status status = USB_OTG_OK;
uint32_t dword_count = 0 , i = 0;
__IO uint32_t *fifo;
/* Find the DWORD length, padded by extra bytes as neccessary if MPS
- is not a multiple of DWORD */
dword_count = (bytes + 3) / 4;
fifo = USB_OTG_FS_regs.FIFO[ep_num];
for (i = 0; i < dword_count; i++, src += 4)
{
USB_OTG_WRITE_REG32( fifo, *((__packed uint32_t *)src) );
}
I’m not sure what “ASSERT” you are talking about. I don’t see an ASSERT in the code, and a failed C assertion would normally not cause a fault exception.
A Hard Fault exception can occur for quite a few different reasons. If you can, run with a debugger attached to your target and when the Hard Fault occurs, inspect the fault status registers to see what caused the exception. For instance, just this morning I was debugging a hard fault in gdb (note *1) and used “x/w 0xE000ED2C” to show the hard fault status register (HFSR) value.
Your hard fault is likely due to making an access through a pointer with an invalid address.
References
- [[STM32F10xxx Cortex-M3 programming manual. Sections 2.4.2 “Fault escalation and hard faults” and 2.4.3 “Fault status registers and fault address registers”.](http://www.st.com/stonline/products/literature/pm/15491.pdf)
- [[The Definitive Guide to the ARM Cortex-M3. Joseph Yiu. Appendix E “Cortex-M3 Troubleshooting Guide”.](http://books.google.com/books?id=mb5d_xeINZEC&pg=PA422&lpg=PA422&dq=hfsr+cortex-m3&source=bl&ots=kNfGYAEOd0&sig=n5DiKiU7hnziSnh3b16vufBTsls&hl=en&ei=34_kTZiRAoeqsAOF5bkW&sa=X&oi=book_result&ct=result&resnum=3&ved=0CDAQ6AEwAg)[/list]
Notes