I have a project with KL25, and USB with general HID, it is working fine, but after I port to K20DX256, the USB enum is ok, but windows said it can't start? please give me some idea, where is wrong, thanks

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

I have a project with KL25, and USB with general HID, it is working fine, but after I port to K20DX256, the USB enum is ok, but windows said it can't start? please give me some idea, where is wrong, thanks

跳至解决方案
1,022 次查看
changfuzhao
Contributor III

I have a project with KL25, and USB with general HID, it is working fine, but after I port to K20DX256, the USB enum is ok, but windows said it can't start? please give me some idea, where is wrong, thanks

标签 (2)
0 项奖励
1 解答
661 次查看
mjbcswitzerland
Specialist V

Hi

I loaded your code to my TWR-K20D72M board (standalone - not in tower) and coudl see that the code is not reaching the USB initialisation (the USB registers are still disabled) and the code looks to be in an exception trap (forever loop).

Therefore I couldn't check any USB operation.

What I have done is built the uTasker oproject for your board with USB-HID mouse operation on the local USB interface. Pressing the two user buttons on the board will move the mouse up and down to allow verifying that it is operating correctly. The system clock is set to 72MHz, bus clock 36MHz and the 48MHz USB clock is derived from the system clock divided by 1.5 using SIM_CLKDIV2 = 5 and SIM_SOPT2 = 0x00051000

If you can verify that this runs correctly on your board you can then use it as reference (compare its register settings to yours).

Regards

Mark

在原帖中查看解决方案

0 项奖励
12 回复数
661 次查看
mjbcswitzerland
Specialist V

Hi

Differences between KL and K for USB:

1. USB controller has to be given rights to access FLASH

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

2. The USB clock source must be selected (in SIM_SOPT2) correctly and have the right speed

3. The MPU is usually disabled so that USB can access resources

MPU_CESR = 0;                                                    // allow concurrent access to MPU controller

But that is about it.

Regards

Mark

0 项奖励
661 次查看
changfuzhao
Contributor III

thank you for give me this answer.

I think USB controler only read and write to RAM, not Flash, is it right?

0 项奖励
661 次查看
mjbcswitzerland
Specialist V

Hi

The USB controller can send data (such as emumeration descriptors or strings) directly from FLASH. It depends on the SW implementation. Some SW only uses only RAM and so has to first copy const data to a RAM buffer, which is however less efficient (in terms of code size and speed).

Therefore I always send directly from Flash if there is no reason not to.

Of course the USB controller never writes to Flash directly.

Regardfs

Mark

0 项奖励
661 次查看
changfuzhao
Contributor III

HI, Mark,

yes, I put  every thing into RAM. and I also add code:

 

FMC_PFAPR |= (1<<6);

I can't find  MPU_CESR


the device enum is fine at beginning, but after 15 to 20 second, windows notice to  "This device cannot start. (Code 10)"

does here have some difference else  between KL25 and K20?

0 项奖励
661 次查看
mjbcswitzerland
Specialist V

Hi

If your processor has a MPU (memory protection unit) it will not allow USB to work without either disabling it or configuring a slave port configuration for it.

Usually it is simply disabled by

MPU_CESR = 0; [Memory Protection Unit Control/Error Status Register]


If you have a 72MHz or 50MH K20 it doesn't have this and so doesn't need it.


Apart from that you just need to ensure that the USB module is clocked with an accurate 48MHz clock.


Regards


Mark


http://www.utasker.com/kinetis.html

0 项奖励
661 次查看
changfuzhao
Contributor III

Hi, Mark,

I post my USB_Init  code here, please take time and have a look, may be some thing wrong at them

0 项奖励
661 次查看
mjbcswitzerland
Specialist V

Hi

I am sorry but it takes too long to search through large blocks of code without knowing other details about the processor and its other settings.

If you would like me to tell me what is wrong with it please post a binary that can be loaded to a Freescale reference board and then I can see what the problem is.

Otherwise you can take working USB code from the uTasker project at KINETIS Project Code - this doesn't need any porting between processors and so will run on all KL and K devices with USB. If you run your settings in its simulator it will tell you if anything is incorrect and can't work.

Regards

Mark

0 项奖励
661 次查看
changfuzhao
Contributor III

thanks Mark, I post my s19 to you, please try it when you have time

thank you a lot


0 项奖励
661 次查看
mjbcswitzerland
Specialist V

Hi

Please tell me which board I can run this on.

Thanks

Mark

0 项奖励
661 次查看
changfuzhao
Contributor III

HI, Mark,

I use freescale, TWR-k20d72M

thanks


0 项奖励
662 次查看
mjbcswitzerland
Specialist V

Hi

I loaded your code to my TWR-K20D72M board (standalone - not in tower) and coudl see that the code is not reaching the USB initialisation (the USB registers are still disabled) and the code looks to be in an exception trap (forever loop).

Therefore I couldn't check any USB operation.

What I have done is built the uTasker oproject for your board with USB-HID mouse operation on the local USB interface. Pressing the two user buttons on the board will move the mouse up and down to allow verifying that it is operating correctly. The system clock is set to 72MHz, bus clock 36MHz and the 48MHz USB clock is derived from the system clock divided by 1.5 using SIM_CLKDIV2 = 5 and SIM_SOPT2 = 0x00051000

If you can verify that this runs correctly on your board you can then use it as reference (compare its register settings to yours).

Regards

Mark

0 项奖励
661 次查看
changfuzhao
Contributor III

thanks Mark

0 项奖励