I am using CodeWarrior 6.3 C Compiler for Coldfire MCF52223 on the Freescale M52223EVB Development board. I need to use the processor USB interface in Host mode. My software is based on the CMX routines (Host Demo) downloaded from Freescale Web Site.
My problems is:
1) In the reference manual of the MCF52223 about chapter “184.108.40.206 Frame Number Register Low/High (FRM_NUML, FRM_NUMH)” the descriptor is errata. (it is the same of 220.127.116.11).
2) In the demo code CMX I have discovered a bug in this loop in subroutine “usb_host_start_transaction(..)” in the file “usb_host.c”
It seems that the MCF_USB_FRM_NUM register, sometimes returns invalid values. So the elapsed time between two transactions may be less than desired , so the device stops working.
I believe you've found a bug...
The #define from mcf5222x_reg.h:
#define MCF_USB_FRM_NUM (MCF_USB_INT_STAT=MCF_USB_INT_STAT_SOF_TOK ,MCF_USB_FRM_NUML | (((hcc_u16)MCF_USB_FRM_NUMH)<<8))
Is not atomic -- it can read the low and high bytes in either order, and one can be before a rollover and the other can be after.
To protect this, I believe you'd need to assemble the 16 bit result and "validate" it -- if it looks invalid (i.e., if the low and high bytes don't appear to have consistently rolled over), you'd have to retry the assembly -- if new low is less than old low (i.e., rollover occurred) and new high is not greater than old high (rollover did not occur consistently), then retry the assembly.
Or for your purposes (depending on the interval required), you might be able to get by just using the low 8 bits of the frame number.
Hi Rich, sorry for my late.
Your note seems to be correct, that could be the problem.
Now I have solved the problem checking the loop number in the “wait till frame is due”. If this is less than 3, I wait other my_device.eps[ep].interval times.
This is not correct but now my device does not crash.
This is my code:
I am using the mouse and the keyboard devices and typically the my_device.eps[ep].interval is 10ms, therefore I can use only the low byte of the frame register.
I have another problem with the hid_set_report(hcc_u8 report_id, hcc_u8 *buffer, hcc_u16 length) to turn on/off the keyboard leds. I think that this problem is due to the SOF threshold and frame registers misaligned. I'm investigating this, if I can not find the solution I will open another thread in this forum.
In this moment I have already found an error of the toggle DATA0/1 in usb_host_start_transaction(..) in a setup transaction:
Thank you very much for your answers .
Rich T wrote:But I'm guessing changing endpoints is your bigger problem... :smileysad:-- Rich
Maybe, in fact if I use the hid_set_report(0, &leds, 1) to turn on/off the keyboard leds (I need to use EP=0 for this command and change to EP=1 for others commands) often the keyboard hangs up; if not both mouse and keyboard work correctly.