From 043e5dbf3c45acd605a0e93a875ffe0b2269a8d4 Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 5 Mar 2014 15:03:38 +0700 Subject: [PATCH] somehow could not get printf work with IAR both SWD & uart on NGX4330 --- .../embedded_artists/ea4357/board_ea4357.c | 4 + demos/bsp/boards/ngx/board_ngx4330.c | 256 ++-- demos/bsp/boards/printf_retarget.c | 377 +++-- demos/host/host_os_none/host_os_none.ewd | 1297 +++++++++++++++++ demos/host/host_os_none/host_os_none.ewp | 924 ++++++++++++ demos/host/src/main.c | 7 +- 6 files changed, 2543 insertions(+), 322 deletions(-) diff --git a/demos/bsp/boards/embedded_artists/ea4357/board_ea4357.c b/demos/bsp/boards/embedded_artists/ea4357/board_ea4357.c index 16453c44..4c0e8fbb 100644 --- a/demos/bsp/boards/embedded_artists/ea4357/board_ea4357.c +++ b/demos/bsp/boards/embedded_artists/ea4357/board_ea4357.c @@ -132,6 +132,10 @@ uint8_t board_uart_getchar(void) { return UART_ReceiveByte(BOARD_UART_PORT); } +void board_uart_putchar(uint8_t c) +{ + UART_Send(BOARD_UART_PORT, &c, 1, BLOCKING); +} #endif #endif diff --git a/demos/bsp/boards/ngx/board_ngx4330.c b/demos/bsp/boards/ngx/board_ngx4330.c index a8acdd8f..4462eb2d 100644 --- a/demos/bsp/boards/ngx/board_ngx4330.c +++ b/demos/bsp/boards/ngx/board_ngx4330.c @@ -1,128 +1,128 @@ -/**************************************************************************/ -/*! - @file board_ngx4330.c - @author hathach (tinyusb.org) - - @section LICENSE - - 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. Neither the name of the copyright holders nor the - names of its contributors may be used to endorse or promote products - derived from this software without specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''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 COPYRIGHT HOLDER 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 tinyusb stack. -*/ -/**************************************************************************/ - -#include "../board.h" - -#if BOARD == BOARD_NGX4330 - -#define BOARD_UART_PORT LPC_USART0 - -#define BOARD_MAX_LEDS 2 -const static struct { - uint8_t mux_port; - uint8_t mux_pin; - - uint8_t gpio_port; - uint8_t gpio_pin; -}leds[BOARD_MAX_LEDS] = { {2, 11, 1, 11}, {2, 12, 1,12} }; - -void board_init(void) -{ - CGU_Init(); - SysTick_Config( CGU_GetPCLKFrequency(CGU_PERIPHERAL_M4CORE)/CFG_TICKS_PER_SECOND ); /* 1 ms Timer */ - - //------------- USB Bus power 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 - - //------------- LED -------------// - for (uint8_t i=0; i \r\n - int length = iLength; - char* p_newline_pos = memchr(pcBuffer, '\n', length); - - while(p_newline_pos != NULL) - { - uint32_t chunk_len = p_newline_pos - pcBuffer; - - board_uart_send((uint8_t*)pcBuffer, chunk_len); - board_uart_send(&"\r\n", 2); - - pcBuffer += (chunk_len + 1); - length -= (chunk_len + 1); - p_newline_pos = memchr(pcBuffer, '\n', length); - } - - board_uart_send((uint8_t*)pcBuffer, length); - - return iLength; - -#elif CFG_PRINTF_TARGET == PRINTF_TARGET_SWO - #error author does not know how to retarget SWO with lpcxpresso/red-suite -#endif - -} - -// Called by bottom level of scanf routine within RedLib C library to read -// a character. With the default semihosting stub, this would read the character -// from the debugger console window (which acts as stdin). But this version reads -// the character from the UART. -int __sys_readc (void) -{ - return (int) retarget_getchar(); -} - -//--------------------------------------------------------------------+ -// KEIL -//--------------------------------------------------------------------+ -#elif defined __CC_ARM // keil - -#if CFG_PRINTF_TARGET == PRINTF_TARGET_UART - #define retarget_putc(c) board_uart_send( (uint8_t*) &c, 1); -#elif CFG_PRINTF_TARGET == PRINTF_TARGET_SWO - volatile int32_t ITM_RxBuffer; - #define retarget_putc(c) ITM_SendChar(c) -#endif - -struct __FILE { - uint32_t handle; -}; - -int fgetc(FILE *f) -{ - return retarget_getchar(); -} - -int fputc(int ch, FILE *f) -{ - if (ch == '\n') - { - uint8_t carry = '\r'; - retarget_putc(carry); - } - - retarget_putc(ch); - - return ch; -} - -void _ttywrch(int ch) -{ - if ( ch == '\n' ) - { - uint8_t carry = '\r'; - retarget_putc(carry); - } - - retarget_putc(ch); -} - - -//--------------------------------------------------------------------+ -// IAR -//--------------------------------------------------------------------+ -#elif defined __ICCARM__ - -#if CFG_PRINTF_TARGET == PRINTF_TARGET_UART -#include - -size_t __write(int handle, const unsigned char *buf, size_t bufSize) -{ - /* Check for the command to flush all handles */ - if (handle == -1) return 0; - - /* Check for stdout and stderr (only necessary if FILE descriptors are enabled.) */ - if (handle != 1 && handle != 2) return -1; - - for (size_t i=0; i + +size_t __write(int handle, const unsigned char *buf, size_t length) +{ + /* Check for the command to flush all handles */ + if (handle == -1) return 0; + + /* Check for stdout and stderr (only necessary if FILE descriptors are enabled.) */ + if (handle != 1 && handle != 2) return -1; + + size_t ret = length; + for (size_t i=0; i + + Board NGX4330 + + ARM + + 1 + + C-SPY + 2 + + 25 + 1 + 1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ARMSIM_ID + 2 + + 1 + 1 + 1 + + + + + + + + ANGEL_ID + 2 + + 0 + 1 + 1 + + + + + + + + + + + + CMSISDAP_ID + 2 + + 0 + 1 + 1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + GDBSERVER_ID + 2 + + 0 + 1 + 1 + + + + + + + + + + + IARROM_ID + 2 + + 1 + 1 + 1 + + + + + + + + + IJET_ID + 2 + + 2 + 1 + 1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + JLINK_ID + 2 + + 15 + 1 + 1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + LMIFTDI_ID + 2 + + 2 + 1 + 1 + + + + + + + + + + MACRAIGOR_ID + 2 + + 3 + 1 + 1 + + + + + + + + + + + + + + + + + + + + + + + PEMICRO_ID + 2 + + 1 + 1 + 1 + + + + + + + + + + + + + + + + + + + RDI_ID + 2 + + 2 + 1 + 1 + + + + + + + + + + + + + + + + STLINK_ID + 2 + + 2 + 1 + 1 + + + + + + + + + + + THIRDPARTY_ID + 2 + + 0 + 1 + 1 + + + + + + + + XDS100_ID + 2 + + 2 + 1 + 1 + + + + + + + + + + + + + $TOOLKIT_DIR$\plugins\middleware\HCCWare\HCCWare.ewplugin + 0 + + + $TOOLKIT_DIR$\plugins\rtos\AVIX\AVIX.ENU.ewplugin + 0 + + + $TOOLKIT_DIR$\plugins\rtos\CMX\CmxArmPlugin.ENU.ewplugin + 0 + + + $TOOLKIT_DIR$\plugins\rtos\CMX\CmxTinyArmPlugin.ENU.ewplugin + 0 + + + $TOOLKIT_DIR$\plugins\rtos\embOS\embOSPlugin.ewplugin + 0 + + + $TOOLKIT_DIR$\plugins\rtos\MQX\MQXRtosPlugin.ewplugin + 0 + + + $TOOLKIT_DIR$\plugins\rtos\OpenRTOS\OpenRTOSPlugin.ewplugin + 0 + + + $TOOLKIT_DIR$\plugins\rtos\PowerPac\PowerPacRTOS.ewplugin + 0 + + + $TOOLKIT_DIR$\plugins\rtos\Quadros\Quadros_EWB6_Plugin.ewplugin + 0 + + + $TOOLKIT_DIR$\plugins\rtos\SafeRTOS\SafeRTOSPlugin.ewplugin + 0 + + + $TOOLKIT_DIR$\plugins\rtos\ThreadX\ThreadXArmPlugin.ENU.ewplugin + 0 + + + $TOOLKIT_DIR$\plugins\rtos\uCOS-II\uCOS-II-286-KA-CSpy.ewplugin + 0 + + + $TOOLKIT_DIR$\plugins\rtos\uCOS-II\uCOS-II-KA-CSpy.ewplugin + 0 + + + $TOOLKIT_DIR$\plugins\rtos\uCOS-III\uCOS-III-KA-CSpy.ewplugin + 0 + + + $EW_DIR$\common\plugins\CodeCoverage\CodeCoverage.ENU.ewplugin + 1 + + + $EW_DIR$\common\plugins\Orti\Orti.ENU.ewplugin + 0 + + + $EW_DIR$\common\plugins\SymList\SymList.ENU.ewplugin + 1 + + + $EW_DIR$\common\plugins\uCProbe\uCProbePlugin.ENU.ewplugin + 0 + + + diff --git a/demos/host/host_os_none/host_os_none.ewp b/demos/host/host_os_none/host_os_none.ewp index e9672748..eb221327 100644 --- a/demos/host/host_os_none/host_os_none.ewp +++ b/demos/host/host_os_none/host_os_none.ewp @@ -1848,6 +1848,929 @@ + + Board NGX4330 + + ARM + + 1 + + General + 3 + + 21 + 1 + 1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ICCARM + 2 + + 28 + 1 + 1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + AARM + 2 + + 8 + 1 + 1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + OBJCOPY + 0 + + 1 + 1 + 1 + + + + + + + + + CUSTOM + 3 + + + + + + + BICOMP + 0 + + + + BUILDACTION + 1 + + + + + + + ILINK + 0 + + 15 + 1 + 1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + IARCHIVE + 0 + + 0 + 1 + 1 + + + + + + + BILINK + 0 + + + app @@ -1899,6 +2822,7 @@ lpc175x_6x Board EA4357 + Board NGX4330 $PROJ_DIR$\..\..\bsp\lpc175x_6x\CMSISv2p00_LPC17xx\src\core_cm3.c diff --git a/demos/host/src/main.c b/demos/host/src/main.c index 8c7ff5ac..4ead7c6b 100644 --- a/demos/host/src/main.c +++ b/demos/host/src/main.c @@ -158,7 +158,7 @@ int main(void) OSAL_TASK_FUNCTION( led_blinking_task ) (void* p_task_para) { static uint32_t led_on_mask = 0; - + OSAL_TASK_LOOP_BEGIN osal_task_delay(1000); @@ -174,7 +174,7 @@ OSAL_TASK_FUNCTION( led_blinking_task ) (void* p_task_para) //--------------------------------------------------------------------+ void print_greeting(void) { - printf("\n\ + puts("\n\ --------------------------------------------------------------------\n\ - Host Demo (a tinyusb example)\n\ - if you find any bugs or get any questions, feel free to file an\n\ @@ -188,5 +188,4 @@ void print_greeting(void) if (TUSB_CFG_HOST_HID_KEYBOARD ) puts(" - HID Keyboard"); if (TUSB_CFG_HOST_MSC ) puts(" - Mass Storage"); if (TUSB_CFG_HOST_CDC ) puts(" - Communication Device Class"); -} - +} \ No newline at end of file