Skip to content

Commit e444f35

Browse files
committed
Make USBD clock setup HIC-specific for K20, KL26 and KL27 devices
1 parent c573873 commit e444f35

File tree

7 files changed

+203
-25
lines changed

7 files changed

+203
-25
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**
2+
* @file hic_init.c
3+
* @brief
4+
*
5+
* DAPLink Interface Firmware
6+
* Copyright (c) 2009-2016, ARM Limited, All Rights Reserved
7+
* Copyright (c) 2016-2017 NXP
8+
* SPDX-License-Identifier: Apache-2.0
9+
*
10+
* Licensed under the Apache License, Version 2.0 (the "License"); you may
11+
* not use this file except in compliance with the License.
12+
* You may obtain a copy of the License at
13+
*
14+
* http://www.apache.org/licenses/LICENSE-2.0
15+
*
16+
* Unless required by applicable law or agreed to in writing, software
17+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
18+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19+
* See the License for the specific language governing permissions and
20+
* limitations under the License.
21+
*/
22+
23+
#include "fsl_device_registers.h"
24+
25+
/* Enable all clocks needed for USB to function */
26+
void hic_enable_usb_clocks(void)
27+
{
28+
/* Set USB clock to 48 MHz */
29+
SIM->SOPT2 |= SIM_SOPT2_USBSRC_MASK | /* MCGPLLCLK used as src */
30+
SIM_SOPT2_PLLFLLSEL_MASK ; /* Select MCGPLLCLK as clock */
31+
SIM->CLKDIV2 &= ~(SIM_CLKDIV2_USBFRAC_MASK | /* Clear CLKDIV2 FS values */
32+
SIM_CLKDIV2_USBDIV_MASK);
33+
SIM->CLKDIV2 = SIM_CLKDIV2_USBDIV(0) ; /* USB clk = (PLL*1/2) */
34+
/* = ( 48*1/1)=48 */
35+
SIM->SCGC4 |= SIM_SCGC4_USBOTG_MASK; /* Enable USBOTG clock */
36+
}
37+
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* @file hic_init.h
3+
* @brief
4+
*
5+
* DAPLink Interface Firmware
6+
* Copyright (c) 2009-2016, ARM Limited, All Rights Reserved
7+
* Copyright (c) 2016-2017 NXP
8+
* SPDX-License-Identifier: Apache-2.0
9+
*
10+
* Licensed under the Apache License, Version 2.0 (the "License"); you may
11+
* not use this file except in compliance with the License.
12+
* You may obtain a copy of the License at
13+
*
14+
* http://www.apache.org/licenses/LICENSE-2.0
15+
*
16+
* Unless required by applicable law or agreed to in writing, software
17+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
18+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19+
* See the License for the specific language governing permissions and
20+
* limitations under the License.
21+
*/
22+
23+
#if defined(__cplusplus)
24+
extern "C" {
25+
#endif
26+
27+
//! @brief Enable clocks required for USB operation.
28+
void hic_enable_usb_clocks(void);
29+
30+
#if defined(__cplusplus)
31+
}
32+
#endif
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/**
2+
* @file hic_init.c
3+
* @brief
4+
*
5+
* DAPLink Interface Firmware
6+
* Copyright (c) 2009-2016, ARM Limited, All Rights Reserved
7+
* Copyright (c) 2016-2017 NXP
8+
* SPDX-License-Identifier: Apache-2.0
9+
*
10+
* Licensed under the Apache License, Version 2.0 (the "License"); you may
11+
* not use this file except in compliance with the License.
12+
* You may obtain a copy of the License at
13+
*
14+
* http://www.apache.org/licenses/LICENSE-2.0
15+
*
16+
* Unless required by applicable law or agreed to in writing, software
17+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
18+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19+
* See the License for the specific language governing permissions and
20+
* limitations under the License.
21+
*/
22+
23+
#include "fsl_device_registers.h"
24+
25+
/* Enable all clocks needed for USB to function */
26+
void hic_enable_usb_clocks(void)
27+
{
28+
/* Set USB clock to 48 MHz */
29+
SIM->SOPT2 |= SIM_SOPT2_USBSRC_MASK | /* MCGPLLCLK used as src */
30+
SIM_SOPT2_PLLFLLSEL_MASK ; /* Select MCGPLLCLK as clock */
31+
SIM->SCGC4 |= SIM_SCGC4_USBOTG_MASK; /* Enable USBOTG clock */
32+
}
33+
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* @file hic_init.h
3+
* @brief
4+
*
5+
* DAPLink Interface Firmware
6+
* Copyright (c) 2009-2016, ARM Limited, All Rights Reserved
7+
* Copyright (c) 2016-2017 NXP
8+
* SPDX-License-Identifier: Apache-2.0
9+
*
10+
* Licensed under the Apache License, Version 2.0 (the "License"); you may
11+
* not use this file except in compliance with the License.
12+
* You may obtain a copy of the License at
13+
*
14+
* http://www.apache.org/licenses/LICENSE-2.0
15+
*
16+
* Unless required by applicable law or agreed to in writing, software
17+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
18+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19+
* See the License for the specific language governing permissions and
20+
* limitations under the License.
21+
*/
22+
23+
#if defined(__cplusplus)
24+
extern "C" {
25+
#endif
26+
27+
//! @brief Enable clocks required for USB operation.
28+
void hic_enable_usb_clocks(void);
29+
30+
#if defined(__cplusplus)
31+
}
32+
#endif
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* @file hic_init.c
3+
* @brief
4+
*
5+
* DAPLink Interface Firmware
6+
* Copyright (c) 2009-2016, ARM Limited, All Rights Reserved
7+
* Copyright (c) 2016-2017 NXP
8+
* SPDX-License-Identifier: Apache-2.0
9+
*
10+
* Licensed under the Apache License, Version 2.0 (the "License"); you may
11+
* not use this file except in compliance with the License.
12+
* You may obtain a copy of the License at
13+
*
14+
* http://www.apache.org/licenses/LICENSE-2.0
15+
*
16+
* Unless required by applicable law or agreed to in writing, software
17+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
18+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19+
* See the License for the specific language governing permissions and
20+
* limitations under the License.
21+
*/
22+
23+
#include "fsl_device_registers.h"
24+
25+
/* Enable all clocks needed for USB to function */
26+
void hic_enable_usb_clocks(void)
27+
{
28+
/* Set USB clock to 48 MHz */
29+
MCG->MC |= MCG_MC_HIRCEN_MASK; /* Enable the HIRC clock in the MCG */
30+
SIM->SCGC4 |= SIM_SCGC4_USBFS_MASK; /* Enable the USB clock */
31+
USB0->CLK_RECOVER_INT_EN |= USB_CLK_RECOVER_IRC_EN_IRC_EN_MASK;
32+
USB0->CLK_RECOVER_CTRL |= USB_CLK_RECOVER_CTRL_CLOCK_RECOVER_EN_MASK;
33+
SIM->SOPT2 |= SIM_SOPT2_USBSRC_MASK; /* MCGPLLCLK used as src */
34+
}
35+
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* @file hic_init.h
3+
* @brief
4+
*
5+
* DAPLink Interface Firmware
6+
* Copyright (c) 2009-2016, ARM Limited, All Rights Reserved
7+
* Copyright (c) 2016-2017 NXP
8+
* SPDX-License-Identifier: Apache-2.0
9+
*
10+
* Licensed under the Apache License, Version 2.0 (the "License"); you may
11+
* not use this file except in compliance with the License.
12+
* You may obtain a copy of the License at
13+
*
14+
* http://www.apache.org/licenses/LICENSE-2.0
15+
*
16+
* Unless required by applicable law or agreed to in writing, software
17+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
18+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19+
* See the License for the specific language governing permissions and
20+
* limitations under the License.
21+
*/
22+
23+
#if defined(__cplusplus)
24+
extern "C" {
25+
#endif
26+
27+
//! @brief Enable clocks required for USB operation.
28+
void hic_enable_usb_clocks(void);
29+
30+
#if defined(__cplusplus)
31+
}
32+
#endif

source/hic_hal/freescale/usbd_kinetis.c

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "cortex_m.h"
2525
#include "util.h"
2626
#include "string.h"
27+
#include "hic_init.h"
2728

2829
#define __NO_USB_LIB_C
2930
#include "usb_config.c"
@@ -139,32 +140,8 @@ void USBD_IntrEna(void)
139140
void USBD_Init(void)
140141
{
141142
OutEpSize[0] = USBD_MAX_PACKET0;
142-
/* Enable all clocks needed for USB to function */
143-
/* Set USB clock to 48 MHz */
144143

145-
146-
#if defined(INTERFACE_KL27Z)
147-
MCG->MC |= MCG_MC_HIRCEN_MASK; /* Enable the HIRC clock in the MCG */
148-
SIM->SCGC4 |= SIM_SCGC4_USBFS_MASK; /* Enable the USB clock */
149-
USB0->CLK_RECOVER_INT_EN |= USB_CLK_RECOVER_IRC_EN_IRC_EN_MASK;
150-
USB0->CLK_RECOVER_CTRL |= USB_CLK_RECOVER_CTRL_CLOCK_RECOVER_EN_MASK;
151-
SIM->SOPT2 |= SIM_SOPT2_USBSRC_MASK; /* MCGPLLCLK used as src */
152-
#else
153-
SIM->SOPT2 |= SIM_SOPT2_USBSRC_MASK | /* MCGPLLCLK used as src */
154-
SIM_SOPT2_PLLFLLSEL_MASK ; /* Select MCGPLLCLK as clock */
155-
#endif // INTERFACE_KL27Z
156-
157-
#if defined(INTERFACE_K20D5)
158-
SIM->CLKDIV2 &= ~(SIM_CLKDIV2_USBFRAC_MASK | /* Clear CLKDIV2 FS values */
159-
SIM_CLKDIV2_USBDIV_MASK);
160-
SIM->CLKDIV2 = SIM_CLKDIV2_USBDIV(0) ; /* USB clk = (PLL*1/2) */
161-
/* = ( 48*1/1)=48 */
162-
#endif // INTERFACE_K20D5
163-
164-
#if defined(INTERFACE_KL27Z)
165-
#else
166-
SIM->SCGC4 |= SIM_SCGC4_USBOTG_MASK; /* Enable USBOTG clock */
167-
#endif // INTERFACE_KL27Z
144+
hic_enable_usb_clocks();
168145

169146
USBD_IntrEna();
170147
USB0->USBTRC0 |= USB_USBTRC0_USBRESET_MASK;

0 commit comments

Comments
 (0)