Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
12690 Discussions

NIOS II hangs when switching to onchip memory

Altera_Forum
Honored Contributor II
1,648 Views

Hi, 

 

I've trouble moving from a NIOS II system with flash and external SRAM to a self contained system runnning with onchip memory only. We need this for programming our flash the very first time, so the small system using onchip memory only should be able to program the flash. The data for flash programming come from an external interface, in this case not the JTAG interface. 

Our system and code run fine, if external memory is used , switching to onchip memory, the system hangs when calling "alt_flash_open_dev" from the HAL. 

Maybe the system even restarts. 

 

No warnings about low memory or other things come up in the NIOS IDE. 

Our NIOS system has its reset vector and interrupts set to the beginning of the onchip ram, 24kByte in our case, and no JTAG interface installed. Interrutps occur during communication with external interfaces. 

 

Sure, we optimized our compiler settings to make the code fit into the onchip memory: 

application settings 

* faster code, no frame pointer : on 

* optimize most (-=3) 

* Debug Level none 

 

system library setting: 

* faster code, no frame pointer : on 

* optimize most (-=3) 

* Debug Level none 

 

* stdout: null 

* stderr : null 

* stdin: null 

* Periodic system timer: none 

* Timestamp timer: none 

* Max file dscriptors:4 

* Clean exit: unchecked 

* Small C library: checked 

* ModelSim only: unchecked 

* Reduced device drivers: unchecked (we need the HAL handling the flash memory for us) 

* Link with profiling library: unchecked 

 

* we use an auto-generated linker script 

* Program memory (.text): onchip_memory 

* Read-only data memory (.rodata): onchip_memory 

* Read/write memory: ext_sram, 1Mbyte in this case. 

 

When compiling the code, the IDE messages a program size of 25KBytes (code + initialized data) and 1012kBytes free for stack + heap. 

How can this program fit into an onchip memory of 24kBytes size? 

Any idea what's on? 

 

 

Thanks!
0 Kudos
5 Replies
Altera_Forum
Honored Contributor II
596 Views

I’m surprised that you didn’t get an error when you tried to link this application, but the numbers you give at the bottom explain the problem. You can’t boot 25K’s worth of code & data out of a 24K memory. You will need to either increase the size of the memory, or reduce the size of your code. 

 

One option that may help is that you can select small footprint drivers. If you still want to use the CFI flash driver in this case, you can do so by adding the define ALT_USE_CFI_FLASH to the list of defined symbols for the system library project. This is done on the C/C++ Build tab of the properties page. In your particular case, this may not make much of a difference since you don’t seem to have any other effected devices in the system – but it may be worth a go. 

 

I don't know if you've already done this, but you should also add the define: ALT_NO_INSTRUCTION_EMULATION. This will remove the software emulation of multiply and divide instructions. This emulation is generally not needed for HAL based applications, since the apropriate compiler flags are set to ensure multiply and divide instructions are not used when they're not available.
0 Kudos
Altera_Forum
Honored Contributor II
596 Views

And you might want to try different optimisation options.  

 

-O3 means optimise for speed. This often generates bigger code than -O2. 

 

If you want to optimise for code size then use -Os (the 1.0 compiler implements this but it isn't available in the GUI until 1.1)
0 Kudos
Altera_Forum
Honored Contributor II
596 Views

Might want to take a look at the document "Developing Programs using the HAL" pages 4-23 to 4-28. That details some of the steps you can take to reduce your memory footprint

0 Kudos
Altera_Forum
Honored Contributor II
596 Views

Thank you all for your suggestions. 

With your input I reduced the code footprint down to 23k, which fits into the 24k of on chip memory. 

However, still there's no function, the NIOS hangs when calling "alt_flash_open_dev". 

I tried to reproduce this simulating the NIOS in modelsim and found out that the NIOS hangs when calling strlen from within "alt_flash_open_dev", but only if the read-only data memory is set to onchip memory. 

Setting the read-only data memory to external SRAM it behaves fine in modelsim, but in reality there's still no function. 

 

BTW: is it legal to set the read-only section to not initialízable external memory? Does the startup code handle the initialisation?
0 Kudos
Altera_Forum
Honored Contributor II
596 Views

maybe 23 is to close to 24 if you need some stack space, ... 

 

Stefaan.
0 Kudos
Reply