Programming AVR controllers with Freepascal I try to read strings from flash.
In ASM I put the z-pointer to the string address in flash and read by LPM instruction. In AVR-GCC I use PSTR("MyString") and pgm_read_byte(address) to tell the compiler to read from flash.
In Freepascal I tried with
buffer : array[0..16] of char;
buffer := pchar('MyStringMyString');
for i := 0 to 15 do
sendchar(buffer[i]);
This runs, I can put strings to the buffer und send the chars.
But the strings are not read from flash but from ram:
ldi r19,lo8(_sGH_DISPLAYs_Ld3)
ldi r18,hi8(_sGH_DISPLAYs_Ld3) <= get ram address
ldi r26,17 <= count chars
mov r20,r26
mov r30,r19
mov r31,r18 <= ram address to z-pointer
ldi r18,lo8(U_sGH_DEFINE_ss_BUFFER)
ldi r19,hi8(U_sGH_DEFINE_ss_BUFFER) <= buffer address
movw r26,r18 <= buffer address to x-pointer
.Lj33:
ld r0,Z+ <= read from ram
st X+,r0 <= write to buffer
dec r20
brne .Lj33
So I checked the complete hexfile by disassembling and found:
72: a0 e0 ldi r26, 0x00 ; 0
74: b1 e0 ldi r27, 0x01 ; 1
76: d1 e0 ldi r29, 0x01 ; 1
78: ee ee ldi r30, 0xEE ; 238 <= z-pointer to flash address, strings start here
7a: f8 e0 ldi r31, 0x08 ; 8
7c: 02 c0 rjmp .+4 ; 0x82
7e: 05 90 lpm r0, Z+ <= read chars from flash
80: 0d 92 st X+, r0 <= store chars in ram
82: a6 34 cpi r26, 0x46 ; 70
84: bd 07 cpc r27, r29
86: d9 f7 brne .-10 ; 0x7e
So at first all string are copied from flash to ram and then single strings are copied from ram to buffer (also ram). As the ram in the AVR controllers is limited this is no good idea.
Is it possible to tell the compiler to copy strings from flash to buffer directly? Or can I access flash data without copying it to ram?Sorry, there is not much information about programming AVR controllers with Freepascal out there.