Forum Menu




 


Log in Problems?
New User? Sign Up!
AVR Freaks Forum Index

Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Author Message
Hendrik_AVR
PostPosted: Aug 02, 2011 - 09:23 PM
Newbie


Joined: Aug 02, 2011
Posts: 7
Location: BELGIUM

Hey,

I am new on AVR freaks.
Can you help me?

strlcpy_PF is using "lpm" instead of "elpm" while pgm_read_byte_far is working correctly by using "elpm".

I put a string at the end of program memory using #define FLASHDATA __attribute__ ((section ("FLASHEND")))
without initializing the memory segment. I think that this is not the correct way, but it is working!...
How to do it correctly?...

Thanks.

/***************************************************
------ Build started: Project: Test_PF, Configuration: Debug AVR ------
Build started.
Project "Test_PF.avrgccproj" (default targets):
Target "PreBuildEvent" skipped, due to false condition; ('$(PreBuildEvent)'!='') was evaluated as (''!='').
Target "CoreBuild" in file "C:\Program Files\Atmel\AVR Studio 5.0\Vs\AvrGCC.targets" from project "D:\AVRstudio5\Test_PF\Test_PF\Test_PF.avrgccproj" (target "Build" depends on it):
Task "RunAvrGCC"
C:\Program Files\Atmel\AVR Studio 5.0\AVR ToolChain\bin\make.exe all
Code2ReachUpper64K.c
Invoking: AVR/GNU C Compiler
"C:/Program Files/Atmel/AVR Studio 5.0/AVR ToolChain/bin/avr-gcc.exe" -funsigned-char -funsigned-bitfields -DF_CPU=20000000 -O0 -fpack-struct -fshort-enums -g3 -Wall -c -std=gnu99 -mmcu=atmega1284p -MD -MP -MF"Code2ReachUpper64K.d" -MT"Code2ReachUpper64K.d" -o"Code2ReachUpper64K.o" "../../Code2ReachUpper64K.c"
Finished building: ../../Code2ReachUpper64K.c
FlashData.c
Invoking: AVR/GNU C Compiler
"C:/Program Files/Atmel/AVR Studio 5.0/AVR ToolChain/bin/avr-gcc.exe" -funsigned-char -funsigned-bitfields -DF_CPU=20000000 -O0 -fpack-struct -fshort-enums -g3 -Wall -c -std=gnu99 -mmcu=atmega1284p -MD -MP -MF"FlashData.d" -MT"FlashData.d" -o"FlashData.o" "../../FlashData.c"
Finished building: ../../FlashData.c
Test_PF.c
Invoking: AVR/GNU C Compiler
"C:/Program Files/Atmel/AVR Studio 5.0/AVR ToolChain/bin/avr-gcc.exe" -funsigned-char -funsigned-bitfields -DF_CPU=20000000 -O0 -fpack-struct -fshort-enums -g3 -Wall -c -std=gnu99 -mmcu=atmega1284p -MD -MP -MF"Test_PF.d" -MT"Test_PF.d" -o"Test_PF.o" ".././Test_PF.c"
.././Test_PF.c: In function 'main':
D:\AVRstudio5\Test_PF\Test_PF\Test_PF.c(27,19): unused variable 'size'
D:\AVRstudio5\Test_PF\Test_PF\Test_PF.c(25,7): unused variable 'test'
Finished building: .././Test_PF.c
Building target: Test_PF.elf
Invoking: AVR/GNU C/C++ Linker
"C:/Program Files/Atmel/AVR Studio 5.0/AVR ToolChain/bin/avr-gcc.exe" -mmcu=atmega1284p -Wl,-Map=Test_PF.map -o Test_PF.elf Code2ReachUpper64K.o FlashData.o Test_PF.o
Finished building target: Test_PF.elf
"C:/Program Files/Atmel/AVR Studio 5.0/AVR ToolChain/bin/avr-objcopy.exe" -O ihex -R .eeprom -R .fuse -R .lock -R .signature "Test_PF.elf" "Test_PF.hex"
"C:/Program Files/Atmel/AVR Studio 5.0/AVR ToolChain/bin/avr-objdump.exe" -h -S "Test_PF.elf" > "Test_PF.lss"
"C:/Program Files/Atmel/AVR Studio 5.0/AVR ToolChain/bin/avr-objcopy.exe" -j .eeprom --set-section-flags=.eeprom=alloc,load --change-section-lma .eeprom=0 --no-change-warnings -O ihex "Test_PF.elf" "Test_PF.eep" || exit 0
AVR Memory Usage
----------------
Device: atmega1284p
Program: 71620 bytes (54.6% Full)
(.text + .data + .bootloader)
Data: 0 bytes (0.0% Full)
(.data + .bss + .noinit)
Done executing task "RunAvrGCC".
Done building target "CoreBuild" in project "Test_PF.avrgccproj".
Target "PostBuildEvent" skipped, due to false condition; ('$(PostBuildEvent)' != '') was evaluated as ('' != '').
Target "Build" in file "C:\Program Files\Atmel\AVR Studio 5.0\Vs\Avr.common.targets" from project "D:\AVRstudio5\Test_PF\Test_PF\Test_PF.avrgccproj" (entry point):
Done building target "Build" in project "Test_PF.avrgccproj".
Done building project "Test_PF.avrgccproj".

Build succeeded.
========== Build: 1 succeeded or up-to-date, 0 failed, 0 skipped ==========

/***************************************************
 
 View user's profile Send private message  
Reply with quote Back to top
meslomp
PostPosted: Aug 03, 2011 - 06:27 AM
Raving lunatic


Joined: May 02, 2007
Posts: 3708
Location: Nieuwegein, Netherlands

what compiler is used?
what version is it?

if you use winavr ( but it does not seem to be)
then you need to use the PROGMEM attribute.

You can read all about it in the tutorials forum. There is an extensive and very clear tutorial on using the PROGMEM attribute there.

regards

_________________
1)Datasheet and application notes checked?
2)tutorial forum
3)Newbie start here
 
 View user's profile Send private message  
Reply with quote Back to top
wek
PostPosted: Aug 03, 2011 - 11:21 AM
Raving lunatic


Joined: Dec 16, 2005
Posts: 3198
Location: Bratislava, Slovakia

meslomp: it's the version from AVRStudio5.

Hendrik_AVR: the LPM instead of ELPM is problably result of incorrectly compiled libraries, and thus stepbrother of http://www.avrfreaks.net/index.php?name ... p;t=108702

As far as the section placement goes, the linker gracefully places an undefined input section wherever it sees fit, and you've been just lucky. I've simply modified the default linker script to include a "high progmem" section and added a couple of macros into the appropriate header (in times when the _far stuff was not official part of avr-libc), but that has been rejected by the high esteemed avr-libc developers.

JW


Last edited by wek on Aug 03, 2011 - 10:17 PM; edited 2 times in total
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
theusch
PostPosted: Aug 03, 2011 - 02:12 PM
10k+ Postman


Joined: Feb 19, 2001
Posts: 28226
Location: Wisconsin USA

Quote:

Program: 71620 bytes (54.6% Full)
(.text + .data + .bootloader)
Data: 0 bytes (0.0% Full)
(.data + .bss + .noinit)

An interesting app/programming style. 64+k of program (though from the thread it may be mostly constant tables) and not a single global variable? Not >>my<< style for sure. (And ironically this is the AVR8 model with the most SRAM.)

Lee
 
 View user's profile Send private message  
Reply with quote Back to top
wek
PostPosted: Aug 03, 2011 - 02:32 PM
Raving lunatic


Joined: Dec 16, 2005
Posts: 3198
Location: Bratislava, Slovakia

I doubt data=0bytes is true. The avr-size utility might got confused by the extra section.

JW
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
wek
PostPosted: Aug 03, 2011 - 10:15 PM
Raving lunatic


Joined: Dec 16, 2005
Posts: 3198
Location: Bratislava, Slovakia

above, I wrote:
the LPM instead of ELPM is problably result of incorrectly compiled libraries,

Confirmed experimentally. Submitted to the avr-libc tracker here.

As a workaround, I recommend to get the sources of the _PF files - maybe directly from Carlos Lamas' files, or from the avr-libc file repositories - and compile and link them to your sources explicitly. That should override the library versions.


I also wrote:
Different issue, don't understand why it happened but also don't intend to investigate, as this is built by Atmel internally.

JW
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
Hendrik_AVR
PostPosted: Aug 05, 2011 - 09:27 PM
Newbie


Joined: Aug 02, 2011
Posts: 7
Location: BELGIUM

Hi 'theusch' , 'wek',
Hi all,

I am using AVRStudio 5.

The only goal was to test strlcpy_PF in a test-project with the need to place a string in the >64K of the flash.

I choosed to place it at the end of the used flashspace to use this later in my current project to place a integer (checksum) to test the used flashspace.

I builded a unused function by copying my 'test_ram' code, with local variables in the registers, just until I reached the >64K of flash.
In the main function I test strlcpy_PF using the debugger (AVR Simulator or JTAGICE 3). I have no global variables in this test_project.
That's why data = 0 bytes.


Now I understand the strlcpy_FP problem.
It's a bug.

But I do not understand how I placed the string (strlcpy_PF), or integer (checksum) in my recent project. I used the 'section attribute' and it don't matter that I initialise it, and where, or not (AVRStudio 5 --> GCC Project options and configuration --> Memory options ).
The variable is always placed at the end of the used flashspace.
Ok, it is working but will it still working as my recent project, with i.a. my checksum_flash function, is growing?

I like to understand the use of memory sections in AVRStudio 5.

Thanks for the support.
 
 View user's profile Send private message  
Reply with quote Back to top
clawson
PostPosted: Aug 05, 2011 - 09:39 PM
10k+ Postman


Joined: Jul 18, 2005
Posts: 69416
Location: (using avr-gcc in) Finchingfield, Essex, England

Quote:

I like to understand the use of memory sections in AVRStudio 5.


Well for one thing I wouldn't use AS5 or more particularly I wouldn't use the AVR Toolchain that ships with it as it's been shown to have some serious errors.

But anyway, start by looking at the linker scripts. From the base of an avr-gcc install they are in avr\lib\ldscripts\. In the case of 1284p the file that will be used is avr51.x

While you can add your own __attribute__((section(".foo"))) and --section-start=.foo=NNNNN you can only place things like this (in flash) beyond where the linker has used (otherwise you get a link error about conflicting areas). If you want to place something "in the middle" you need to either modify the system copy of avr51.x (which then affects all future projects) or, better, take a local copy then pass "-T mylinkscript.x" to the linker to over-ride the use of the default one. You are then able to insert your own named sections "in the middle" of the link map if you want.

_________________
 
 View user's profile Send private message  
Reply with quote Back to top
wek
PostPosted: Aug 07, 2011 - 08:18 AM
Raving lunatic


Joined: Dec 16, 2005
Posts: 3198
Location: Bratislava, Slovakia

Hendrik,

Have you read my remarks in http://www.avrfreaks.net/index.php?name ... ht=remarks ? I know it's lengthy, and also my English is not the best so that maybe it's not everything clear enough especially for a novice, but I wrote it with the intention to help excetly in these situations and I believe the substantial information is in there.

JW
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT + 1 Hour
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Powered by PNphpBB2 © 2003-2006 The PNphpBB Group
Credits