Change in osmo-ccid-firmware[master]: Switch SERCOM7 (Debug UART) to sync mode + add STDIO

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Kévin Redon gerrit-no-reply at lists.osmocom.org
Wed Feb 27 13:17:17 UTC 2019


Kévin Redon has submitted this change and it was merged. ( https://gerrit.osmocom.org/13035 )

Change subject: Switch SERCOM7 (Debug UART) to sync mode + add STDIO
......................................................................

Switch SERCOM7 (Debug UART) to sync mode + add STDIO

this will allow us to do printf()

Change-Id: Ibf4ba961d4bbf8d787558f38f3d557422587aad3
---
M sysmoOCTSIM/AtmelStart.gpdsc
M sysmoOCTSIM/atmel_start.c
M sysmoOCTSIM/atmel_start.h
M sysmoOCTSIM/atmel_start_config.atstart
A sysmoOCTSIM/config/stdio_redirect_config.h
A sysmoOCTSIM/documentation/stdio.rst
M sysmoOCTSIM/driver_init.c
M sysmoOCTSIM/driver_init.h
M sysmoOCTSIM/examples/driver_examples.c
M sysmoOCTSIM/gcc/Makefile
M sysmoOCTSIM/hpl/sercom/hpl_sercom.c
M sysmoOCTSIM/main.c
A sysmoOCTSIM/stdio_redirect/gcc/read.c
A sysmoOCTSIM/stdio_redirect/gcc/write.c
A sysmoOCTSIM/stdio_redirect/iar/read.c
A sysmoOCTSIM/stdio_redirect/iar/write.c
A sysmoOCTSIM/stdio_redirect/keil/Retarget.c
A sysmoOCTSIM/stdio_redirect/stdio_io.c
A sysmoOCTSIM/stdio_redirect/stdio_io.h
A sysmoOCTSIM/stdio_start.c
A sysmoOCTSIM/stdio_start.h
21 files changed, 769 insertions(+), 131 deletions(-)

Approvals:
  Kévin Redon: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/sysmoOCTSIM/AtmelStart.gpdsc b/sysmoOCTSIM/AtmelStart.gpdsc
index 6546fb5..5d35944 100644
--- a/sysmoOCTSIM/AtmelStart.gpdsc
+++ b/sysmoOCTSIM/AtmelStart.gpdsc
@@ -36,6 +36,14 @@
       <require Dname="ATSAME54N19A"/>
       <accept Tcompiler="GCC"/>
     </condition>
+    <condition id="IAR">
+      <require Dname="ATSAME54N19A"/>
+      <accept Tcompiler="IAR"/>
+    </condition>
+    <condition id="ARMCC">
+      <require Dname="ATSAME54N19A"/>
+      <accept Tcompiler="ARMCC"/>
+    </condition>
   </conditions>
   <components generator="AtmelStart">
     <component Cclass="AtmelStart" Cgroup="Framework" Cversion="1.0.0" condition="CMSIS Device Startup">
@@ -43,6 +51,7 @@
       <RTE_Components_h>#define ATMEL_START</RTE_Components_h>
       <files>
         <file category="doc" condition="ARMCC, GCC, IAR" name="hal/documentation/usart_async.rst"/>
+        <file category="doc" condition="ARMCC, GCC, IAR" name="hal/documentation/usart_sync.rst"/>
         <file category="doc" condition="ARMCC, GCC, IAR" name="hal/documentation/usb_device_async.rst"/>
         <file category="header" condition="ARMCC, GCC, IAR" name="hal/include/hal_atomic.h"/>
         <file category="header" condition="ARMCC, GCC, IAR" name="hal/include/hal_cache.h"/>
@@ -155,6 +164,14 @@
         <file category="header" condition="ARMCC, GCC, IAR" name="usb/usb_includes.h"/>
         <file category="source" condition="ARMCC, GCC, IAR" name="usb/usb_protocol.c"/>
         <file category="header" condition="ARMCC, GCC, IAR" name="usb/usb_protocol.h"/>
+        <file category="doc" condition="ARMCC, GCC, IAR" name="documentation/stdio.rst"/>
+        <file category="source" condition="GCC" name="stdio_redirect/gcc/read.c"/>
+        <file category="source" condition="GCC" name="stdio_redirect/gcc/write.c"/>
+        <file category="source" condition="IAR" name="stdio_redirect/iar/read.c"/>
+        <file category="source" condition="IAR" name="stdio_redirect/iar/write.c"/>
+        <file category="source" condition="ARMCC" name="stdio_redirect/keil/Retarget.c"/>
+        <file category="source" condition="ARMCC, GCC, IAR" name="stdio_redirect/stdio_io.c"/>
+        <file category="header" condition="ARMCC, GCC, IAR" name="stdio_redirect/stdio_io.h"/>
         <file category="source" condition="ARMCC, GCC, IAR" name="main.c"/>
         <file category="source" condition="ARMCC, GCC, IAR" name="driver_init.c"/>
         <file category="header" condition="ARMCC, GCC, IAR" name="driver_init.h"/>
@@ -162,6 +179,7 @@
         <file category="header" condition="ARMCC, GCC, IAR" name="examples/driver_examples.h"/>
         <file category="source" condition="ARMCC, GCC, IAR" name="examples/driver_examples.c"/>
         <file category="header" condition="ARMCC, GCC, IAR" name="hal/include/hal_usart_async.h"/>
+        <file category="header" condition="ARMCC, GCC, IAR" name="hal/include/hal_usart_sync.h"/>
         <file category="header" condition="ARMCC, GCC, IAR" name="hal/include/hpl_missing_features.h"/>
         <file category="header" condition="ARMCC, GCC, IAR" name="hal/include/hpl_reset.h"/>
         <file category="header" condition="ARMCC, GCC, IAR" name="hal/include/hpl_spi_m_async.h"/>
@@ -172,6 +190,7 @@
         <file category="header" condition="ARMCC, GCC, IAR" name="hal/include/hpl_usart_async.h"/>
         <file category="header" condition="ARMCC, GCC, IAR" name="hal/include/hpl_usart_sync.h"/>
         <file category="source" condition="ARMCC, GCC, IAR" name="hal/src/hal_usart_async.c"/>
+        <file category="source" condition="ARMCC, GCC, IAR" name="hal/src/hal_usart_sync.c"/>
         <file category="header" condition="ARMCC, GCC, IAR" name="hal/utils/include/parts.h"/>
         <file category="source" condition="ARMCC, GCC, IAR" name="hpl/cmcc/hpl_cmcc.c"/>
         <file category="source" condition="ARMCC, GCC, IAR" name="hpl/core/hpl_core_m4.c"/>
@@ -191,6 +210,8 @@
         <file category="source" condition="ARMCC, GCC, IAR" name="hpl/usb/hpl_usb.c"/>
         <file category="source" condition="ARMCC, GCC, IAR" name="usb_start.c"/>
         <file category="header" condition="ARMCC, GCC, IAR" name="usb_start.h"/>
+        <file category="source" condition="ARMCC, GCC, IAR" name="stdio_start.c"/>
+        <file category="header" condition="ARMCC, GCC, IAR" name="stdio_start.h"/>
         <file category="header" condition="ARMCC, GCC, IAR" name="atmel_start.h"/>
         <file category="source" condition="ARMCC, GCC, IAR" name="atmel_start.c"/>
         <file attr="config" category="header" condition="ARMCC, GCC, IAR" name="config/hpl_cmcc_config.h"/>
@@ -204,6 +225,7 @@
         <file attr="config" category="header" condition="ARMCC, GCC, IAR" name="config/hpl_usb_config.h"/>
         <file attr="config" category="header" condition="ARMCC, GCC, IAR" name="config/peripheral_clk_config.h"/>
         <file attr="config" category="header" condition="ARMCC, GCC, IAR" name="config/usbd_config.h"/>
+        <file attr="config" category="header" condition="ARMCC, GCC, IAR" name="config/stdio_redirect_config.h"/>
         <file category="include" condition="ARMCC, GCC, IAR" name=""/>
         <file category="include" condition="ARMCC, GCC, IAR" name="config"/>
         <file category="include" condition="ARMCC, GCC, IAR" name="examples"/>
@@ -229,6 +251,9 @@
         <file category="include" condition="ARMCC, GCC, IAR" name="usb/class/cdc/device"/>
         <file category="include" condition="ARMCC, GCC, IAR" name="usb/device"/>
         <file category="include" condition="ARMCC, GCC, IAR" name=""/>
+        <file category="include" condition="ARMCC, GCC, IAR" name="config"/>
+        <file category="include" condition="ARMCC, GCC, IAR" name="stdio_redirect"/>
+        <file category="include" condition="ARMCC, GCC, IAR" name=""/>
       </files>
     </component>
   </components>
diff --git a/sysmoOCTSIM/atmel_start.c b/sysmoOCTSIM/atmel_start.c
index 9a5f36c..fc6016a 100644
--- a/sysmoOCTSIM/atmel_start.c
+++ b/sysmoOCTSIM/atmel_start.c
@@ -7,4 +7,5 @@
 {
 	system_init();
 	usb_init();
+	stdio_redirect_init();
 }
diff --git a/sysmoOCTSIM/atmel_start.h b/sysmoOCTSIM/atmel_start.h
index 953f947..92afa47 100644
--- a/sysmoOCTSIM/atmel_start.h
+++ b/sysmoOCTSIM/atmel_start.h
@@ -7,6 +7,7 @@
 
 #include "driver_init.h"
 #include "usb_start.h"
+#include "stdio_start.h"
 
 /**
  * Initializes MCU, drivers and middleware in the project
diff --git a/sysmoOCTSIM/atmel_start_config.atstart b/sysmoOCTSIM/atmel_start_config.atstart
index a301385..1bbad8f 100644
--- a/sysmoOCTSIM/atmel_start_config.atstart
+++ b/sysmoOCTSIM/atmel_start_config.atstart
@@ -82,6 +82,14 @@
     dependencies:
       USB Device Stack Core Instance: USB_DEVICE_STACK_CORE_INSTANCE
       USB Class CDC: USB_CLASS_CDC
+  STDIO_REDIRECT_0:
+    user_label: STDIO_REDIRECT_0
+    configuration: {}
+    definition: Atmel:STDIO_redirect:0.0.1::STDIO_Redirect
+    functionality: STDIO_Redirect
+    api: STDIO:Redirect:IO
+    dependencies:
+      Target IO: UART_debug
 drivers:
   CMCC:
     user_label: CMCC
@@ -1276,9 +1284,9 @@
           slow_gclk_selection: Generic clock generator 3
   UART_debug:
     user_label: UART_debug
-    definition: Atmel:SAME54_Drivers:0.0.1::SAME54N19A-AF::SERCOM7::driver_config_definition::UART::HAL:Driver:USART.Async
+    definition: Atmel:SAME54_Drivers:0.0.1::SAME54N19A-AF::SERCOM7::driver_config_definition::UART::HAL:Driver:USART.Sync
     functionality: USART
-    api: HAL:Driver:USART_Async
+    api: HAL:Driver:USART_Sync
     configuration:
       usart_advanced: false
       usart_arch_clock_mode: USART with internal clock
diff --git a/sysmoOCTSIM/config/stdio_redirect_config.h b/sysmoOCTSIM/config/stdio_redirect_config.h
new file mode 100644
index 0000000..3515c0c
--- /dev/null
+++ b/sysmoOCTSIM/config/stdio_redirect_config.h
@@ -0,0 +1,9 @@
+/* Auto-generated config file stdio_redirect_config.h */
+#ifndef STDIO_REDIRECT_CONFIG_H
+#define STDIO_REDIRECT_CONFIG_H
+
+// <<< Use Configuration Wizard in Context Menu >>>
+
+// <<< end of configuration section >>>
+
+#endif // STDIO_REDIRECT_CONFIG_H
diff --git a/sysmoOCTSIM/documentation/stdio.rst b/sysmoOCTSIM/documentation/stdio.rst
new file mode 100644
index 0000000..2864b49
--- /dev/null
+++ b/sysmoOCTSIM/documentation/stdio.rst
@@ -0,0 +1,34 @@
+STDIO redirection
+=================
+
+The STDIO redirection provides means to redirect standard input/output to HAL
+IO.
+
+On initialization, the HAL IO descriptor is assigned so that all input and
+output is redirected to access it. The IO descriptor can also be changed
+through stdio_io_set_io(). All stdin or stdout access is redirected to the
+IO descriptor. When the IO descriptor is set to NULL, all input and output 
+are discarded.
+
+For GCC redirection, the stdout and stdin buffer are turned off, the
+standard _read() and _write() are overridden.
+
+For IAR redirection, the __read() and __write() are overridden.
+
+For Keil redirection, the Retarget.c are modified to override fputc(), fgetc(),
+etc.
+
+Features
+--------
+
+* Standard input/output redirection (e.g., printf to EDBG COM port)
+
+Dependencies
+------------
+
+* HAL IO driver
+
+Limitations
+-----------
+
+* IO read/write operation should be synchronous
diff --git a/sysmoOCTSIM/driver_init.c b/sysmoOCTSIM/driver_init.c
index 1a58ad9..5808f01 100644
--- a/sysmoOCTSIM/driver_init.c
+++ b/sysmoOCTSIM/driver_init.c
@@ -32,9 +32,6 @@
 /*! The buffer size for USART */
 #define SIM6_BUFFER_SIZE 16
 
-/*! The buffer size for USART */
-#define UART_DEBUG_BUFFER_SIZE 16
-
 struct usart_async_descriptor SIM0;
 struct usart_async_descriptor SIM1;
 struct usart_async_descriptor SIM2;
@@ -42,7 +39,6 @@
 struct usart_async_descriptor SIM4;
 struct usart_async_descriptor SIM5;
 struct usart_async_descriptor SIM6;
-struct usart_async_descriptor UART_debug;
 
 static uint8_t SIM0_buffer[SIM0_BUFFER_SIZE];
 static uint8_t SIM1_buffer[SIM1_BUFFER_SIZE];
@@ -51,7 +47,8 @@
 static uint8_t SIM4_buffer[SIM4_BUFFER_SIZE];
 static uint8_t SIM5_buffer[SIM5_BUFFER_SIZE];
 static uint8_t SIM6_buffer[SIM6_BUFFER_SIZE];
-static uint8_t UART_debug_buffer[UART_DEBUG_BUFFER_SIZE];
+
+struct usart_sync_descriptor UART_debug;
 
 /**
  * \brief USART Clock initialization function
@@ -312,26 +309,7 @@
 	SIM6_PORT_init();
 }
 
-/**
- * \brief USART Clock initialization function
- *
- * Enables register interface and peripheral clock
- */
-void UART_debug_CLOCK_init()
-{
-
-	hri_gclk_write_PCHCTRL_reg(GCLK, SERCOM7_GCLK_ID_CORE, CONF_GCLK_SERCOM7_CORE_SRC | (1 << GCLK_PCHCTRL_CHEN_Pos));
-	hri_gclk_write_PCHCTRL_reg(GCLK, SERCOM7_GCLK_ID_SLOW, CONF_GCLK_SERCOM7_SLOW_SRC | (1 << GCLK_PCHCTRL_CHEN_Pos));
-
-	hri_mclk_set_APBDMASK_SERCOM7_bit(MCLK);
-}
-
-/**
- * \brief USART pinmux initialization function
- *
- * Set each required pin to USART functionality
- */
-void UART_debug_PORT_init()
+void UART_debug_PORT_init(void)
 {
 
 	gpio_set_pin_function(UART_TX, PINMUX_PB30C_SERCOM7_PAD0);
@@ -339,15 +317,18 @@
 	gpio_set_pin_function(UART_RX, PINMUX_PB31C_SERCOM7_PAD1);
 }
 
-/**
- * \brief USART initialization function
- *
- * Enables USART peripheral, clocks and initializes USART driver
- */
+void UART_debug_CLOCK_init(void)
+{
+	hri_gclk_write_PCHCTRL_reg(GCLK, SERCOM7_GCLK_ID_CORE, CONF_GCLK_SERCOM7_CORE_SRC | (1 << GCLK_PCHCTRL_CHEN_Pos));
+	hri_gclk_write_PCHCTRL_reg(GCLK, SERCOM7_GCLK_ID_SLOW, CONF_GCLK_SERCOM7_SLOW_SRC | (1 << GCLK_PCHCTRL_CHEN_Pos));
+
+	hri_mclk_set_APBDMASK_SERCOM7_bit(MCLK);
+}
+
 void UART_debug_init(void)
 {
 	UART_debug_CLOCK_init();
-	usart_async_init(&UART_debug, SERCOM7, UART_debug_buffer, UART_DEBUG_BUFFER_SIZE, (void *)NULL);
+	usart_sync_init(&UART_debug, SERCOM7, (void *)NULL);
 	UART_debug_PORT_init();
 }
 
@@ -860,6 +841,7 @@
 	SIM4_init();
 	SIM5_init();
 	SIM6_init();
+
 	UART_debug_init();
 
 	USB_DEVICE_INSTANCE_init();
diff --git a/sysmoOCTSIM/driver_init.h b/sysmoOCTSIM/driver_init.h
index a0fbb88..d809db8 100644
--- a/sysmoOCTSIM/driver_init.h
+++ b/sysmoOCTSIM/driver_init.h
@@ -28,7 +28,8 @@
 #include <hal_usart_async.h>
 #include <hal_usart_async.h>
 #include <hal_usart_async.h>
-#include <hal_usart_async.h>
+
+#include <hal_usart_sync.h>
 
 #include "hal_usb_device.h"
 
@@ -39,7 +40,8 @@
 extern struct usart_async_descriptor SIM4;
 extern struct usart_async_descriptor SIM5;
 extern struct usart_async_descriptor SIM6;
-extern struct usart_async_descriptor UART_debug;
+
+extern struct usart_sync_descriptor UART_debug;
 
 void SIM0_PORT_init(void);
 void SIM0_CLOCK_init(void);
diff --git a/sysmoOCTSIM/examples/driver_examples.c b/sysmoOCTSIM/examples/driver_examples.c
index 14f1ae5..4ab0ef4 100644
--- a/sysmoOCTSIM/examples/driver_examples.c
+++ b/sysmoOCTSIM/examples/driver_examples.c
@@ -215,29 +215,12 @@
 
 /**
  * Example of using UART_debug to write "Hello World" using the IO abstraction.
- *
- * Since the driver is asynchronous we need to use statically allocated memory for string
- * because driver initiates transfer and then returns before the transmission is completed.
- *
- * Once transfer has been completed the tx_cb function will be called.
  */
-
-static uint8_t example_UART_debug[12] = "Hello World!";
-
-static void tx_cb_UART_debug(const struct usart_async_descriptor *const io_descr)
-{
-	/* Transfer completed */
-}
-
 void UART_debug_example(void)
 {
 	struct io_descriptor *io;
+	usart_sync_get_io_descriptor(&UART_debug, &io);
+	usart_sync_enable(&UART_debug);
 
-	usart_async_register_callback(&UART_debug, USART_ASYNC_TXC_CB, tx_cb_UART_debug);
-	/*usart_async_register_callback(&UART_debug, USART_ASYNC_RXC_CB, rx_cb);
-	usart_async_register_callback(&UART_debug, USART_ASYNC_ERROR_CB, err_cb);*/
-	usart_async_get_io_descriptor(&UART_debug, &io);
-	usart_async_enable(&UART_debug);
-
-	io_write(io, example_UART_debug, 12);
+	io_write(io, (uint8_t *)"Hello World!", 12);
 }
diff --git a/sysmoOCTSIM/gcc/Makefile b/sysmoOCTSIM/gcc/Makefile
index 5e3c38c..1c90257 100644
--- a/sysmoOCTSIM/gcc/Makefile
+++ b/sysmoOCTSIM/gcc/Makefile
@@ -26,32 +26,37 @@
 # List the subdirectories for creating object files
 SUB_DIRS +=  \
  \
-hpl/pm \
+hal/src \
+hpl/ramecc \
+examples \
+hpl/oscctrl \
+stdio_redirect/gcc \
 gcc \
 hpl/osc32kctrl \
-hpl/ramecc \
+usb \
 hpl/dmac \
 usb/class/cdc/device \
-hal/src \
-hpl/mclk \
-usb \
+stdio_redirect \
 hal/utils/src \
-hpl/sercom \
-examples \
-hpl/gclk \
-usb/device \
-hpl/oscctrl \
-gcc/gcc \
 hpl/usb \
-hpl/core \
-hpl/cmcc
+hpl/pm \
+hpl/cmcc \
+hpl/gclk \
+gcc/gcc \
+hpl/mclk \
+usb/device \
+hpl/sercom \
+hpl/core
 
 # List the object files
 OBJS +=  \
 hal/src/hal_io.o \
+stdio_redirect/stdio_io.o \
+stdio_redirect/gcc/write.o \
 hpl/core/hpl_core_m4.o \
 usb/class/cdc/device/cdcdf_acm.o \
 hal/utils/src/utils_syscalls.o \
+stdio_redirect/gcc/read.o \
 usb_start.o \
 gcc/system_same54.o \
 hpl/usb/hpl_usb.o \
@@ -63,8 +68,10 @@
 hal/utils/src/utils_assert.o \
 hpl/dmac/hpl_dmac.o \
 hpl/oscctrl/hpl_oscctrl.o \
+hal/src/hal_usart_sync.o \
 hpl/mclk/hpl_mclk.o \
 hpl/ramecc/hpl_ramecc.o \
+stdio_start.o \
 usb/usb_protocol.o \
 hal/src/hal_init.o \
 gcc/gcc/startup_same54.o \
@@ -90,9 +97,12 @@
 
 OBJS_AS_ARGS +=  \
 "hal/src/hal_io.o" \
+"stdio_redirect/stdio_io.o" \
+"stdio_redirect/gcc/write.o" \
 "hpl/core/hpl_core_m4.o" \
 "usb/class/cdc/device/cdcdf_acm.o" \
 "hal/utils/src/utils_syscalls.o" \
+"stdio_redirect/gcc/read.o" \
 "usb_start.o" \
 "gcc/system_same54.o" \
 "hpl/usb/hpl_usb.o" \
@@ -104,8 +114,10 @@
 "hal/utils/src/utils_assert.o" \
 "hpl/dmac/hpl_dmac.o" \
 "hpl/oscctrl/hpl_oscctrl.o" \
+"hal/src/hal_usart_sync.o" \
 "hpl/mclk/hpl_mclk.o" \
 "hpl/ramecc/hpl_ramecc.o" \
+"stdio_start.o" \
 "usb/usb_protocol.o" \
 "hal/src/hal_init.o" \
 "gcc/gcc/startup_same54.o" \
@@ -133,12 +145,14 @@
 DEPS := $(OBJS:%.o=%.d)
 
 DEPS_AS_ARGS +=  \
+"stdio_redirect/stdio_io.d" \
 "hal/utils/src/utils_event.d" \
 "hal/src/hal_io.d" \
 "hpl/ramecc/hpl_ramecc.d" \
 "hpl/core/hpl_core_m4.d" \
 "hal/utils/src/utils_syscalls.d" \
 "usb/class/cdc/device/cdcdf_acm.d" \
+"stdio_redirect/gcc/write.d" \
 "gcc/gcc/startup_same54.d" \
 "hpl/usb/hpl_usb.d" \
 "hal/utils/src/utils_list.d" \
@@ -149,12 +163,15 @@
 "hpl/core/hpl_init.d" \
 "hpl/pm/hpl_pm.d" \
 "usb/usb_protocol.d" \
+"stdio_start.d" \
 "hpl/gclk/hpl_gclk.d" \
 "hal/src/hal_usb_device.d" \
 "usb_start.d" \
 "hal/src/hal_init.d" \
+"hal/src/hal_usart_sync.d" \
 "hpl/mclk/hpl_mclk.d" \
 "driver_init.d" \
+"stdio_redirect/gcc/read.d" \
 "hal/src/hal_usart_async.d" \
 "hpl/osc32kctrl/hpl_osc32kctrl.d" \
 "main.d" \
@@ -218,7 +235,7 @@
 	@echo ARM/GNU C Compiler
 	$(QUOTE)arm-none-eabi-gcc$(QUOTE) -x c -mthumb -DDEBUG -Os -ffunction-sections -mlong-calls -g3 -Wall -c -std=gnu99 \
 -D__SAME54N19A__ -mcpu=cortex-m4 -mfloat-abi=softfp -mfpu=fpv4-sp-d16 \
--I"../" -I"../config" -I"../examples" -I"../hal/include" -I"../hal/utils/include" -I"../hpl/cmcc" -I"../hpl/core" -I"../hpl/dmac" -I"../hpl/gclk" -I"../hpl/mclk" -I"../hpl/osc32kctrl" -I"../hpl/oscctrl" -I"../hpl/pm" -I"../hpl/port" -I"../hpl/ramecc" -I"../hpl/sercom" -I"../hpl/usb" -I"../hri" -I"../" -I"../config" -I"../usb" -I"../usb/class/cdc" -I"../usb/class/cdc/device" -I"../usb/device" -I"../" -I"../CMSIS/Include" -I"../include"  \
+-I"../" -I"../config" -I"../examples" -I"../hal/include" -I"../hal/utils/include" -I"../hpl/cmcc" -I"../hpl/core" -I"../hpl/dmac" -I"../hpl/gclk" -I"../hpl/mclk" -I"../hpl/osc32kctrl" -I"../hpl/oscctrl" -I"../hpl/pm" -I"../hpl/port" -I"../hpl/ramecc" -I"../hpl/sercom" -I"../hpl/usb" -I"../hri" -I"../" -I"../config" -I"../usb" -I"../usb/class/cdc" -I"../usb/class/cdc/device" -I"../usb/device" -I"../" -I"../config" -I"../stdio_redirect" -I"../" -I"../CMSIS/Include" -I"../include"  \
 -MD -MP -MF "$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -MT"$(@:%.o=%.o)"  -o "$@" "$<"
 	@echo Finished building: $<
 
@@ -227,7 +244,7 @@
 	@echo ARM/GNU Assembler
 	$(QUOTE)arm-none-eabi-as$(QUOTE) -x c -mthumb -DDEBUG -Os -ffunction-sections -mlong-calls -g3 -Wall -c -std=gnu99 \
 -D__SAME54N19A__ -mcpu=cortex-m4 -mfloat-abi=softfp -mfpu=fpv4-sp-d16 \
--I"../" -I"../config" -I"../examples" -I"../hal/include" -I"../hal/utils/include" -I"../hpl/cmcc" -I"../hpl/core" -I"../hpl/dmac" -I"../hpl/gclk" -I"../hpl/mclk" -I"../hpl/osc32kctrl" -I"../hpl/oscctrl" -I"../hpl/pm" -I"../hpl/port" -I"../hpl/ramecc" -I"../hpl/sercom" -I"../hpl/usb" -I"../hri" -I"../" -I"../config" -I"../usb" -I"../usb/class/cdc" -I"../usb/class/cdc/device" -I"../usb/device" -I"../" -I"../CMSIS/Include" -I"../include"  \
+-I"../" -I"../config" -I"../examples" -I"../hal/include" -I"../hal/utils/include" -I"../hpl/cmcc" -I"../hpl/core" -I"../hpl/dmac" -I"../hpl/gclk" -I"../hpl/mclk" -I"../hpl/osc32kctrl" -I"../hpl/oscctrl" -I"../hpl/pm" -I"../hpl/port" -I"../hpl/ramecc" -I"../hpl/sercom" -I"../hpl/usb" -I"../hri" -I"../" -I"../config" -I"../usb" -I"../usb/class/cdc" -I"../usb/class/cdc/device" -I"../usb/device" -I"../" -I"../config" -I"../stdio_redirect" -I"../" -I"../CMSIS/Include" -I"../include"  \
 -MD -MP -MF "$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -MT"$(@:%.o=%.o)"  -o "$@" "$<"
 	@echo Finished building: $<
 
@@ -236,7 +253,7 @@
 	@echo ARM/GNU Preprocessing Assembler
 	$(QUOTE)arm-none-eabi-gcc$(QUOTE) -x c -mthumb -DDEBUG -Os -ffunction-sections -mlong-calls -g3 -Wall -c -std=gnu99 \
 -D__SAME54N19A__ -mcpu=cortex-m4 -mfloat-abi=softfp -mfpu=fpv4-sp-d16 \
--I"../" -I"../config" -I"../examples" -I"../hal/include" -I"../hal/utils/include" -I"../hpl/cmcc" -I"../hpl/core" -I"../hpl/dmac" -I"../hpl/gclk" -I"../hpl/mclk" -I"../hpl/osc32kctrl" -I"../hpl/oscctrl" -I"../hpl/pm" -I"../hpl/port" -I"../hpl/ramecc" -I"../hpl/sercom" -I"../hpl/usb" -I"../hri" -I"../" -I"../config" -I"../usb" -I"../usb/class/cdc" -I"../usb/class/cdc/device" -I"../usb/device" -I"../" -I"../CMSIS/Include" -I"../include"  \
+-I"../" -I"../config" -I"../examples" -I"../hal/include" -I"../hal/utils/include" -I"../hpl/cmcc" -I"../hpl/core" -I"../hpl/dmac" -I"../hpl/gclk" -I"../hpl/mclk" -I"../hpl/osc32kctrl" -I"../hpl/oscctrl" -I"../hpl/pm" -I"../hpl/port" -I"../hpl/ramecc" -I"../hpl/sercom" -I"../hpl/usb" -I"../hri" -I"../" -I"../config" -I"../usb" -I"../usb/class/cdc" -I"../usb/class/cdc/device" -I"../usb/device" -I"../" -I"../config" -I"../stdio_redirect" -I"../" -I"../CMSIS/Include" -I"../include"  \
 -MD -MP -MF "$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -MT"$(@:%.o=%.o)"  -o "$@" "$<"
 	@echo Finished building: $<
 
diff --git a/sysmoOCTSIM/hpl/sercom/hpl_sercom.c b/sysmoOCTSIM/hpl/sercom/hpl_sercom.c
index f235115..b14e720 100644
--- a/sysmoOCTSIM/hpl/sercom/hpl_sercom.c
+++ b/sysmoOCTSIM/hpl/sercom/hpl_sercom.c
@@ -177,8 +177,6 @@
 
 static struct _usart_async_device *_sercom6_dev = NULL;
 
-static struct _usart_async_device *_sercom7_dev = NULL;
-
 static uint8_t _get_sercom_index(const void *const hw);
 static uint8_t _sercom_get_irq_num(const void *const hw);
 static void    _sercom_init_irq_param(const void *const hw, void *dev);
@@ -667,10 +665,6 @@
 	if (hw == SERCOM6) {
 		_sercom6_dev = (struct _usart_async_device *)dev;
 	}
-
-	if (hw == SERCOM7) {
-		_sercom7_dev = (struct _usart_async_device *)dev;
-	}
 }
 
 /**
@@ -2634,35 +2628,6 @@
 	_sercom_usart_interrupt_handler(_sercom6_dev);
 }
 
-/**
- * \internal Sercom interrupt handler
- */
-void SERCOM7_0_Handler(void)
-{
-	_sercom_usart_interrupt_handler(_sercom7_dev);
-}
-/**
- * \internal Sercom interrupt handler
- */
-void SERCOM7_1_Handler(void)
-{
-	_sercom_usart_interrupt_handler(_sercom7_dev);
-}
-/**
- * \internal Sercom interrupt handler
- */
-void SERCOM7_2_Handler(void)
-{
-	_sercom_usart_interrupt_handler(_sercom7_dev);
-}
-/**
- * \internal Sercom interrupt handler
- */
-void SERCOM7_3_Handler(void)
-{
-	_sercom_usart_interrupt_handler(_sercom7_dev);
-}
-
 int32_t _spi_m_sync_init(struct _spi_m_sync_dev *dev, void *const hw)
 {
 	const struct sercomspi_regs_cfg *regs = _spi_get_regs((uint32_t)hw);
diff --git a/sysmoOCTSIM/main.c b/sysmoOCTSIM/main.c
index 50e82c6..c79d5aa 100644
--- a/sysmoOCTSIM/main.c
+++ b/sysmoOCTSIM/main.c
@@ -27,20 +27,6 @@
 #include "octsim_i2c.h"
 #include "ncn8025.h"
 
-volatile static bool data_arrived = false;
-
-static void tx_cb_UART_debug(const struct usart_async_descriptor *const io_descr)
-{
-	/* Transfer completed */
-	//gpio_toggle_pin_level(LED_system);
-}
-
-static void rx_cb_UART_debug(const struct usart_async_descriptor *const io_descr)
-{
-	/* Receive completed */
-	gpio_toggle_pin_level(USER_LED);
-	data_arrived = true;
-}
 
 static void board_init()
 {
@@ -65,23 +51,18 @@
 {
 	atmel_start_init();
 
-	usart_async_register_callback(&UART_debug, USART_ASYNC_TXC_CB, tx_cb_UART_debug);
-	usart_async_register_callback(&UART_debug, USART_ASYNC_RXC_CB, rx_cb_UART_debug);
-	usart_async_enable(&UART_debug);
+	usart_sync_enable(&UART_debug);
 
 	usb_start();
 
 	board_init();
 
-	const char* welcome = "\r\n\r\nsysmocom sysmoOCTSIM\r\n";
-	while (io_write(&UART_debug.io, (const uint8_t*)welcome, strlen(welcome)) != strlen(welcome)); // print welcome message
+	printf("\r\n\r\nsysmocom sysmoOCTSIM\r\n");
 	while (true) { // main loop
-		if (data_arrived) { // input on UART debug
-			data_arrived = false; // clear flag
-			uint8_t recv_char; // to store the input
-			while (io_read(&UART_debug.io, &recv_char, 1) == 1) { // read input
-				while (io_write(&UART_debug.io, &recv_char, 1) != 1); // echo back to output
-			}
+		if (usart_sync_is_rx_not_empty(&UART_debug)) {
+			gpio_toggle_pin_level(USER_LED);
+			int c = getchar();
+			putchar(c);
 		}
 	}
 }
diff --git a/sysmoOCTSIM/stdio_redirect/gcc/read.c b/sysmoOCTSIM/stdio_redirect/gcc/read.c
new file mode 100644
index 0000000..90e4618
--- /dev/null
+++ b/sysmoOCTSIM/stdio_redirect/gcc/read.c
@@ -0,0 +1,53 @@
+/**
+ * \file
+ *
+ * \brief STDIO redirection
+ *
+ * Copyright (c) 2015-2018 Microchip Technology Inc. and its subsidiaries.
+ *
+ * \asf_license_start
+ *
+ * \page License
+ *
+ * Subject to your compliance with these terms, you may use Microchip
+ * software and any derivatives exclusively with Microchip products.
+ * It is your responsibility to comply with third party license terms applicable
+ * to your use of third party software (including open source software) that
+ * may accompany Microchip software.
+ *
+ * THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
+ * WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
+ * INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
+ * AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
+ * LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
+ * LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
+ * SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
+ * POSSIBILITY OR THE DAMAGES ARE FORESEEABLE.  TO THE FULLEST EXTENT
+ * ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
+ * RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
+ * THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
+ *
+ * \asf_license_stop
+ *
+ */
+
+#include <stdio_io.h>
+#include <stdio.h>
+
+int __attribute__((weak)) _read(int file, char *ptr, int len); /* Remove GCC compiler warning */
+
+int __attribute__((weak)) _read(int file, char *ptr, int len)
+{
+	int n = 0;
+
+	if (file != 0) {
+		return -1;
+	}
+
+	n = stdio_io_read((uint8_t *)ptr, len);
+	if (n < 0) {
+		return -1;
+	}
+
+	return n;
+}
diff --git a/sysmoOCTSIM/stdio_redirect/gcc/write.c b/sysmoOCTSIM/stdio_redirect/gcc/write.c
new file mode 100644
index 0000000..44fa815
--- /dev/null
+++ b/sysmoOCTSIM/stdio_redirect/gcc/write.c
@@ -0,0 +1,53 @@
+/**
+ * \file
+ *
+ * \brief STDIO redirection
+ *
+ * Copyright (c) 2015-2018 Microchip Technology Inc. and its subsidiaries.
+ *
+ * \asf_license_start
+ *
+ * \page License
+ *
+ * Subject to your compliance with these terms, you may use Microchip
+ * software and any derivatives exclusively with Microchip products.
+ * It is your responsibility to comply with third party license terms applicable
+ * to your use of third party software (including open source software) that
+ * may accompany Microchip software.
+ *
+ * THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
+ * WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
+ * INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
+ * AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
+ * LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
+ * LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
+ * SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
+ * POSSIBILITY OR THE DAMAGES ARE FORESEEABLE.  TO THE FULLEST EXTENT
+ * ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
+ * RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
+ * THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
+ *
+ * \asf_license_stop
+ *
+ */
+
+#include <stdio_io.h>
+#include <stdio.h>
+
+int __attribute__((weak)) _write(int file, char *ptr, int len); /* Remove GCC compiler warning */
+
+int __attribute__((weak)) _write(int file, char *ptr, int len)
+{
+	int n = 0;
+
+	if ((file != 1) && (file != 2) && (file != 3)) {
+		return -1;
+	}
+
+	n = stdio_io_write((const uint8_t *)ptr, len);
+	if (n < 0) {
+		return -1;
+	}
+
+	return n;
+}
diff --git a/sysmoOCTSIM/stdio_redirect/iar/read.c b/sysmoOCTSIM/stdio_redirect/iar/read.c
new file mode 100644
index 0000000..df192cb
--- /dev/null
+++ b/sysmoOCTSIM/stdio_redirect/iar/read.c
@@ -0,0 +1,114 @@
+/**
+ * \file
+ *
+ * \brief STDIO redirection
+ *
+ * Copyright (c) 2015-2018 Microchip Technology Inc. and its subsidiaries.
+ *
+ * \asf_license_start
+ *
+ * \page License
+ *
+ * Subject to your compliance with these terms, you may use Microchip
+ * software and any derivatives exclusively with Microchip products.
+ * It is your responsibility to comply with third party license terms applicable
+ * to your use of third party software (including open source software) that
+ * may accompany Microchip software.
+ *
+ * THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
+ * WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
+ * INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
+ * AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
+ * LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
+ * LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
+ * SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
+ * POSSIBILITY OR THE DAMAGES ARE FORESEEABLE.  TO THE FULLEST EXTENT
+ * ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
+ * RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
+ * THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
+ *
+ * \asf_license_stop
+ *
+ */
+
+#include <stdio_io.h>
+#include <stdio.h>
+
+#ifndef _UNIT_TEST_
+#include <yfuns.h>
+#else
+#define _STD_BEGIN
+#define _STD_END
+#define _LLIO_ERROR ((size_t)-1) /* For __read and __write. */
+#define _LLIO_STDIN 0
+#define _LLIO_STDOUT 1
+#define _LLIO_STDERR 2
+#endif
+
+#if (__VER__ < 8010000)
+/* Refer http://ftp.iar.se/WWWfiles/arm/webic/doc/EWARM_MigrationGuide.ENU.pdf */
+_STD_BEGIN
+#endif
+
+#pragma module_name = "?__read"
+
+/*! \brief Reads a number of bytes, at most \a size, into the memory area
+ *         pointed to by \a buffer.
+ *
+ * \param handle File handle to read from.
+ * \param buffer Pointer to buffer to write read bytes to.
+ * \param size Number of bytes to read.
+ *
+ * \return The number of bytes read, \c 0 at the end of the file, or
+ *         \c _LLIO_ERROR on failure.
+ */
+size_t __read(int handle, unsigned char *buffer, size_t size)
+{
+	int n = 0;
+	/* This implementation only reads from stdin.
+	 * For all other file handles, it returns failure. */
+	if (handle != _LLIO_STDIN) {
+		return _LLIO_ERROR;
+	}
+
+	n = stdio_io_read((uint8_t *)buffer, size);
+	if (n < 0) {
+		return _LLIO_ERROR;
+	}
+	return n;
+}
+
+/*! \brief This routine is required by IAR DLIB library since EWAVR V6.10
+ * the implementation is empty to be compatible with old IAR version.
+ */
+int __close(int handle)
+{
+	(void)(handle);
+	return 0;
+}
+
+#ifndef __GNUC__
+/*! \brief This routine is required by IAR DLIB library since EWAVR V6.10
+ * the implementation is empty to be compatible with old IAR version.
+ */
+int remove(const char *val)
+{
+	(void)(val);
+	return 0;
+}
+#endif
+
+/*! \brief This routine is required by IAR DLIB library since EWAVR V6.10
+ * the implementation is empty to be compatible with old IAR version.
+ */
+long __lseek(int handle, long val, int val2)
+{
+	(void)(handle);
+	(void)(val2);
+	return val;
+}
+
+#if (__VER__ < 8010000)
+/* Refer http://ftp.iar.se/WWWfiles/arm/webic/doc/EWARM_MigrationGuide.ENU.pdf */
+_STD_END
+#endif
diff --git a/sysmoOCTSIM/stdio_redirect/iar/write.c b/sysmoOCTSIM/stdio_redirect/iar/write.c
new file mode 100644
index 0000000..7bc8f78
--- /dev/null
+++ b/sysmoOCTSIM/stdio_redirect/iar/write.c
@@ -0,0 +1,94 @@
+/**
+ * \file
+ *
+ * \brief STDIO redirection
+ *
+ * Copyright (c) 2015-2018 Microchip Technology Inc. and its subsidiaries.
+ *
+ * \asf_license_start
+ *
+ * \page License
+ *
+ * Subject to your compliance with these terms, you may use Microchip
+ * software and any derivatives exclusively with Microchip products.
+ * It is your responsibility to comply with third party license terms applicable
+ * to your use of third party software (including open source software) that
+ * may accompany Microchip software.
+ *
+ * THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
+ * WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
+ * INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
+ * AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
+ * LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
+ * LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
+ * SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
+ * POSSIBILITY OR THE DAMAGES ARE FORESEEABLE.  TO THE FULLEST EXTENT
+ * ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
+ * RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
+ * THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
+ *
+ * \asf_license_stop
+ *
+ */
+
+#include <stdio_io.h>
+#include <stdio.h>
+
+#ifndef _UNIT_TEST_
+#include <yfuns.h>
+#else
+#define _STD_BEGIN
+#define _STD_END
+#define _LLIO_ERROR ((size_t)-1) /* For __read and __write. */
+#define _LLIO_STDIN 0
+#define _LLIO_STDOUT 1
+#define _LLIO_STDERR 2
+#endif
+
+#if (__VER__ < 8010000)
+/* Refer http://ftp.iar.se/WWWfiles/arm/webic/doc/EWARM_MigrationGuide.ENU.pdf */
+_STD_BEGIN
+#endif
+
+#pragma module_name = "?__write"
+
+/*! \brief Writes a number of bytes, at most \a size, from the memory area
+ *         pointed to by \a buffer.
+ *
+ * If \a buffer is zero then \ref __write performs flushing of internal buffers,
+ * if any. In this case, \a handle can be \c -1 to indicate that all handles
+ * should be flushed.
+ *
+ * \param handle File handle to write to.
+ * \param buffer Pointer to buffer to read bytes to write from.
+ * \param size Number of bytes to write.
+ *
+ * \return The number of bytes written, or \c _LLIO_ERROR on failure.
+ */
+size_t __write(int handle, const unsigned char *buffer, size_t size)
+{
+	int n = 0;
+
+	if (buffer == 0) {
+		/* This means that we should flush internal buffers. */
+		return 0;
+	}
+
+	/* This implementation only writes to stdout and stderr.
+	 * For all other file handles, it returns failure. */
+	if (handle != _LLIO_STDOUT && handle != _LLIO_STDERR) {
+		return _LLIO_ERROR;
+	}
+
+	n = stdio_io_write((const uint8_t *)buffer, size);
+	if (n < 0) {
+		return _LLIO_ERROR;
+	}
+
+	return n;
+}
+
+#if (__VER__ < 8010000)
+/* Refer http://ftp.iar.se/WWWfiles/arm/webic/doc/EWARM_MigrationGuide.ENU.pdf */
+_STD_END
+#endif
diff --git a/sysmoOCTSIM/stdio_redirect/keil/Retarget.c b/sysmoOCTSIM/stdio_redirect/keil/Retarget.c
new file mode 100644
index 0000000..205e7e5
--- /dev/null
+++ b/sysmoOCTSIM/stdio_redirect/keil/Retarget.c
@@ -0,0 +1,107 @@
+/**
+ * \file
+ *
+ * \brief STDIO redirection
+ *
+ * Copyright (c) 2015-2018 Microchip Technology Inc. and its subsidiaries.
+ *
+ * \asf_license_start
+ *
+ * \page License
+ *
+ * Subject to your compliance with these terms, you may use Microchip
+ * software and any derivatives exclusively with Microchip products.
+ * It is your responsibility to comply with third party license terms applicable
+ * to your use of third party software (including open source software) that
+ * may accompany Microchip software.
+ *
+ * THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
+ * WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
+ * INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
+ * AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
+ * LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
+ * LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
+ * SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
+ * POSSIBILITY OR THE DAMAGES ARE FORESEEABLE.  TO THE FULLEST EXTENT
+ * ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
+ * RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
+ * THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
+ *
+ * \asf_license_stop
+ *
+ */
+
+#include <stdio.h>
+
+#ifdef _UNIT_TEST_
+#undef fputc
+#undef fgetc
+#undef ferror
+#define fputc ut_fputc
+#define fgetc ut_fgetc
+#define ferror ut_ferror
+#endif
+
+#include <stdio_io.h>
+
+/* Disable semihosting */
+#if defined(__GNUC__) && (__ARMCOMPILER_VERSION > 6000000) /*  Keil MDK with ARM Compiler 6 */
+__asm(".global __use_no_semihosting\n\t");
+#else
+#pragma import(__use_no_semihosting_swi)
+#endif
+
+#ifndef __GNUC__
+struct __FILE {
+	int handle;
+};
+#endif
+FILE __stdout;
+FILE __stdin;
+FILE __stderr;
+
+int fputc(int ch, FILE *f)
+{
+	if ((f == stdout) || (f == stderr)) {
+		uint8_t tmp = (uint8_t)ch;
+		if (stdio_io_write(&tmp, 1) < 0) {
+			return EOF;
+		}
+		return ch;
+	} else {
+		return EOF;
+	}
+}
+
+int fgetc(FILE *f)
+{
+	if (f == stdin) {
+		uint8_t tmp = 0;
+		if (stdio_io_read(&tmp, 1) < 0) {
+			return EOF;
+		}
+		return tmp;
+	} else {
+		return EOF;
+	}
+}
+
+void _ttywrch(int ch)
+{
+	uint8_t tmp = (uint8_t)ch;
+	stdio_io_write(&tmp, 1);
+}
+
+int ferror(FILE *f)
+{
+	(void)f;
+	/* Your implementation of ferror */
+	return EOF;
+}
+
+void _sys_exit(int return_code)
+{
+	(void)return_code;
+	while (1) {
+	}; /* endless loop */
+}
diff --git a/sysmoOCTSIM/stdio_redirect/stdio_io.c b/sysmoOCTSIM/stdio_redirect/stdio_io.c
new file mode 100644
index 0000000..7659f3d
--- /dev/null
+++ b/sysmoOCTSIM/stdio_redirect/stdio_io.c
@@ -0,0 +1,74 @@
+/**
+ * \file
+ *
+ * \brief STDIO redirection terminal
+ *
+ * Copyright (c) 2015-2018 Microchip Technology Inc. and its subsidiaries.
+ *
+ * \asf_license_start
+ *
+ * \page License
+ *
+ * Subject to your compliance with these terms, you may use Microchip
+ * software and any derivatives exclusively with Microchip products.
+ * It is your responsibility to comply with third party license terms applicable
+ * to your use of third party software (including open source software) that
+ * may accompany Microchip software.
+ *
+ * THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
+ * WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
+ * INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
+ * AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
+ * LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
+ * LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
+ * SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
+ * POSSIBILITY OR THE DAMAGES ARE FORESEEABLE.  TO THE FULLEST EXTENT
+ * ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
+ * RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
+ * THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
+ *
+ * \asf_license_stop
+ *
+ */
+
+#include <stdio.h>
+#include <stdio_io.h>
+
+/** IO descriptor for STDIO access. */
+static struct io_descriptor *stdio_io = NULL;
+
+void stdio_io_init(struct io_descriptor *io)
+{
+#if defined(__GNUC__)
+	/* Specify that stdout and stdin should not be buffered. */
+	setbuf(stdout, NULL);
+	setbuf(stdin, NULL);
+	/* Note: Already the case in IAR's Normal DLIB default configuration
+	 * and AVR GCC library:
+	 * - printf() emits one character at a time.
+	 * - getchar() requests only 1 byte to exit.
+	 */
+#endif
+	stdio_io = io;
+}
+
+void stdio_io_set_io(struct io_descriptor *io)
+{
+	stdio_io = io;
+}
+
+int32_t stdio_io_read(uint8_t *buf, const int32_t len)
+{
+	if (stdio_io == NULL) {
+		return 0;
+	}
+	return io_read(stdio_io, buf, len);
+}
+
+int32_t stdio_io_write(const uint8_t *buf, const int32_t len)
+{
+	if (stdio_io == NULL) {
+		return 0;
+	}
+	return io_write(stdio_io, buf, len);
+}
diff --git a/sysmoOCTSIM/stdio_redirect/stdio_io.h b/sysmoOCTSIM/stdio_redirect/stdio_io.h
new file mode 100644
index 0000000..973adad
--- /dev/null
+++ b/sysmoOCTSIM/stdio_redirect/stdio_io.h
@@ -0,0 +1,81 @@
+/**
+ * \file
+ *
+ * \brief STDIO redirection terminal
+ *
+ * Copyright (c) 2015-2018 Microchip Technology Inc. and its subsidiaries.
+ *
+ * \asf_license_start
+ *
+ * \page License
+ *
+ * Subject to your compliance with these terms, you may use Microchip
+ * software and any derivatives exclusively with Microchip products.
+ * It is your responsibility to comply with third party license terms applicable
+ * to your use of third party software (including open source software) that
+ * may accompany Microchip software.
+ *
+ * THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
+ * WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
+ * INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
+ * AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
+ * LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
+ * LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
+ * SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
+ * POSSIBILITY OR THE DAMAGES ARE FORESEEABLE.  TO THE FULLEST EXTENT
+ * ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
+ * RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
+ * THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
+ *
+ * \asf_license_stop
+ *
+ */
+
+#ifndef _STDIO_IO_H_INCLUDED
+#define _STDIO_IO_H_INCLUDED
+
+#include <hal_io.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+/**
+ *  \brief Initialize STDIO access
+ *  \param[in] io Pointer to IO descriptor,
+ *                NULL to discard R/W without any error.
+ */
+void stdio_io_init(struct io_descriptor *io);
+
+/**
+ *  \brief Change IO descriptor for terminal to R/W data
+ *  \param[in] io Pointer to IO descriptor,
+ *                NULL to discard R/W without any error.
+ */
+void stdio_io_set_io(struct io_descriptor *io);
+
+/**
+ *  \brief Read through specified terminal
+ *  \param[out] buf Pointer to buffer to place read data
+ *  \param[in] len Data length in number of bytes
+ *  \return status
+ *  \retval >=0 number of bytes read
+ *  \retval <0 error
+ */
+int32_t stdio_io_read(uint8_t *buf, const int32_t len);
+
+/**
+ *  \brief Write through specified terminal
+ *  \param[in] buf Pointer to buffer to place data to write
+ *  \param[in] len Data length in number of bytes
+ *  \return status
+ *  \retval >=0 number of bytes read
+ *  \retval <0 error
+ */
+int32_t stdio_io_write(const uint8_t *buf, const int32_t len);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* _STDIO_IO_H_INCLUDED */
diff --git a/sysmoOCTSIM/stdio_start.c b/sysmoOCTSIM/stdio_start.c
new file mode 100644
index 0000000..7450a08
--- /dev/null
+++ b/sysmoOCTSIM/stdio_start.c
@@ -0,0 +1,23 @@
+/*
+ * Code generated from Atmel Start.
+ *
+ * This file will be overwritten when reconfiguring your Atmel Start project.
+ * Please copy examples or other code you want to keep to a separate file or main.c
+ * to avoid loosing it when reconfiguring.
+ */
+
+#include "atmel_start.h"
+#include "stdio_start.h"
+
+void STDIO_REDIRECT_0_example(void)
+{
+	/* Print welcome message */
+	printf("\r\nHello ATMEL World!\r\n");
+}
+
+void stdio_redirect_init(void)
+{
+
+	usart_sync_enable(&UART_debug);
+	stdio_io_init(&UART_debug.io);
+}
diff --git a/sysmoOCTSIM/stdio_start.h b/sysmoOCTSIM/stdio_start.h
new file mode 100644
index 0000000..bee5325
--- /dev/null
+++ b/sysmoOCTSIM/stdio_start.h
@@ -0,0 +1,31 @@
+/*
+ * Code generated from Atmel Start.
+ *
+ * This file will be overwritten when reconfiguring your Atmel Start project.
+ * Please copy examples or other code you want to keep to a separate file or main.c
+ * to avoid loosing it when reconfiguring.
+ */
+#ifndef STDIO_MAIN_H
+#define STDIO_MAIN_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+#include <stdio.h>
+
+#include <stdio.h>
+#include <stdio_io.h>
+
+void STDIO_REDIRECT_0_example(void);
+
+/**
+ * \brief Initialize STDIO Redirect
+ */
+void stdio_redirect_init(void);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* STDIO_MAIN_H */

-- 
To view, visit https://gerrit.osmocom.org/13035
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-ccid-firmware
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: Ibf4ba961d4bbf8d787558f38f3d557422587aad3
Gerrit-Change-Number: 13035
Gerrit-PatchSet: 3
Gerrit-Owner: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder (1000002)
Gerrit-Reviewer: Kévin Redon <kredon at sysmocom.de>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20190227/6fcc667d/attachment.htm>


More information about the gerrit-log mailing list