liamhays / rk3566-mcu

Reverse engineering, notes, and example code for the RISC-V MCU inside the RK3566 SoC
GNU General Public License v3.0
19 stars 4 forks source link

SRAM for MCU #2

Closed luyi1888 closed 6 months ago

luyi1888 commented 6 months ago

Hi, How do you get to know the whole SRAM(64KB) can be used for MCU? I have do some experiments on RV1106. Rockchip only used last 4KB in SRAM for MCU FW. They will load FW to DDR Memory if FW is large. The MCU in RV1106 can execute from DDR Memory. The RV1106 have 256KB SRAM. I want MCU use SRAM only.

Also, If you want more info about MCU. Rockchip has release the AMP SDK. It contains HAL and RT-Thread. But not too many document inside. rk356x_amp_sdk_release_v1.2.3_20230515

luyi1888 commented 6 months ago

Do you have try to use UART for debug output? I saw you use mailbox for that. Is the MCU can't access peripherals?

liamhays commented 6 months ago

I know that the whole SRAM can be used for the MCU because if I clear SRAM from Linux, nothing breaks. However, be aware that I'm using the Plebian distribution, which contains no Rockchip BSP code. Issue #1 showed that the vendor kernel is doing something with the MCU (possibly related to the "PVTM" performance/temperature monitoring subsystem? I'm not sure).

From what I've found, the RK3566 MCU can't execute from DDR, but it can read data from DDR. I could be wrong, there might be other config registers that allow the MCU to execute from DDR.

It looks like the AMP SDK is intended for use on the main ARM cores of the chip, not the little RISC-V MCU. Either way, thanks for pointing me to it.

Finally, the MCU can definitely access peripherals, but a) I don't know what happens if the MCU tries to access a peripheral that Linux has already configured, like the UART, and b) using the mailbox requires less code and I'm kind of lazy :).

luyi1888 commented 6 months ago

Thank you. I will try to use SRAM.

The AMP SDK has RK3568 and RV1126 MCU code. But document only has provided RK3568 ARM setup. maybe it not usable for commercial. In hal_conf.h, they only enable UART driver for RK3568/RV1126 MCU. The RV1106 MCU has the most complete support. Also, Only RV1106 MCU has cache. I have tried to run dhrystone benchmark before. It is huge difference with/without cache enabled. I think it is the reason they have less use MCU in 3568/1126.

For UART It can share the same UART with linux. Actually I'm using the same UART with linux. Because I don't want to configure(115200 8N1) it again. Just call this function.

//This is UART2 on RV1106.
#define ROCKCHIP_UART_BASE 0xff4c0000
#define ROCKCHIP_UART_LSR 0xff4c0014

void rockchip_uart_putchar(char s)
{
    volatile char *out_ptr = (void*)ROCKCHIP_UART_BASE;
    volatile char *out_lsr = (void*)ROCKCHIP_UART_LSR;
    while(1)
    {
        if(*out_lsr & 0x40)
        {
            if(s == '\n')
                *out_ptr = '\r';
            else
                *out_ptr = s;

            break;
        }
    }
}