Skip to content

Commit 01ee625

Browse files
committed
added examples; tesing qflash bit; general test for psram
1 parent 35d2271 commit 01ee625

File tree

4 files changed

+134
-0
lines changed

4 files changed

+134
-0
lines changed

examples/has_psram/CMakeLists.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
cmake_minimum_required(VERSION 3.13)
2+
3+
include($ENV{PICO_SDK_PATH}/external/pico_sdk_import.cmake)
4+
5+
project(has_psram C CXX ASM)
6+
set(CMAKE_C_STANDARD 11)
7+
set(CMAKE_CXX_STANDARD 17)
8+
pico_sdk_init()
9+
10+
add_executable(has_psram has_psram.c)
11+
12+
# To run example, copy over the sparkfun_pico folder
13+
add_subdirectory(sparkfun_pico)
14+
15+
pico_enable_stdio_usb(has_psram 1)
16+
pico_enable_stdio_uart(has_psram 1)
17+
18+
# pull in common dependencies and additional spi hardware support
19+
target_link_libraries(has_psram pico_stdlib sparkfun_pico)
20+
21+
# create map/bin/hex file etc.
22+
pico_add_extra_outputs(has_psram)

examples/has_psram/has_psram.c

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
/**
2+
3+
*/
4+
5+
// include the sparkfun_pico library - copy this into this folder to run
6+
#include "pico/stdlib.h"
7+
#include "sparkfun_pico/sfe_pico_boards.h"
8+
#include "sparkfun_pico/sfe_psram.h"
9+
10+
#include <math.h>
11+
#include <stdio.h>
12+
#include <stdlib.h>
13+
#include <string.h>
14+
15+
// Defines for the test. Note the PSRAM location is from the datasheet
16+
#define PSRAM_LOCATION _u(0x11000000)
17+
#define DATA_ELEMENTS 4096
18+
#define DATA_BLOCK_SIZE (DATA_ELEMENTS * sizeof(int32_t))
19+
20+
static void erase_data_block(int32_t *data_buffer)
21+
{
22+
for (size_t i = 0; i < DATA_ELEMENTS; i++)
23+
data_buffer[i] = 0xFFFFFFFF;
24+
}
25+
static void write_data_block(int32_t *source_data, int32_t *data_buffer, int32_t offset)
26+
{
27+
for (size_t i = 0; i < DATA_ELEMENTS; i++)
28+
data_buffer[i] = source_data[i] + offset;
29+
}
30+
31+
static bool check_data_block(int32_t *source_data, int32_t *data_buffer, int32_t offset)
32+
{
33+
for (size_t i = 0; i < DATA_ELEMENTS; i++)
34+
{
35+
if (source_data[i] + offset != data_buffer[i])
36+
{
37+
printf("ERROR : [%d] != [%d]\n", source_data[i] + offset, data_buffer[i]);
38+
return false;
39+
}
40+
}
41+
return true;
42+
}
43+
int main()
44+
{
45+
stdio_init_all();
46+
47+
// wait a little bit - for startup
48+
sleep_ms(2000);
49+
printf("\n-----------------------------------------------------------\n");
50+
printf("SparkFun - Basic PSRAM Test - starting\n");
51+
sleep_ms(2000);
52+
53+
size_t psram_size = sfe_setup_psram(SFE_RP2350_XIP_CSI_PIN);
54+
55+
printf("PSRAM setup complete. PSRAM size 0x%lX\n", psram_size);
56+
57+
if (psram_size == 0)
58+
{
59+
printf("PSRAM not detected - done\n");
60+
return 1;
61+
}
62+
63+
printf("Generating Random Data\n");
64+
// cook up some random data
65+
int32_t *random_data = (int32_t *)malloc(DATA_BLOCK_SIZE);
66+
if (!random_data)
67+
{
68+
printf("Random data allocation failed\n");
69+
return 1;
70+
}
71+
for (int i = 0; i < DATA_ELEMENTS; i++)
72+
random_data[i] = rand();
73+
74+
// How many data blocks to write - use all of PSRAM
75+
size_t nDataBlocks = psram_size / DATA_BLOCK_SIZE;
76+
printf("PSRAM data block testing - n data blocks: %d\n", nDataBlocks);
77+
78+
// Write data blocks to PSRAM - then read them back and check
79+
for (int i = 0; i < nDataBlocks; i++)
80+
{
81+
int32_t *data_buffer = (int32_t *)(PSRAM_LOCATION + i * DATA_BLOCK_SIZE);
82+
erase_data_block(data_buffer);
83+
write_data_block(random_data, data_buffer, i * 0x2);
84+
}
85+
printf("Data blocks written\n");
86+
int nPassed = 0;
87+
88+
for (size_t i = 0; i < nDataBlocks; i++)
89+
{
90+
if (i % 10 == 0)
91+
{
92+
printf(".");
93+
stdio_flush();
94+
}
95+
int32_t *data_buffer = (int32_t *)(PSRAM_LOCATION + i * DATA_BLOCK_SIZE);
96+
if (!check_data_block(random_data, data_buffer, i * 0x2))
97+
printf("Data block %d failed\n", (int)i);
98+
else
99+
nPassed++;
100+
}
101+
102+
free(random_data);
103+
104+
printf("\n\nTest Run: %d, Passed: %d, Failed: %d\n", nDataBlocks, nPassed, nDataBlocks - nPassed);
105+
106+
printf("DONE\n");
107+
printf("-----------------------------------------------------------\n");
108+
while (1)
109+
{
110+
sleep_ms(1000);
111+
}
112+
}
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)