/var/www/restricted/ssh/stm32/www/stm32circle/ STM CircleOS forum / USB Mass Storage Library hitting with HardFault.. Please help

Username:     
Password:     
             

Forum
  • Index
  •  » STM32 Family
  •  » USB Mass Storage Library hitting with HardFault.. Please help

# 1   2011-05-17 12:25:01 USB Mass Storage Library hitting with HardFault.. Please help

saiRam
Member
Registered: 2011-03-21
Posts: 18

USB Mass Storage Library hitting with HardFault.. Please help

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) );
  }

Offline

 

# 2   2011-05-18 06:45:49 USB Mass Storage Library hitting with HardFault.. Please help

yrt
Administrator
From: Grenoble-France
Registered: 2008-06-11
Posts: 520
Website

Re: USB Mass Storage Library hitting with HardFault.. Please help

I met this kind of issue, and found a bug in ST library (v3.1.0), with Ride using, when I ported CircleOS for STM32F107. Some variables was not initialized in the "OTGD_FS_CoreInitDev" function, which computes the fifo addresses. I should add the line "txfifosize.b.startaddr = 0;"
But the new library version is very different and I don't know if it works better.

Which version do you use ?

Offline

 

# 3   2011-05-20 17:40:17 USB Mass Storage Library hitting with HardFault.. Please help

saiRam
Member
Registered: 2011-03-21
Posts: 18

Re: USB Mass Storage Library hitting with HardFault.. Please help

Hi,

I changed as per your suggestion. It did not fix the issue. I am using Version 3.2.1.

By the way, my flash is 8MB one with 128 blocks each with 64K size. Each block contains 16 sectors each of 4K size. For this, I defined the size as follows:


  Mass_Block_Size[lun] =  65536;
    Mass_Block_Count[lun] = 128;
    Mass_Memory_Size[lun] = (128* 65536);

Crash happens only in this scenario. If I change the values to lower values(just for testing), crash does not happen..Am I missing something here?

Offline

 

# 4   2011-05-23 07:27:09 USB Mass Storage Library hitting with HardFault.. Please help

yrt
Administrator
From: Grenoble-France
Registered: 2008-06-11
Posts: 520
Website

Re: USB Mass Storage Library hitting with HardFault.. Please help

How many LUN did you declare, and what is the value of lun in your declaration ?
The ST library works with only 2, declared like that :

Code:

Mass_Block_Size[0] = 512;

and for NAND flash :

Code:

Mass_Block_Count[1] = NAND_ZONE_SIZE * NAND_BLOCK_SIZE * NAND_MAX_ZONE ;
Mass_Block_Size[1]  = NAND_PAGE_SIZE;
Mass_Memory_Size[1] = (Mass_Block_Count[1] * Mass_Block_Size[1]);

May be the issue is about this ?

Offline

 

# 5   2011-09-20 07:27:23 USB Mass Storage Library hitting with HardFault.. Please help

Johnmayor
New member
Registered: 2011-09-20
Posts: 3

Re: USB Mass Storage Library hitting with HardFault.. Please help

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”.
The Definitive Guide to the ARM Cortex-M3. Joseph Yiu. Appendix E “Cortex-M3 Troubleshooting Guide”.

Notes
*1 Incidentally, my hard faults were caused by the ST SystemInit() trying to set the system clock to 72 MHz on a Value Line chip, max 24 MHz... stupid ST library silently assumes a default MCU of a high-end chip if you don't define one of the proper STM32* preprocessor symbols. There, I fixed that for you... inserted #error instead of assuming a default.


__________________________
website development services in bangalore

Offline

 

  • Index
  •  » STM32 Family
  •  » USB Mass Storage Library hitting with HardFault.. Please help

Board footer