You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by GitBox <gi...@apache.org> on 2022/11/24 09:02:11 UTC

[GitHub] [incubator-nuttx] Gary-Hobson opened a new pull request, #7678: drivers/segger: Add Segger RTT stream support

Gary-Hobson opened a new pull request, #7678:
URL: https://github.com/apache/incubator-nuttx/pull/7678

   ## Summary
   Read and write Segger RTT data through the stream interface
   
   ## Impact
   
   ## Testing
   
   


-- 
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-unsubscribe@nuttx.apache.org

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


[GitHub] [nuttx] xiaoxiang781216 commented on a diff in pull request #7678: drivers/segger: Add Segger RTT stream support

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #7678:
URL: https://github.com/apache/nuttx/pull/7678#discussion_r1032546737


##########
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;
+  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)
+{
+  int ret;
+  FAR struct lib_rttoutstream_s *stream = this;
+  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 = this;
+
+  DEBUGASSERT(stream);
+  stream->public.nget++;
+  SEGGER_RTT_Read(stream->channel, &ch, 1);
+  return ch;
+}
+
+/****************************************************************************
+ * 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)
+{
+  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:
   need call SEGGER_RTT_AllocDownBuffer when channel isn't equal zero



##########
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;
+  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)
+{
+  int ret;
+  FAR struct lib_rttoutstream_s *stream = this;
+  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 = this;
+
+  DEBUGASSERT(stream);
+  stream->public.nget++;
+  SEGGER_RTT_Read(stream->channel, &ch, 1);
+  return ch;
+}
+
+/****************************************************************************
+ * 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)
+{
+  DEBUGASSERT(stream != NULL);

Review Comment:
   need call SEGGER_RTT_AllocUpBuffer when channel isn't equal zero



##########
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;
+  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)
+{
+  int ret;
+  FAR struct lib_rttoutstream_s *stream = this;
+  ret = SEGGER_RTT_Write(stream->channel, buf, len);

Review Comment:
   merge with the next line



##########
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;
+  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)
+{
+  int ret;
+  FAR struct lib_rttoutstream_s *stream = this;

Review Comment:
   need cast



##########
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:
   need cast



##########
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;
+  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)
+{
+  int ret;
+  FAR struct lib_rttoutstream_s *stream = this;
+  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 = this;
+
+  DEBUGASSERT(stream);
+  stream->public.nget++;
+  SEGGER_RTT_Read(stream->channel, &ch, 1);
+  return ch;
+}
+
+/****************************************************************************
+ * 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)
+{
+  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)
+{
+  DEBUGASSERT(stream != NULL);
+  stream->public.get = rttstream_getc;

Review Comment:
   let's implement gets too



-- 
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-unsubscribe@nuttx.apache.org

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


[GitHub] [nuttx] xiaoxiang781216 commented on a diff in pull request #7678: drivers/segger: Add Segger RTT stream support

Posted by GitBox <gi...@apache.org>.
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-unsubscribe@nuttx.apache.org

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


[GitHub] [nuttx] xiaoxiang781216 commented on a diff in pull request #7678: drivers/segger: Add Segger RTT stream support

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #7678:
URL: https://github.com/apache/nuttx/pull/7678#discussion_r1032878286


##########
drivers/segger/stream_rtt.c:
##########
@@ -0,0 +1,192 @@
+/****************************************************************************
+ * drivers/segger/stream_rtt.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 =
+                                 (FAR struct lib_rttoutstream_s *)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)
+{
+  FAR struct lib_rttinstream_s *stream =
+                                (FAR struct lib_rttinstream_s *)this;
+  int ch = -1;
+
+  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)
+{
+  FAR struct lib_rttinstream_s *stream =
+                                (FAR struct lib_rttinstream_s *)this;
+  int ret;
+
+  DEBUGASSERT(stream);
+  ret = SEGGER_RTT_Read(stream->channel, buffer, size);
+  stream->public.nget += ret;
+  return ret;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: lib_rttoutstream_open
+ *
+ * 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
+ *   bufsize - Size of the RTT buffer
+ *
+ * Returned Value:
+ *   None (User allocated instance initialized).
+ *
+ ****************************************************************************/
+
+void lib_rttoutstream_open(FAR struct lib_rttoutstream_s *stream,
+                           int channel, size_t bufsize)

Review Comment:
   or add below before line 122:
   bufsize = bufsize ? bufsize : SEGGER_BUFFER_SIZE_UP;



-- 
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-unsubscribe@nuttx.apache.org

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


[GitHub] [nuttx] anchao commented on pull request #7678: drivers/segger: Add Segger RTT stream support

Posted by GitBox <gi...@apache.org>.
anchao commented on PR #7678:
URL: https://github.com/apache/nuttx/pull/7678#issuecomment-1327884622

   >> @xiaoxiang781216 I recall you were doing a documentation about using Segger JLink System View with NuttX, do you have some news about it?
   
   > @anchao could you take a time:)?
   
   @acassis @xiaoxiang781216  Sure, let me prepare the relevant documents and provide them later


-- 
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-unsubscribe@nuttx.apache.org

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


[GitHub] [nuttx] xiaoxiang781216 commented on a diff in pull request #7678: drivers/segger: Add Segger RTT stream support

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #7678:
URL: https://github.com/apache/nuttx/pull/7678#discussion_r1032878323


##########
drivers/segger/stream_rtt.c:
##########
@@ -0,0 +1,192 @@
+/****************************************************************************
+ * drivers/segger/stream_rtt.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 =
+                                 (FAR struct lib_rttoutstream_s *)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)
+{
+  FAR struct lib_rttinstream_s *stream =
+                                (FAR struct lib_rttinstream_s *)this;
+  int ch = -1;
+
+  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)
+{
+  FAR struct lib_rttinstream_s *stream =
+                                (FAR struct lib_rttinstream_s *)this;
+  int ret;
+
+  DEBUGASSERT(stream);
+  ret = SEGGER_RTT_Read(stream->channel, buffer, size);
+  stream->public.nget += ret;
+  return ret;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: lib_rttoutstream_open
+ *
+ * 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
+ *   bufsize - Size of the RTT buffer
+ *
+ * Returned Value:
+ *   None (User allocated instance initialized).
+ *
+ ****************************************************************************/
+
+void lib_rttoutstream_open(FAR struct lib_rttoutstream_s *stream,
+                           int channel, size_t bufsize)
+{
+  if (channel)
+    {
+      stream->buffer = (FAR char *)kmm_malloc(bufsize);
+      DEBUGASSERT(stream->buffer);
+      sprintf(stream->name, "rtt%d", channel);
+      SEGGER_RTT_ConfigUpBuffer(channel, stream->name, stream->buffer,
+                            bufsize, SEGGER_RTT_MODE_DEFAULT);
+    }
+
+  stream->public.put = rttstream_putc;
+  stream->public.puts = rttstream_puts;
+  stream->public.flush = lib_noflush;
+  stream->public.nput = 0;
+  stream->channel = channel;
+}
+
+/****************************************************************************
+ * Name: lib_rttoutstream_close
+ ****************************************************************************/
+
+void lib_rttoutstream_close(FAR struct lib_rttoutstream_s *stream)
+{
+  kmm_free(stream->buffer);
+  SEGGER_RTT_ConfigUpBuffer(stream->channel, NULL, NULL,
+                            0, SEGGER_RTT_MODE_DEFAULT);
+}
+
+/****************************************************************************
+ * Name: lib_rttinstream
+ *
+ * Description:
+ *   Initializes input 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
+ *   bufsize - Size of the RTT input buffer
+ *
+ ****************************************************************************/
+
+void lib_rttinstream_open(FAR struct lib_rttinstream_s *stream,
+                          int channel, size_t bufsize)

Review Comment:
   or add below before line 169:
   bufsize = bufsize ? bufsize : SEGGER_BUFFER_SIZE_DOWN;



-- 
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-unsubscribe@nuttx.apache.org

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


[GitHub] [nuttx] xiaoxiang781216 commented on a diff in pull request #7678: drivers/segger: Add Segger RTT stream support

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #7678:
URL: https://github.com/apache/nuttx/pull/7678#discussion_r1032870655


##########
drivers/segger/stream_rtt.c:
##########
@@ -0,0 +1,192 @@
+/****************************************************************************
+ * drivers/segger/stream_rtt.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 =
+                                 (FAR struct lib_rttoutstream_s *)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)
+{
+  FAR struct lib_rttinstream_s *stream =
+                                (FAR struct lib_rttinstream_s *)this;
+  int ch = -1;
+
+  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)
+{
+  FAR struct lib_rttinstream_s *stream =
+                                (FAR struct lib_rttinstream_s *)this;
+  int ret;
+
+  DEBUGASSERT(stream);
+  ret = SEGGER_RTT_Read(stream->channel, buffer, size);
+  stream->public.nget += ret;
+  return ret;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: lib_rttoutstream_open
+ *
+ * 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
+ *   bufsize - Size of the RTT buffer
+ *
+ * Returned Value:
+ *   None (User allocated instance initialized).
+ *
+ ****************************************************************************/
+
+void lib_rttoutstream_open(FAR struct lib_rttoutstream_s *stream,
+                           int channel, size_t bufsize)
+{
+  if (channel)
+    {
+      stream->buffer = (FAR char *)kmm_malloc(bufsize);
+      DEBUGASSERT(stream->buffer);
+      sprintf(stream->name, "rtt%d", channel);
+      SEGGER_RTT_ConfigUpBuffer(channel, stream->name, stream->buffer,
+                            bufsize, SEGGER_RTT_MODE_DEFAULT);
+    }
+
+  stream->public.put = rttstream_putc;
+  stream->public.puts = rttstream_puts;
+  stream->public.flush = lib_noflush;
+  stream->public.nput = 0;
+  stream->channel = channel;
+}
+
+/****************************************************************************
+ * Name: lib_rttoutstream_close
+ ****************************************************************************/
+
+void lib_rttoutstream_close(FAR struct lib_rttoutstream_s *stream)
+{
+  kmm_free(stream->buffer);
+  SEGGER_RTT_ConfigUpBuffer(stream->channel, NULL, NULL,
+                            0, SEGGER_RTT_MODE_DEFAULT);
+}
+
+/****************************************************************************
+ * Name: lib_rttinstream
+ *
+ * Description:
+ *   Initializes input 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
+ *   bufsize - Size of the RTT input buffer
+ *
+ ****************************************************************************/
+
+void lib_rttinstream_open(FAR struct lib_rttinstream_s *stream,
+                          int channel, size_t bufsize)

Review Comment:
   should we use BUFFER_SIZE_DOWN?



-- 
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-unsubscribe@nuttx.apache.org

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


[GitHub] [nuttx] xiaoxiang781216 commented on pull request #7678: drivers/segger: Add Segger RTT stream support

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on PR #7678:
URL: https://github.com/apache/nuttx/pull/7678#issuecomment-1327500179

   > @xiaoxiang781216 I recall you were doing a documentation about using Segger JLink System View with NuttX, do you have some news about it?
   
   @anchao could you take a time:)?


-- 
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-unsubscribe@nuttx.apache.org

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


[GitHub] [nuttx] Gary-Hobson commented on pull request #7678: drivers/segger: Add Segger RTT stream support

Posted by GitBox <gi...@apache.org>.
Gary-Hobson commented on PR #7678:
URL: https://github.com/apache/nuttx/pull/7678#issuecomment-1328095141

   done~
   
   it feels so much better now
   


-- 
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-unsubscribe@nuttx.apache.org

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


[GitHub] [nuttx] xiaoxiang781216 commented on a diff in pull request #7678: drivers/segger: Add Segger RTT stream support

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #7678:
URL: https://github.com/apache/nuttx/pull/7678#discussion_r1032868682


##########
drivers/segger/stream_rtt.c:
##########
@@ -0,0 +1,192 @@
+/****************************************************************************
+ * drivers/segger/stream_rtt.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 =
+                                 (FAR struct lib_rttoutstream_s *)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)
+{
+  FAR struct lib_rttinstream_s *stream =
+                                (FAR struct lib_rttinstream_s *)this;
+  int ch = -1;
+
+  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)
+{
+  FAR struct lib_rttinstream_s *stream =
+                                (FAR struct lib_rttinstream_s *)this;
+  int ret;
+
+  DEBUGASSERT(stream);
+  ret = SEGGER_RTT_Read(stream->channel, buffer, size);
+  stream->public.nget += ret;
+  return ret;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: lib_rttoutstream_open
+ *
+ * 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
+ *   bufsize - Size of the RTT buffer
+ *
+ * Returned Value:
+ *   None (User allocated instance initialized).
+ *
+ ****************************************************************************/
+
+void lib_rttoutstream_open(FAR struct lib_rttoutstream_s *stream,
+                           int channel, size_t bufsize)
+{
+  if (channel)
+    {
+      stream->buffer = (FAR char *)kmm_malloc(bufsize);
+      DEBUGASSERT(stream->buffer);
+      sprintf(stream->name, "rtt%d", channel);
+      SEGGER_RTT_ConfigUpBuffer(channel, stream->name, stream->buffer,
+                            bufsize, SEGGER_RTT_MODE_DEFAULT);
+    }
+
+  stream->public.put = rttstream_putc;
+  stream->public.puts = rttstream_puts;
+  stream->public.flush = lib_noflush;
+  stream->public.nput = 0;
+  stream->channel = channel;
+}
+
+/****************************************************************************
+ * Name: lib_rttoutstream_close
+ ****************************************************************************/
+
+void lib_rttoutstream_close(FAR struct lib_rttoutstream_s *stream)
+{
+  kmm_free(stream->buffer);
+  SEGGER_RTT_ConfigUpBuffer(stream->channel, NULL, NULL,
+                            0, SEGGER_RTT_MODE_DEFAULT);
+}
+
+/****************************************************************************
+ * Name: lib_rttinstream
+ *
+ * Description:
+ *   Initializes input 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
+ *   bufsize - Size of the RTT input buffer
+ *
+ ****************************************************************************/
+
+void lib_rttinstream_open(FAR struct lib_rttinstream_s *stream,
+                          int channel, size_t bufsize)
+{
+  if (channel)
+    {
+      stream->buffer = (FAR char *)kmm_malloc(bufsize);
+      DEBUGASSERT(stream->buffer);
+      sprintf(stream->name, "rtt%d", channel);
+      SEGGER_RTT_ConfigDownBuffer(channel, stream->name, stream->buffer,
+                                  bufsize, SEGGER_RTT_MODE_DEFAULT);
+    }
+
+  stream->public.get = rttstream_getc;
+  stream->public.gets = rttstream_gets;
+  stream->public.nget = 0;
+  stream->channel = channel;
+}
+
+/****************************************************************************
+ * Name: lib_rttinstream_close
+ ****************************************************************************/
+
+void lib_rttinstream_close(FAR struct lib_rttinstream_s *stream)
+{
+  if (stream->channel)
+    {
+      kmm_free(stream->buffer);
+    }
+
+  SEGGER_RTT_ConfigDownBuffer(stream->channel, NULL, NULL,

Review Comment:
   move after line 187



##########
drivers/segger/stream_rtt.c:
##########
@@ -0,0 +1,192 @@
+/****************************************************************************
+ * drivers/segger/stream_rtt.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 =
+                                 (FAR struct lib_rttoutstream_s *)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)
+{
+  FAR struct lib_rttinstream_s *stream =
+                                (FAR struct lib_rttinstream_s *)this;
+  int ch = -1;
+
+  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)
+{
+  FAR struct lib_rttinstream_s *stream =
+                                (FAR struct lib_rttinstream_s *)this;
+  int ret;
+
+  DEBUGASSERT(stream);
+  ret = SEGGER_RTT_Read(stream->channel, buffer, size);
+  stream->public.nget += ret;
+  return ret;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: lib_rttoutstream_open
+ *
+ * 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
+ *   bufsize - Size of the RTT buffer
+ *
+ * Returned Value:
+ *   None (User allocated instance initialized).
+ *
+ ****************************************************************************/
+
+void lib_rttoutstream_open(FAR struct lib_rttoutstream_s *stream,
+                           int channel, size_t bufsize)
+{
+  if (channel)
+    {
+      stream->buffer = (FAR char *)kmm_malloc(bufsize);
+      DEBUGASSERT(stream->buffer);
+      sprintf(stream->name, "rtt%d", channel);
+      SEGGER_RTT_ConfigUpBuffer(channel, stream->name, stream->buffer,
+                            bufsize, SEGGER_RTT_MODE_DEFAULT);
+    }
+
+  stream->public.put = rttstream_putc;
+  stream->public.puts = rttstream_puts;
+  stream->public.flush = lib_noflush;
+  stream->public.nput = 0;
+  stream->channel = channel;
+}
+
+/****************************************************************************
+ * Name: lib_rttoutstream_close
+ ****************************************************************************/
+
+void lib_rttoutstream_close(FAR struct lib_rttoutstream_s *stream)
+{
+  kmm_free(stream->buffer);

Review Comment:
   ```suggestion
     if (stream->channel)
       {
         kmm_free(stream->buffer);
   ```



##########
drivers/segger/stream_rtt.c:
##########
@@ -0,0 +1,192 @@
+/****************************************************************************
+ * drivers/segger/stream_rtt.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 =
+                                 (FAR struct lib_rttoutstream_s *)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)
+{
+  FAR struct lib_rttinstream_s *stream =
+                                (FAR struct lib_rttinstream_s *)this;
+  int ch = -1;
+
+  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)
+{
+  FAR struct lib_rttinstream_s *stream =
+                                (FAR struct lib_rttinstream_s *)this;
+  int ret;
+
+  DEBUGASSERT(stream);
+  ret = SEGGER_RTT_Read(stream->channel, buffer, size);
+  stream->public.nget += ret;
+  return ret;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: lib_rttoutstream_open
+ *
+ * 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
+ *   bufsize - Size of the RTT buffer
+ *
+ * Returned Value:
+ *   None (User allocated instance initialized).
+ *
+ ****************************************************************************/
+
+void lib_rttoutstream_open(FAR struct lib_rttoutstream_s *stream,
+                           int channel, size_t bufsize)
+{
+  if (channel)
+    {
+      stream->buffer = (FAR char *)kmm_malloc(bufsize);
+      DEBUGASSERT(stream->buffer);
+      sprintf(stream->name, "rtt%d", channel);
+      SEGGER_RTT_ConfigUpBuffer(channel, stream->name, stream->buffer,
+                            bufsize, SEGGER_RTT_MODE_DEFAULT);

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



-- 
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-unsubscribe@nuttx.apache.org

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


[GitHub] [nuttx] xiaoxiang781216 merged pull request #7678: drivers/segger: Add Segger RTT stream support

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 merged PR #7678:
URL: https://github.com/apache/nuttx/pull/7678


-- 
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-unsubscribe@nuttx.apache.org

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


[GitHub] [incubator-nuttx] Gary-Hobson commented on a diff in pull request #7678: drivers/segger: Add Segger RTT stream support

Posted by GitBox <gi...@apache.org>.
Gary-Hobson commented on code in PR #7678:
URL: https://github.com/apache/incubator-nuttx/pull/7678#discussion_r1031320667


##########
drivers/segger/Kconfig:
##########
@@ -77,6 +79,50 @@ config SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL
 
 endchoice # SEGGER_RTT_MODE
 
+endif
+
+config RTT_CHANNEL1

Review Comment:
   done



-- 
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-unsubscribe@nuttx.apache.org

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


[GitHub] [incubator-nuttx] xiaoxiang781216 commented on a diff in pull request #7678: drivers/segger: Add Segger RTT stream support

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #7678:
URL: https://github.com/apache/incubator-nuttx/pull/7678#discussion_r1031492204


##########
include/nuttx/segger/rtt.h:
##########
@@ -0,0 +1,88 @@
+/****************************************************************************
+ * 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
+ ****************************************************************************/
+
+#ifdef CONFIG_SEGGER_RTT
+#define rtt_write(stream, buf, len) \

Review Comment:
   not move yet.



-- 
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-unsubscribe@nuttx.apache.org

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


[GitHub] [nuttx] acassis commented on pull request #7678: drivers/segger: Add Segger RTT stream support

Posted by GitBox <gi...@apache.org>.
acassis commented on PR #7678:
URL: https://github.com/apache/nuttx/pull/7678#issuecomment-1327391290

   @xiaoxiang781216 I recall you were doing a documentation about using Segger JLink System View with NuttX, do you have some news about it?


-- 
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-unsubscribe@nuttx.apache.org

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


[GitHub] [nuttx] xiaoxiang781216 commented on a diff in pull request #7678: drivers/segger: Add Segger RTT stream support

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #7678:
URL: https://github.com/apache/nuttx/pull/7678#discussion_r1032814848


##########
drivers/segger/rtt_stream.c:
##########
@@ -0,0 +1,203 @@
+/****************************************************************************
+ * 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 =
+                                 (FAR struct lib_rttoutstream_s *)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)
+{
+  FAR struct lib_rttinstream_s *stream =
+                                (FAR struct lib_rttinstream_s *)this;
+  int ch = -1;
+
+  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)
+{
+  FAR struct lib_rttinstream_s *stream =
+                                (FAR struct lib_rttinstream_s *)this;
+  int ret;
+
+  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
+ *   bufsize - Size of the RTT channel buffer
+ *
+ * Returned Value:
+ *   None (User allocated instance initialized).
+ *
+ ****************************************************************************/
+
+void lib_rttoutstream(FAR struct lib_rttoutstream_s *stream, int channel,
+                      size_t bufsize)
+{
+  FAR char *name = (FAR char *)kmm_malloc(32);
+  FAR char *upbuf = (FAR char *)kmm_malloc(bufsize);
+
+  DEBUGASSERT(upbuf);
+  DEBUGASSERT(name);
+  sprintf(name, "rtt%d", channel);
+  SEGGER_RTT_ConfigUpBuffer(channel, name, upbuf,
+                            bufsize, SEGGER_RTT_MODE_NO_BLOCK_SKIP);
+
+  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 input 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
+ *   bufsize - Size of the RTT channel buffer
+ *
+ ****************************************************************************/
+
+void lib_rttinstream(FAR struct lib_rttinstream_s *stream,
+                     int channel, size_t bufsize)
+{
+  FAR char *name = (FAR char *)kmm_malloc(32);
+  FAR char *downbuf = (FAR char *)kmm_malloc(bufsize);
+
+  DEBUGASSERT(downbuf);
+  DEBUGASSERT(name);
+  sprintf(name, "rtt%d", channel);
+  SEGGER_RTT_ConfigDownBuffer(channel, name, downbuf,
+                              bufsize, SEGGER_RTT_MODE_DEFAULT);
+
+  stream->public.get = rttstream_getc;
+  stream->public.gets = rttstream_gets;
+  stream->public.nget = 0;
+  stream->channel = channel;
+}
+
+/****************************************************************************
+ * Name: lib_rttoutstream_uninit
+ ****************************************************************************/
+
+void lib_rttoutstream_uninit(FAR struct lib_rttoutstream_s *stream,
+                             int channel)
+{
+  FAR SEGGER_RTT_CB *RTTCB;
+  FAR SEGGER_RTT_BUFFER_UP *UP;
+
+  RTTCB = (SEGGER_RTT_CB *)((unsigned char *)
+                             &_SEGGER_RTT + SEGGER_RTT_UNCACHED_OFF);
+  UP = &RTTCB->aUp[channel];
+  kmm_free((FAR void *)UP->sName);
+  kmm_free(UP->pBuffer);
+  SEGGER_RTT_ConfigUpBuffer(channel, NULL, NULL, 0, SEGGER_RTT_MODE_DEFAULT);
+}
+
+/****************************************************************************
+ * Name: lib_rttinstream_uninit
+ ****************************************************************************/
+
+void lib_rttinstream_uninit(FAR struct lib_rttinstream_s *stream,
+                            int channel)

Review Comment:
   ditto



##########
include/nuttx/segger/rtt.h:
##########
@@ -0,0 +1,96 @@
+/****************************************************************************
+ * 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_rttoutstream_uninit
+ ****************************************************************************/
+
+void lib_rttoutstream_uninit(FAR struct lib_rttoutstream_s *stream,

Review Comment:
   ```suggestion
   void lib_rttoutstream_close(FAR struct lib_rttoutstream_s *stream,
   ```



##########
drivers/segger/rtt_stream.c:
##########
@@ -0,0 +1,203 @@
+/****************************************************************************
+ * 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 =
+                                 (FAR struct lib_rttoutstream_s *)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)
+{
+  FAR struct lib_rttinstream_s *stream =
+                                (FAR struct lib_rttinstream_s *)this;
+  int ch = -1;
+
+  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)
+{
+  FAR struct lib_rttinstream_s *stream =
+                                (FAR struct lib_rttinstream_s *)this;
+  int ret;
+
+  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
+ *   bufsize - Size of the RTT channel buffer
+ *
+ * Returned Value:
+ *   None (User allocated instance initialized).
+ *
+ ****************************************************************************/
+
+void lib_rttoutstream(FAR struct lib_rttoutstream_s *stream, int channel,
+                      size_t bufsize)
+{
+  FAR char *name = (FAR char *)kmm_malloc(32);
+  FAR char *upbuf = (FAR char *)kmm_malloc(bufsize);
+
+  DEBUGASSERT(upbuf);
+  DEBUGASSERT(name);
+  sprintf(name, "rtt%d", channel);
+  SEGGER_RTT_ConfigUpBuffer(channel, name, upbuf,
+                            bufsize, SEGGER_RTT_MODE_NO_BLOCK_SKIP);
+
+  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 input 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
+ *   bufsize - Size of the RTT channel buffer
+ *
+ ****************************************************************************/
+
+void lib_rttinstream(FAR struct lib_rttinstream_s *stream,
+                     int channel, size_t bufsize)
+{
+  FAR char *name = (FAR char *)kmm_malloc(32);
+  FAR char *downbuf = (FAR char *)kmm_malloc(bufsize);

Review Comment:
   ditto



##########
drivers/segger/rtt_stream.c:
##########
@@ -0,0 +1,203 @@
+/****************************************************************************
+ * 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 =
+                                 (FAR struct lib_rttoutstream_s *)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)
+{
+  FAR struct lib_rttinstream_s *stream =
+                                (FAR struct lib_rttinstream_s *)this;
+  int ch = -1;
+
+  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)
+{
+  FAR struct lib_rttinstream_s *stream =
+                                (FAR struct lib_rttinstream_s *)this;
+  int ret;
+
+  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
+ *   bufsize - Size of the RTT channel buffer
+ *
+ * Returned Value:
+ *   None (User allocated instance initialized).
+ *
+ ****************************************************************************/
+
+void lib_rttoutstream(FAR struct lib_rttoutstream_s *stream, int channel,
+                      size_t bufsize)
+{
+  FAR char *name = (FAR char *)kmm_malloc(32);
+  FAR char *upbuf = (FAR char *)kmm_malloc(bufsize);
+
+  DEBUGASSERT(upbuf);
+  DEBUGASSERT(name);
+  sprintf(name, "rtt%d", channel);
+  SEGGER_RTT_ConfigUpBuffer(channel, name, upbuf,
+                            bufsize, SEGGER_RTT_MODE_NO_BLOCK_SKIP);
+
+  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 input 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
+ *   bufsize - Size of the RTT channel buffer
+ *
+ ****************************************************************************/
+
+void lib_rttinstream(FAR struct lib_rttinstream_s *stream,
+                     int channel, size_t bufsize)
+{
+  FAR char *name = (FAR char *)kmm_malloc(32);
+  FAR char *downbuf = (FAR char *)kmm_malloc(bufsize);
+
+  DEBUGASSERT(downbuf);
+  DEBUGASSERT(name);
+  sprintf(name, "rtt%d", channel);
+  SEGGER_RTT_ConfigDownBuffer(channel, name, downbuf,
+                              bufsize, SEGGER_RTT_MODE_DEFAULT);
+
+  stream->public.get = rttstream_getc;
+  stream->public.gets = rttstream_gets;
+  stream->public.nget = 0;
+  stream->channel = channel;
+}
+
+/****************************************************************************
+ * Name: lib_rttoutstream_uninit
+ ****************************************************************************/
+
+void lib_rttoutstream_uninit(FAR struct lib_rttoutstream_s *stream,
+                             int channel)

Review Comment:
   remove channel



##########
include/nuttx/segger/rtt.h:
##########
@@ -0,0 +1,96 @@
+/****************************************************************************
+ * 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_rttoutstream_uninit
+ ****************************************************************************/
+
+void lib_rttoutstream_uninit(FAR struct lib_rttoutstream_s *stream,
+                             int channel);
+
+#endif
+
+/****************************************************************************
+ * Name: lib_rttinstream_uninit
+ ****************************************************************************/
+
+void lib_rttinstream_uninit(FAR struct lib_rttinstream_s *stream,
+                            int channel);

Review Comment:
   remove



##########
drivers/segger/rtt_stream.c:
##########
@@ -0,0 +1,203 @@
+/****************************************************************************
+ * 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 =
+                                 (FAR struct lib_rttoutstream_s *)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)
+{
+  FAR struct lib_rttinstream_s *stream =
+                                (FAR struct lib_rttinstream_s *)this;
+  int ch = -1;
+
+  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)
+{
+  FAR struct lib_rttinstream_s *stream =
+                                (FAR struct lib_rttinstream_s *)this;
+  int ret;
+
+  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
+ *   bufsize - Size of the RTT channel buffer
+ *
+ * Returned Value:
+ *   None (User allocated instance initialized).
+ *
+ ****************************************************************************/
+
+void lib_rttoutstream(FAR struct lib_rttoutstream_s *stream, int channel,
+                      size_t bufsize)
+{
+  FAR char *name = (FAR char *)kmm_malloc(32);
+  FAR char *upbuf = (FAR char *)kmm_malloc(bufsize);

Review Comment:
   let's use the fix allocation as the suggestion



##########
include/nuttx/segger/rtt.h:
##########
@@ -0,0 +1,96 @@
+/****************************************************************************
+ * 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,

Review Comment:
   ```suggestion
   void lib_rttoutstream_open(FAR struct lib_rttoutstream_s *stream,
   ```



-- 
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-unsubscribe@nuttx.apache.org

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


[GitHub] [nuttx] xiaoxiang781216 commented on a diff in pull request #7678: drivers/segger: Add Segger RTT stream support

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #7678:
URL: https://github.com/apache/nuttx/pull/7678#discussion_r1032831794


##########
include/nuttx/segger/rtt.h:
##########
@@ -0,0 +1,94 @@
+/****************************************************************************
+ * 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;
+  char name[32];
+  char *buffer;
+  int channel;
+};
+
+struct lib_rttinstream_s
+{
+  struct lib_instream_s public;
+  char name[32];
+  char *buffer;
+  int channel;
+};
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+/****************************************************************************
+* Name: lib_rttoutstream_open
+*****************************************************************************/
+
+void lib_rttoutstream_open(FAR struct lib_rttoutstream_s *stream,
+                           int channel, size_t bufsize);
+
+/****************************************************************************
+* Name: lib_rttinstream_open
+*****************************************************************************/
+
+void lib_rttinstream_open(FAR struct lib_rttinstream_s *stream,
+                          int channel, size_t size);
+
+/****************************************************************************
+ * Name: lib_rttoutstream_close
+ ****************************************************************************/
+
+void lib_rttoutstream_close(FAR struct lib_rttoutstream_s *stream);

Review Comment:
   move before line 70



##########
include/nuttx/segger/rtt.h:
##########
@@ -0,0 +1,94 @@
+/****************************************************************************
+ * 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;
+  char name[32];
+  char *buffer;
+  int channel;
+};
+
+struct lib_rttinstream_s
+{
+  struct lib_instream_s public;
+  char name[32];
+  char *buffer;

Review Comment:
   add FAR



##########
drivers/segger/rtt_stream.c:
##########
@@ -0,0 +1,188 @@
+/****************************************************************************
+ * 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 =
+                                 (FAR struct lib_rttoutstream_s *)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)
+{
+  FAR struct lib_rttinstream_s *stream =
+                                (FAR struct lib_rttinstream_s *)this;
+  int ch = -1;
+
+  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)
+{
+  FAR struct lib_rttinstream_s *stream =
+                                (FAR struct lib_rttinstream_s *)this;
+  int ret;
+
+  DEBUGASSERT(stream);
+  ret = SEGGER_RTT_Read(stream->channel, buffer, size);
+  stream->public.nget += ret;
+  return ret;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: lib_rttoutstream_open
+ *
+ * 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
+ *   bufsize - Size of the RTT buffer
+ *
+ * Returned Value:
+ *   None (User allocated instance initialized).
+ *
+ ****************************************************************************/
+
+void lib_rttoutstream_open(FAR struct lib_rttoutstream_s *stream,
+                           int channel, size_t bufsize)
+{
+  if (channel)
+    {
+      stream->buffer = (FAR char *)kmm_malloc(bufsize);
+      DEBUGASSERT(stream->buffer);
+      sprintf(stream->name, "rtt%d", channel);
+      SEGGER_RTT_ConfigUpBuffer(channel, stream->name, stream->buffer,
+                            bufsize, SEGGER_RTT_MODE_DEFAULT);
+    }
+
+  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 input 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
+ *   bufsize - Size of the RTT input buffer
+ *
+ ****************************************************************************/
+
+void lib_rttinstream_open(FAR struct lib_rttinstream_s *stream,
+                          int channel, size_t bufsize)
+{
+  if (channel)
+    {
+      stream->buffer = (FAR char *)kmm_malloc(bufsize);
+      DEBUGASSERT(stream->buffer);
+      sprintf(stream->name, "rtt%d", channel);
+      SEGGER_RTT_ConfigDownBuffer(channel, stream->name, stream->buffer,
+                                  bufsize, SEGGER_RTT_MODE_DEFAULT);
+    }
+
+  stream->public.get = rttstream_getc;
+  stream->public.gets = rttstream_gets;
+  stream->public.nget = 0;
+  stream->channel = channel;
+}
+
+/****************************************************************************
+ * Name: lib_rttoutstream_uninit
+ ****************************************************************************/
+
+void lib_rttoutstream_close(FAR struct lib_rttoutstream_s *stream)
+{
+  kmm_free(stream->buffer);
+  SEGGER_RTT_ConfigUpBuffer(stream->channel, NULL, NULL,
+                            0, SEGGER_RTT_MODE_DEFAULT);
+}
+
+/****************************************************************************
+ * Name: lib_rttinstream_uninit
+ ****************************************************************************/
+
+void lib_rttinstream_close(FAR struct lib_rttinstream_s *stream)
+{
+  kmm_free(stream->buffer);

Review Comment:
   check channel != 0



##########
drivers/segger/rtt_stream.c:
##########
@@ -0,0 +1,188 @@
+/****************************************************************************
+ * 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 =
+                                 (FAR struct lib_rttoutstream_s *)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)
+{
+  FAR struct lib_rttinstream_s *stream =
+                                (FAR struct lib_rttinstream_s *)this;
+  int ch = -1;
+
+  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)
+{
+  FAR struct lib_rttinstream_s *stream =
+                                (FAR struct lib_rttinstream_s *)this;
+  int ret;
+
+  DEBUGASSERT(stream);
+  ret = SEGGER_RTT_Read(stream->channel, buffer, size);
+  stream->public.nget += ret;
+  return ret;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: lib_rttoutstream_open
+ *
+ * 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
+ *   bufsize - Size of the RTT buffer
+ *
+ * Returned Value:
+ *   None (User allocated instance initialized).
+ *
+ ****************************************************************************/
+
+void lib_rttoutstream_open(FAR struct lib_rttoutstream_s *stream,
+                           int channel, size_t bufsize)
+{
+  if (channel)
+    {
+      stream->buffer = (FAR char *)kmm_malloc(bufsize);
+      DEBUGASSERT(stream->buffer);
+      sprintf(stream->name, "rtt%d", channel);
+      SEGGER_RTT_ConfigUpBuffer(channel, stream->name, stream->buffer,
+                            bufsize, SEGGER_RTT_MODE_DEFAULT);
+    }
+
+  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 input 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
+ *   bufsize - Size of the RTT input buffer
+ *
+ ****************************************************************************/
+
+void lib_rttinstream_open(FAR struct lib_rttinstream_s *stream,
+                          int channel, size_t bufsize)
+{
+  if (channel)
+    {
+      stream->buffer = (FAR char *)kmm_malloc(bufsize);
+      DEBUGASSERT(stream->buffer);
+      sprintf(stream->name, "rtt%d", channel);
+      SEGGER_RTT_ConfigDownBuffer(channel, stream->name, stream->buffer,
+                                  bufsize, SEGGER_RTT_MODE_DEFAULT);
+    }
+
+  stream->public.get = rttstream_getc;
+  stream->public.gets = rttstream_gets;
+  stream->public.nget = 0;
+  stream->channel = channel;
+}
+
+/****************************************************************************
+ * Name: lib_rttoutstream_uninit
+ ****************************************************************************/
+
+void lib_rttoutstream_close(FAR struct lib_rttoutstream_s *stream)
+{
+  kmm_free(stream->buffer);

Review Comment:
   add if ((stream->channel)



##########
include/nuttx/segger/rtt.h:
##########
@@ -0,0 +1,94 @@
+/****************************************************************************
+ * 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;
+  char name[32];
+  char *buffer;

Review Comment:
   add FAR



##########
drivers/segger/rtt_stream.c:
##########
@@ -0,0 +1,188 @@
+/****************************************************************************
+ * 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 =
+                                 (FAR struct lib_rttoutstream_s *)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)
+{
+  FAR struct lib_rttinstream_s *stream =
+                                (FAR struct lib_rttinstream_s *)this;
+  int ch = -1;
+
+  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)
+{
+  FAR struct lib_rttinstream_s *stream =
+                                (FAR struct lib_rttinstream_s *)this;
+  int ret;
+
+  DEBUGASSERT(stream);
+  ret = SEGGER_RTT_Read(stream->channel, buffer, size);
+  stream->public.nget += ret;
+  return ret;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: lib_rttoutstream_open
+ *
+ * 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
+ *   bufsize - Size of the RTT buffer
+ *
+ * Returned Value:
+ *   None (User allocated instance initialized).
+ *
+ ****************************************************************************/
+
+void lib_rttoutstream_open(FAR struct lib_rttoutstream_s *stream,
+                           int channel, size_t bufsize)
+{
+  if (channel)
+    {
+      stream->buffer = (FAR char *)kmm_malloc(bufsize);
+      DEBUGASSERT(stream->buffer);
+      sprintf(stream->name, "rtt%d", channel);
+      SEGGER_RTT_ConfigUpBuffer(channel, stream->name, stream->buffer,
+                            bufsize, SEGGER_RTT_MODE_DEFAULT);
+    }
+
+  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 input 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
+ *   bufsize - Size of the RTT input buffer
+ *
+ ****************************************************************************/
+
+void lib_rttinstream_open(FAR struct lib_rttinstream_s *stream,
+                          int channel, size_t bufsize)
+{
+  if (channel)
+    {
+      stream->buffer = (FAR char *)kmm_malloc(bufsize);
+      DEBUGASSERT(stream->buffer);
+      sprintf(stream->name, "rtt%d", channel);
+      SEGGER_RTT_ConfigDownBuffer(channel, stream->name, stream->buffer,
+                                  bufsize, SEGGER_RTT_MODE_DEFAULT);
+    }
+
+  stream->public.get = rttstream_getc;
+  stream->public.gets = rttstream_gets;
+  stream->public.nget = 0;
+  stream->channel = channel;
+}
+
+/****************************************************************************
+ * Name: lib_rttoutstream_uninit

Review Comment:
   ```suggestion
    * Name: lib_rttoutstream_close
   ```



##########
drivers/segger/rtt_stream.c:
##########
@@ -0,0 +1,188 @@
+/****************************************************************************
+ * 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 =
+                                 (FAR struct lib_rttoutstream_s *)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)
+{
+  FAR struct lib_rttinstream_s *stream =
+                                (FAR struct lib_rttinstream_s *)this;
+  int ch = -1;
+
+  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)
+{
+  FAR struct lib_rttinstream_s *stream =
+                                (FAR struct lib_rttinstream_s *)this;
+  int ret;
+
+  DEBUGASSERT(stream);
+  ret = SEGGER_RTT_Read(stream->channel, buffer, size);
+  stream->public.nget += ret;
+  return ret;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: lib_rttoutstream_open
+ *
+ * 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
+ *   bufsize - Size of the RTT buffer
+ *
+ * Returned Value:
+ *   None (User allocated instance initialized).
+ *
+ ****************************************************************************/
+
+void lib_rttoutstream_open(FAR struct lib_rttoutstream_s *stream,
+                           int channel, size_t bufsize)
+{
+  if (channel)
+    {
+      stream->buffer = (FAR char *)kmm_malloc(bufsize);
+      DEBUGASSERT(stream->buffer);
+      sprintf(stream->name, "rtt%d", channel);
+      SEGGER_RTT_ConfigUpBuffer(channel, stream->name, stream->buffer,
+                            bufsize, SEGGER_RTT_MODE_DEFAULT);
+    }
+
+  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 input 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
+ *   bufsize - Size of the RTT input buffer
+ *
+ ****************************************************************************/
+
+void lib_rttinstream_open(FAR struct lib_rttinstream_s *stream,
+                          int channel, size_t bufsize)
+{
+  if (channel)
+    {
+      stream->buffer = (FAR char *)kmm_malloc(bufsize);
+      DEBUGASSERT(stream->buffer);
+      sprintf(stream->name, "rtt%d", channel);
+      SEGGER_RTT_ConfigDownBuffer(channel, stream->name, stream->buffer,
+                                  bufsize, SEGGER_RTT_MODE_DEFAULT);
+    }
+
+  stream->public.get = rttstream_getc;
+  stream->public.gets = rttstream_gets;
+  stream->public.nget = 0;
+  stream->channel = channel;
+}
+
+/****************************************************************************
+ * Name: lib_rttoutstream_uninit
+ ****************************************************************************/
+
+void lib_rttoutstream_close(FAR struct lib_rttoutstream_s *stream)

Review Comment:
   move before line 136



##########
drivers/segger/Make.defs:
##########
@@ -54,6 +54,10 @@ TARGET_ZIP += $(SGDIR)/RTT.zip
 
 endif
 
+ifeq ($(CONFIG_SEGGER_RTT),y)
+  CSRCS += segger/rtt_stream.c

Review Comment:
   ```suggestion
     CSRCS += segger/stream_rtt.c
   ```



##########
drivers/segger/rtt_stream.c:
##########
@@ -0,0 +1,188 @@
+/****************************************************************************
+ * 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 =
+                                 (FAR struct lib_rttoutstream_s *)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)
+{
+  FAR struct lib_rttinstream_s *stream =
+                                (FAR struct lib_rttinstream_s *)this;
+  int ch = -1;
+
+  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)
+{
+  FAR struct lib_rttinstream_s *stream =
+                                (FAR struct lib_rttinstream_s *)this;
+  int ret;
+
+  DEBUGASSERT(stream);
+  ret = SEGGER_RTT_Read(stream->channel, buffer, size);
+  stream->public.nget += ret;
+  return ret;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: lib_rttoutstream_open
+ *
+ * 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
+ *   bufsize - Size of the RTT buffer
+ *
+ * Returned Value:
+ *   None (User allocated instance initialized).
+ *
+ ****************************************************************************/
+
+void lib_rttoutstream_open(FAR struct lib_rttoutstream_s *stream,
+                           int channel, size_t bufsize)
+{
+  if (channel)
+    {
+      stream->buffer = (FAR char *)kmm_malloc(bufsize);
+      DEBUGASSERT(stream->buffer);
+      sprintf(stream->name, "rtt%d", channel);
+      SEGGER_RTT_ConfigUpBuffer(channel, stream->name, stream->buffer,
+                            bufsize, SEGGER_RTT_MODE_DEFAULT);
+    }
+
+  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 input 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
+ *   bufsize - Size of the RTT input buffer
+ *
+ ****************************************************************************/
+
+void lib_rttinstream_open(FAR struct lib_rttinstream_s *stream,
+                          int channel, size_t bufsize)
+{
+  if (channel)
+    {
+      stream->buffer = (FAR char *)kmm_malloc(bufsize);
+      DEBUGASSERT(stream->buffer);
+      sprintf(stream->name, "rtt%d", channel);
+      SEGGER_RTT_ConfigDownBuffer(channel, stream->name, stream->buffer,
+                                  bufsize, SEGGER_RTT_MODE_DEFAULT);
+    }
+
+  stream->public.get = rttstream_getc;
+  stream->public.gets = rttstream_gets;
+  stream->public.nget = 0;
+  stream->channel = channel;
+}
+
+/****************************************************************************
+ * Name: lib_rttoutstream_uninit
+ ****************************************************************************/
+
+void lib_rttoutstream_close(FAR struct lib_rttoutstream_s *stream)
+{
+  kmm_free(stream->buffer);
+  SEGGER_RTT_ConfigUpBuffer(stream->channel, NULL, NULL,
+                            0, SEGGER_RTT_MODE_DEFAULT);
+}
+
+/****************************************************************************
+ * Name: lib_rttinstream_uninit

Review Comment:
   ```suggestion
    * Name: lib_rttinstream_close
   ```



-- 
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-unsubscribe@nuttx.apache.org

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


[GitHub] [incubator-nuttx] xiaoxiang781216 commented on a diff in pull request #7678: drivers/segger: Add Segger RTT stream support

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #7678:
URL: https://github.com/apache/incubator-nuttx/pull/7678#discussion_r1031494823


##########
include/nuttx/segger/rtt.h:
##########
@@ -0,0 +1,79 @@
+/****************************************************************************
+ * 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
+ ****************************************************************************/
+
+#ifdef CONFIG_SEGGER_RTT
+#define rtt_write(stream, buf, len) \
+        stream->output.puts((FAR struct lib_outstream_s *)stream, buf, len)
+#define rtt_putc(stream, ch) \
+        stream->output.putc(((FAR struct lib_outstream_s *))stream, ch)
+#define rtt_getc(stream) stream->input.getc()
+#else
+#define rtt_write(stream, buf, len)
+#define rtt_putc(stream, ch)
+#define rtt_getc(stream)
+#endif
+
+/****************************************************************************
+ * Type Declarations
+ ****************************************************************************/
+
+struct lib_rttstream_s

Review Comment:
   let's split to lib_rttoutstream_s and lib_rttinstream_s



-- 
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-unsubscribe@nuttx.apache.org

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


[GitHub] [incubator-nuttx] xiaoxiang781216 commented on a diff in pull request #7678: drivers/segger: Add Segger RTT stream support

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #7678:
URL: https://github.com/apache/incubator-nuttx/pull/7678#discussion_r1031228659


##########
include/nuttx/segger/rtt.h:
##########
@@ -0,0 +1,88 @@
+/****************************************************************************
+ * 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
+ ****************************************************************************/
+
+#ifdef CONFIG_SEGGER_RTT
+#define rtt_write(stream, buf, len) \
+        stream->output.puts((FAR struct lib_outstream_s *)stream, buf, len)
+#define rtt_putc(stream, ch) \
+        stream->output.putc(((FAR struct lib_outstream_s *))stream, ch)
+#define rtt_getc(stream) stream->input.getc()
+#else
+#define rtt_write(stream, buf, len)
+#define rtt_putc(stream, ch)
+#define rtt_getc(stream)
+#endif
+
+/****************************************************************************
+ * Type Declarations
+ ****************************************************************************/
+
+struct lib_rttstream_s
+{
+  struct lib_outstream_s output;
+  struct lib_instream_s input;
+  int channel;
+};
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+/****************************************************************************
+* Name: rtt_channel_initialize
+*****************************************************************************/
+
+#ifdef CONFIG_SEGGER_RTT
+void rtt_channel_initialize(int channel, FAR char *name, size_t upsize,

Review Comment:
   move to new patch



##########
include/nuttx/segger/rtt.h:
##########
@@ -0,0 +1,88 @@
+/****************************************************************************
+ * 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
+ ****************************************************************************/
+
+#ifdef CONFIG_SEGGER_RTT
+#define rtt_write(stream, buf, len) \

Review Comment:
   create a new patch for the general macro wrapper and move to nuttx/streams.h



##########
drivers/drivers_initialize.c:
##########
@@ -68,6 +69,16 @@ void drivers_initialize(void)
   devnull_register();   /* Standard /dev/null */
 #endif
 
+#if defined(CONFIG_RTT_CHANNEL1)

Review Comment:
   move to new patch



##########
drivers/segger/Kconfig:
##########
@@ -77,6 +79,50 @@ config SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL
 
 endchoice # SEGGER_RTT_MODE
 
+endif
+
+config RTT_CHANNEL1

Review Comment:
   move to new patch



-- 
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-unsubscribe@nuttx.apache.org

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


[GitHub] [nuttx] Gary-Hobson commented on pull request #7678: drivers/segger: Add Segger RTT stream support

Posted by GitBox <gi...@apache.org>.
Gary-Hobson commented on PR #7678:
URL: https://github.com/apache/nuttx/pull/7678#issuecomment-1328076571

   I have changed to initializing the RTT buffer in lib_rttoutstream, but I still feel like this is not a good design.
   
   This can cause some unnecessary troubles:
   When calling lib_rttinstream to initialize channel 0, it will cause an internal static buffer leak, which we cannot release or use
   
   We need to get some internal data structures of Segger RTT in the code, its style is not compatible with nuttx
   
   The initialization of the segger RTT channel is a very independent thing that only needs to be done once. There is no need to process it once in different codes, and there is no need for uninitialization


-- 
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-unsubscribe@nuttx.apache.org

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


[GitHub] [nuttx] xiaoxiang781216 commented on a diff in pull request #7678: drivers/segger: Add Segger RTT stream support

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #7678:
URL: https://github.com/apache/nuttx/pull/7678#discussion_r1032870628


##########
drivers/segger/stream_rtt.c:
##########
@@ -0,0 +1,192 @@
+/****************************************************************************
+ * drivers/segger/stream_rtt.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 =
+                                 (FAR struct lib_rttoutstream_s *)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)
+{
+  FAR struct lib_rttinstream_s *stream =
+                                (FAR struct lib_rttinstream_s *)this;
+  int ch = -1;
+
+  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)
+{
+  FAR struct lib_rttinstream_s *stream =
+                                (FAR struct lib_rttinstream_s *)this;
+  int ret;
+
+  DEBUGASSERT(stream);
+  ret = SEGGER_RTT_Read(stream->channel, buffer, size);
+  stream->public.nget += ret;
+  return ret;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: lib_rttoutstream_open
+ *
+ * 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
+ *   bufsize - Size of the RTT buffer
+ *
+ * Returned Value:
+ *   None (User allocated instance initialized).
+ *
+ ****************************************************************************/
+
+void lib_rttoutstream_open(FAR struct lib_rttoutstream_s *stream,
+                           int channel, size_t bufsize)

Review Comment:
   should we use SEGGER_BUFFER_SIZE_UP directly?



-- 
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-unsubscribe@nuttx.apache.org

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


[GitHub] [nuttx] xiaoxiang781216 commented on pull request #7678: drivers/segger: Add Segger RTT stream support

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on PR #7678:
URL: https://github.com/apache/nuttx/pull/7678#issuecomment-1328085547

   > I have changed to initializing the RTT buffer in lib_rttoutstream, but I still feel like this is not a good design.
   > 
   > This can cause some unnecessary troubles: When calling lib_rttinstream to initialize channel 0, it will cause an internal static buffer leak, which we cannot release or use
   > 
   
   Since channel 0 is initialized by RTT internally, you can just skip the stream initialization code for channel 0.
   
   > We need to get some internal data structures of Segger RTT in the code, its style is not compatible with nuttx
   > 
   
   you can simply save fields in lib_rttoutstream_s:
   ```
   struct lib_rttoutstream_s
   {
     struct lib_outstream_s public;
     char name[32];
     int channel;
     FAR void *buffer;
   };
   ```
   
   > The initialization of the segger RTT channel is a very independent thing that only needs to be done once. There is no need to process it once in different codes, and there is no need for uninitialization
   


-- 
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-unsubscribe@nuttx.apache.org

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


[GitHub] [nuttx] xiaoxiang781216 commented on pull request #7678: drivers/segger: Add Segger RTT stream support

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on PR #7678:
URL: https://github.com/apache/nuttx/pull/7678#issuecomment-1328212553

   @Gary-Hobson please rebase the patch to the latest master, ci broken is fixed by: https://github.com/apache/nuttx/pull/7706


-- 
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-unsubscribe@nuttx.apache.org

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


[GitHub] [incubator-nuttx] xiaoxiang781216 commented on a diff in pull request #7678: drivers/segger: Add Segger RTT stream support

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #7678:
URL: https://github.com/apache/incubator-nuttx/pull/7678#discussion_r1031493117


##########
drivers/segger/Make.defs:
##########
@@ -23,6 +23,7 @@ SGDIR      = segger
 
 ifeq ($(CONFIG_SEGGER_RTT),y)
   CSRCS += segger/RTT/RTT/SEGGER_RTT.c
+  CSRCS += segger/rtt_stream.c

Review Comment:
   should we use stream_rtt.c like syslog_rtt.c?



-- 
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-unsubscribe@nuttx.apache.org

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