Traumflug / Teacup_Firmware

Firmware for RepRap and other 3D printers
http://forums.reprap.org/read.php?147
GNU General Public License v2.0
312 stars 199 forks source link

PROGMEM only single file? #84

Closed Traumflug closed 10 years ago

Traumflug commented 10 years ago

First of all, sorry for pushing 3 commits to experimental yesterday without testing on a printer. I just reset them, they're the first three on the looping branch now.

The trouble came in with this commit: 0908af956a1cce657b9b0b60790334f4a51f328d

To the best of my eyeballs, I can't find something wrong there. A constant array in flash memory, used by an inline function. Compiles without errors, without warnings. Printer axes don't move, though.

To investigate I checked this new function in dda_maths.h and found axis_qn[a] and axis_qr[a] to be always zero. Accordingly I get zero steps to move, of course.

I also tried to access these two arrays from a normal, non-inline function and I get all zeros, too.

A 1:1 copy of one of the arrays directly into the file where it's used works properly, so it's not a typo. The only way to get the code working as intended was to remove the PROGMEM. When stored in RAM, these arrays work fine.

Any ideas?

triffid commented 10 years ago

The avr8 harvard architecture does not have unified address space. Flash is completely separate from ram, and flash addresses may overlap ram addresses. PROGMEM requires the use of a special instruction (LPM) to read flash contents. You need to use the pgmread* macros, eg pgm_read_byte() or pgm_read_word()

see http://www.nongnu.org/avr-libc/user-manual/pgmspace.html

hope that helps :)

On 10 June 2014 07:47, Traumflug notifications@github.com wrote:

First of all, sorry for pushing 3 commits to experimental yesterday without testing on a printer. I just reset them, they're the first three on the looping branch now.

The trouble came in with this commit: 0908af9 https://github.com/Traumflug/Teacup_Firmware/commit/0908af956a1cce657b9b0b60790334f4a51f328d

To the best of my eyeballs, I can't find something wrong there. A constant array in flash memory, used by an inline function. Compiles without errors, without warnings. Printer axes don't move, though.

To investigate I checked this new function in dda_maths.h and found axis_qn[a] and axis_qr[a] to be always zero. Accordingly I get zero steps to move, of course.

I also tried to access these two arrays from a normal, non-inline function and I get all zeros, too.

A 1:1 copy of one of the arrays directly into the file where it's used works properly, so it's not a typo. The only way to get the code working as intended was to remove the PROGMEM. When stored in RAM, these arrays work fine.

Any ideas?

— Reply to this email directly or view it on GitHub https://github.com/Traumflug/Teacup_Firmware/issues/84.

Traumflug commented 10 years ago

Thanks, @triffid, this was on the spot. Problem solved.