ATtiny 1-Series - Flash mapped to RAM and problem with calculating program space

Go To Last Post
6 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello

 

I find Flash mapping feature into data space is very useful, because it allows me to get rid of all PROGMEM, PSTR, etc. Everything works very well but something is wrong with calculation program space. Have a look on this example I tested on ATtiny1616:

 

#include <avr/io.h>
#include "uart.h"

const char BigData[] = "Very Long String...\r\n";

int main(void) {
	Uart_Init();
	Uart_Write(BigData);
	while(1);
}

Uart_Write is defined this way:

void Uart_Write(const char * text) {
	while(*text) Uart_Write(*text++);
}

void Uart_Write(uint8_t Data) {
	// Just copying Data to USART register and checking flags
	// Not important at this time
}

 

Everything works fine when BigData[] is defined as char or const char. When it's char BigData[] it's stored in RAM at address 0x3800, which is begin of RAM data, so after building the program I get:

                Program Memory Usage     :    580 bytes   3,5 % Full
                Data Memory Usage         :    29 bytes   1,4 % Full

 

The usage both of RAM and Flash increases with increasing the length of the string, what is completely obvious. 

 

When I change it to const char BigData[] the string is stored at 0x8218 which is Flash space. Usage of RAM is decreased but usage of Flash is also decresed! Why?

                Program Memory Usage     :    536 bytes   3,3 % Full
                Data Memory Usage         :    7 bytes   0,3 % Full

 

Moreover, the usage of Flash is independent of the string length. When I add something to the string:

const char BigData[] = "Very Loooooooooooooooooooooooooooooooooooooooong String...\r\n";

i get also 

                Program Memory Usage     :    536 bytes   3,3 % Full
                Data Memory Usage         :    7 bytes   0,3 % Full

 

This way I can run out of program space whereas the compiler says there's a lot of free space left. What am I doing wrong?

extronic.pl

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Atmel Studio probably doesn’t take into account the strings in flash when it calculates the used flash. Hopefully the Microchip guys pick up on this thread and comment.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You will understand it by looking at the LSS.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The best thing to see what happen is to look in the .LSS file.

 

Which optimize level do you use? 

 

UPS to slow :)

Last Edited: Tue. Dec 25, 2018 - 02:07 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Optimization level is default -O1

 

When string is declared as 'const' it goes to rodata section (read only data? or what?). 

 

chat BigData[]:

LSS

Sections:
Idx Name          Size      VMA       LMA       File off  Algn
  0 .data         00000016  00803800  0000022e  000002c2  2**0
                  CONTENTS, ALLOC, LOAD, DATA
  1 .text         0000022e  00000000  00000000  00000094  2**1
                  CONTENTS, ALLOC, LOAD, READONLY, CODE

MAP

 .data.BigData  0x00803800       0x16 main.o
                0x00803800                BigData

const char BigData[]:

LSS

Sections:
Idx Name          Size      VMA       LMA       File off  Algn
  0 .data         00000000  00803800  00803800  000002c2  2**0
                  CONTENTS, ALLOC, LOAD, DATA
  1 .text         00000218  00000000  00000000  00000094  2**1
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
  2 .rodata       00000016  00008218  00000218  000002ac  2**0
                  CONTENTS, ALLOC, LOAD, READONLY, DATA

MAP

 .rodata._ZL7BigData
                0x00008218       0x16 main.o

 

 

 

 

 

 

extronic.pl

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Damn, I'm blind... Total memory usage is shown three lines over 'Program Memory Usage'.

		   text	   data	    bss	    dec	    hex	filename

		  33303	      0	      7	  33310	   821e	ATtiny1-Progmem.elf
	Done executing task "RunCompilerTask".
	Task "RunOutputFileVerifyTask"
				Program Memory Usage 	:	536 bytes   3,3 % Full
				Data Memory Usage 		:	7 bytes   0,3 % Full

 

 

But I think it's interesting bug. When a string is declared with const char PROGMEM its size is added to Program Memory Usage, whereas const char is not. In this case there's no warning when you run out of memory space. I have declared ridiculously big const char BigData[32767]  and the compiler haven't thrown any error at all! I could uplaod this prog to ATtiny1616 but of course it was not working.

extronic.pl