109 lines
3.6 KiB
C
109 lines
3.6 KiB
C
/*
|
|
* Copyright (c) 2007-2015 Freescale Semiconductor, Inc.
|
|
* Copyright 2018-2019 NXP
|
|
*
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
*
|
|
* FreeMASTER Communication Driver - Example Application
|
|
*/
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
// Includes
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
#include "pin_mux.h"
|
|
#include "fsl_common.h"
|
|
#include "fsl_power.h"
|
|
#include "fsl_clock.h"
|
|
#include "fsl_debug_console.h"
|
|
#include "board.h"
|
|
|
|
#include "usb_device_config.h"
|
|
|
|
#include "freemaster.h"
|
|
#include "freemaster_usb.h"
|
|
|
|
#include "freemaster_example.h"
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
// Variables
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//! Note: All global variables accessed by FreeMASTER are defined in a shared
|
|
//! freemaster_example.c file
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
// Prototypes
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
// Code
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
int main(void)
|
|
{
|
|
/* attach main clock divide to FLEXCOMM0 (debug console) */
|
|
CLOCK_AttachClk(BOARD_DEBUG_UART_CLK_ATTACH);
|
|
|
|
/* set BOD VBAT level to 1.65V */
|
|
POWER_SetBodVbatLevel(kPOWER_BodVbatLevel1650mv, kPOWER_BodHystLevel50mv, false);
|
|
|
|
/* Board initialization */
|
|
BOARD_InitPins();
|
|
BOARD_BootClockFROHF96M();
|
|
BOARD_InitDebugConsole();
|
|
|
|
NVIC_ClearPendingIRQ(USB0_IRQn);
|
|
NVIC_ClearPendingIRQ(USB0_NEEDCLK_IRQn);
|
|
NVIC_ClearPendingIRQ(USB1_IRQn);
|
|
NVIC_ClearPendingIRQ(USB1_NEEDCLK_IRQn);
|
|
|
|
POWER_DisablePD(kPDRUNCFG_PD_USB0_PHY); /*< Turn on USB0 Phy */
|
|
POWER_DisablePD(kPDRUNCFG_PD_USB1_PHY); /*< Turn on USB1 Phy */
|
|
|
|
/* reset the IP to make sure it's in reset state. */
|
|
RESET_PeripheralReset(kUSB0D_RST_SHIFT_RSTn);
|
|
RESET_PeripheralReset(kUSB0HSL_RST_SHIFT_RSTn);
|
|
RESET_PeripheralReset(kUSB0HMR_RST_SHIFT_RSTn);
|
|
RESET_PeripheralReset(kUSB1H_RST_SHIFT_RSTn);
|
|
RESET_PeripheralReset(kUSB1D_RST_SHIFT_RSTn);
|
|
RESET_PeripheralReset(kUSB1_RST_SHIFT_RSTn);
|
|
RESET_PeripheralReset(kUSB1RAM_RST_SHIFT_RSTn);
|
|
|
|
//POWER_DisablePD(kPDRUNCFG_PD_USB0_PHY); /*< Turn on USB Phy */
|
|
CLOCK_SetClkDiv(kCLOCK_DivUsb0Clk, 1, false);
|
|
CLOCK_AttachClk(kFRO_HF_to_USB0_CLK);
|
|
/* enable usb0 host clock */
|
|
CLOCK_EnableClock(kCLOCK_Usbhsl0);
|
|
/*According to reference mannual, device mode setting has to be set by access usb host register */
|
|
*((uint32_t *)(USBFSH_BASE + 0x5C)) |= USBFSH_PORTMODE_DEV_ENABLE_MASK;
|
|
/* disable usb0 host clock */
|
|
CLOCK_DisableClock(kCLOCK_Usbhsl0);
|
|
|
|
/* Initialize the USB peripheral clock */
|
|
/* enable USB IP clock */
|
|
CLOCK_EnableUsbfs0DeviceClock(kCLOCK_UsbfsSrcFro, CLOCK_GetFroHfFreq());
|
|
|
|
for (int i = 0; i < FSL_FEATURE_USB_USB_RAM; i++)
|
|
{
|
|
((uint8_t *)FSL_FEATURE_USB_USB_RAM_BASE_ADDRESS)[i] = 0x00U;
|
|
}
|
|
|
|
/* FreeMASTER communication layer initialization */
|
|
FMSTR_ExampleUsbInit();
|
|
|
|
/* This example uses shared code from FreeMASTER generic example application */
|
|
FMSTR_Example_Init();
|
|
|
|
while(1)
|
|
{
|
|
/* FreeMASTER example increments several variables periodically,
|
|
use the FreeMASTER PC Host tool to visualize the variables */
|
|
FMSTR_Example_Poll();
|
|
}
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
// EOF
|
|
/////////////////////////////////////////////////////////////////////////////////
|