Skip to content

Commit 046f3cd

Browse files
committed
Update USB driver for devices with Kinetis SDK support
1. Fix build issues with IAR and GCC toolchain 2. Update clock initialization code Signed-off-by: Mahadevan Mahesh <[email protected]>
1 parent 4a4d09f commit 046f3cd

File tree

1 file changed

+8
-17
lines changed

1 file changed

+8
-17
lines changed

features/unsupported/USBDevice/USBDevice/USBHAL_KL25Z.cpp

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818

1919
#if defined(TARGET_KL25Z) | defined(TARGET_KL43Z) | defined(TARGET_KL46Z) | defined(TARGET_K20D50M) | defined(TARGET_K64F) | defined(TARGET_K22F) | defined(TARGET_TEENSY3_1)
2020

21+
#if defined(TARGET_KSDK2_MCUS)
22+
#include "fsl_common.h"
23+
#endif
2124
#include "USBHAL.h"
2225

2326
USBHAL * USBHAL::instance;
@@ -65,7 +68,8 @@ typedef struct BDT {
6568
// there are:
6669
// * 16 bidirectionnal endpt -> 32 physical endpt
6770
// * as there are ODD and EVEN buffer -> 32*2 bdt
68-
__attribute__((__aligned__(512))) BDT bdt[NUMBER_OF_PHYSICAL_ENDPOINTS * 2];
71+
MBED_ALIGN(512) BDT bdt[NUMBER_OF_PHYSICAL_ENDPOINTS * 2]; // 512 bytes aligned!
72+
6973
uint8_t * endpoint_buffer[(NUMBER_OF_PHYSICAL_ENDPOINTS - 2) * 2];
7074
uint8_t * endpoint_buffer_iso[2*2];
7175

@@ -86,7 +90,7 @@ USBHAL::USBHAL(void) {
8690
// Disable IRQ
8791
NVIC_DisableIRQ(USB0_IRQn);
8892

89-
#if defined(TARGET_K64F)
93+
#if (defined(FSL_FEATURE_SOC_MPU_COUNT) && (FSL_FEATURE_SOC_MPU_COUNT > 0U))
9094
MPU->CESR=0;
9195
#endif
9296
// fill in callback array
@@ -121,18 +125,9 @@ USBHAL::USBHAL(void) {
121125
epCallback[28] = &USBHAL::EP15_OUT_callback;
122126
epCallback[29] = &USBHAL::EP15_IN_callback;
123127

124-
#if defined(TARGET_KL43Z)
128+
#if defined(TARGET_KL43Z) || defined(TARGET_K22F) || defined(TARGET_K64F)
125129
// enable USBFS clock
126-
SIM->SCGC4 |= SIM_SCGC4_USBFS_MASK;
127-
128-
// enable the IRC48M clock
129-
USB0->CLK_RECOVER_IRC_EN |= USB_CLK_RECOVER_IRC_EN_IRC_EN_MASK;
130-
131-
// enable the USB clock recovery tuning
132-
USB0->CLK_RECOVER_CTRL |= USB_CLK_RECOVER_CTRL_CLOCK_RECOVER_EN_MASK;
133-
134-
// choose usb src clock
135-
SIM->SOPT2 |= SIM_SOPT2_USBSRC_MASK;
130+
CLOCK_EnableUsbfs0Clock(kCLOCK_UsbSrcIrc48M, 48000000U);
136131
#else
137132
// choose usb src as PLL
138133
SIM->SOPT2 &= ~SIM_SOPT2_PLLFLLSEL_MASK;
@@ -148,10 +143,6 @@ USBHAL::USBHAL(void) {
148143
NVIC_EnableIRQ(USB0_IRQn);
149144

150145
// USB Module Configuration
151-
// Reset USB Module
152-
USB0->USBTRC0 |= USB_USBTRC0_USBRESET_MASK;
153-
while(USB0->USBTRC0 & USB_USBTRC0_USBRESET_MASK);
154-
155146
// Set BDT Base Register
156147
USB0->BDTPAGE1 = (uint8_t)((uint32_t)bdt>>8);
157148
USB0->BDTPAGE2 = (uint8_t)((uint32_t)bdt>>16);

0 commit comments

Comments
 (0)