The "getchar" function call does not work when I run the code from OCM memory.
Similarly, other newlib C library routines do not work when run in certain memory configurations. The newlib library delivered with EDK is compiled with the "-mrelocatable-lib" option. This option produces code that READS from the ".text" section for self-referencing entries.
When I execute the code, there are certain load instructions which load from addresses that are in the .text section (i.e., this requires that the .text should be readable/data-side accessible). OCM is one memory configuration which exhibits this issue. OCM designs do not HAVE a D-side interface to the ISOCM memory. If there was a D-side i/f to the same OCM memory address, the load would succeed.
For example, the same problem will occur with PLB BRAM if the user had two BRAM blocks, one for I-side and one for D-side and they are mapped to different addresses. So, if such code runs out of the first block, it will have illegal memory access when coming to those particular instructions in the Newlib routines. Such memory organization is not common, as you will not be able to download/debug such designs, but yet it is possible.
To work around this issue, you can do one of the following:
- Do not run the application code containing "getchar" or other newlib function calls from OCM memory.
- Use the UART driver function calls to read characters directly from the UART peripheral.