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++
12606 Discussions

why was my code footprint not be reduced?

Altera_Forum
Honored Contributor II
1,035 Views

hello, 

i wrote a code based on the count_binary about PIO. 

in sopc builder, i customed the NiosII processor as following: 

 

Nios/e 

on chip memory: 4K (if is it small?) 

uart:default settings 

PIO_7SEG:8bit output 

PIO_BUTTON:2bit input,generate IRQ,ring edge 

 

but the builting project failed! 

the error message: 

 

region onchip_memory_0 is full  

Region needs to be 1228 bytes larger. 

 

my question is: 

 

if the 4K memory is not enough? 

 

BTW: 

 

i am confused about the STANDARD C data type and HAL data type. 

what's the difference between them? 

i read the SW manual,but failed to get it out. Any one could give me a example to explain it? 

 

Thanks! 

http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/unsure.gif
0 Kudos
3 Replies
Altera_Forum
Honored Contributor II
318 Views

 

--- Quote Start ---  

originally posted by nios_ii@Apr 7 2006, 08:59 AM 

hello, 

i wrote a code based on the count_binary about pio. 

in sopc builder, i customed the niosii processor as following: 

 

nios/e 

on chip memory: 4k (if is it small?) 

uart:default settings 

pio_7seg:8bit output 

pio_button:2bit input,generate irq,ring edge 

 

but the builting project failed! 

the error message: 

 

region onchip_memory_0 is full  

region needs to be 1228 bytes larger. 

 

my question is: 

 

if the 4k memory is not enough? 

 

btw: 

 

i am confused about the standard c data type and hal data type. 

what&#39;s the difference between them? 

i read the sw manual,but failed to get it out. any one could give me a example to explain it? 

 

thanks! 

http://forum.niosforum.com/work2/style_emoticons/<#emo_dir#>/unsure.gif  

<div align='right'><{post_snapback}> (index.php?act=findpost&pid=14127) 

--- quote end ---  

 

--- Quote End ---  

 

 

 

Read the section on reducing code footprint in the Nios II Software Developers handbook. It&#39;s in the documents directory it&#39;s somehting like niisw_5v2.pdf. 

 

As for the HAL data types versus the C data types. C data types do not have guaranteed widths they change from compiler to compiler architecture to architecture. The HAL types give you a type of the width you choose on Nios
0 Kudos
Altera_Forum
Honored Contributor II
318 Views

rugbybloke, 

 

Thank you for your reply. 

 

I just read <<Nios II Software Developer’s Handbook>>,and set the preproccess options according to concerned chapter of the handbook.but it still failed. 

maybe,the code i wrote needs large region.i set the on chip memory size to 8K in sopc builder,and set the sytem library according to the Reduce the code footprint chapter of the handbook,then builid the project, Succeeded!.the info in console is :(hello_world_0.elf) 6292 Bytes program size (code + initialized data). 

 

herein, i have a another problem. 

in the code i wrote for my customed NiosII system,the printf function was called to write some character to the STDOUT,but once the program run,i don&#39;t get the character i want,i just get the info:terminate the program in NiosII IDE or Ctrl-C. 

Could you tell me why and how i get i want in the console? 

 

Thanks! http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/blink.gif
0 Kudos
Altera_Forum
Honored Contributor II
318 Views

 

--- Quote Start ---  

originally posted by nios_ii@Apr 8 2006, 06:29 AM 

herein, i have a another problem. 

in the code i wrote for my customed niosii system,the printf function was called to write some character to the stdout,but once the program run,i don&#39;t get the character i want,i just get the info:terminate the program in niosii ide or ctrl-c. 

could you tell me why and how i get i want in the console? 

 

thanks!  http://forum.niosforum.com/work2/style_emoticons/<#emo_dir#>/blink.gif  

<div align='right'><{post_snapback}> (index.php?act=findpost&pid=14146) 

--- quote end ---  

 

--- Quote End ---  

 

 

It is likely that you are still running out of memory, but at runtime rather than during software build. There is a key difference here because during software build, the linker has no idea how much memory your program might use in operation, only the memory used by the program itself and any global data that you statically delcare. 

 

Once your program is running, though, any declared vairables or arrays at subroutine entry get placed on the stack, and any memory requested through malloc() is placed on the heap. In the case of printf(), I know that at least a couple of kilobytes of memory can be used via malloc calls (in reality printf asks for little memory from malloc, but malloc itself is optimized to allocate more memory than is needed to make future malloc calls more quick/efficient). The result is stack/heap collission and erratic/unpredictable program operation. 

 

There is a Nios II feature that helps with this - runtime stack checking - that works if your stack and heap are in the same memory device (or onchip ram). It can be enabled via the system library properties dialog. Be aware, though, that to perform these checks extra code is required, and that will bump up memory usage just a bit in itself. 

 

The best bet for deeply embedded systems with just a few kilobytes of ram is ususally to be very careful of memory use and to know exactly how much is used at any point... calling C library routines without knowing their effect on memory use is, sadly, a common point of failure.
0 Kudos
Reply