add uart for mcb1800

This commit is contained in:
hathach 2020-05-03 14:50:12 +07:00
parent d1141c2d9d
commit 9538ca7d74
2 changed files with 56 additions and 41 deletions

View File

@ -30,8 +30,8 @@
#define UART_DEV LPC_USART0 #define UART_DEV LPC_USART0
#define UART_PORT 0x0f #define UART_PORT 0x0f
#define UART_PIN_TX 10 // PF.10 : UART0_TXD #define UART_PIN_TX 10
#define UART_PIN_RX 11 // PF.11 : UART0_RXD #define UART_PIN_RX 11
// P9_1 joystick down // P9_1 joystick down
#define BUTTON_PORT 4 #define BUTTON_PORT 4
@ -66,6 +66,10 @@ static const PINMUX_GRP_T pinmuxing[] =
// Button // Button
{0x9, 1, (SCU_MODE_INBUFF_EN | SCU_MODE_INACT | SCU_MODE_FUNC0 | SCU_MODE_PULLUP)}, {0x9, 1, (SCU_MODE_INBUFF_EN | SCU_MODE_INACT | SCU_MODE_FUNC0 | SCU_MODE_PULLUP)},
// UART
{UART_PORT, UART_PIN_TX, SCU_MODE_PULLDOWN | SCU_MODE_FUNC1},
{UART_PORT, UART_PIN_RX, SCU_MODE_INACT | SCU_MODE_INBUFF_EN | SCU_MODE_ZIF_DIS | SCU_MODE_FUNC1},
// USB // USB
}; };
@ -119,9 +123,6 @@ void board_init(void)
Chip_GPIO_SetPinDIRInput(LPC_GPIO_PORT, BUTTON_PORT, BUTTON_PIN); Chip_GPIO_SetPinDIRInput(LPC_GPIO_PORT, BUTTON_PORT, BUTTON_PIN);
//------------- UART -------------// //------------- UART -------------//
Chip_SCU_PinMuxSet(UART_PORT, UART_PIN_TX, (SCU_MODE_PULLDOWN | SCU_MODE_FUNC1));
Chip_SCU_PinMuxSet(UART_PORT, UART_PIN_RX, (SCU_MODE_INACT | SCU_MODE_INBUFF_EN | SCU_MODE_ZIF_DIS | SCU_MODE_FUNC1));
Chip_UART_Init(UART_DEV); Chip_UART_Init(UART_DEV);
Chip_UART_SetBaud(UART_DEV, CFG_BOARD_UART_BAUDRATE); Chip_UART_SetBaud(UART_DEV, CFG_BOARD_UART_BAUDRATE);
Chip_UART_ConfigData(UART_DEV, UART_LCR_WLEN8 | UART_LCR_SBS_1BIT | UART_LCR_PARITY_DIS); Chip_UART_ConfigData(UART_DEV, UART_LCR_WLEN8 | UART_LCR_SBS_1BIT | UART_LCR_PARITY_DIS);
@ -139,15 +140,20 @@ void board_init(void)
}; };
/* USB0 /* USB0
* For USB Device operation; insert jumpers in position 1-2 in JP17/JP18/JP19. GPIO28 controls USB * For USB0 Device operation:
* connect functionality and LED32 lights when the USB Device is connected. SJ4 has pads 1-2 shorted * - insert jumpers in position 1-2 in JP17/JP18/JP19.
* by default. LED33 is controlled by GPIO27 and signals USB-up state. GPIO54 is used for VBUS * - GPIO28 controls USB connect functionality
* - LED32 lights when the USB Device is connected. SJ4 has pads 1-2 shorted by default.
* - LED33 is controlled by GPIO27 and signals USB-up state. GPIO54 is used for VBUS
* sensing. * sensing.
* For USB Host operation; insert jumpers in position 2-3 in JP17/JP18/JP19. USB Host power is *
* controlled via distribution switch U20 (found in schematic page 11). Signal GPIO26 is active low and * For USB0 Host operation:
* enables +5V on VBUS2. LED35 light whenever +5V is present on VBUS2. GPIO55 is connected to * - insert jumpers in position 2-3 in JP17/JP18/JP19.
* status feedback from the distribution switch. GPIO54 is used for VBUS sensing. 15Kohm pull-down * - USB Host power is controlled via distribution switch U20 (found in schematic page 11).
* resistors are always active * - Signal GPIO26 is active low and enables +5V on VBUS2.
* - LED35 light whenever +5V is present on VBUS2.
* - GPIO55 is connected to status feedback from the distribution switch.
* - GPIO54 is used for VBUS sensing. 15Kohm pull-down resistors are always active
*/ */
#if CFG_TUSB_RHPORT0_MODE #if CFG_TUSB_RHPORT0_MODE
Chip_USB0_Init(); Chip_USB0_Init();
@ -168,22 +174,25 @@ void board_init(void)
#endif #endif
/* USB1 /* USB1
* When USB channel #1 is used as USB Host, 15Kohm pull-down resistors are needed on the USB data
* signals. These are activated inside the USB OTG chip (U31), and this has to be done via the I2C
* interface of GPIO52/GPIO53.
* J20 is the connector to use when USB Host is used. In order to provide +5V to the external USB
* device connected to this connector (J20), channel A of U20 must be enabled. It is enabled by default
* since SJ5 is normally connected between pin 1-2. LED34 lights green when +5V is available on J20.
* JP15 shall not be inserted. JP16 has no effect
* *
* When USB channel #1 is used as USB Device, a 1.5Kohm pull-up resistor is needed on the USB DP * For USB Device:
* data signal. There are two methods to create this. JP15 is inserted and the pull-up resistor is always * - a 1.5Kohm pull-up resistor is needed on the USB DP data signal. There are two methods to create this.
* enabled. Alternatively, the pull-up resistor is activated inside the USB OTG chip (U31), and this has to * JP15 is inserted and the pull-up resistor is always enabled. Alternatively, the pull-up resistor is activated
* be done via the I2C interface of GPIO52/GPIO53. In the latter case, JP15 shall not be inserted. * inside the USB OTG chip (U31), and this has to be done via the I2C interface of GPIO52/GPIO53. In the latter case,
* J19 is the connector to use when USB Device is used. Normally it should be a USB-B connector for * JP15 shall not be inserted.
* - J19 is the connector to use when USB Device is used. Normally it should be a USB-B connector for
* creating a USB Device interface, but the mini-AB connector can also be used in this case. The status * creating a USB Device interface, but the mini-AB connector can also be used in this case. The status
* of VBUS can be read via U31. * of VBUS can be read via U31.
* JP16 shall not be inserted. * - JP16 shall not be inserted.
*
* For USB Host:
* - 15Kohm pull-down resistors are needed on the USB data signals. These are activated inside the USB OTG chip (U31),
* and this has to be done via the I2C interface of GPIO52/GPIO53.
* - J20 is the connector to use when USB Host is used. In order to provide +5V to the external USB
* device connected to this connector (J20), channel A of U20 must be enabled. It is enabled by default
* since SJ5 is normally connected between pin 1-2.
* - LED34 lights green when +5V is available on J20.
* - JP15 shall not be inserted. JP16 has no effect
*/ */
#if CFG_TUSB_RHPORT1_MODE #if CFG_TUSB_RHPORT1_MODE
Chip_USB1_Init(); Chip_USB1_Init();

View File

@ -64,6 +64,11 @@ void USB1_IRQHandler(void)
#define BUTTON_PORT 2 #define BUTTON_PORT 2
#define BUTTON_PIN 0 #define BUTTON_PIN 0
#define UART_DEV LPC_USART3
#define UART_PORT 0x02
#define UART_PIN_TX 3
#define UART_PIN_RX 4
/* System configuration variables used by chip driver */ /* System configuration variables used by chip driver */
const uint32_t OscRateIn = 12000000; const uint32_t OscRateIn = 12000000;
@ -84,6 +89,10 @@ static const PINMUX_GRP_T pinmuxing[] =
// Button // Button
{0x4, 0, (SCU_MODE_INBUFF_EN | SCU_MODE_INACT | SCU_MODE_FUNC0 | SCU_MODE_PULLUP)}, {0x4, 0, (SCU_MODE_INBUFF_EN | SCU_MODE_INACT | SCU_MODE_FUNC0 | SCU_MODE_PULLUP)},
// UART
{UART_PORT, UART_PIN_TX, SCU_MODE_PULLDOWN | SCU_MODE_FUNC2 },
{UART_PORT, UART_PIN_RX, SCU_MODE_INACT | SCU_MODE_INBUFF_EN | SCU_MODE_ZIF_DIS | SCU_MODE_FUNC2 },
/* I2S */ /* I2S */
{0x3, 0, (SCU_PINIO_FAST | SCU_MODE_FUNC2)}, {0x3, 0, (SCU_PINIO_FAST | SCU_MODE_FUNC2)},
{0x6, 0, (SCU_PINIO_FAST | SCU_MODE_FUNC4)}, {0x6, 0, (SCU_PINIO_FAST | SCU_MODE_FUNC4)},
@ -137,19 +146,11 @@ void board_init(void)
// Button // Button
Chip_GPIO_SetPinDIRInput(LPC_GPIO_PORT, BUTTON_PORT, BUTTON_PIN); Chip_GPIO_SetPinDIRInput(LPC_GPIO_PORT, BUTTON_PORT, BUTTON_PIN);
#if 0
//------------- UART -------------// //------------- UART -------------//
scu_pinmux(BOARD_UART_PIN_PORT, BOARD_UART_PIN_TX, MD_PDN, FUNC1); Chip_UART_Init(UART_DEV);
scu_pinmux(BOARD_UART_PIN_PORT, BOARD_UART_PIN_RX, MD_PLN | MD_EZI | MD_ZI, FUNC1); Chip_UART_SetBaud(UART_DEV, CFG_BOARD_UART_BAUDRATE);
Chip_UART_ConfigData(UART_DEV, UART_LCR_WLEN8 | UART_LCR_SBS_1BIT | UART_LCR_PARITY_DIS);
UART_CFG_Type UARTConfigStruct; Chip_UART_TXEnable(UART_DEV);
UART_ConfigStructInit(&UARTConfigStruct);
UARTConfigStruct.Baud_rate = CFG_BOARD_UART_BAUDRATE;
UARTConfigStruct.Clock_Speed = 0;
UART_Init(BOARD_UART_PORT, &UARTConfigStruct);
UART_TxCmd(BOARD_UART_PORT, ENABLE); // Enable UART Transmit
#endif
//------------- USB -------------// //------------- USB -------------//
enum { enum {
@ -223,9 +224,14 @@ int board_uart_read(uint8_t* buf, int len)
int board_uart_write(void const * buf, int len) int board_uart_write(void const * buf, int len)
{ {
//UART_Send(BOARD_UART_PORT, &c, 1, BLOCKING); uint8_t const* buf8 = (uint8_t const*) buf;
(void) buf; (void) len; for(int i=0; i<len; i++)
return 0; {
while ((Chip_UART_ReadLineStatus(UART_DEV) & UART_LSR_THRE) == 0) {}
Chip_UART_SendByte(UART_DEV, buf8[i]);
}
return len;
} }
#if CFG_TUSB_OS == OPT_OS_NONE #if CFG_TUSB_OS == OPT_OS_NONE