| Author |
Message |
|
|
Posted: Apr 21, 2012 - 02:04 PM |
|

Joined: Nov 07, 2006
Posts: 130
|
|
Dear Sir,
I am writing a datalogger application for which i have to placed some function in flash memory and some data bytes as well. I have successfully done this type of work in avrstudio 4.12 with the make file.
Now i am using avrstudio 5, i have tried as follows:
1. LDFLAGS += -Wl,--section-start=.bootloader=0x7100
where in 0x7100 is byte address equivalent to word address of 0x3880(tried passing word address as well).
2. I have to write byte 0x00 in flash with "program_page" which is tested function in the older version of avrstudio.
3. while implementating the flash page write...i remembered we have to put program_page (i.e. SPM instructions...i guess) into bootloader section
4.i am not able to find any link only objects (old version Makefile) type fields...where to add anything in this new makefile, any tutorial...?
Please revert on this as soon as possible...i am stuck...every help would always be appreciated..!!!
thanks and regards,
hgaurav
MAKEFILE :
Code:
################################################################################
# Automatically-generated file. Do not edit!
################################################################################
SHELL := cmd.exe
RM := rm -rf
USER_OBJS :=
LDFLAGS += -Wl,--section-start=.bootloader=0x7100
LIBS :=
PROJ :=
O_SRCS :=
C_SRCS :=
S_SRCS :=
S_UPPER_SRCS :=
OBJ_SRCS :=
ASM_SRCS :=
PREPROCESSING_SRCS :=
OBJS :=
OBJS_AS_ARGS :=
C_DEPS :=
C_DEPS_AS_ARGS :=
EXECUTABLES :=
LIB_AS_ARGS :=
OUTPUT_FILE_PATH :=
OUTPUT_FILE_PATH_AS_ARGS :=
HEX_FLASH_FILE_PATH :=
HEX_FLASH_FILE_PATH_AS_ARGS :=
HEX_EEPROM_FILE_PATH :=
HEX_EEPROM_FILE_PATH_AS_ARGS :=
LSS_FILE_PATH :=
LSS_FILE_PATH_AS_ARGS :=
MAP_FILE_PATH :=
MAP_FILE_PATH_AS_ARGS :=
AVR_APP_PATH :=C:/Program Files/Atmel/AVR Studio 5.0/AVR ToolChain/bin/
QUOTE := "
ADDITIONAL_DEPENDENCIES:=
OUTPUT_FILE_DEP:=
# Every subdirectory with source files must be described here
SUBDIRS :=
# Add inputs and outputs from these tool invocations to the build variables
C_SRCS += \
../ADC.c \
../GHCrimper32V_1.c \
../Keyboard.c \
../LCD.c \
../RTC.c \
../Serial.c \
../sevensegment.c \
../Timer.c
PREPROCESSING_SRCS +=
ASM_SRCS +=
OBJS += \
ADC.o \
GHCrimper32V_1.o \
Keyboard.o \
LCD.o \
RTC.o \
Serial.o \
sevensegment.o \
Timer.o
OBJS_AS_ARGS += \
ADC.o \
GHCrimper32V_1.o \
Keyboard.o \
LCD.o \
RTC.o \
Serial.o \
sevensegment.o \
Timer.o
C_DEPS += \
ADC.d \
GHCrimper32V_1.d \
Keyboard.d \
LCD.d \
RTC.d \
Serial.d \
sevensegment.d \
Timer.d
C_DEPS_AS_ARGS += \
ADC.d \
GHCrimper32V_1.d \
Keyboard.d \
LCD.d \
RTC.d \
Serial.d \
sevensegment.d \
Timer.d
OUTPUT_FILE_PATH +=GHCrimper32V_1.elf
OUTPUT_FILE_PATH_AS_ARGS +=GHCrimper32V_1.elf
HEX_FLASH_FILE_PATH +=GHCrimper32V_1.hex
HEX_FLASH_FILE_PATH_AS_ARGS +=GHCrimper32V_1.hex
HEX_EEPROM_FILE_PATH +=GHCrimper32V_1.eep
HEX_EEPROM_FILE_PATH_AS_ARGS +=GHCrimper32V_1.eep
LSS_FILE_PATH +=GHCrimper32V_1.lss
LSS_FILE_PATH_AS_ARGS +=GHCrimper32V_1.lss
MAP_FILE_PATH =GHCrimper32V_1.map
MAP_FILE_PATH_AS_ARGS =GHCrimper32V_1.map
LIB_AS_ARGS +=libGHCrimper32V_1.a
ADDITIONAL_DEPENDENCIES:= $(HEX_FLASH_FILE_PATH) $(LSS_FILE_PATH) $(HEX_EEPROM_FILE_PATH) size
OUTPUT_FILE_DEP:= ./makedep.mk
# AVR/GNU C Compiler
./%.o: .././%.c
@echo Building file: $<
@echo Invoking: AVR/GNU C Compiler
$(QUOTE)$(AVR_APP_PATH)avr-gcc.exe$(QUOTE) -funsigned-char -funsigned-bitfields -Os -fpack-struct -fshort-enums -Wall -c -std=gnu99 -mmcu=atmega32 -MD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o"$@" "$<"
@echo Finished building: $<
# AVR/GNU Assembler
ifneq ($(MAKECMDGOALS),clean)
ifneq ($(strip $(C_DEPS)),)
-include $(C_DEPS)
endif
endif
# Add inputs and outputs from these tool invocations to the build variables
# All Target
all: $(OUTPUT_FILE_PATH) $(ADDITIONAL_DEPENDENCIES)
# AVR/GNU C/C++ Linker
$(OUTPUT_FILE_PATH): $(OBJS) $(USER_OBJS) $(OUTPUT_FILE_DEP)
@echo Building target: $@
@echo Invoking: AVR/GNU C/C++ Linker
$(QUOTE)$(AVR_APP_PATH)avr-gcc.exe$(QUOTE) -mmcu=atmega32 -Wl,-Map=$(MAP_FILE_PATH_AS_ARGS) -o$(OUTPUT_FILE_PATH_AS_ARGS) $(OBJS_AS_ARGS) $(USER_OBJS) $(LIBS)
@echo Finished building target: $@
$(HEX_FLASH_FILE_PATH): $(OUTPUT_FILE_PATH)
$(QUOTE)$(AVR_APP_PATH)avr-objcopy.exe$(QUOTE) -O ihex -R .eeprom -R .fuse -R .lock -R .signature $(QUOTE)$<$(QUOTE) $(QUOTE)$@$(QUOTE)
$(HEX_EEPROM_FILE_PATH): $(OUTPUT_FILE_PATH)
-$(QUOTE)$(AVR_APP_PATH)avr-objcopy.exe$(QUOTE) -j .eeprom --set-section-flags=.eeprom=alloc,load --change-section-lma .eeprom=0 --no-change-warnings -O ihex $(QUOTE)$<$(QUOTE) $(QUOTE)$@$(QUOTE) || exit 0
$(LSS_FILE_PATH): $(OUTPUT_FILE_PATH)
$(QUOTE)$(AVR_APP_PATH)avr-objdump.exe$(QUOTE) -h -S $(QUOTE)$<$(QUOTE) > $(QUOTE)$@$(QUOTE)
size: $(OUTPUT_FILE_PATH)
@$(QUOTE)$(AVR_APP_PATH)avr-size.exe$(QUOTE) -C --mcu=atmega32 $(OUTPUT_FILE_PATH_AS_ARGS)
# Other Targets
clean:
-$(RM) $(OBJS_AS_ARGS)$(C_DEPS_AS_ARGS) $(EXECUTABLES) $(LIB_AS_ARGS) $(HEX_FLASH_FILE_PATH_AS_ARGS) $(HEX_EEPROM_FILE_PATH_AS_ARGS) $(LSS_FILE_PATH_AS_ARGS) $(MAP_FILE_PATH_AS_ARGS)
|
|
|
| |
|
|
|
|
|
Posted: Apr 21, 2012 - 03:31 PM |
|


Joined: Jul 18, 2005
Posts: 62299
Location: (using avr-gcc in) Finchingfield, Essex, England
|
|
Are you saying
Code:
LDFLAGS += -Wl,--section-start=.bootloader=0x7100
did not work then?
certainly if you have functions tagged such as:
Code:
__attribute__((section(".bootloader"))) void boot_do_something(void) {
// code that does SPM
}
this this should be located above the BLS. The .map file will confirm this. |
_________________
|
| |
|
|
|
|
|
Posted: Apr 23, 2012 - 11:49 AM |
|

Joined: Nov 07, 2006
Posts: 130
|
|
Dear cliff,
I have declared:
void program_page (uint32_t,uint8_t*); __attribute__((section (".bootloader")));
In my map file i got following:
Code:
Memory Configuration
Name Origin Length Attributes
text 0x00000000 0x00020000 xr
data 0x00800060 0x0000ffa0 rw !x
eeprom 0x00810000 0x00010000 rw !x
fuse 0x00820000 0x00000400 rw !x
lock 0x00830000 0x00000400 rw !x
signature 0x00840000 0x00000400 rw !x
*default* 0x00000000 0xffffffff
0x00002024 program_page
how do i find out where BLS is located in map file..how to interpret it.....Any example code /make file would be useful..
thanks and Regards,
hgaurav |
|
|
| |
|
|
|
|
|
Posted: Apr 23, 2012 - 12:11 PM |
|


Joined: Jul 18, 2005
Posts: 62299
Location: (using avr-gcc in) Finchingfield, Essex, England
|
|
OK here is a very simple example that works. Take from this what you need:
Code:
#include <avr/io.h>
__attribute__((section(".bootloader"))) void my_fn(void) {
PORTB = 0x55;
}
int main(void) {
my_fn();
}
Code:
LDFLAGS += -Wl,--section-start=.bootloader=0x3F00
Code:
Linking: test.elf
avr-gcc -mmcu=atmega16 -I. -gdwarf-2 -DF_CPU=8000000UL -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-en
ums -Wall -Wstrict-prototypes -Wunreachable-code --save-temps -fverbose-asm -Wa,-adhlns=test.o -std=gnu99 -MMD -MP -MF
.dep/test.elf.d test.o --output test.elf -Wl,-Map=test.map,--cref -lm -Wl,--section-start=.bootloader=0x3F00
Code:
//test.lss
Disassembly of section .bootloader:
00003f00 <my_fn>:
#include <avr/io.h>
__attribute__((section(".bootloader"))) void my_fn(void) {
PORTB = 0x55;
3f00: 85 e5 ldi r24, 0x55 ; 85
3f02: 88 bb out 0x18, r24 ; 24
}
3f04: 08 95 ret
Disassembly of section .text:
00000000 <__vectors>:
0: 0c 94 2a 00 jmp 0x54 ; 0x54 <__ctors_end>
Code:
//test.map
.bootloader 0x00003f00 0x6
.bootloader 0x00003f00 0x6 test.o
0x00003f00 my_fn
|
_________________
|
| |
|
|
|
|
|
Posted: Apr 23, 2012 - 01:24 PM |
|

Joined: Nov 07, 2006
Posts: 130
|
|
Dear Sir,
i am getting following:
I have changed bootloader size to minimum i.e.256 words, start address 0x3F00
Quote:
Error 12 section .bootloader loaded at [0000546a,000054dd] overlaps section .data loaded at [0000546a,000056f9]
please guide,
thanks and regards,
hgaurav |
|
|
| |
|
|
|
|
|
Posted: Apr 23, 2012 - 01:45 PM |
|


Joined: Jul 18, 2005
Posts: 62299
Location: (using avr-gcc in) Finchingfield, Essex, England
|
|
Show the line that invokes your linker when you build. The equivalent of this from my post above:
Code:
avr-gcc -mmcu=atmega16 -I. -gdwarf-2 -DF_CPU=8000000UL -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-en
ums -Wall -Wstrict-prototypes -Wunreachable-code --save-temps -fverbose-asm -Wa,-adhlns=test.o -std=gnu99 -MMD -MP -MF
.dep/test.elf.d test.o --output test.elf -Wl,-Map=test.map,--cref -lm -Wl,--section-start=.bootloader=0x3F00
My guess is that the --section-start is not being passed correctly. |
_________________
|
| |
|
|
|
|
|
Posted: Apr 23, 2012 - 02:57 PM |
|

Joined: Nov 07, 2006
Posts: 130
|
|
Dear sir,
My linker output:
Quote:
Invoking: AVR/GNU C/C++ Linker
"C:/Program Files/Atmel/AVR Studio 5.0/AVR ToolChain/bin/avr-gcc.exe" -mmcu=atmega32 -Wl,-Map=GHCrimper32V_1.map -o GHCrimper32V_1.elf ADC.o GHCrimper32V_1.o Keyboard.o LCD.o RTC.o Serial.o sevensegment.o Timer.o
D:\Software\Projects\GHCrimper\Code\GHCrimper32V_1\GHCrimper32V_1\Release(1,1): section .bootloader loaded at [000053e0,00005453] overlaps section .data loaded at [000053e0,0000566f]
collect2: ld returned 1 exit status
make: *** [GHCrimper32V_1.elf] Error 1
make: Leaving directory `D:/Software/Projects/GHCrimper/Code/GHCrimper32V_1/GHCrimper32V_1/Release'
Done executing task "RunAvrGCC" -- FAILED.
please help
....hgaurav |
|
|
| |
|
|
|
|
|
Posted: Apr 23, 2012 - 03:23 PM |
|


Joined: Jul 18, 2005
Posts: 62299
Location: (using avr-gcc in) Finchingfield, Essex, England
|
|
Where in that do you see anything about:
Code:
-Wl,--section-start=.bootloader=
??
In the first post you said:
Code:
LDFLAGS += -Wl,--section-start=.bootloader=0x7100
I would therefore suggest that the Makefile where this has been entered is NOT being used as the Makefile to actually build the project. That is your problem here. |
_________________
|
| |
|
|
|
|
|
Posted: Apr 25, 2012 - 07:20 AM |
|

Joined: Nov 07, 2006
Posts: 130
|
|
Dear Sir,
I am using Release mode and in project settings i have selected build with external makefile option (Makefile in the release folder).. with the changes in ldflags in makefile....it is as simple as that i guess ....please correct me on this if any....
thanks and regards,
hgaurav |
|
|
| |
|
|
|
|
|
Posted: Apr 25, 2012 - 09:28 AM |
|


Joined: Jul 18, 2005
Posts: 62299
Location: (using avr-gcc in) Finchingfield, Essex, England
|
|
The rule to invoke the linker:
Code:
$(QUOTE)$(AVR_APP_PATH)avr-gcc.exe$(QUOTE) -mmcu=atmega32 -Wl,-Map=$(MAP_FILE_PATH_AS_ARGS) -o$(OUTPUT_FILE_PATH_AS_ARGS) $(OBJS_AS_ARGS) $(USER_OBJS) $(LIBS)
does not appear to use LDFLAGS? Now if you allow a Makefile to operate it's intrinsic rules then LDFLAGS is used automatically for the linker invocation (ISTR) but if you have your own rule for invoking the linker you need to pass LDFLAGS manually. The Mfile template has this:
# Link: create ELF output file from object files.
Code:
.SECONDARY : $(TARGET).elf
.PRECIOUS : $(OBJ)
%.elf: $(OBJ)
@echo
@echo $(MSG_LINKING) $@
$(CC) $(ALL_CFLAGS) $^ --output $@ $(LDFLAGS)
|
_________________
|
| |
|
|
|
|
|
Posted: Apr 25, 2012 - 03:13 PM |
|

Joined: Nov 07, 2006
Posts: 130
|
|
Dear Sir,
I am very sorry to say this...i am not able to interpret it...please elaborate the method...
thanks and regards,
hgaurav |
|
|
| |
|
|
|
|
|
Posted: Apr 25, 2012 - 03:15 PM |
|


Joined: Jul 18, 2005
Posts: 62299
Location: (using avr-gcc in) Finchingfield, Essex, England
|
|
Make this:
Code:
$(QUOTE)$(AVR_APP_PATH)avr-gcc.exe$(QUOTE) -mmcu=atmega32 -Wl,-Map=$(MAP_FILE_PATH_AS_ARGS) -o$(OUTPUT_FILE_PATH_AS_ARGS) $(OBJS_AS_ARGS) $(USER_OBJS) $(LIBS)
into this:
Code:
$(QUOTE)$(AVR_APP_PATH)avr-gcc.exe$(QUOTE) -mmcu=atmega32 $(LDFLAGS) -Wl,-Map=$(MAP_FILE_PATH_AS_ARGS) -o$(OUTPUT_FILE_PATH_AS_ARGS) $(OBJS_AS_ARGS) $(USER_OBJS) $(LIBS)
(I have added $(LDFLAGS) to it). |
_________________
|
| |
|
|
|
|
|
Posted: Apr 26, 2012 - 12:12 PM |
|

Joined: Nov 07, 2006
Posts: 130
|
|
Dear Sir,
After updating the makefile with ldflags: i have following errors
Quote:
Invoking: AVR/GNU C/C++ Linker
"C:/Program Files/Atmel/AVR Studio 5.0/AVR ToolChain/bin/avr-gcc.exe" -mmcu=atmega32 -Wl,--section-start=.bootloader=0x3F00 -Wl,-Map=GHCrimper32V_1.map -o GHCrimper32V_1.elf ADC.o GHCrimper32V_1.o Keyboard.o LCD.o RTC.o Serial.o sevensegment.o Timer.o
D:\Software\Projects\GHCrimper\Code\GHCrimper32V_1\GHCrimper32V_1\Release(1,1): section .bootloader loaded at [00003f00,00003f73] overlaps section .text loaded at [00000000,00005597]
collect2: ld returned 1 exit status
make: *** [GHCrimper32V_1.elf] Error 1
Please guide me on this
regards,
hgaurav |
|
|
| |
|
|
|
|
|
Posted: Apr 26, 2012 - 12:49 PM |
|


Joined: Jul 18, 2005
Posts: 62299
Location: (using avr-gcc in) Finchingfield, Essex, England
|
|
|
Quote:
.bootloader loaded at [00003f00,00003f73] overlaps section .text loaded at [00000000,00005597]
Looks like 3F00 is the wrong address. As this is a 32K micro I'd expect any bootloader to be located above 0x7000. So 0x3F00 is probably a word address that must be doubled. Try changing it to 0x7E00 instead. |
_________________
|
| |
|
|
|
|
|
Posted: Apr 26, 2012 - 02:03 PM |
|

Joined: Nov 07, 2006
Posts: 130
|
|
Dear Sir,
Thanks for valued support...now the program_page function is in BLS now next phase of difficulties started as i am not able to write 0x00 value in flash....
Code:
#define WRADDFLASH 0x5F00
unsigned int buf[128]={0};
for(page=WRADDFLASH;page<=(0x7000);page+=0x80){
program_page(page,buf);
}
//Program Page function:
/* Function to Write data into Flash */
void program_page (uint32_t page, uint8_t *buf)
{
uint16_t i;
uint8_t sreg;
sreg = SREG;
cli(); //Disable all the interrupts
eeprom_busy_wait (); //Wait till EEPROM is busy
boot_page_erase (page); //Erase page
boot_spm_busy_wait (); //Wait until the memory is erased.
for (i=0; i<SPM_PAGESIZE; i+=2){ //Set up little-endian word.
uint16_t w = *buf++;
w += (*buf++) << 8;
boot_page_fill (page + i, w); //Fill the temporary buffer
}//End of for()
boot_page_write (page); //Store buffer in flash page.
boot_spm_busy_wait(); //Wait until the memory is written.
boot_rww_enable (); //Enable the read/write section
SREG = sreg;
}
Please guide on this....thanks
best regards,
hgaurav |
|
|
| |
|
|
|
|
|
Posted: Apr 26, 2012 - 02:19 PM |
|


Joined: Jul 18, 2005
Posts: 62299
Location: (using avr-gcc in) Finchingfield, Essex, England
|
|
| What happens in the simulator (or better still a real AVR if you have a debugger) ? |
_________________
|
| |
|
|
|
|
|
Posted: Apr 26, 2012 - 02:27 PM |
|

Joined: Nov 07, 2006
Posts: 130
|
|
Dear Sir,
I have programmed the atmega and after some time read its flash through mkII...hope to saw 0x00 bytes written on the desired location...but wont got the success....
Thanks and Regards,
hgaurav |
|
|
| |
|
|
|
|
|
Posted: Apr 26, 2012 - 02:40 PM |
|


Joined: Jul 18, 2005
Posts: 62299
Location: (using avr-gcc in) Finchingfield, Essex, England
|
|
| Well it's odd because I can see your code is pretty much that example at the top of boot.h and I've used the very same (mega16 not mega32) myself and know it works well. I cannot immediately spot anything you are doing wrong and you've already spotted the one thing that caused me a problem (I thought the "page" parameter was a 64/128/256 byte page number) but as you are doing it's really just and address and you are correctly stepping it on by 0x80 each time. So, like I say, on the surface that code LOOKS like it should be working. |
_________________
|
| |
|
|
|
|
|
Posted: Apr 27, 2012 - 08:13 AM |
|

Joined: Nov 07, 2006
Posts: 130
|
|
Dear Sir,
I need to confirm one thing....if flash page is to be written, our program_page (SPM Instructions) should be inside the BLS...??
If that is the case my program should work...god knows...whats going wrong... i must see an astrologer..hehe ....need your opinion on this...
regards,
hgaurav |
|
|
| |
|
|
|
|
|
Posted: Apr 27, 2012 - 09:34 AM |
|


Joined: Jul 18, 2005
Posts: 62299
Location: (using avr-gcc in) Finchingfield, Essex, England
|
|
|
Quote:
.if flash page is to be written, our program_page (SPM Instructions) should be inside the BLS...
Yes but that's what all the section-start stuff was about.
Oh wait a minute though. I don't see you doing anything to position your functions into that section. What you need is for any functions that do SPM change them as follows:
Code:
void program_page (uint32_t page, uint8_t *buf)
{
becomes
Code:
void BOOTLOADER_SECTION program_page (uint32_t page, uint8_t *buf)
{
That BOOTLOADER_SECTION macro is defined in boot.h as:
Code:
#define BOOTLOADER_SECTION __attribute__ ((section (".bootloader")))
|
_________________
|
| |
|
|
|
|
|