K210 without KPU

I want to get extra AI 2M RAM. Is there any guid to disable KPU?

Or

I just keep do not call any KPU related API, so the AI address is available for using.

another processor?

The 2MB of AI SRAM at 0x80600000 can be used as normal RAM when the KPU is not used.
You can manage this area separately from the main memory (for example from FreeRTOS) or you can include it into the main memory management by modifying the linker script.
Some limitations exists when using this area, for example it can’t be used in DMA transfers.
No special KPU ‘disabling’ is necessary.

2 Likes

i will try. Thank you

When I try to access the AI ram, the processor hangs (or at least I do not receive anything over serial any more)

=> md.l 80000000
80000000: f1402573 84ae822a 0002f297 1c82b283    s%@.*...........
80000010: 30529073 30401073 57634289 42a11c52    s.R0s.@0.BcWR..B
80000020: 3042a073 031b52c1 035a2010 7133137d    s.B0.R... Z.}.3q
80000030: 850a0053 41a060ef 129381aa 013300e2    S....`.A......3.
80000040: f2974055 b2830002 490524e2 0862a92f    U@.......$.I/.b.
80000050: 00091e63 406060ef 1241bc23 0002f297    c....``@#.A.....
80000060: ff42b283 0310000f 0802a02f 0002f297    ..B...../.......
80000070: fe42b283 a32f4305 000f0862 1ce30230    ..B..C/.b...0...
80000080: 4305fe03 00431333 1801b383 0063e3b3    ...C3.C.......c.
80000090: 1871b023 0310000f 0802a02f 14091e63    #.q...../...c...
800000a0: 49e000ef 49c000ef 00000513 0002ff17    ...I...I........
800000b0: 154f3f03 892a9f02 8a3289ae 00e21293    .?O...*...2.....
800000c0: 40590133 0002f297 08c2b283 405a0fb3    3.Y@..........Z@
800000d0: 0b428663 fe178352 3e030002 0e330eae    c.B.R......>..3.
800000e0: 83b3405e bf0301c2 02a10002 01e33023    ^@..........#0..
800000f0: cae30321 f317fe72 33030002 f397f123    !...r......3#...
=> md.l 80600000
80600000: (hangs here with no further output)

This occurs whether or not I have the AI clock enabled or disabled, PLL1 enabled or disabled, or the AI reset enabled or disabled.

bump

has anyone managed to get the top 2M of ram to work?

If so, what clocks did you have enabled?

You can check my MicroPython for K210, it has an option for building with full 8 MB SRAM used (twotasks prebuilt firmware, built with MICROPY_K210_KPU_USED option not set).
You may explore the project to find more details about it…

Ok, so from here, you have PLL1 enabled, but not AI.

Ok, so I tried this exact setup, and got the same result

=> md.l 50440000
50440000: 00000000 0001c200 026ec7b0 00658560    ..........n.`.e.
50440010: 00458560 00000000 00000b0b 00000000    `.E.............
50440020: 0000f249 00000000 0000003f ccfffffb    I.......?.......
50440030: 00000000 00000000 00010000 03000000    ................
50440040: 00000000 00000000 00000000 00000000    ................
50440050: 00000000 00000100 00400000 0000000f    ..........@.....
50440060: 00000002 040c2040 00000005 00000000    ....@ ..........
50440070: 00000000 00000000 00000000 00000000    ................
50440080: 00000000 00000000 00000000 00000000    ................
50440090: 00000000 00000000 00000000 00000000    ................
504400a0: 00000000 00000000 00000000 00000000    ................
504400b0: 00000000 00000000 00000000 00000000    ................
504400c0: 00000000 00000000 00000000 00000000    ................
504400d0: 00000000 00000000 00000000 00000000    ................
504400e0: 00000000 00000000 00000000 00000000    ................
504400f0: 00000000 00000000 00000000 00000000    ................
=> md.l 80600000
80600000: (hangs here with no further output)

Here is my clock tree (there are some pseudo-clocks for dealing with “even” dividers).

 Rate               Usecnt      Name
------------------------------------------
 26000000             2        |-- osc
 780000000            1        |   |-- pll0
 390000000            1        |   |   `-- pll0_half
 390000000            4        |   |       |-- aclk
 390000000            1        |   |       |   |-- sram0
 390000000            1        |   |       |   |-- sram1
 195000000            0        |   |       |   |-- rom
 390000000            0        |   |       |   |-- dvp
 195000000            0        |   |       |   |-- apb0
 195000000            0        |   |       |   |   |-- gpio
 195000000            0        |   |       |   |   |-- uart1
 195000000            0        |   |       |   |   |-- uart2
 195000000            0        |   |       |   |   |-- uart3
 195000000            0        |   |       |   |   |-- fpioa
 195000000            0        |   |       |   |   `-- sha
 195000000            1        |   |       |   |-- apb1
 195000000            0        |   |       |   |   |-- aes
 195000000            0        |   |       |   |   `-- otp
 195000000            0        |   |       |   |-- apb2
 390000000            2        |   |       |   |-- cpu
 390000000            0        |   |       |   |-- dma
 390000000            0        |   |       |   `-- fft
 97500000             0        |   |       |-- spi3
 390000000            0        |   |       |-- timer0
 390000000            0        |   |       |-- timer1
 390000000            0        |   |       |-- timer2
 390000000            0        |   |       |-- spi0
 390000000            0        |   |       |-- spi1
 390000000            0        |   |       |-- spi2
 390000000            0        |   |       |-- i2c0
 390000000            0        |   |       |-- i2c1
 390000000            0        |   |       `-- i2c2
 299000000            1        |   |-- pll1
 0                    0        |   |   `-- ai
 0                    0        |   |-- pll2
 0                    0        |   |   `-- pll2_half
 0                    0        |   |       |-- i2s0
 0                    0        |   |       |-- i2s1
 0                    0        |   |       |-- i2s2
 0                    0        |   |       |-- i2s0_m
 0                    0        |   |       |-- i2s1_m
 0                    0        |   |       `-- i2s2_m
 13000000             0        |   |-- in0_half
 13000000             0        |   |   |-- wdt0
 13000000             0        |   |   `-- wdt1
 26000000             0        |   `-- rtc

Here is a simple example:

static void _test()
{
    uint8_t *buffer = (uint8_t *)0x80600000;

    memset(buffer, 0xa5, 512);

    printf("Fill the buffer...\n");
    for (int i=0; i<256; i++) {
        buffer[i] = i;
    }

    printf("Read the buffer:");
    for (int i=0; i<272; i++) {
        if ((i % 16) == 0) printf("\n%p:", buffer+i);
        printf(" %02X", buffer[i]);
    }

    printf("\n\nDone.");
}

The function was tested from within MicroPython binded to the function:

STATIC mp_obj_t mp_test()
{
    _test();

    return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_0(mp_test_obj, mp_test);

Result (function executed from within MicroPython):

>>> test.test()
Fill the buffer...
Read the buffer:
80600000: 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
80600010: 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F
80600020: 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F
80600030: 30 31 32 33 34 35 36 37 38 39 3A 3B 3C 3D 3E 3F
80600040: 40 41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F
80600050: 50 51 52 53 54 55 56 57 58 59 5A 5B 5C 5D 5E 5F
80600060: 60 61 62 63 64 65 66 67 68 69 6A 6B 6C 6D 6E 6F
80600070: 70 71 72 73 74 75 76 77 78 79 7A 7B 7C 7D 7E 7F
80600080: 80 81 82 83 84 85 86 87 88 89 8A 8B 8C 8D 8E 8F
80600090: 90 91 92 93 94 95 96 97 98 99 9A 9B 9C 9D 9E 9F
806000a0: A0 A1 A2 A3 A4 A5 A6 A7 A8 A9 AA AB AC AD AE AF
806000b0: B0 B1 B2 B3 B4 B5 B6 B7 B8 B9 BA BB BC BD BE BF
806000c0: C0 C1 C2 C3 C4 C5 C6 C7 C8 C9 CA CB CC CD CE CF
806000d0: D0 D1 D2 D3 D4 D5 D6 D7 D8 D9 DA DB DC DD DE DF
806000e0: E0 E1 E2 E3 E4 E5 E6 E7 E8 E9 EA EB EC ED EE EF
806000f0: F0 F1 F2 F3 F4 F5 F6 F7 F8 F9 FA FB FC FD FE FF
80600100: A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5

Done.
>>> 

You can also use the following function to demonstrate effect of Data cache and differences of accessing cached and non-cached area.

static void _test()
{
    uint8_t *buffer = (uint8_t *)0x80600000;
    uint8_t *buffer_nocache = (uint8_t *)0x40600000;

    memset(buffer_nocache, 0xa5, 512);

    printf("Fill non-cached area...\n");
    for (int i=0; i<256; i++) {
        buffer_nocache[i] = i;
    }

    printf("Read cached area:");
    for (int i=0; i<272; i++) {
        if ((i % 16) == 0) printf("\n%p:", buffer+i);
        printf(" %02X", buffer[i]);
    }
    printf("\n\nRead non-cached area:");
    for (int i=0; i<272; i++) {
        if ((i % 16) == 0) printf("\n%p:", buffer_nocache+i);
        printf(" %02X", buffer_nocache[i]);
    }

    printf("\n\nFill non-cached area...\n");
    for (int i=0; i<256; i++) {
        buffer_nocache[i] = 255-i;
    }

    printf("\n\nRead cached area:");
    for (int i=0; i<272; i++) {
        if ((i % 16) == 0) printf("\n%p:", buffer+i);
        printf(" %02X", buffer[i]);
    }
    printf("\n\nRead non-cached area:");
    for (int i=0; i<272; i++) {
        if ((i % 16) == 0) printf("\n%p:", buffer_nocache+i);
        printf(" %02X", buffer_nocache[i]);
    }

    printf("\n\nCLEAR D-Cache\n");
    asm("fence");   // Clear Data Cache
    //asm("fence.i");   // Clear Instruction Cache

    printf("\n\nFill cached area...\n");
    for (int i=0; i<256; i++) {
        buffer[i] = i/2;
    }

    printf("\n\nRead cached area:");
    for (int i=0; i<272; i++) {
        if ((i % 16) == 0) printf("\n%p:", buffer+i);
        printf(" %02X", buffer[i]);
    }
    printf("\n\nRead non-cached area:");
    for (int i=0; i<272; i++) {
        if ((i % 16) == 0) printf("\n%p:", buffer_nocache+i);
        printf(" %02X", buffer_nocache[i]);
    }

    printf("\n\nDone.");
}
Fill non-cached area...
Read cached area:
80600000: 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
80600010: 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F
80600020: 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F
80600030: 30 31 32 33 34 35 36 37 38 39 3A 3B 3C 3D 3E 3F
80600040: 40 41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F
80600050: 50 51 52 53 54 55 56 57 58 59 5A 5B 5C 5D 5E 5F
80600060: 60 61 62 63 64 65 66 67 68 69 6A 6B 6C 6D 6E 6F
80600070: 70 71 72 73 74 75 76 77 78 79 7A 7B 7C 7D 7E 7F
80600080: 80 81 82 83 84 85 86 87 88 89 8A 8B 8C 8D 8E 8F
80600090: 90 91 92 93 94 95 96 97 98 99 9A 9B 9C 9D 9E 9F
806000a0: A0 A1 A2 A3 A4 A5 A6 A7 A8 A9 AA AB AC AD AE AF
806000b0: B0 B1 B2 B3 B4 B5 B6 B7 B8 B9 BA BB BC BD BE BF
806000c0: C0 C1 C2 C3 C4 C5 C6 C7 C8 C9 CA CB CC CD CE CF
806000d0: D0 D1 D2 D3 D4 D5 D6 D7 D8 D9 DA DB DC DD DE DF
806000e0: E0 E1 E2 E3 E4 E5 E6 E7 E8 E9 EA EB EC ED EE EF
806000f0: F0 F1 F2 F3 F4 F5 F6 F7 F8 F9 FA FB FC FD FE FF
80600100: A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5

Read non-cached area:
40600000: 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
40600010: 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F
40600020: 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F
40600030: 30 31 32 33 34 35 36 37 38 39 3A 3B 3C 3D 3E 3F
40600040: 40 41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F
40600050: 50 51 52 53 54 55 56 57 58 59 5A 5B 5C 5D 5E 5F
40600060: 60 61 62 63 64 65 66 67 68 69 6A 6B 6C 6D 6E 6F
40600070: 70 71 72 73 74 75 76 77 78 79 7A 7B 7C 7D 7E 7F
40600080: 80 81 82 83 84 85 86 87 88 89 8A 8B 8C 8D 8E 8F
40600090: 90 91 92 93 94 95 96 97 98 99 9A 9B 9C 9D 9E 9F
406000a0: A0 A1 A2 A3 A4 A5 A6 A7 A8 A9 AA AB AC AD AE AF
406000b0: B0 B1 B2 B3 B4 B5 B6 B7 B8 B9 BA BB BC BD BE BF
406000c0: C0 C1 C2 C3 C4 C5 C6 C7 C8 C9 CA CB CC CD CE CF
406000d0: D0 D1 D2 D3 D4 D5 D6 D7 D8 D9 DA DB DC DD DE DF
406000e0: E0 E1 E2 E3 E4 E5 E6 E7 E8 E9 EA EB EC ED EE EF
406000f0: F0 F1 F2 F3 F4 F5 F6 F7 F8 F9 FA FB FC FD FE FF
40600100: A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5

Fill non-cached area...


Read cached area:
80600000: 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
80600010: 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F
80600020: 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F
80600030: 30 31 32 33 34 35 36 37 38 39 3A 3B 3C 3D 3E 3F
80600040: 40 41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F
80600050: 50 51 52 53 54 55 56 57 58 59 5A 5B 5C 5D 5E 5F
80600060: 60 61 62 63 64 65 66 67 68 69 6A 6B 6C 6D 6E 6F
80600070: 70 71 72 73 74 75 76 77 78 79 7A 7B 7C 7D 7E 7F
80600080: 80 81 82 83 84 85 86 87 88 89 8A 8B 8C 8D 8E 8F
80600090: 90 91 92 93 94 95 96 97 98 99 9A 9B 9C 9D 9E 9F
806000a0: A0 A1 A2 A3 A4 A5 A6 A7 A8 A9 AA AB AC AD AE AF
806000b0: B0 B1 B2 B3 B4 B5 B6 B7 B8 B9 BA BB BC BD BE BF
806000c0: C0 C1 C2 C3 C4 C5 C6 C7 C8 C9 CA CB CC CD CE CF
806000d0: D0 D1 D2 D3 D4 D5 D6 D7 D8 D9 DA DB DC DD DE DF
806000e0: E0 E1 E2 E3 E4 E5 E6 E7 E8 E9 EA EB EC ED EE EF
806000f0: F0 F1 F2 F3 F4 F5 F6 F7 F8 F9 FA FB FC FD FE FF
80600100: A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5

Read non-cached area:
40600000: FF FE FD FC FB FA F9 F8 F7 F6 F5 F4 F3 F2 F1 F0
40600010: EF EE ED EC EB EA E9 E8 E7 E6 E5 E4 E3 E2 E1 E0
40600020: DF DE DD DC DB DA D9 D8 D7 D6 D5 D4 D3 D2 D1 D0
40600030: CF CE CD CC CB CA C9 C8 C7 C6 C5 C4 C3 C2 C1 C0
40600040: BF BE BD BC BB BA B9 B8 B7 B6 B5 B4 B3 B2 B1 B0
40600050: AF AE AD AC AB AA A9 A8 A7 A6 A5 A4 A3 A2 A1 A0
40600060: 9F 9E 9D 9C 9B 9A 99 98 97 96 95 94 93 92 91 90
40600070: 8F 8E 8D 8C 8B 8A 89 88 87 86 85 84 83 82 81 80
40600080: 7F 7E 7D 7C 7B 7A 79 78 77 76 75 74 73 72 71 70
40600090: 6F 6E 6D 6C 6B 6A 69 68 67 66 65 64 63 62 61 60
406000a0: 5F 5E 5D 5C 5B 5A 59 58 57 56 55 54 53 52 51 50
406000b0: 4F 4E 4D 4C 4B 4A 49 48 47 46 45 44 43 42 41 40
406000c0: 3F 3E 3D 3C 3B 3A 39 38 37 36 35 34 33 32 31 30
406000d0: 2F 2E 2D 2C 2B 2A 29 28 27 26 25 24 23 22 21 20
406000e0: 1F 1E 1D 1C 1B 1A 19 18 17 16 15 14 13 12 11 10
406000f0: 0F 0E 0D 0C 0B 0A 09 08 07 06 05 04 03 02 01 00
40600100: A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5

CLEAR D-Cache


Fill cached area...


Read cached area:
80600000: 00 00 01 01 02 02 03 03 04 04 05 05 06 06 07 07
80600010: 08 08 09 09 0A 0A 0B 0B 0C 0C 0D 0D 0E 0E 0F 0F
80600020: 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17
80600030: 18 18 19 19 1A 1A 1B 1B 1C 1C 1D 1D 1E 1E 1F 1F
80600040: 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27
80600050: 28 28 29 29 2A 2A 2B 2B 2C 2C 2D 2D 2E 2E 2F 2F
80600060: 30 30 31 31 32 32 33 33 34 34 35 35 36 36 37 37
80600070: 38 38 39 39 3A 3A 3B 3B 3C 3C 3D 3D 3E 3E 3F 3F
80600080: 40 40 41 41 42 42 43 43 44 44 45 45 46 46 47 47
80600090: 48 48 49 49 4A 4A 4B 4B 4C 4C 4D 4D 4E 4E 4F 4F
806000a0: 50 50 51 51 52 52 53 53 54 54 55 55 56 56 57 57
806000b0: 58 58 59 59 5A 5A 5B 5B 5C 5C 5D 5D 5E 5E 5F 5F
806000c0: 60 60 61 61 62 62 63 63 64 64 65 65 66 66 67 67
806000d0: 68 68 69 69 6A 6A 6B 6B 6C 6C 6D 6D 6E 6E 6F 6F
806000e0: 70 70 71 71 72 72 73 73 74 74 75 75 76 76 77 77
806000f0: 78 78 79 79 7A 7A 7B 7B 7C 7C 7D 7D 7E 7E 7F 7F
80600100: A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5

Read non-cached area:
40600000: FF FE FD FC FB FA F9 F8 F7 F6 F5 F4 F3 F2 F1 F0
40600010: EF EE ED EC EB EA E9 E8 E7 E6 E5 E4 E3 E2 E1 E0
40600020: DF DE DD DC DB DA D9 D8 D7 D6 D5 D4 D3 D2 D1 D0
40600030: CF CE CD CC CB CA C9 C8 C7 C6 C5 C4 C3 C2 C1 C0
40600040: BF BE BD BC BB BA B9 B8 B7 B6 B5 B4 B3 B2 B1 B0
40600050: AF AE AD AC AB AA A9 A8 A7 A6 A5 A4 A3 A2 A1 A0
40600060: 9F 9E 9D 9C 9B 9A 99 98 97 96 95 94 93 92 91 90
40600070: 8F 8E 8D 8C 8B 8A 89 88 87 86 85 84 83 82 81 80
40600080: 7F 7E 7D 7C 7B 7A 79 78 77 76 75 74 73 72 71 70
40600090: 6F 6E 6D 6C 6B 6A 69 68 67 66 65 64 63 62 61 60
406000a0: 5F 5E 5D 5C 5B 5A 59 58 57 56 55 54 53 52 51 50
406000b0: 4F 4E 4D 4C 4B 4A 49 48 47 46 45 44 43 42 41 40
406000c0: 3F 3E 3D 3C 3B 3A 39 38 37 36 35 34 33 32 31 30
406000d0: 2F 2E 2D 2C 2B 2A 29 28 27 26 25 24 23 22 21 20
406000e0: 1F 1E 1D 1C 1B 1A 19 18 17 16 15 14 13 12 11 10
406000f0: 0F 0E 0D 0C 0B 0A 09 08 07 06 05 04 03 02 01 00
40600100: A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5

Done

The issue is that accessing the AI ram hangs. The command I am using to access it is perfectly capable of doing a read (as evidenced by the other examples I have given accessing other areas of memory).

As you can see from my example, accessing (writting or reading) SRAM at 0x80600000 does not hang.
I don’t understand which function are you using for AI SRAM acces. What is => md.l in your example?

It displays memory at an address. You can see other examples where I display memory at other addresses.