Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

spi_loopback test fails on MCUs with SRAM blocks smaller than 128KB #72792

Closed
ttmut opened this issue May 15, 2024 · 10 comments · Fixed by #72895
Closed

spi_loopback test fails on MCUs with SRAM blocks smaller than 128KB #72792

ttmut opened this issue May 15, 2024 · 10 comments · Fixed by #72895
Assignees
Labels
area: SPI SPI bus bug The issue is a bug, or the PR is fixing a bug priority: low Low impact/importance bug

Comments

@ttmut
Copy link
Contributor

ttmut commented May 15, 2024

Describe the bug
#69081 increases RAM usage by an extra ~100KB, causing .bss section overflows on devices with small memories. I have encountered this on an out-of-tree Arm Cortex M4 board however I expect similar results with other boards.

The PR adds below buffers that I suspect are the cause of overflows.

#define BUF3_SIZE 8192
...
static const char large_tx_data[BUF3_SIZE] = "Thequickbrownfoxjumpsoverthelazydog\0";
static __aligned(32) char large_buffer_tx[BUF3_SIZE] __used __NOCACHE;
static __aligned(32) char large_buffer_rx[BUF3_SIZE] __used __NOCACHE;
...
static uint8_t large_buffer_print_tx[BUF3_SIZE * 5 + 1];
static uint8_t large_buffer_print_rx[BUF3_SIZE * 5 + 1];

Expected behavior
Test should compile successfully.

Logs and console output

...
.../arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.bfd.exe: region `RAM' overflowed by 58432 bytes
collect2.exe: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
FATAL ERROR: command exited with status 1: 'C:\Program Files\CMake\bin\cmake.EXE' --build
...

Environment (please complete the following information):

  • OS: Windows
  • Toolchain: Zephyr SDK 0.16.3
@ttmut ttmut added the bug The issue is a bug, or the PR is fixing a bug label May 15, 2024
Copy link

Hi @ttmut! We appreciate you submitting your first issue for our open-source project. 🌟

Even though I'm a bot, I can assure you that the whole community is genuinely grateful for your time and effort. 🤖💙

@tbursztyka
Copy link
Collaborator

@krish2718 Can you look at it? (perhaps make the test optional via a dedicated option into tests/drivers/spi/spi_loopback/Kconfig )

@krish2718
Copy link
Collaborator

I can make BUF3 configurable and add a min_ram in twister for larger tests for 8192, so, that lower memory boards are skipped.

@erwango
Copy link
Member

erwango commented May 15, 2024

I think you should add a new test variant "long-transfer" that enable BUF3 testing using a dedicated Kconfig flag

@krish2718
Copy link
Collaborator

I think you should add a new test variant "long-transfer" that enable BUF3 testing using a dedicated Kconfig flag

Sure, but instead of conditional test at build time, if I can make BUF3 as default say 128 it would server as a 3rd test, and for those boards that have higher memory, we can run with 8192, this would still be a build time option, but the tests would be constant. WDYT?

@erwango
Copy link
Member

erwango commented May 16, 2024

ok, that should be fine too indeed

@krish2718
Copy link
Collaborator

Looking at the code, the buffer itself is only 8K, it's the buffers used printing the diff that take up too much memory, and for a large buffer it's not that useful, so, I guess we can just remove the display part for large buffer and it should run on all platforms? If there is a fundamental issue then small buffer's diff can be used for debugging.

@ttmut can you please share a build command or board name that reproduces the build overflow?

@ttmut
Copy link
Contributor Author

ttmut commented May 16, 2024

It's an out-of-tree board but you can check the resource usage summary to get an idea. I have not tested on another board.

west build -p -b board_desc .\tests\drivers\spi\spi_loopback

Below is the memory usage summary of another out-of-tree board that has enough RAM:

Memory region         Used Size  Region Size  %age Used
           FLASH:       49980 B         3 MB      1.59%
             RAM:      108096 B       128 KB     82.47%
        IDT_LIST:          0 GB        32 KB      0.00%

If I eliminate print buffers, RAM usage becomes ~26KB:

Memory region         Used Size  Region Size  %age Used
           FLASH:       49980 B         3 MB      1.59%
             RAM:       26432 B       128 KB     20.17%
        IDT_LIST:          0 GB        32 KB      0.00%

This would be enough to solve my case. However, if there are boards with less than ~26KB memory it could still be an issue. I am not sure if there are though.

@krish2718
Copy link
Collaborator

Well, let's start with that as its a simple fix, and even the last time CI had passed, and having extra 8K buffer for a test is reasonable. Will raise a PR, thanks.

@ttmut
Copy link
Contributor Author

ttmut commented May 16, 2024

Thanks for looking into this, @krish2718

krish2718 added a commit to krish2718/zephyr that referenced this issue May 16, 2024
Display diff of contents for large buffers is not quite helpful and
takes up huge RAM, and if a board has less RAM then this causes the test
module build failures.

So, disable display of diff and just log a failure, small buffer tests
can be used to debug such basic issues and large buffer tests can act as
a smoke test for debugging other issues. This saves about 80K of RAM.

Fixes zephyrproject-rtos#72792.

Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
@nashif nashif added the priority: low Low impact/importance bug label May 21, 2024
SebastianBoe pushed a commit to SebastianBoe/zephyr that referenced this issue May 22, 2024
Display diff of contents for large buffers is not quite helpful and
takes up huge RAM, and if a board has less RAM then this causes the test
module build failures.

So, disable display of diff and just log a failure, small buffer tests
can be used to debug such basic issues and large buffer tests can act as
a smoke test for debugging other issues. This saves about 80K of RAM.

Fixes zephyrproject-rtos#72792.

Upstream PR: zephyrproject-rtos#72895

Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
SebastianBoe pushed a commit to SebastianBoe/zephyr that referenced this issue May 23, 2024
Display diff of contents for large buffers is not quite helpful and
takes up huge RAM, and if a board has less RAM then this causes the test
module build failures.

So, disable display of diff and just log a failure, small buffer tests
can be used to debug such basic issues and large buffer tests can act as
a smoke test for debugging other issues. This saves about 80K of RAM.

Fixes zephyrproject-rtos#72792.

Upstream PR: zephyrproject-rtos#72895

Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
jori-nordic pushed a commit to jori-nordic/zephyr that referenced this issue May 29, 2024
Display diff of contents for large buffers is not quite helpful and
takes up huge RAM, and if a board has less RAM then this causes the test
module build failures.

So, disable display of diff and just log a failure, small buffer tests
can be used to debug such basic issues and large buffer tests can act as
a smoke test for debugging other issues. This saves about 80K of RAM.

Fixes zephyrproject-rtos#72792.

Upstream PR: zephyrproject-rtos#72895

Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: SPI SPI bus bug The issue is a bug, or the PR is fixing a bug priority: low Low impact/importance bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants