xiaoxiang781216 commented on code in PR #7678:
URL: https://github.com/apache/nuttx/pull/7678#discussion_r1032734790


##########
drivers/segger/rtt_stream.c:
##########
@@ -0,0 +1,192 @@
+/****************************************************************************
+ * drivers/segger/rtt_stream.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <assert.h>
+#include <stdio.h>
+
+#include <nuttx/config.h>
+#include <nuttx/kmalloc.h>
+#include <nuttx/streams.h>
+#include <nuttx/segger/rtt.h>
+
+#include <SEGGER_RTT.h>
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: rttstream_putc
+ ****************************************************************************/
+
+static void rttstream_putc(FAR struct lib_outstream_s *this, int ch)
+{
+  FAR struct lib_rttoutstream_s *stream = this;
+  stream->public.nput += SEGGER_RTT_PutChar(stream->channel, ch);
+}
+
+/****************************************************************************
+ * Name: rttstream_puts
+ ****************************************************************************/
+
+static int rttstream_puts(FAR struct lib_outstream_s *this,
+                          FAR const void *buf, int len)
+{
+  FAR struct lib_rttoutstream_s *stream =
+                                (FAR struct lib_rttoutstream_s *)this;
+  int ret = SEGGER_RTT_Write(stream->channel, buf, len);
+  stream->public.nput += ret;
+  return ret;
+}
+
+/****************************************************************************
+ * Name: rttstream_getc
+ ****************************************************************************/
+
+static int rttstream_getc(FAR struct lib_instream_s *this)
+{
+  int ch;
+  FAR struct lib_rttinstream_s *stream =
+                                (FAR struct lib_rttinstream_s *)this;
+
+  DEBUGASSERT(stream);
+  stream->public.nget++;
+  SEGGER_RTT_Read(stream->channel, &ch, 1);
+  return ch;
+}
+
+/****************************************************************************
+ * Name: rttstream_gets
+ ****************************************************************************/
+
+static int rttstream_gets(FAR struct lib_instream_s *this,
+                          FAR void * buffer, int size)
+{
+  int ret;
+  FAR struct lib_rttinstream_s *stream =
+                                (FAR struct lib_rttinstream_s *)this;
+
+  DEBUGASSERT(stream);
+  ret = SEGGER_RTT_Read(stream->channel, buffer, size);
+  stream->public.nget += ret;
+  return ret;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: lib_rttoutstream
+ *
+ * Description:
+ *   Initializes a stream for use with the configured RTT interface.
+ *
+ * Input Parameters:
+ *   stream - User allocated, uninitialized instance of struct
+ *            lib_rttoutstream_s to be initialized.
+ *   channel - SEGGER RTT channel number
+ *
+ * Returned Value:
+ *   None (User allocated instance initialized).
+ *
+ ****************************************************************************/
+
+void lib_rttoutstream(FAR struct lib_rttoutstream_s *stream, int channel,
+                      size_t bufsize)
+{
+  char name[8] = {0};
+  FAR char *upbuf = (FAR char *)kmm_malloc(bufsize);
+  DEBUGASSERT(upbuf);
+
+  sprintf(name, "rtt%d", channel);
+  SEGGER_RTT_ConfigUpBuffer(channel, name, upbuf,
+                            bufsize, SEGGER_RTT_MODE_NO_BLOCK_SKIP);
+
+  DEBUGASSERT(stream != NULL);
+  stream->public.put = rttstream_putc;
+  stream->public.puts = rttstream_puts;
+  stream->public.flush = lib_noflush;
+  stream->public.nput = 0;
+  stream->channel = channel;
+}
+
+/****************************************************************************
+ * Name: lib_rttinstream
+ *
+ * Description:
+ *   Initializes output stream for use with the configured RTT interface.
+ *
+ * Input Parameters:
+ *   stream - User allocated, uninitialized instance of struct
+ *            lib_rttinstream_s to be initialized.
+ *   channel - SEGGER RTT channel number
+ *
+ ****************************************************************************/
+
+void lib_rttinstream(FAR struct lib_rttinstream_s *stream, int channel,
+                     size_t bufsize)
+{
+  char name[8] = {0};
+  FAR char *downbuf = (FAR char *)kmm_malloc(bufsize);
+  DEBUGASSERT(downbuf);
+
+  sprintf(name, "rtt%d", channel);
+  SEGGER_RTT_ConfigUpBuffer(channel, name, downbuf,
+                            bufsize, SEGGER_RTT_MODE_NO_BLOCK_SKIP);
+
+  DEBUGASSERT(stream != NULL);
+  SEGGER_RTT_ConfigDownBuffer(channel, name, downbuf,
+                              bufsize, SEGGER_RTT_MODE_NO_BLOCK_SKIP);
+
+  DEBUGASSERT(stream != NULL);
+  stream->public.get = rttstream_getc;
+  stream->public.gets = rttstream_gets;
+  stream->public.nget = 0;
+  stream->channel = channel;
+}
+
+/****************************************************************************
+ * Name: lib_rttinstream_uninit
+ ****************************************************************************/
+
+void lib_rttinstream_uninit(FAR struct lib_rttinstream_s *stream,
+                            int channel)
+{
+  SEGGER_RTT_ConfigDownBuffer(channel, NULL, NULL, 0,
+                              SEGGER_RTT_MODE_NO_BLOCK_SKIP);
+  stream->channel = -1;
+}
+
+/****************************************************************************
+ * Name: lib_rttoutstream_uninit
+ ****************************************************************************/
+
+void lib_rttoutstream_uninit(FAR struct lib_rttoutstream_s *stream,
+                             int channel)
+{
+  SEGGER_RTT_ConfigUpBuffer(channel, NULL, NULL, 0,

Review Comment:
   need free memory



##########
drivers/segger/rtt_stream.c:
##########
@@ -0,0 +1,192 @@
+/****************************************************************************
+ * drivers/segger/rtt_stream.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <assert.h>
+#include <stdio.h>
+
+#include <nuttx/config.h>
+#include <nuttx/kmalloc.h>
+#include <nuttx/streams.h>
+#include <nuttx/segger/rtt.h>
+
+#include <SEGGER_RTT.h>
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: rttstream_putc
+ ****************************************************************************/
+
+static void rttstream_putc(FAR struct lib_outstream_s *this, int ch)
+{
+  FAR struct lib_rttoutstream_s *stream = this;
+  stream->public.nput += SEGGER_RTT_PutChar(stream->channel, ch);
+}
+
+/****************************************************************************
+ * Name: rttstream_puts
+ ****************************************************************************/
+
+static int rttstream_puts(FAR struct lib_outstream_s *this,
+                          FAR const void *buf, int len)
+{
+  FAR struct lib_rttoutstream_s *stream =
+                                (FAR struct lib_rttoutstream_s *)this;
+  int ret = SEGGER_RTT_Write(stream->channel, buf, len);
+  stream->public.nput += ret;
+  return ret;
+}
+
+/****************************************************************************
+ * Name: rttstream_getc
+ ****************************************************************************/
+
+static int rttstream_getc(FAR struct lib_instream_s *this)
+{
+  int ch;
+  FAR struct lib_rttinstream_s *stream =
+                                (FAR struct lib_rttinstream_s *)this;
+
+  DEBUGASSERT(stream);
+  stream->public.nget++;
+  SEGGER_RTT_Read(stream->channel, &ch, 1);
+  return ch;
+}
+
+/****************************************************************************
+ * Name: rttstream_gets
+ ****************************************************************************/
+
+static int rttstream_gets(FAR struct lib_instream_s *this,
+                          FAR void * buffer, int size)
+{
+  int ret;

Review Comment:
   move after line 87



##########
drivers/segger/rtt_stream.c:
##########
@@ -0,0 +1,192 @@
+/****************************************************************************
+ * drivers/segger/rtt_stream.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <assert.h>
+#include <stdio.h>
+
+#include <nuttx/config.h>
+#include <nuttx/kmalloc.h>
+#include <nuttx/streams.h>
+#include <nuttx/segger/rtt.h>
+
+#include <SEGGER_RTT.h>
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: rttstream_putc
+ ****************************************************************************/
+
+static void rttstream_putc(FAR struct lib_outstream_s *this, int ch)
+{
+  FAR struct lib_rttoutstream_s *stream = this;
+  stream->public.nput += SEGGER_RTT_PutChar(stream->channel, ch);
+}
+
+/****************************************************************************
+ * Name: rttstream_puts
+ ****************************************************************************/
+
+static int rttstream_puts(FAR struct lib_outstream_s *this,
+                          FAR const void *buf, int len)
+{
+  FAR struct lib_rttoutstream_s *stream =
+                                (FAR struct lib_rttoutstream_s *)this;
+  int ret = SEGGER_RTT_Write(stream->channel, buf, len);
+  stream->public.nput += ret;
+  return ret;
+}
+
+/****************************************************************************
+ * Name: rttstream_getc
+ ****************************************************************************/
+
+static int rttstream_getc(FAR struct lib_instream_s *this)
+{
+  int ch;
+  FAR struct lib_rttinstream_s *stream =
+                                (FAR struct lib_rttinstream_s *)this;
+
+  DEBUGASSERT(stream);
+  stream->public.nget++;
+  SEGGER_RTT_Read(stream->channel, &ch, 1);
+  return ch;
+}
+
+/****************************************************************************
+ * Name: rttstream_gets
+ ****************************************************************************/
+
+static int rttstream_gets(FAR struct lib_instream_s *this,
+                          FAR void * buffer, int size)
+{
+  int ret;
+  FAR struct lib_rttinstream_s *stream =
+                                (FAR struct lib_rttinstream_s *)this;
+
+  DEBUGASSERT(stream);
+  ret = SEGGER_RTT_Read(stream->channel, buffer, size);
+  stream->public.nget += ret;
+  return ret;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: lib_rttoutstream
+ *
+ * Description:
+ *   Initializes a stream for use with the configured RTT interface.
+ *
+ * Input Parameters:
+ *   stream - User allocated, uninitialized instance of struct
+ *            lib_rttoutstream_s to be initialized.
+ *   channel - SEGGER RTT channel number
+ *
+ * Returned Value:
+ *   None (User allocated instance initialized).
+ *
+ ****************************************************************************/
+
+void lib_rttoutstream(FAR struct lib_rttoutstream_s *stream, int channel,
+                      size_t bufsize)
+{
+  char name[8] = {0};
+  FAR char *upbuf = (FAR char *)kmm_malloc(bufsize);
+  DEBUGASSERT(upbuf);
+
+  sprintf(name, "rtt%d", channel);
+  SEGGER_RTT_ConfigUpBuffer(channel, name, upbuf,
+                            bufsize, SEGGER_RTT_MODE_NO_BLOCK_SKIP);
+
+  DEBUGASSERT(stream != NULL);
+  stream->public.put = rttstream_putc;
+  stream->public.puts = rttstream_puts;
+  stream->public.flush = lib_noflush;
+  stream->public.nput = 0;
+  stream->channel = channel;
+}
+
+/****************************************************************************
+ * Name: lib_rttinstream
+ *
+ * Description:
+ *   Initializes output stream for use with the configured RTT interface.
+ *
+ * Input Parameters:
+ *   stream - User allocated, uninitialized instance of struct
+ *            lib_rttinstream_s to be initialized.
+ *   channel - SEGGER RTT channel number
+ *
+ ****************************************************************************/
+
+void lib_rttinstream(FAR struct lib_rttinstream_s *stream, int channel,
+                     size_t bufsize)
+{
+  char name[8] = {0};
+  FAR char *downbuf = (FAR char *)kmm_malloc(bufsize);
+  DEBUGASSERT(downbuf);
+
+  sprintf(name, "rtt%d", channel);
+  SEGGER_RTT_ConfigUpBuffer(channel, name, downbuf,
+                            bufsize, SEGGER_RTT_MODE_NO_BLOCK_SKIP);
+
+  DEBUGASSERT(stream != NULL);
+  SEGGER_RTT_ConfigDownBuffer(channel, name, downbuf,
+                              bufsize, SEGGER_RTT_MODE_NO_BLOCK_SKIP);
+
+  DEBUGASSERT(stream != NULL);
+  stream->public.get = rttstream_getc;
+  stream->public.gets = rttstream_gets;
+  stream->public.nget = 0;
+  stream->channel = channel;
+}
+
+/****************************************************************************
+ * Name: lib_rttinstream_uninit
+ ****************************************************************************/
+
+void lib_rttinstream_uninit(FAR struct lib_rttinstream_s *stream,
+                            int channel)
+{
+  SEGGER_RTT_ConfigDownBuffer(channel, NULL, NULL, 0,
+                              SEGGER_RTT_MODE_NO_BLOCK_SKIP);
+  stream->channel = -1;
+}
+
+/****************************************************************************
+ * Name: lib_rttoutstream_uninit
+ ****************************************************************************/
+
+void lib_rttoutstream_uninit(FAR struct lib_rttoutstream_s *stream,

Review Comment:
   move after line 134



##########
include/nuttx/segger/rtt.h:
##########
@@ -0,0 +1,99 @@
+/****************************************************************************
+ * include/nuttx/segger/rtt.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __INCLUDE_NUTTX_SEGGER_RTT_H
+#define __INCLUDE_NUTTX_SEGGER_RTT_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+
+#include <nuttx/streams.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Type Declarations
+ ****************************************************************************/
+
+struct lib_rttoutstream_s
+{
+  struct lib_outstream_s public;
+  int channel;
+};
+
+struct lib_rttinstream_s
+{
+  struct lib_instream_s public;
+  int channel;
+};
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#ifdef CONFIG_SEGGER_RTT
+
+/****************************************************************************
+* Name: lib_rttoutstream
+*****************************************************************************/
+
+void lib_rttoutstream(FAR struct lib_rttoutstream_s *stream, int channel,

Review Comment:
   ```suggestion
   void lib_rttoutstream(FAR struct lib_rttoutstream_s *stream,
                         int channel, size_t bufsize);
   ```



##########
include/nuttx/segger/rtt.h:
##########
@@ -0,0 +1,99 @@
+/****************************************************************************
+ * include/nuttx/segger/rtt.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __INCLUDE_NUTTX_SEGGER_RTT_H
+#define __INCLUDE_NUTTX_SEGGER_RTT_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+
+#include <nuttx/streams.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Type Declarations
+ ****************************************************************************/
+
+struct lib_rttoutstream_s
+{
+  struct lib_outstream_s public;
+  int channel;
+};
+
+struct lib_rttinstream_s
+{
+  struct lib_instream_s public;
+  int channel;
+};
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#ifdef CONFIG_SEGGER_RTT
+
+/****************************************************************************
+* Name: lib_rttoutstream
+*****************************************************************************/
+
+void lib_rttoutstream(FAR struct lib_rttoutstream_s *stream, int channel,
+                      size_t bufsize);
+
+/****************************************************************************
+* Name: lib_rttinstream
+*****************************************************************************/
+
+void lib_rttinstream(FAR struct lib_rttinstream_s *stream, int channel,
+                     size_t bufsize);
+
+
+/****************************************************************************
+ * Name: lib_rttinstream_uninit
+ ****************************************************************************/
+
+void lib_rttinstream_uninit(FAR struct lib_rttinstream_s *stream,
+                            int channel);

Review Comment:
   remove channel argument



##########
include/nuttx/segger/rtt.h:
##########
@@ -0,0 +1,99 @@
+/****************************************************************************
+ * include/nuttx/segger/rtt.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __INCLUDE_NUTTX_SEGGER_RTT_H
+#define __INCLUDE_NUTTX_SEGGER_RTT_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+

Review Comment:
   remove the extra line



##########
drivers/segger/rtt_stream.c:
##########
@@ -0,0 +1,192 @@
+/****************************************************************************
+ * drivers/segger/rtt_stream.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <assert.h>
+#include <stdio.h>
+
+#include <nuttx/config.h>
+#include <nuttx/kmalloc.h>
+#include <nuttx/streams.h>
+#include <nuttx/segger/rtt.h>
+
+#include <SEGGER_RTT.h>
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: rttstream_putc
+ ****************************************************************************/
+
+static void rttstream_putc(FAR struct lib_outstream_s *this, int ch)
+{
+  FAR struct lib_rttoutstream_s *stream = this;
+  stream->public.nput += SEGGER_RTT_PutChar(stream->channel, ch);
+}
+
+/****************************************************************************
+ * Name: rttstream_puts
+ ****************************************************************************/
+
+static int rttstream_puts(FAR struct lib_outstream_s *this,
+                          FAR const void *buf, int len)
+{
+  FAR struct lib_rttoutstream_s *stream =
+                                (FAR struct lib_rttoutstream_s *)this;
+  int ret = SEGGER_RTT_Write(stream->channel, buf, len);
+  stream->public.nput += ret;
+  return ret;
+}
+
+/****************************************************************************
+ * Name: rttstream_getc
+ ****************************************************************************/
+
+static int rttstream_getc(FAR struct lib_instream_s *this)
+{
+  int ch;
+  FAR struct lib_rttinstream_s *stream =
+                                (FAR struct lib_rttinstream_s *)this;
+
+  DEBUGASSERT(stream);
+  stream->public.nget++;
+  SEGGER_RTT_Read(stream->channel, &ch, 1);
+  return ch;
+}
+
+/****************************************************************************
+ * Name: rttstream_gets
+ ****************************************************************************/
+
+static int rttstream_gets(FAR struct lib_instream_s *this,
+                          FAR void * buffer, int size)
+{
+  int ret;
+  FAR struct lib_rttinstream_s *stream =
+                                (FAR struct lib_rttinstream_s *)this;
+
+  DEBUGASSERT(stream);
+  ret = SEGGER_RTT_Read(stream->channel, buffer, size);
+  stream->public.nget += ret;
+  return ret;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: lib_rttoutstream
+ *
+ * Description:
+ *   Initializes a stream for use with the configured RTT interface.
+ *
+ * Input Parameters:
+ *   stream - User allocated, uninitialized instance of struct
+ *            lib_rttoutstream_s to be initialized.
+ *   channel - SEGGER RTT channel number
+ *
+ * Returned Value:
+ *   None (User allocated instance initialized).
+ *
+ ****************************************************************************/
+
+void lib_rttoutstream(FAR struct lib_rttoutstream_s *stream, int channel,
+                      size_t bufsize)
+{
+  char name[8] = {0};
+  FAR char *upbuf = (FAR char *)kmm_malloc(bufsize);
+  DEBUGASSERT(upbuf);
+
+  sprintf(name, "rtt%d", channel);
+  SEGGER_RTT_ConfigUpBuffer(channel, name, upbuf,
+                            bufsize, SEGGER_RTT_MODE_NO_BLOCK_SKIP);
+
+  DEBUGASSERT(stream != NULL);
+  stream->public.put = rttstream_putc;
+  stream->public.puts = rttstream_puts;
+  stream->public.flush = lib_noflush;
+  stream->public.nput = 0;
+  stream->channel = channel;
+}
+
+/****************************************************************************
+ * Name: lib_rttinstream
+ *
+ * Description:
+ *   Initializes output stream for use with the configured RTT interface.
+ *
+ * Input Parameters:
+ *   stream - User allocated, uninitialized instance of struct
+ *            lib_rttinstream_s to be initialized.
+ *   channel - SEGGER RTT channel number
+ *
+ ****************************************************************************/
+
+void lib_rttinstream(FAR struct lib_rttinstream_s *stream, int channel,
+                     size_t bufsize)
+{
+  char name[8] = {0};
+  FAR char *downbuf = (FAR char *)kmm_malloc(bufsize);
+  DEBUGASSERT(downbuf);
+
+  sprintf(name, "rtt%d", channel);
+  SEGGER_RTT_ConfigUpBuffer(channel, name, downbuf,
+                            bufsize, SEGGER_RTT_MODE_NO_BLOCK_SKIP);
+
+  DEBUGASSERT(stream != NULL);

Review Comment:
   remove



##########
include/nuttx/segger/rtt.h:
##########
@@ -0,0 +1,99 @@
+/****************************************************************************
+ * include/nuttx/segger/rtt.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __INCLUDE_NUTTX_SEGGER_RTT_H
+#define __INCLUDE_NUTTX_SEGGER_RTT_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+
+#include <nuttx/streams.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Type Declarations
+ ****************************************************************************/
+
+struct lib_rttoutstream_s
+{
+  struct lib_outstream_s public;
+  int channel;
+};
+
+struct lib_rttinstream_s
+{
+  struct lib_instream_s public;
+  int channel;
+};
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#ifdef CONFIG_SEGGER_RTT
+
+/****************************************************************************
+* Name: lib_rttoutstream
+*****************************************************************************/
+
+void lib_rttoutstream(FAR struct lib_rttoutstream_s *stream, int channel,
+                      size_t bufsize);
+
+/****************************************************************************
+* Name: lib_rttinstream
+*****************************************************************************/
+
+void lib_rttinstream(FAR struct lib_rttinstream_s *stream, int channel,

Review Comment:
   ```suggestion
   void lib_rttinstream(FAR struct lib_rttinstream_s *stream,
                        int channel,  size_t bufsize);
   ```



##########
include/nuttx/segger/rtt.h:
##########
@@ -0,0 +1,99 @@
+/****************************************************************************
+ * include/nuttx/segger/rtt.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __INCLUDE_NUTTX_SEGGER_RTT_H
+#define __INCLUDE_NUTTX_SEGGER_RTT_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+
+#include <nuttx/streams.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Type Declarations
+ ****************************************************************************/
+
+struct lib_rttoutstream_s
+{
+  struct lib_outstream_s public;
+  int channel;
+};
+
+struct lib_rttinstream_s
+{
+  struct lib_instream_s public;
+  int channel;
+};
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#ifdef CONFIG_SEGGER_RTT
+
+/****************************************************************************
+* Name: lib_rttoutstream
+*****************************************************************************/
+
+void lib_rttoutstream(FAR struct lib_rttoutstream_s *stream, int channel,
+                      size_t bufsize);
+
+/****************************************************************************
+* Name: lib_rttinstream
+*****************************************************************************/
+
+void lib_rttinstream(FAR struct lib_rttinstream_s *stream, int channel,
+                     size_t bufsize);
+
+
+/****************************************************************************
+ * Name: lib_rttinstream_uninit
+ ****************************************************************************/
+
+void lib_rttinstream_uninit(FAR struct lib_rttinstream_s *stream,

Review Comment:
   move before line 71



##########
drivers/segger/rtt_stream.c:
##########
@@ -0,0 +1,192 @@
+/****************************************************************************
+ * drivers/segger/rtt_stream.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <assert.h>
+#include <stdio.h>
+
+#include <nuttx/config.h>
+#include <nuttx/kmalloc.h>
+#include <nuttx/streams.h>
+#include <nuttx/segger/rtt.h>
+
+#include <SEGGER_RTT.h>
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: rttstream_putc
+ ****************************************************************************/
+
+static void rttstream_putc(FAR struct lib_outstream_s *this, int ch)
+{
+  FAR struct lib_rttoutstream_s *stream = this;
+  stream->public.nput += SEGGER_RTT_PutChar(stream->channel, ch);
+}
+
+/****************************************************************************
+ * Name: rttstream_puts
+ ****************************************************************************/
+
+static int rttstream_puts(FAR struct lib_outstream_s *this,
+                          FAR const void *buf, int len)
+{
+  FAR struct lib_rttoutstream_s *stream =
+                                (FAR struct lib_rttoutstream_s *)this;
+  int ret = SEGGER_RTT_Write(stream->channel, buf, len);
+  stream->public.nput += ret;
+  return ret;
+}
+
+/****************************************************************************
+ * Name: rttstream_getc
+ ****************************************************************************/
+
+static int rttstream_getc(FAR struct lib_instream_s *this)
+{
+  int ch;
+  FAR struct lib_rttinstream_s *stream =
+                                (FAR struct lib_rttinstream_s *)this;
+
+  DEBUGASSERT(stream);
+  stream->public.nget++;
+  SEGGER_RTT_Read(stream->channel, &ch, 1);
+  return ch;
+}
+
+/****************************************************************************
+ * Name: rttstream_gets
+ ****************************************************************************/
+
+static int rttstream_gets(FAR struct lib_instream_s *this,
+                          FAR void * buffer, int size)
+{
+  int ret;
+  FAR struct lib_rttinstream_s *stream =
+                                (FAR struct lib_rttinstream_s *)this;
+
+  DEBUGASSERT(stream);
+  ret = SEGGER_RTT_Read(stream->channel, buffer, size);
+  stream->public.nget += ret;
+  return ret;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: lib_rttoutstream
+ *
+ * Description:
+ *   Initializes a stream for use with the configured RTT interface.
+ *
+ * Input Parameters:
+ *   stream - User allocated, uninitialized instance of struct
+ *            lib_rttoutstream_s to be initialized.
+ *   channel - SEGGER RTT channel number
+ *
+ * Returned Value:
+ *   None (User allocated instance initialized).
+ *
+ ****************************************************************************/
+
+void lib_rttoutstream(FAR struct lib_rttoutstream_s *stream, int channel,
+                      size_t bufsize)
+{
+  char name[8] = {0};
+  FAR char *upbuf = (FAR char *)kmm_malloc(bufsize);
+  DEBUGASSERT(upbuf);
+
+  sprintf(name, "rtt%d", channel);
+  SEGGER_RTT_ConfigUpBuffer(channel, name, upbuf,
+                            bufsize, SEGGER_RTT_MODE_NO_BLOCK_SKIP);
+
+  DEBUGASSERT(stream != NULL);
+  stream->public.put = rttstream_putc;
+  stream->public.puts = rttstream_puts;
+  stream->public.flush = lib_noflush;
+  stream->public.nput = 0;
+  stream->channel = channel;
+}
+
+/****************************************************************************
+ * Name: lib_rttinstream
+ *
+ * Description:
+ *   Initializes output stream for use with the configured RTT interface.
+ *
+ * Input Parameters:
+ *   stream - User allocated, uninitialized instance of struct
+ *            lib_rttinstream_s to be initialized.
+ *   channel - SEGGER RTT channel number
+ *
+ ****************************************************************************/
+
+void lib_rttinstream(FAR struct lib_rttinstream_s *stream, int channel,
+                     size_t bufsize)
+{
+  char name[8] = {0};

Review Comment:
   ```suggestion
     char name[32];
   ```



##########
drivers/segger/rtt_stream.c:
##########
@@ -0,0 +1,192 @@
+/****************************************************************************
+ * drivers/segger/rtt_stream.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <assert.h>
+#include <stdio.h>
+
+#include <nuttx/config.h>
+#include <nuttx/kmalloc.h>
+#include <nuttx/streams.h>
+#include <nuttx/segger/rtt.h>
+
+#include <SEGGER_RTT.h>
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: rttstream_putc
+ ****************************************************************************/
+
+static void rttstream_putc(FAR struct lib_outstream_s *this, int ch)
+{
+  FAR struct lib_rttoutstream_s *stream = this;
+  stream->public.nput += SEGGER_RTT_PutChar(stream->channel, ch);
+}
+
+/****************************************************************************
+ * Name: rttstream_puts
+ ****************************************************************************/
+
+static int rttstream_puts(FAR struct lib_outstream_s *this,
+                          FAR const void *buf, int len)
+{
+  FAR struct lib_rttoutstream_s *stream =
+                                (FAR struct lib_rttoutstream_s *)this;
+  int ret = SEGGER_RTT_Write(stream->channel, buf, len);
+  stream->public.nput += ret;
+  return ret;
+}
+
+/****************************************************************************
+ * Name: rttstream_getc
+ ****************************************************************************/
+
+static int rttstream_getc(FAR struct lib_instream_s *this)
+{
+  int ch;
+  FAR struct lib_rttinstream_s *stream =
+                                (FAR struct lib_rttinstream_s *)this;
+
+  DEBUGASSERT(stream);
+  stream->public.nget++;
+  SEGGER_RTT_Read(stream->channel, &ch, 1);
+  return ch;
+}
+
+/****************************************************************************
+ * Name: rttstream_gets
+ ****************************************************************************/
+
+static int rttstream_gets(FAR struct lib_instream_s *this,
+                          FAR void * buffer, int size)
+{
+  int ret;
+  FAR struct lib_rttinstream_s *stream =
+                                (FAR struct lib_rttinstream_s *)this;
+
+  DEBUGASSERT(stream);
+  ret = SEGGER_RTT_Read(stream->channel, buffer, size);
+  stream->public.nget += ret;
+  return ret;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: lib_rttoutstream
+ *
+ * Description:
+ *   Initializes a stream for use with the configured RTT interface.
+ *
+ * Input Parameters:
+ *   stream - User allocated, uninitialized instance of struct
+ *            lib_rttoutstream_s to be initialized.
+ *   channel - SEGGER RTT channel number
+ *
+ * Returned Value:
+ *   None (User allocated instance initialized).
+ *
+ ****************************************************************************/
+
+void lib_rttoutstream(FAR struct lib_rttoutstream_s *stream, int channel,
+                      size_t bufsize)
+{
+  char name[8] = {0};

Review Comment:
   ```suggestion
     char name[32];
   ```



##########
include/nuttx/segger/rtt.h:
##########
@@ -0,0 +1,99 @@
+/****************************************************************************
+ * include/nuttx/segger/rtt.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __INCLUDE_NUTTX_SEGGER_RTT_H
+#define __INCLUDE_NUTTX_SEGGER_RTT_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+
+#include <nuttx/streams.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Type Declarations
+ ****************************************************************************/
+
+struct lib_rttoutstream_s
+{
+  struct lib_outstream_s public;
+  int channel;
+};
+
+struct lib_rttinstream_s
+{
+  struct lib_instream_s public;
+  int channel;
+};
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#ifdef CONFIG_SEGGER_RTT
+
+/****************************************************************************
+* Name: lib_rttoutstream
+*****************************************************************************/
+
+void lib_rttoutstream(FAR struct lib_rttoutstream_s *stream, int channel,
+                      size_t bufsize);
+
+/****************************************************************************
+* Name: lib_rttinstream
+*****************************************************************************/
+
+void lib_rttinstream(FAR struct lib_rttinstream_s *stream, int channel,
+                     size_t bufsize);
+
+
+/****************************************************************************
+ * Name: lib_rttinstream_uninit
+ ****************************************************************************/
+
+void lib_rttinstream_uninit(FAR struct lib_rttinstream_s *stream,
+                            int channel);
+
+/****************************************************************************
+ * Name: lib_rttoutstream_uninit
+ ****************************************************************************/
+
+void lib_rttoutstream_uninit(FAR struct lib_rttoutstream_s *stream,
+                             int channel);

Review Comment:
   remove channel argument



##########
drivers/segger/rtt_stream.c:
##########
@@ -0,0 +1,192 @@
+/****************************************************************************
+ * drivers/segger/rtt_stream.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <assert.h>
+#include <stdio.h>
+
+#include <nuttx/config.h>
+#include <nuttx/kmalloc.h>
+#include <nuttx/streams.h>
+#include <nuttx/segger/rtt.h>
+
+#include <SEGGER_RTT.h>
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: rttstream_putc
+ ****************************************************************************/
+
+static void rttstream_putc(FAR struct lib_outstream_s *this, int ch)
+{
+  FAR struct lib_rttoutstream_s *stream = this;
+  stream->public.nput += SEGGER_RTT_PutChar(stream->channel, ch);
+}
+
+/****************************************************************************
+ * Name: rttstream_puts
+ ****************************************************************************/
+
+static int rttstream_puts(FAR struct lib_outstream_s *this,
+                          FAR const void *buf, int len)
+{
+  FAR struct lib_rttoutstream_s *stream =
+                                (FAR struct lib_rttoutstream_s *)this;
+  int ret = SEGGER_RTT_Write(stream->channel, buf, len);
+  stream->public.nput += ret;
+  return ret;
+}
+
+/****************************************************************************
+ * Name: rttstream_getc
+ ****************************************************************************/
+
+static int rttstream_getc(FAR struct lib_instream_s *this)
+{
+  int ch;

Review Comment:
   need handle the big endian and SEGGER_RTT_Read return nothing correctly:
   ```
     FAR struct lib_rttinstream_s *stream =
                                   (FAR struct lib_rttinstream_s *)this;
     signed char ch = -1;
   
     DEBUGASSERT(stream);
     stream->public.nget += SEGGER_RTT_Read(stream->channel, &ch, 1);
     return ch;
   ```



##########
drivers/segger/rtt_stream.c:
##########
@@ -0,0 +1,192 @@
+/****************************************************************************
+ * drivers/segger/rtt_stream.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <assert.h>
+#include <stdio.h>
+
+#include <nuttx/config.h>
+#include <nuttx/kmalloc.h>
+#include <nuttx/streams.h>
+#include <nuttx/segger/rtt.h>
+
+#include <SEGGER_RTT.h>
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: rttstream_putc
+ ****************************************************************************/
+
+static void rttstream_putc(FAR struct lib_outstream_s *this, int ch)
+{
+  FAR struct lib_rttoutstream_s *stream = this;
+  stream->public.nput += SEGGER_RTT_PutChar(stream->channel, ch);
+}
+
+/****************************************************************************
+ * Name: rttstream_puts
+ ****************************************************************************/
+
+static int rttstream_puts(FAR struct lib_outstream_s *this,
+                          FAR const void *buf, int len)
+{
+  FAR struct lib_rttoutstream_s *stream =
+                                (FAR struct lib_rttoutstream_s *)this;
+  int ret = SEGGER_RTT_Write(stream->channel, buf, len);
+  stream->public.nput += ret;
+  return ret;
+}
+
+/****************************************************************************
+ * Name: rttstream_getc
+ ****************************************************************************/
+
+static int rttstream_getc(FAR struct lib_instream_s *this)
+{
+  int ch;
+  FAR struct lib_rttinstream_s *stream =
+                                (FAR struct lib_rttinstream_s *)this;
+
+  DEBUGASSERT(stream);
+  stream->public.nget++;
+  SEGGER_RTT_Read(stream->channel, &ch, 1);
+  return ch;
+}
+
+/****************************************************************************
+ * Name: rttstream_gets
+ ****************************************************************************/
+
+static int rttstream_gets(FAR struct lib_instream_s *this,
+                          FAR void * buffer, int size)
+{
+  int ret;
+  FAR struct lib_rttinstream_s *stream =
+                                (FAR struct lib_rttinstream_s *)this;
+
+  DEBUGASSERT(stream);
+  ret = SEGGER_RTT_Read(stream->channel, buffer, size);
+  stream->public.nget += ret;
+  return ret;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: lib_rttoutstream
+ *
+ * Description:
+ *   Initializes a stream for use with the configured RTT interface.
+ *
+ * Input Parameters:
+ *   stream - User allocated, uninitialized instance of struct
+ *            lib_rttoutstream_s to be initialized.
+ *   channel - SEGGER RTT channel number
+ *
+ * Returned Value:
+ *   None (User allocated instance initialized).
+ *
+ ****************************************************************************/
+
+void lib_rttoutstream(FAR struct lib_rttoutstream_s *stream, int channel,
+                      size_t bufsize)
+{
+  char name[8] = {0};
+  FAR char *upbuf = (FAR char *)kmm_malloc(bufsize);
+  DEBUGASSERT(upbuf);
+
+  sprintf(name, "rtt%d", channel);
+  SEGGER_RTT_ConfigUpBuffer(channel, name, upbuf,
+                            bufsize, SEGGER_RTT_MODE_NO_BLOCK_SKIP);

Review Comment:
   ```suggestion
                               bufsize, SEGGER_RTT_MODE_DEFAULT);
   ```



##########
drivers/segger/rtt_stream.c:
##########
@@ -0,0 +1,192 @@
+/****************************************************************************
+ * drivers/segger/rtt_stream.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <assert.h>
+#include <stdio.h>
+
+#include <nuttx/config.h>
+#include <nuttx/kmalloc.h>
+#include <nuttx/streams.h>
+#include <nuttx/segger/rtt.h>
+
+#include <SEGGER_RTT.h>
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: rttstream_putc
+ ****************************************************************************/
+
+static void rttstream_putc(FAR struct lib_outstream_s *this, int ch)
+{
+  FAR struct lib_rttoutstream_s *stream = this;
+  stream->public.nput += SEGGER_RTT_PutChar(stream->channel, ch);
+}
+
+/****************************************************************************
+ * Name: rttstream_puts
+ ****************************************************************************/
+
+static int rttstream_puts(FAR struct lib_outstream_s *this,
+                          FAR const void *buf, int len)
+{
+  FAR struct lib_rttoutstream_s *stream =
+                                (FAR struct lib_rttoutstream_s *)this;
+  int ret = SEGGER_RTT_Write(stream->channel, buf, len);
+  stream->public.nput += ret;
+  return ret;
+}
+
+/****************************************************************************
+ * Name: rttstream_getc
+ ****************************************************************************/
+
+static int rttstream_getc(FAR struct lib_instream_s *this)
+{
+  int ch;
+  FAR struct lib_rttinstream_s *stream =
+                                (FAR struct lib_rttinstream_s *)this;
+
+  DEBUGASSERT(stream);
+  stream->public.nget++;
+  SEGGER_RTT_Read(stream->channel, &ch, 1);
+  return ch;
+}
+
+/****************************************************************************
+ * Name: rttstream_gets
+ ****************************************************************************/
+
+static int rttstream_gets(FAR struct lib_instream_s *this,
+                          FAR void * buffer, int size)
+{
+  int ret;
+  FAR struct lib_rttinstream_s *stream =
+                                (FAR struct lib_rttinstream_s *)this;
+
+  DEBUGASSERT(stream);
+  ret = SEGGER_RTT_Read(stream->channel, buffer, size);
+  stream->public.nget += ret;
+  return ret;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: lib_rttoutstream
+ *
+ * Description:
+ *   Initializes a stream for use with the configured RTT interface.
+ *
+ * Input Parameters:
+ *   stream - User allocated, uninitialized instance of struct
+ *            lib_rttoutstream_s to be initialized.
+ *   channel - SEGGER RTT channel number
+ *
+ * Returned Value:
+ *   None (User allocated instance initialized).
+ *
+ ****************************************************************************/
+
+void lib_rttoutstream(FAR struct lib_rttoutstream_s *stream, int channel,
+                      size_t bufsize)
+{
+  char name[8] = {0};
+  FAR char *upbuf = (FAR char *)kmm_malloc(bufsize);
+  DEBUGASSERT(upbuf);
+
+  sprintf(name, "rtt%d", channel);
+  SEGGER_RTT_ConfigUpBuffer(channel, name, upbuf,
+                            bufsize, SEGGER_RTT_MODE_NO_BLOCK_SKIP);
+
+  DEBUGASSERT(stream != NULL);
+  stream->public.put = rttstream_putc;
+  stream->public.puts = rttstream_puts;
+  stream->public.flush = lib_noflush;
+  stream->public.nput = 0;
+  stream->channel = channel;
+}
+
+/****************************************************************************
+ * Name: lib_rttinstream
+ *
+ * Description:
+ *   Initializes output stream for use with the configured RTT interface.
+ *
+ * Input Parameters:
+ *   stream - User allocated, uninitialized instance of struct
+ *            lib_rttinstream_s to be initialized.
+ *   channel - SEGGER RTT channel number
+ *
+ ****************************************************************************/
+
+void lib_rttinstream(FAR struct lib_rttinstream_s *stream, int channel,
+                     size_t bufsize)
+{
+  char name[8] = {0};
+  FAR char *downbuf = (FAR char *)kmm_malloc(bufsize);
+  DEBUGASSERT(downbuf);
+
+  sprintf(name, "rtt%d", channel);
+  SEGGER_RTT_ConfigUpBuffer(channel, name, downbuf,
+                            bufsize, SEGGER_RTT_MODE_NO_BLOCK_SKIP);

Review Comment:
   ```suggestion
                               bufsize, SEGGER_RTT_MODE_DEFAULT);
   ```



##########
drivers/segger/rtt_stream.c:
##########
@@ -0,0 +1,192 @@
+/****************************************************************************
+ * drivers/segger/rtt_stream.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <assert.h>
+#include <stdio.h>
+
+#include <nuttx/config.h>
+#include <nuttx/kmalloc.h>
+#include <nuttx/streams.h>
+#include <nuttx/segger/rtt.h>
+
+#include <SEGGER_RTT.h>
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: rttstream_putc
+ ****************************************************************************/
+
+static void rttstream_putc(FAR struct lib_outstream_s *this, int ch)
+{
+  FAR struct lib_rttoutstream_s *stream = this;
+  stream->public.nput += SEGGER_RTT_PutChar(stream->channel, ch);
+}
+
+/****************************************************************************
+ * Name: rttstream_puts
+ ****************************************************************************/
+
+static int rttstream_puts(FAR struct lib_outstream_s *this,
+                          FAR const void *buf, int len)
+{
+  FAR struct lib_rttoutstream_s *stream =
+                                (FAR struct lib_rttoutstream_s *)this;
+  int ret = SEGGER_RTT_Write(stream->channel, buf, len);
+  stream->public.nput += ret;
+  return ret;
+}
+
+/****************************************************************************
+ * Name: rttstream_getc
+ ****************************************************************************/
+
+static int rttstream_getc(FAR struct lib_instream_s *this)
+{
+  int ch;
+  FAR struct lib_rttinstream_s *stream =
+                                (FAR struct lib_rttinstream_s *)this;
+
+  DEBUGASSERT(stream);
+  stream->public.nget++;
+  SEGGER_RTT_Read(stream->channel, &ch, 1);
+  return ch;
+}
+
+/****************************************************************************
+ * Name: rttstream_gets
+ ****************************************************************************/
+
+static int rttstream_gets(FAR struct lib_instream_s *this,
+                          FAR void * buffer, int size)
+{
+  int ret;
+  FAR struct lib_rttinstream_s *stream =
+                                (FAR struct lib_rttinstream_s *)this;
+
+  DEBUGASSERT(stream);
+  ret = SEGGER_RTT_Read(stream->channel, buffer, size);
+  stream->public.nget += ret;
+  return ret;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: lib_rttoutstream
+ *
+ * Description:
+ *   Initializes a stream for use with the configured RTT interface.
+ *
+ * Input Parameters:
+ *   stream - User allocated, uninitialized instance of struct
+ *            lib_rttoutstream_s to be initialized.
+ *   channel - SEGGER RTT channel number
+ *
+ * Returned Value:
+ *   None (User allocated instance initialized).
+ *
+ ****************************************************************************/
+
+void lib_rttoutstream(FAR struct lib_rttoutstream_s *stream, int channel,
+                      size_t bufsize)
+{
+  char name[8] = {0};
+  FAR char *upbuf = (FAR char *)kmm_malloc(bufsize);
+  DEBUGASSERT(upbuf);
+
+  sprintf(name, "rtt%d", channel);
+  SEGGER_RTT_ConfigUpBuffer(channel, name, upbuf,
+                            bufsize, SEGGER_RTT_MODE_NO_BLOCK_SKIP);
+
+  DEBUGASSERT(stream != NULL);
+  stream->public.put = rttstream_putc;
+  stream->public.puts = rttstream_puts;
+  stream->public.flush = lib_noflush;
+  stream->public.nput = 0;
+  stream->channel = channel;
+}
+
+/****************************************************************************
+ * Name: lib_rttinstream
+ *
+ * Description:
+ *   Initializes output stream for use with the configured RTT interface.
+ *
+ * Input Parameters:
+ *   stream - User allocated, uninitialized instance of struct
+ *            lib_rttinstream_s to be initialized.
+ *   channel - SEGGER RTT channel number
+ *
+ ****************************************************************************/
+
+void lib_rttinstream(FAR struct lib_rttinstream_s *stream, int channel,
+                     size_t bufsize)
+{
+  char name[8] = {0};
+  FAR char *downbuf = (FAR char *)kmm_malloc(bufsize);
+  DEBUGASSERT(downbuf);
+
+  sprintf(name, "rtt%d", channel);
+  SEGGER_RTT_ConfigUpBuffer(channel, name, downbuf,
+                            bufsize, SEGGER_RTT_MODE_NO_BLOCK_SKIP);
+
+  DEBUGASSERT(stream != NULL);
+  SEGGER_RTT_ConfigDownBuffer(channel, name, downbuf,
+                              bufsize, SEGGER_RTT_MODE_NO_BLOCK_SKIP);
+
+  DEBUGASSERT(stream != NULL);
+  stream->public.get = rttstream_getc;
+  stream->public.gets = rttstream_gets;
+  stream->public.nget = 0;
+  stream->channel = channel;
+}
+
+/****************************************************************************
+ * Name: lib_rttinstream_uninit
+ ****************************************************************************/
+
+void lib_rttinstream_uninit(FAR struct lib_rttinstream_s *stream,
+                            int channel)
+{
+  SEGGER_RTT_ConfigDownBuffer(channel, NULL, NULL, 0,

Review Comment:
   need free memory



##########
drivers/segger/rtt_stream.c:
##########
@@ -0,0 +1,192 @@
+/****************************************************************************
+ * drivers/segger/rtt_stream.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <assert.h>
+#include <stdio.h>
+
+#include <nuttx/config.h>
+#include <nuttx/kmalloc.h>
+#include <nuttx/streams.h>
+#include <nuttx/segger/rtt.h>
+
+#include <SEGGER_RTT.h>
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: rttstream_putc
+ ****************************************************************************/
+
+static void rttstream_putc(FAR struct lib_outstream_s *this, int ch)
+{
+  FAR struct lib_rttoutstream_s *stream = this;
+  stream->public.nput += SEGGER_RTT_PutChar(stream->channel, ch);
+}
+
+/****************************************************************************
+ * Name: rttstream_puts
+ ****************************************************************************/
+
+static int rttstream_puts(FAR struct lib_outstream_s *this,
+                          FAR const void *buf, int len)
+{
+  FAR struct lib_rttoutstream_s *stream =
+                                (FAR struct lib_rttoutstream_s *)this;
+  int ret = SEGGER_RTT_Write(stream->channel, buf, len);
+  stream->public.nput += ret;
+  return ret;
+}
+
+/****************************************************************************
+ * Name: rttstream_getc
+ ****************************************************************************/
+
+static int rttstream_getc(FAR struct lib_instream_s *this)
+{
+  int ch;
+  FAR struct lib_rttinstream_s *stream =
+                                (FAR struct lib_rttinstream_s *)this;
+
+  DEBUGASSERT(stream);
+  stream->public.nget++;
+  SEGGER_RTT_Read(stream->channel, &ch, 1);
+  return ch;
+}
+
+/****************************************************************************
+ * Name: rttstream_gets
+ ****************************************************************************/
+
+static int rttstream_gets(FAR struct lib_instream_s *this,
+                          FAR void * buffer, int size)
+{
+  int ret;
+  FAR struct lib_rttinstream_s *stream =
+                                (FAR struct lib_rttinstream_s *)this;
+
+  DEBUGASSERT(stream);
+  ret = SEGGER_RTT_Read(stream->channel, buffer, size);
+  stream->public.nget += ret;
+  return ret;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: lib_rttoutstream
+ *
+ * Description:
+ *   Initializes a stream for use with the configured RTT interface.
+ *
+ * Input Parameters:
+ *   stream - User allocated, uninitialized instance of struct
+ *            lib_rttoutstream_s to be initialized.
+ *   channel - SEGGER RTT channel number
+ *
+ * Returned Value:
+ *   None (User allocated instance initialized).
+ *
+ ****************************************************************************/
+
+void lib_rttoutstream(FAR struct lib_rttoutstream_s *stream, int channel,

Review Comment:
   ```suggestion
   void lib_rttoutstream(FAR struct lib_rttoutstream_s *stream,
                         int channel, size_t bufsize)
   ```



##########
drivers/segger/rtt_stream.c:
##########
@@ -0,0 +1,192 @@
+/****************************************************************************
+ * drivers/segger/rtt_stream.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <assert.h>
+#include <stdio.h>
+
+#include <nuttx/config.h>
+#include <nuttx/kmalloc.h>
+#include <nuttx/streams.h>
+#include <nuttx/segger/rtt.h>
+
+#include <SEGGER_RTT.h>
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: rttstream_putc
+ ****************************************************************************/
+
+static void rttstream_putc(FAR struct lib_outstream_s *this, int ch)
+{
+  FAR struct lib_rttoutstream_s *stream = this;
+  stream->public.nput += SEGGER_RTT_PutChar(stream->channel, ch);
+}
+
+/****************************************************************************
+ * Name: rttstream_puts
+ ****************************************************************************/
+
+static int rttstream_puts(FAR struct lib_outstream_s *this,
+                          FAR const void *buf, int len)
+{
+  FAR struct lib_rttoutstream_s *stream =
+                                (FAR struct lib_rttoutstream_s *)this;
+  int ret = SEGGER_RTT_Write(stream->channel, buf, len);
+  stream->public.nput += ret;
+  return ret;
+}
+
+/****************************************************************************
+ * Name: rttstream_getc
+ ****************************************************************************/
+
+static int rttstream_getc(FAR struct lib_instream_s *this)
+{
+  int ch;
+  FAR struct lib_rttinstream_s *stream =
+                                (FAR struct lib_rttinstream_s *)this;
+
+  DEBUGASSERT(stream);
+  stream->public.nget++;
+  SEGGER_RTT_Read(stream->channel, &ch, 1);
+  return ch;
+}
+
+/****************************************************************************
+ * Name: rttstream_gets
+ ****************************************************************************/
+
+static int rttstream_gets(FAR struct lib_instream_s *this,
+                          FAR void * buffer, int size)
+{
+  int ret;
+  FAR struct lib_rttinstream_s *stream =
+                                (FAR struct lib_rttinstream_s *)this;
+
+  DEBUGASSERT(stream);
+  ret = SEGGER_RTT_Read(stream->channel, buffer, size);
+  stream->public.nget += ret;
+  return ret;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: lib_rttoutstream
+ *
+ * Description:
+ *   Initializes a stream for use with the configured RTT interface.
+ *
+ * Input Parameters:
+ *   stream - User allocated, uninitialized instance of struct
+ *            lib_rttoutstream_s to be initialized.
+ *   channel - SEGGER RTT channel number
+ *
+ * Returned Value:
+ *   None (User allocated instance initialized).
+ *
+ ****************************************************************************/
+
+void lib_rttoutstream(FAR struct lib_rttoutstream_s *stream, int channel,
+                      size_t bufsize)
+{
+  char name[8] = {0};
+  FAR char *upbuf = (FAR char *)kmm_malloc(bufsize);
+  DEBUGASSERT(upbuf);
+
+  sprintf(name, "rtt%d", channel);
+  SEGGER_RTT_ConfigUpBuffer(channel, name, upbuf,
+                            bufsize, SEGGER_RTT_MODE_NO_BLOCK_SKIP);
+
+  DEBUGASSERT(stream != NULL);
+  stream->public.put = rttstream_putc;
+  stream->public.puts = rttstream_puts;
+  stream->public.flush = lib_noflush;
+  stream->public.nput = 0;
+  stream->channel = channel;
+}
+
+/****************************************************************************
+ * Name: lib_rttinstream
+ *
+ * Description:
+ *   Initializes output stream for use with the configured RTT interface.
+ *
+ * Input Parameters:
+ *   stream - User allocated, uninitialized instance of struct
+ *            lib_rttinstream_s to be initialized.
+ *   channel - SEGGER RTT channel number
+ *
+ ****************************************************************************/
+
+void lib_rttinstream(FAR struct lib_rttinstream_s *stream, int channel,

Review Comment:
   ```suggestion
   void lib_rttinstream(FAR struct lib_rttoutstream_s *stream,
                        int channel, size_t bufsize)
   ```



##########
drivers/segger/rtt_stream.c:
##########
@@ -0,0 +1,126 @@
+/****************************************************************************
+ * drivers/segger/rtt_stream.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <assert.h>
+
+#include <nuttx/config.h>
+#include <nuttx/kmalloc.h>
+#include <nuttx/streams.h>
+#include <nuttx/segger/rtt.h>
+
+#include <SEGGER_RTT.h>
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: rttstream_putc
+ ****************************************************************************/
+
+static void rttstream_putc(FAR struct lib_outstream_s *this, int ch)
+{
+  FAR struct lib_rttoutstream_s *stream = this;

Review Comment:
   not change? please compile the code locally and ensure no error and warning



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to