Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
15 years ago

Full On-Chip Memory

Hi,

I'd like to know how to determine if the memory space of an on-chip memory is full.

In my nios II system, I generated an on-chip M4K memory. It's size is 4096 bytes with a 32 bits data width. So I've done some trial and error and some calculation about the specifications and have concluded that I have 1023 addressable spaces from 0x000 - 0x3ff. I have calculated that each addressable space can contain 32 bits of data.

I tested this with the following code:

IOWR(ONCHIP_MEMORY2_1_BASE, 0x3fe, "THIS IS TO TEST HOW MUCH DATA CAN A MEMORY SPACE CONTAIN");
alt_printf("%s\n", IORD(ONCHIP_MEMORY2_1_BASE, 0x3fe));
alt_printf("%s\n", IORD(ONCHIP_MEMORY2_1_BASE, 0x3ff));

The problem I face now is I don't know how big 32 bits of data is because I know that a character is 1 byte and so I hypothesized that a memory space addressed by 0x3fe for example would contain just 4 characters. However it held more than that (the string "this is to test how much data can a memory space contain").

How big is a string anyway? and when I try to read out on a memory space that I didn't write to I get the garbage values below.

nios2-terminal: connected to hardware target using JTAG UART on cable
nios2-terminal: "USB-Blaster ", device 1, instance 0
nios2-terminal: (Use the IDE stop button or Ctrl-C to terminate)
Hello onchip mem!
THIS IS TO TEST HOW MUCH DATA CAN A MEMORY SPACE CONTAIN
ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ
... (goes on for around 400+ lines)

What happened here?

Thanks in advanced!

Regards,

27 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    dsl, okay thank you.

    jacol, IORD_8DIRECT or IORD_16DIRECT can access the data in between 32bit words?
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Hi again,

    if the IP-Core you are using supports it. A good sign are connected Byte_Enbles to the IP-Core.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- Quote Start ---

    dsl, okay thank you.

    jacol, IORD_8DIRECT or IORD_16DIRECT can access the data in between 32bit words?

    --- Quote End ---

    I answered that question in my first post in this topic.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Hi Daixiwen,

    --- Quote Start ---

    The *address* of the string is read back from the onchip memory and given to alt_printf(), that will read the string from the .text section and print it.

    --- Quote End ---

    And why will the function read from the .text section, I thought the string is stored in the .data section?
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    I made a mistake. I meant the .data section (or if fact the .rodata, as explained by dsl). The string data is read from the location it was written to, of course. Sorry for the confusion... I've corrected my post

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- Quote Start ---

    4096 bytes is 1024 words of 32 bits.

    The IORD/IOWR macros read and write 32 bit words only, and it isn't an address that you give them, but a register number. When you do IORD(ONCHIP_MEMORY2_1_BASE, 0x3fe), the actual addresses accessed are the 4 bytes at ONCHIP_MEMORY2_1_BASE+4*0x3fe to ONCHIP_MEMORY2_1_BASE+4*0x3fe+3 (0x00011ff8 - 0x00011ffb).

    When you do IOWR(ONCHIP_MEMORY2_1_BASE, 0x3fe, "THIS IS TO TEST HOW MUCH DATA CAN A MEMORY SPACE CONTAIN") you don't write the string to the onchip memory, you just write its address, which is a 32-bit word. The size of the string doesn't matter.

    --- Quote End ---

    Hi

    I also have a problem with the on-chip memory in my project. I'm using a Cyclone 3c25 fpga and I once set my on-chip RAM to 60kb and the project did compile without any problem. But now it doesnt and I get error messages such as "error:can't fit RAM cells in design". If I'm correct the limit capacity of the on-chip RAM on this cyclone board is 66kb and it did work once. What could be the issue now?

    Please help.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    The NIOS core itself can use some M9K blocks, so they won't all be available for you to use. Furthermore I know that some megawizard instantiations have problems with non power-of-two sizes, so it may try to allocate 128 blocks to create your on-chip memory.