fix board uart init with NGX4330 (use UART0)

add USB1_PWR_EN (GPIO5[6])
This commit is contained in:
hathach 2013-04-08 02:36:43 +07:00
parent 4b63a2bc5c
commit 95df92055c
4 changed files with 102 additions and 20 deletions

View File

@ -62,8 +62,7 @@ void board_init(void)
#if 0
// Leds Init
uint8_t i;
for (i=0; i<CFG_LED_NUMBER; i++)
for (uint8_t i=0; i<CFG_LED_NUMBER; i++)
{
scu_pinmux(leds[i].port, leds[i].pin, MD_PUP|MD_EZI|MD_ZI, 0); // MD_PDN
GPIO_SetDir(leds[i].port, BIT_(leds[i].pin), 1); // output
@ -71,7 +70,7 @@ void board_init(void)
#endif
#if CFG_UART_ENABLE
// pinsel for UART
//------------- UART init -------------//
scu_pinmux(0xF ,10 , MD_PDN, FUNC1); // PF.10 : UART0_TXD
scu_pinmux(0xF ,11 , MD_PLN|MD_EZI|MD_ZI, FUNC1); // PF.11 : UART0_RXD

View File

@ -57,26 +57,26 @@ const static struct {
void board_init(void)
{
SystemInit();
CGU_Init();
SysTick_Config( CGU_GetPCLKFrequency(CGU_PERIPHERAL_M4CORE)/CFG_TICKS_PER_SECOND ); /* 1 ms Timer */
// USB Pin init
/* Turn on 5V USB VBUS TODO Should be Host-only */
scu_pinmux(0x2, 6, MD_PUP | MD_EZI, FUNC4); // P2_6 USB1_PWR_EN, USB1 VBus function
scu_pinmux(0x2, 5, MD_PLN | MD_EZI | MD_ZI, FUNC2); // P2_5 USB1_VBUS, MUST CONFIGURE THIS SIGNAL FOR USB1 NORMAL OPERATION
//------------- USB Bus power HOST ONLY-------------//
scu_pinmux(0x1, 7, MD_PUP | MD_EZI, FUNC4); // P1_7 USB0_PWR_EN, USB0 VBus function Xplorer
/* Turn on 5V USB VBUS TODO Should be Host-only */
scu_pinmux(0x1, 7, MD_PUP | MD_EZI, FUNC4); // P1_7 USB0_PWR_EN, USB0 VBus function Xplorer
scu_pinmux(0x2, 6, MD_PUP | MD_EZI, FUNC4); // P2_6 is configured as GPIO5[6] for USB1_PWR_EN
GPIO_SetDir (5, BIT_(6), 1); // GPIO5[6] is output
GPIO_SetValue (5, BIT_(6)); // GPIO5[6] output high
// Leds Init
uint8_t i;
for (i=0; i<BOARD_MAX_LEDS; i++)
for (uint8_t i=0; i<BOARD_MAX_LEDS; i++)
{
scu_pinmux(leds[i].port, leds[i].pin, MD_PUP|MD_EZI|MD_ZI, FUNC0);
GPIO_SetDir(leds[i].port, BIT_(leds[i].pin), 1); // output
}
// UART init
#if CFG_UART_ENABLE
//------------- UART init -------------//
UART_CFG_Type UARTConfigStruct;
scu_pinmux(0x6 ,4, MD_PDN|MD_EZI, FUNC2); // UART0_TXD
@ -87,12 +87,13 @@ void board_init(void)
UART_Init((LPC_USARTn_Type*) LPC_USART0, &UARTConfigStruct); // Initialize UART port
UART_TxCmd((LPC_USARTn_Type*) LPC_USART0, ENABLE); // Enable UART
#endif
}
void board_leds(uint32_t mask, uint32_t state)
{
uint8_t i;
for(i=0; i<BOARD_MAX_LEDS; i++)
for(uint8_t i=0; i<BOARD_MAX_LEDS; i++)
{
if ( mask & BIT_(i) )
{
@ -103,12 +104,12 @@ void board_leds(uint32_t mask, uint32_t state)
uint32_t board_uart_send(uint8_t *p_buffer, uint32_t length)
{
return UART_Send((LPC_USARTn_Type*) LPC_UART1, p_buffer, length, BLOCKING);
return UART_Send((LPC_USARTn_Type*) LPC_USART0, p_buffer, length, BLOCKING);
}
uint32_t board_uart_recv(uint8_t *p_buffer, uint32_t length)
{
return UART_Receive((LPC_USARTn_Type*) LPC_UART1, p_buffer, length, BLOCKING);
return UART_Receive((LPC_USARTn_Type*) LPC_USART0, p_buffer, length, BLOCKING);
}
#endif

View File

@ -0,0 +1,76 @@
/*
* board_ngx4330.h
*
* Created on: Jan 17, 2013
* Author: hathach
*/
/*
* Software License Agreement (BSD License)
* Copyright (c) 2013, hathach (tinyusb.org)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* This file is part of the tiny usb stack.
*/
/** \file
* \brief TBD
*
* \note TBD
*/
/** \ingroup TBD
* \defgroup TBD
* \brief TBD
*
* @{
*/
#ifndef _TUSB_BOARD_NGX4330_H_
#define _TUSB_BOARD_NGX4330_H_
#ifdef __cplusplus
extern "C" {
#endif
#include "LPC43xx.h"
#include "lpc43xx_scu.h"
#include "lpc43xx_cgu.h"
#include "lpc43xx_gpio.h"
#include "lpc43xx_uart.h"
#define CFG_LED_NUMBER 0
#define CFG_LED_ON (1)
#define CFG_LED_OFF (0)
#define CFG_PRINTF_TARGET PRINTF_TARGET_UART
#ifdef __cplusplus
}
#endif
#endif /* _TUSB_BOARD_NGX4330_H_ */
/** @} */

View File

@ -28,11 +28,17 @@ int main(void)
keyboard_app_task();
mouse_app_task();
if (current_tick + 10*CFG_TICKS_PER_SECOND < system_ticks)
if (current_tick + CFG_TICKS_PER_SECOND < system_ticks)
{
current_tick = system_ticks;
// board_leds(0x01, (current_tick/CFG_TICKS_PER_SECOND)%2); /* Toggle LED once per second */
printf("tinyusb: " __DATE__ "\t" __TIME__ "\n"); // toggle leds on EA4357 is quite troublesome
static uint8_t timeout_10_ms = 0;
timeout_10_ms = (timeout_10_ms+1) % 10;
if (timeout_10_ms % 10 == 0)
{
printf("tinyusb: " __DATE__ "\t" __TIME__ "\n"); // toggle leds on EA4357 is quite troublesome
}
current_tick += CFG_TICKS_PER_SECOND;
board_leds(0x01, (current_tick/CFG_TICKS_PER_SECOND)%2); /* Toggle LED once per second */
}
}