USB Stack: Putting enumeration strings in FLASH?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

USB Stack: Putting enumeration strings in FLASH?

794 Views
wre
Contributor III

Using the USB Stack v4.1.1 (for HID device) on an MK20DX128VLH5, I noticed that the enumeration structures were in RAM due to the following macro definitions at the top of usb_descriptor.c:

#if (defined __MCF52xxx_H__) || (defined __MK_xxx_H__)

/* Put descriptors in RAM */

#define USB_DESC_CONST

#else

#define USB_DESC_CONST const

#endif

where __MK_xxx_H__ is defined in the project. 

If I change the macro above to only "#if (defined __MCF52xxx_H__)" in order to put the structures into FLASH the code will compile fine (IAR EWARM) but the device will not enumerate.

Is there a fundamental reason that the enumeration strings can not be in FLASH?

Thanks,

Bill

Labels (2)
Tags (4)
1 Reply

566 Views
mjbcswitzerland
Specialist V

Bill

By default the USB controller doesn't have rights to access Flash and so, when it does, it reads usually 0xff or rubbish, which is then sent out, causing the emuleration to fail.

To work with descriptors in Flash do the following initialisations:

FMC_PFAPR |= FMC_FPAPR_USB_FS;                                  // allow USB controller to read from Flash

where FMC_FPAPR_USB_FS is  FMC_PFAPR_M3AP_RD (0x00000040) when using a K20 50MHz

or FMC_PFAPR_M4AP_RD (0x00000100) when using a 100MHz K20

[Which bus master number the USB controller has depends on the exact chip]

Also set

MPU_CESR = 0;                                              

// allow concurrent access to MPU controller

if you have a 100MHz plus part that has the memory protection unit.

The uTasker UBS stack [µTasker Kinetis support] works with all descriptors and strings directly in Flash and handles such processor configuration details transparently.

Regards

Mark