0

Weird Problem where Segger RTT breaks if using more than 8kB of RAM

edougal gravatar image

asked 2017-04-21 20:00:11 +0200

updated 2017-04-22 01:43:55 +0200

I started a new software project on the nRF52832 a couple of weeks ago. I've been using Segger RTT for a lot of debugging with no problem throughout the beginning of the process. I've recently hit an issue where the Segger RTT printf statements stop showing up when I use more than 8kB of RAM. I should have almost 49,000 bytes of RAM remaining, so I'm nowhere near close to running out of RAM.

I've gotten to the point where I can compile my code with or without a single global uint32_t variable and if that variable is included the Segger RTT stuff will not work properly (note that as far as I can tell, everything else appears to work properly).

I'm using the S132 Soft Device and am using GCC to compile the code.

Here are the code size results from compilation:

   text    data     bss  
  40860     176    7828

This uses 8004 Bytes of RAM, and that's when the Segger RTT breaks.

Here's the linker script that I'm using:

/* Linker script to configure memory regions. */

SEARCH_DIR(.)
GROUP(-lgcc -lc -lnosys)

MEMORY
{
  FLASH (rx) : ORIGIN = 0x1f000, LENGTH = 0x61000   /* 397312 Bytes */ 
  RAM (rwx) :  ORIGIN = 0x20002128, LENGTH = 0xded8 /* 57048 Bytes */ 
}

SECTIONS
{
  .fs_data :
  {
    PROVIDE(__start_fs_data = .);
    KEEP(*(.fs_data))
    PROVIDE(__stop_fs_data = .);
  } > RAM
} INSERT AFTER .data;

INCLUDE "nrf5x_common.ld"

EDIT: I realized it might be worth mentioning that I'm allocating 4608 Bytes of RAM via the SDK provided memory manager.

edit retag flag offensive close delete report spam

Comments

How does the RTT "break"? Can it be something related tot he RTT buffer size? I use this RTT buffer size configuration:

ifndef SEGGER_RTT_CONFIG_BUFFER_SIZE_UP

define SEGGER_RTT_CONFIG_BUFFER_SIZE_UP 1024

endif

What's your current RTT buffer size value?

Matt ( 2017-04-21 21:25:54 +0200 )editconvert to answer

RTT breaks by no longer printing out to the console. Here are the #defines I see in my SEGGER_RTT_Conf.h file:

#define SEGGER_RTT_MAX_NUM_UP_BUFFERS             (2)     // Max. number of up-buffers (T->H) available on this target    (Default: 2)
#define SEGGER_RTT_MAX_NUM_DOWN_BUFFERS           (2)     // Max. number of down-buffers (H->T) available on this target  (Default: 2)

#define BUFFER_SIZE_UP                            (1024)  // Size of the buffer for terminal output of target, up to host (Default: 1k)
#define BUFFER_SIZE_DOWN                          (16)    // Size of the buffer for terminal input to target from host (Usually keyboard input) (Default: 16)

#define SEGGER_RTT_PRINTF_BUFFER_SIZE             (64u)    // Size of buffer for RTT printf to bulk-send chars via RTT     (Default: 64)

#define SEGGER_RTT_MODE_DEFAULT                   SEGGER_RTT_MODE_NO_BLOCK_SKIP // Mode for pre-initialized terminal channel (buffer 0)
edougal ( 2017-04-21 21:41:23 +0200 )editconvert to answer

1 answer

Sort by » oldest newest most voted
1
Timur gravatar image

answered 2017-04-21 22:44:21 +0200

In the make file you can adjust the stack and the heap size:

ASMFLAGS += -D__STACK_SIZE=16392
ASMFLAGS += -D__HEAP_SIZE=16392

then in the SDK folder nRF5_SDK_11_0_0_89a8197\components\toolchain\gcc there is file called gcc_startup_nrf52.s. I am always just making sure that the heap and stack settings in there are the same as in the makefile. However, I am not sure about the correlation though.

If you do very very fancy printf things you might be running out of stack. Quiet unlikely since the default value is actually set to 8kb. Anyway still worth trying.

edit flag offensive delete publish link more

Comments

Making these changes did not seem to help. The previous values in the .S file were both 8192.

edougal ( 2017-04-22 01:36:34 +0200 )editconvert to answer
1

How about increasing the BUFFER_SIZE_UP to, say, 2048? Do you "print" a lot of data using RTT?

Matt ( 2017-04-22 01:48:12 +0200 )editconvert to answer

That actually worked, but I'm not quite sure why. I'm not printing a lot (just a version number, the BT advertising name, and then some data in a callback. Also, it was commenting or uncommenting other variables (unrelated to the Segger RTT) which caused it to stop working.

Either way it works now, so thank you very much for the suggestion!

edougal ( 2017-04-22 01:54:55 +0200 )editconvert to answer

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer. Do not ask a new question or reply to an answer here.

[hide preview]

Question Tools

1 follower

Stats

Asked: 2017-04-21 20:00:11 +0200

Seen: 51 times

Last updated: Apr 22