PSRAM

[中文]

1 Functional Overview

Note

On BK7258, PSRAM is enabled by default on the CP side, no additional enablement is required on the AP side.

2 Code Paths

  • Demo path:
    components\bk_cli\cli_psram.c
  • Driver source path:
    middleware\driver\psram\psram_driver.c

Note

  • psram_driver.c: PSRAM driver implementation

  • cli_psram.c: PSRAM test command implementation

3 Main PSRAM APIs

Initialization and Configuration

bk_err_t bk_psram_init(void);
bk_err_t bk_psram_deinit(void);
bk_err_t bk_psram_id_auto_detect(void);
bk_err_t bk_psram_set_clk(psram_clk_t clk);
bk_err_t bk_psram_set_voltage(psram_voltage_t voltage);

Description: - Initialize and deinitialize PSRAM hardware resources. - Configure operating frequency (80M/120M/160M) and supply voltage (e.g. 1.8V). - Auto-detect chip ID for boot-time adaptation.

Data Read/Write Interfaces

bk_err_t bk_psram_memcpy(uint8_t *dst, uint8_t *src, uint32_t len);
bk_err_t bk_psram_memread(uint8_t *src, uint8_t *dst, uint32_t len);

Description: Block memory read/write operations with higher performance than DTCM, suitable for audio/video buffering.

Low-Level Read/Write (Byte/Half-word/Word)

void bk_psram_byte_write(uint8_t *addr, uint8_t val);
void bk_psram_half_word_write(uint16_t *addr, uint16_t val);
void bk_psram_word_write(uint32_t *addr, uint32_t val);
void bk_psram_word_memcpy(void *dst, void *src, uint32_t len);

Description: Supports unaligned writes, with internal handling for address alignment and masking.

String Operations

char *bk_psram_strcat(char *start_addr, const char *data_buf);

Description: Similar to strcat, appends a string to PSRAM.

Heap Initialization Flag

bool bk_psram_heap_init_flag_get(void);
bk_err_t bk_psram_heap_init_flag_set(bool init);

Description: Indicates whether PSRAM heap is initialized; useful for dynamic memory allocation management.

Write-Through Area Management

psram_write_through_area_t bk_psram_alloc_write_through_channel(void);
bk_err_t bk_psram_free_write_through_channel(psram_write_through_area_t area);
bk_err_t bk_psram_enable_write_through(psram_write_through_area_t area, uint32_t start, uint32_t end);
bk_err_t bk_psram_disable_write_through(psram_write_through_area_t area);

Description: - Write-through areas are suitable for DMA2D high-performance reads/writes, bypassing cache. - Region addresses must be 32-byte aligned; data must be written in multiples of 32 bytes. - Each region can only be accessed by one master device.

4 CLI Command Overview

Demo macro configuration dependencies:

NAME

Description

File

Value

CONFIG_PSRAM

Enable PSRAM

middleware\soc\bk7236\bk7236.defconfig

y

CONFIG_PSRAM_TEST

Enable PSRAM test command

middleware\soc\bk7236\bk7236.defconfig

y

Supported CLI Commands:

Command

Param

Description

psram_test start

cpu

cacheable: 0/1 delay_time: N

Test the read/write function of PSRAM. Options: Enable or disable cache. Number of loop delays. Cache base = 0x64000000

psram_test stop

none

Stop PSRAM test

psram_task_create

none

Create a task using PSRAM memory

psram_test start

dma cacheable: 0/1 delay_time: N

Use DMA for copy instead of CPU Enable or disable cache Number of loop delays