esp32: Add SPIRAM test application

Adds application to test SPIRAM

Signed-off-by: Shubham Kulkarni <shubham.kulkarni@espressif.com>
This commit is contained in:
Shubham Kulkarni 2020-12-21 18:44:41 +05:30 committed by Anas Nashif
commit 0719973436
5 changed files with 142 additions and 0 deletions

View file

@ -0,0 +1,8 @@
# SPDX-License-Identifier: Apache-2.0
cmake_minimum_required(VERSION 3.13.1)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(spiram_test)
target_sources(app PRIVATE src/main.c)

View file

@ -0,0 +1,36 @@
.. _spiram_test:
Espressif ESP32 SPIRAM test
###########################
Overview
********
This sample allocates memory from internal DRAM and SPIRAM by calling `k_malloc`, frees
allocated memory by calling `k_free` and checks if memory can be allocated again.
Capability of allocated memory is decided by ESP_HEAP_MIN_EXTRAM_THRESHOLD. If size is less than
ESP_HEAP_MIN_EXTRAM_THRESHOLD, memory is allocated from internal DRAM. If size is greater than
ESP_HEAP_MIN_EXTRAM_THRESHOLD, memory is allocated from SPIRAM.
Building and Running
********************
Make sure you have the ESP32_WROVER_KIT connected over USB port.
.. code-block:: console
west build -b esp32 samples/boards/esp32/spiram_test
west flash --esp-device /dev/ttyUSB0
Sample Output
=============
To check output of this sample, any serial console program can be used (i.e. on Linux minicom, putty, screen, etc)
This example uses ``picocom`` on the serial port ``/dev/ttyUS0``:
.. code-block:: console
mem test ok! 209
SPIRAM mem test pass
mem test ok! 194
Internal mem test pass

View file

@ -0,0 +1,5 @@
CONFIG_ESP_SPIRAM=y
CONFIG_ESP_HEAP_MIN_EXTRAM_THRESHOLD=2048
CONFIG_HEAP_MEM_POOL_SIZE=98304
CONFIG_ESP_HEAP_MEM_POOL_REGION_1_SIZE=100000
CONFIG_ESP_HEAP_SEARCH_ALL_REGIONS=n

View file

@ -0,0 +1,7 @@
sample:
description: Application to test memory allocation from SPIRAM
name: spiram_test
tests:
sample.board.esp32:
platform_allow: esp32
tags: esp32

View file

@ -0,0 +1,86 @@
/*
* Copyright (c) 2021 Espressif Systems (Shanghai) Co., Ltd.
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr.h>
#include <sys/printk.h>
#include <soc/soc_memory_layout.h>
static int check_allocated_memory(int *m1, size_t size)
{
int ret = 0;
if (size < CONFIG_ESP_HEAP_MIN_EXTRAM_THRESHOLD) {
if (!esp_ptr_internal(m1)) {
printk("Memory allocation is not within"
" specified bounds\n");
ret = -1;
}
} else {
if (!esp_ptr_external_ram(m1)) {
printk("Memory allocation is not within"
" specified bounds\n");
ret = -1;
}
}
return ret;
}
static int test_heap_caps(size_t size)
{
int *m1, *m2;
int cnt = 0, err = 0;
m2 = NULL;
/* Allocated as much as we can, and create linked list */
while ((m1 = k_malloc(size))) {
if (check_allocated_memory(m1, size) == -1) {
err = -1;
goto ret;
}
*(int **) m1 = m2;
m2 = m1;
cnt++;
}
/* Free all allocated memory */
while (m2) {
m1 = *(int **) m2;
k_free(m2);
m2 = m1;
}
/* Confirm that allocation can succeed now */
m1 = k_malloc(size);
if (check_allocated_memory(m1, size) == -1) {
err = -1;
goto ret;
}
if (!m1) {
err = -1;
} else {
k_free(m1);
printk("mem test ok! %d\n", cnt);
}
ret:
return err;
}
void main(void)
{
int err = test_heap_caps(10001);
if (err == -1) {
printk("SPIRAM mem test failed\n");
} else {
printk("SPIRAM mem test pass\n");
}
err = test_heap_caps(1001);
if (err == -1) {
printk("Internal mem test failed\n");
} else {
printk("Internal mem test pass\n");
}
}