Skip to content

examples/psram: BK7258 PSRAM test/heap/memalign commands - #116

Open
yz471686525-eng wants to merge 4 commits into
open-vela:dev-ai-contest-2026from
yz471686525-eng:bk7258-psram
Open

examples/psram: BK7258 PSRAM test/heap/memalign commands#116
yz471686525-eng wants to merge 4 commits into
open-vela:dev-ai-contest-2026from
yz471686525-eng:bk7258-psram

Conversation

@yz471686525-eng

Copy link
Copy Markdown

NSH command used to bring up PSRAM on the BK7258 DevKit:
id / probe / test / alias / width / heap / alloc / align / fbtest / freeall.

Timing uses clock_gettime(CLOCK_MONOTONIC) and prints the measured interval
next to the throughput, so a broken time base cannot masquerade as slow
memory -- which is exactly what happened here before the SysTick fix in the
matching nuttx PR.

Alignment arguments are validated (non-zero power of two) because the mod
checks would otherwise divide by zero.

Add NSH builtin app for PSRAM testing:
- psram id: show chip ID and size
- psram probe: init + single-word data path test
- psram test [N]: address-in-address test (default 1MB)
- psram alias: detect address aliasing
- psram width: test 8/16/32-bit access widths

Depends on CONFIG_BK7258_PSRAM.

Signed-off-by: Zhang Yan <zhangyan68@xiaomi.com>
- psram heap: show PSRAM heap status (arena/used/free/largest)
- psram alloc <KB>: allocate from PSRAM heap, verify
  address in 0x60xxxxxx, quick read/write check
- psram freeall: release all alloc'd blocks
- Prove malloc() still returns SRAM after PSRAM alloc

Signed-off-by: Zhang Yan <zhangyan68@xiaomi.com>
- psram align <A> <KB>: memalign allocation with alignment
  verification (mod check printed)
- psram fbtest: camera framebuffer validation — alloc 614KB at
  32 and 64 byte alignment, read/write pattern test, report
  KB/s bandwidth, verify all freed
- Both commands prove malloc() still returns SRAM

Signed-off-by: Zhang Yan <zhangyan68@xiaomi.com>
Three fixes to the S4 commands, all found by actually building and
running them:

1. clock_systime_ticks() was called without a prototype (implicit int
   declaration) and is documented as an OS-internal interface that
   applications should not use.  A raw tick delta also bakes in
   CONFIG_USEC_PER_TICK (10 ms here), which is far too coarse for these
   measurements.  Use clock_gettime(CLOCK_MONOTONIC) and compute
   microseconds, and print the measured interval next to the throughput
   so a broken clock can no longer masquerade as slow memory.

2. "psram align <A> <KB>" computed (uintptr_t)ptr % A before checking A,
   so A=0 divided by zero.  Validate that the alignment is a non-zero
   power of two and that the size is non-zero.

3. Silence -Wshadow on the per-branch "int ret" declarations and print
   the chip ID with a matching format specifier (uint32_t is
   unsigned long on this ABI).

Measured on BK7258 DevKit after the SysTick fix:
  psram test 16  -> 11619.8 / 8668.7 KB/s (wr/rd), 16 MB, 0 errors
  psram fbtest   -> 4093.3 / 3611.7 KB/s (wr/rd) for byte-wide access
@yz471686525-eng
yz471686525-eng requested review from a team as code owners August 14, 2026 13:34
@yz471686525-eng yz471686525-eng changed the title NSH command used to bring up PSRAM on the BK7258 DevKit: id / probe / test / alias / width / heap / alloc / align / fbtest / freeall. Timing uses clock_gettime(CLOCK_MONOTONIC) and prints the measured interval next to the throughput, so a broken time base cannot masquerade as slow memory -- which is exactly what happened here before the SysTick fix in the matching nuttx PR. Alignment arguments are validated (non-zero power of two) because the mod checks would otherwise divide by zero. examples/psram: BK7258 PSRAM test/heap/memalign commands Aug 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant