USB DCD example for Kinetis K21

cancel
Showing results for 
Search instead for 
Did you mean: 

USB DCD example for Kinetis K21

91 Views
Contributor IV

Hi. 

I want that my MCU will available to detect USB connection. I have read this instruction https://www.maximintegrated.com/en/design/technical-documents/tutorials/5/5936.html and I am looking for a code example for using USB DCD in Kinetis MK21FN1MAxxx12. I know that MK21 has USB Device Charger Detection Module.

  1. How to use it to detect if my MCU is connected to the PC USB or to the charger?
  2. There is any library for use?
  3. Are there any restrictions on the use of this module with USB Device?

Thanks

Evgeni

0 Kudos
5 Replies

70 Views
NXP TechSupport
NXP TechSupport

Hi

 

There is a sample code for the USBDCD but this is for the K70 (bare metal), you can check it and use it as a reference

Kinetis® 120MHz bare metal sample code 

Regards

 

0 Kudos

63 Views
Contributor IV

Hi Vicente.

Thanks for your reply. I have added your code sample to the Tower K21 CDC project. But I don't see that it's work: no interrupt, no polling mode. The function DCD_SignalTestig() all-time reads '0' (not 'Active') in every check. The project is attached. Where is a problem?

Thanks.

Evgeni

0 Kudos

52 Views
NXP TechSupport
NXP TechSupport

In this case maybe is better that you use the sample code on the sdk

 dev_phdc_weightscale 

​please check the define 
 
USB_DEVICE_CHARGER_DETECT_ENABLE
to set the DCD
0 Kudos

35 Views
Contributor IV

Hi Vicente.

I have checked this project and have found that in "startup_MK21FA12.s" file doesn't define information according to USBDCD interrupt.
I have added the next content:

PUBWEAK USBDCD_IRQHandler
PUBWEAK USB_DeviceDcdIsrFunction
SECTION .text:CODE:REORDER:NOROOT(2)
USBDCD_IRQHandler
LDR R0, =USB_DeviceDcdIsrFunction
BX R0
and have replaced at USBDCD_IRQHandler after this coded (below) to USB_DeviceDcdIsrFunction. After this correction the USBDCD interrupt begins to work, but with not full detection. It can detect that connected the real charger - it goes to section "Depricated_charger". But in other cases, when USB is connected or not connected to PC I can't view differences: program goes to the same section: "SDP_Detected". I have transferred USBDCD code configuration to my project to files USBCDC.c and USBCDC.h and get the same detection.
For me is very important to detect are my system is connected to PC USB or not connected. After detection I want to decide: do reset from the Main application and go to Bootloader or stay work with the Main application.

The Main application doesn't have driver communication to PC, the Main application is the Baredoard project. Therefore I have created my own USBDCD file and not use with the NXP driver.
I have checked my USBDCD code and don't found any differences vs original weight project USBDCD configuration. My code is very simple but doesn't work. I am working with the Tower board. May be needed to configure any jumpers on the Tower board (I have already checked Tower documentation)? For debugger, I am using a J2 connector and fo USBDCD detection I am using with J19 connector, like for USB CDC communication.
What is wrong?

0 Kudos

32 Views
Contributor IV

Hi.

I have checked this project and have found that in "startup_MK21FA12.s" file doesn't define information according to USBDCD interrupt.
I have added the next content:

PUBWEAK USBDCD_IRQHandler
PUBWEAK USB_DeviceDcdIsrFunction
SECTION .text:CODE:REORDER:NOROOT(2)
USBDCD_IRQHandler
LDR R0, =USB_DeviceDcdIsrFunction
BX R0
and have replaced at USBDCD_IRQHandler after this coded (below) to USB_DeviceDcdIsrFunction. After this correction the USBDCD interrupt begins to work, but with not full detection. It can detect that connected the real charger - it goes to section "Depricated_charger". But in other cases, when USB is connected or not connected to PC I can't view differences: program goes to the same section: "SDP_Detected". I have transferred the USBDCD code configuration to my project to files USBCDC.c and USBCDC.h and get the same detection.
For me is very important to detect are my system is connected to PC USB or not connected. After detection I want to decide: do reset from the Main application and go to Bootloader or stay work with the Main application.

The Main application doesn't have driver communication to PC, the Main application is the Baredoard project. Therefore I have created my own USBDCD file and not use with the NXP driver.
I have checked my USBDCD code and don't found any differences vs original weight scale project USBDCD configuration. My code is very simple but doesn't work. I am working with the Tower board. May be needed to configure any jumpers on the Tower board (I have already checked Tower documentation)? For debugger, I am using a J2 connector and fo USBDCD detection I am using with J19 connector, like for USB CDC communication. I have attached an updated project with new USBCDC files.
What is wrong?

0 Kudos