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

WIP: add psram support #2

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft

Conversation

jakezhu9
Copy link
Member

Background

To run more complex applications like the Linux kernel, we need more memory. Therefore, we plan to support PSRAM (Pseudo-Static Random Access Memory).

Progress

By analyzing the code in bouffalo_sdk, we have a basic understanding of the PSRAM initialization process and ported it to Rust, completing the psram-demo. This program initializes PSRAM by directly reading and writing memory, runs a simple test and outputs the result through the serial port. We flashed it into the sipeed M1s DOCK board, and it ran successfully. However, the program has some issues, including a 0.3%~1% error rate in memory read/write operations and unexpected read/write latency (likely due to clock configuration). We will continue to improve it.

f64a5ab5918074cb92a559eacd9abc04

TODO

  • fix memory read/write error rate
  • optimize read/write latency
  • organize the code as a support library, avoid hard-coded memory read/write operations

@jakezhu9
Copy link
Member Author

Progress Update (10.13)

To address the memory read and write error rate, we tried adjusting various registers, but this didn't lead to significant improvements. We then analyzed the bouffalo_sdk code. However, its complexity and size made it difficult to pinpoint the issue, especially since some initialization code is scattered across different files.

We decided to take a new approach: register comparison. With support from the chip and development board's JTAG function, we used T-Head Debug Server and GDB to directly read the chip's register values and compare them with the original firmware that has been correctly initialized.

d138e4a15a95776f5f675f496cdb391c

From our analysis, we identified that the PSRAM-related registers are mainly located in a 4KB memory range starting at 0x20000000, 0x3000F000, and 0x2000E000. We dumped this memory using GDB and the commands like dump memory memory_dump_0x20000000.bin 0x20000000 0x20000FFF

When comparing the two memory dumps, we noticed some register values were different:

96d54c51fd8c9c08d1c9e699b7fe88b1

Since investigating each specific register value would be very time-consuming, we chose to generate the necessary write code directly based on the file comparison:

dca416de895b5dffd6c9e8f0e78275f0

However, when we implemented this code, the program encountered a blockage at certain points. It seemed that modifying some specific register values might be the cause. To troubleshoot, we added output statements after each memory write, which helped us isolate the problem. We discovered that addresses 0x3000F130 and 0x3000F134 were causing the issues, but we couldn't find relevant instructions in the official manual to clarify their functions. Therefore, we decided to exclude writing to these locations for now.

After persistent efforts, we finally achieved stable read and write operations for 64MB of PSRAM!

78a21e71eeda65c38a03ec2865c26d7f

Next Steps

  • optimize read/write latency
  • Analyze and confirm the function of certain memory areas
  • Organize the code into a support library to avoid hard-coded memory operations

Copy link
Member

@luojia65 luojia65 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great thanks! It's a huge and nice work.

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.

2 participants