Actually the latest FSL USB stack has become part of KSDK , so it is recommended customer design USB application based on KSDK, while there are some old parts like K70, K60F and KL25 are still not supported in KSDK yet, so USB stack ver 4.1.1 is somewhat of help for those who still develop application based on those parts.
USB stack ver 4.1.1 supports K70 instead of K60F, but since they are both Kinetis 120MHz parts, so the porting is very easy, here I provide a porting guide for this part.
The porting is based on K70 USB examples, either Host or Device.
1. Replace the device header file.
Use MK60F12.h instead, which may be extracted from KINETIS_120MHz_SC(Kinetis 120MHz bare metal sample code) , and put this header file in the folder of "C:\Freescale\Freescale USB Stack v4.1.1\Source\Host\source\bsp\P3" for Host or "C:\Freescale\Freescale USB Stack v4.1.1\Source\Device\app\common\kinetis" for device, and modify derivative.h as below:
2. Macro definition changes
in MK60F12.h, MCU_MK60F12 is defined instead of MCU_MK70F12, so in this step we will have to change some code snippet related with MCU_MK70F12.
Firstly search MCU_MK70F12 in the project, for example , in the Host demo USB_MSD project based on IAR, you may do that as below:
and you may find some macro like "#ifdef MCU_MK70F12" or "#ifndef MCU_MK70F12", and change them as below:
#ifdef MCU_MK70F12 ----> #if (defined MCU_MK60F12) || (defined MCU_MK70F12)
#ifndef MCU_MK70F12 ----> #if (!defined MCU_MK60F12) && (!defined MCU_MK70F12)
3. IO driver modification.
Since TWR-K70F120 has almost the same hardware as TWR-K60F120, there is no need to change the driver code after replacing the header file, except the serial port driver, referring to USB_MSD demo, the serial driver is in sci_kinetis.c, TWR-K70F120M uses PTE16 and PTE17(UART2) as the console, while TWR-K60F120M use PTE8 and PTE9(UART5) instead, so you have to change the driver as below to make printf work properly.
void sci2_init(){
#if (defined MCU_MK60F12) || (defined MCU_MK70F12)
register uint_16 sbr, brfa;
uint_8 temp;
#ifdef MCU_MK70F12
/* Enable the UART2_TXD function on PTD3 */
PORTE_PCR16 = PORT_PCR_MUX(0x3); // UART is alt3 function for this pin
/* Enable the UART2_RXD function on PTD2 */
PORTE_PCR17 = PORT_PCR_MUX(0x3); // UART is alt3 function for this pin
/* Enable the clock */
SIM_SCGC4 |= SIM_SCGC4_UART2_MASK;
/* Make sure that the transmitter and receiver are disabled while we
* change settings.
*/
UART_C2_REG(UART2_BASE_PTR) &= ~(UART_C2_TE_MASK | UART_C2_RE_MASK);
/* Configure the UART for 8-bit mode, no parity */
UART_C1_REG(UART2_BASE_PTR) = 0; /* We need all default settings, so entire register is cleared */
/* Calculate baud settings */
sbr = (uint_16)((SYSCLK*1000)/(UART_BAUDRATE * 16));
/* Save off the current value of the UARTx_BDH except for the SBR field */
temp = UART_BDH_REG(UART2_BASE_PTR) & ~(UART_BDH_SBR(0x1F));
UART_BDH_REG(UART2_BASE_PTR) = temp | UART_BDH_SBR(((sbr & 0x1F00) >> 8));
UART_BDL_REG(UART2_BASE_PTR) = (uint_8)(sbr & UART_BDL_SBR_MASK);
/* Determine if a fractional divider is needed to get closer to the baud rate */
brfa = (((SYSCLK*32000)/(UART_BAUDRATE * 16)) - (sbr * 32));
/* Save off the current value of the UARTx_C4 register except for the BRFA field */
temp = UART_C4_REG(UART2_BASE_PTR) & ~(UART_C4_BRFA(0x1F));
UART_C4_REG(UART2_BASE_PTR) = temp | UART_C4_BRFA(brfa);
/* Enable receiver and transmitter */
UART_C2_REG(UART2_BASE_PTR) |= (UART_C2_TE_MASK | UART_C2_RE_MASK);
#else //MCU_MK60F12
/* Enable the UART2_TXD function on PTE8 */
PORTE_PCR8 = PORT_PCR_MUX(0x3); // UART is alt3 function for this pin
/* Enable the UART2_RXD function on PTE9 */
PORTE_PCR9 = PORT_PCR_MUX(0x3); // UART is alt3 function for this pin
/* Enable the clock */
SIM_SCGC1 |= SIM_SCGC1_UART5_MASK;
/* Make sure that the transmitter and receiver are disabled while we
* change settings.
*/
UART_C2_REG(UART5_BASE_PTR) &= ~(UART_C2_TE_MASK | UART_C2_RE_MASK);
/* Configure the UART for 8-bit mode, no parity */
UART_C1_REG(UART5_BASE_PTR) = 0; /* We need all default settings, so entire register is cleared */
/* Calculate baud settings */
sbr = (uint_16)((SYSCLK*1000)/(UART_BAUDRATE * 16));
/* Save off the current value of the UARTx_BDH except for the SBR field */
temp = UART_BDH_REG(UART5_BASE_PTR) & ~(UART_BDH_SBR(0x1F));
UART_BDH_REG(UART5_BASE_PTR) = temp | UART_BDH_SBR(((sbr & 0x1F00) >> 8));
UART_BDL_REG(UART5_BASE_PTR) = (uint_8)(sbr & UART_BDL_SBR_MASK);
/* Determine if a fractional divider is needed to get closer to the baud rate */
brfa = (((SYSCLK*32000)/(UART_BAUDRATE * 16)) - (sbr * 32));
/* Save off the current value of the UARTx_C4 register except for the BRFA field */
temp = UART_C4_REG(UART5_BASE_PTR) & ~(UART_C4_BRFA(0x1F));
UART_C4_REG(UART5_BASE_PTR) = temp | UART_C4_BRFA(brfa);
/* Enable receiver and transmitter */
UART_C2_REG(UART5_BASE_PTR) |= (UART_C2_TE_MASK | UART_C2_RE_MASK);
#endif
#endif
}
#ifdef __CC_ARM
int sendchar (int ch)
#else
void TERMIO_PutChar (char ch)
#endif
{
#if (!defined MCU_MK60F12) && (!defined MCU_MK70F12)
#if (defined MCU_MK20D5) || (defined MCU_MK20D7) || (defined MCU_MK40D7)
/* Wait until space is available in the FIFO */
while(!(UART1_S1 & UART_S1_TDRE_MASK)){};
/* Send the character */
UART1_D = (uint_8)ch;
#elif(defined MCU_MK21D5)
while(!(UART2_S1 & UART_S1_TDRE_MASK)){};
/* Send the character */
UART2_D = (uint_8)ch;
#elif(defined MCU_MKL25Z4) || (defined MCU_MKL46Z4)
/* Wait until space is available in the FIFO */
while(!(UART0_S1 & UART_S1_TDRE_MASK)){};
/* Send the character */
UART0_D = (uint_8)ch;
#else
/* Wait until space is available in the FIFO */
while(!(UART3_S1 & UART_S1_TDRE_MASK)){};
/* Send the character */
UART3_D = (uint_8)ch;
#endif
#else
#ifdef MCU_MK70F12
/* Wait until space is available in the FIFO */
while(!(UART2_S1 & UART_S1_TDRE_MASK)){};
/* Send the character */
UART2_D = (uint_8)ch;
#else
/* Wait until space is available in the FIFO */
while(!(UART5_S1 & UART_S1_TDRE_MASK)){};
/* Send the character */
UART5_D = (uint_8)ch;
#endif
#endif
}
4. Set the correct device type in IDE settings.
For IAR, change the device family in view of project options.
Now, you can start to run the USB demos on TWR-K60F120M, please note the above steps is ok for USB device stack, but USB Host stack has some code issue , as mentioned in [USB stack ver 4.1.1] a code issue in msd_mfs_generic host demo , so please fix the issue before going further.
Hope that helps,
Best Regards,
Kan
Hi,
I made these changes but ran into an error due to this function not being defined when compiling: void USB_ISR(void);
In usb_dci_kinetis.h, this function is only defined for #if !HIGH_SPEED_DEVICE
Is this portion of the code different for a HIGH_SPEED_DEVICE? I am trying to use HS for my application. Thanks for any insights!!