Welcome! Log In Create A New Profile

Advanced

The latest host software does not start with Gen3 electronics. Bug report

Posted by Anton Dmitrievsky 
Hi,

I ask to read this post carefully because I think I've found a critical bug in the firmware.

I've started another thread [forums.reprap.org] but it has less informative title so I start a new topic.

Description of the bug:
I use the Gen3 electronics, latest stable firmware 20110509. I've also tried firmware from svn (rev 4144), the same thing.

To compile firmware I've done the following steps:
1. Uncommented the line #define DEFAULTS MENDEL_GEN3_DEFAULTS, configuration.h, line 19
2. Selected #define TEMP_SENSOR TEMP_SENSOR_AD595_THERMOCOUPLE, configuration.h, line 174.
3. Compiled with arduino, I've got 28366 bytes of firmware.
4. Uploaded it to motherboard.
5. unlink ~/.reprap/reprap.properties
6. Set baud rate to 19200, enabled debug and comms debug, removed space in ttyUSB0
7. ./reprap

I've got the following output:

DEBUG: The distribution preferences file and yours match. This is good. [0,004s/-1312015938816ms]

DEBUG: GCode opening port /dev/ttyUSB0 [0,125s/121ms]

Stable Library

=========================================

Native lib Version = RXTX-2.2pre2

Java lib Version = RXTX-2.1-7

WARNING: RXTX Version mismatch

Jar version = RXTX-2.1-7

native lib Version = RXTX-2.2pre2

DEBUG: Attempting to initialize Arduino/Sanguino [1,230s/1105ms]

comms: G-code: N0 M110 *3 dequeued and sent [3,232s/2002ms]

Nothing happens more.

I've also tried picocom -b 19200 /dev/ttyUSB0 but there is empty screen. It does not react on commands like M105 etc.

Proof of the bug:
I've found temporary files used by arduino to generate the firmware in the following place /tmp/build7110454194171438363.tmp/. The numbers are always different each arduino run.
There is FiveD_GCode_Interpreter.cpp.elf file.

The output of the
$ avr-objdump -s -j .data FiveD_GCode_Interpreter.cpp.elf
command is the following (In fact there is hex output, but I've changed the view for clarity, there is the full output the command in attachments):

FiveD_GCode_Interpreter.cpp.elf:ile format elf32-avr

Contents of section .data:

intercom::ackError(): %s.intercom::checksumError(): %s.%ul. \. .intercom::waitError().intercom::queueError().intercom::waitTimeout().intercom::listenTimeout().intercom::talkTimeout().intercom::corrupt().intercom::queueCollision().intercom::listenCollision().intercom::talkCollision().intercom::inputBufferOverflow().intercomeye popping smileyutputBufferOverflow().Extruder temperature not rising - hard fault..!!.ok.rs . T:. B:. Cangry smiley:. Y:. Z:. E:.PROTOCOL_VERSION:.0.1.FIRMWARE_NAME:.FiveD.FIRMWARE_VERSION:.20101023.FIRMWARE_URL:.http%3A//reprap.org.MACHINE_TYPE:.Mendel.X-EXTRUDER_COUNT:.1.X-FIRMWARE_BUILD_TIMESTAMP.Jul 30 2011 14:46:59.X-REVISION:.1.8.X-CPUTYPE:.X-DEFAULTS:.X-MOVEMENT_TYPE:.X-ENDSTOP_OPTO_TYPE:.X-ENABLE_PIN_STATE:.X-TEMP_SENSOR:.X-BED_TEMP_SENSOR:.X-EXTRUDER_THERMAL_MASS:.X-EXTRUDER_CONTROLLER:.X-THERMAL_CONTROL:.X-DATA_SOURCE:.X-ACCELERATION:.X-HEATED_BED:.X-STEPPER_BOARD:.X-INVERT_X_DIR:.X-INVERT_Y_DIR:.X-INVERT_Z_DIR:.X-ENDSTOPS_MIN_ENABLED:.X-ENDSTOPS_MAX_ENABLED:.X-ENABLE_LINES:.X-DISABLE_X:.X-DISABLE_Y:.X-DISABLE_Z:.X-DISABLE_E:.X-FAST_XY_FEEDRATE:.X-FAST_Z_FEEDRATE:.X-X_STEPS_PER_MM:.X-Y_STEPS_PER_MM:.X-Z_STEPS_PER_MM:.X-E0_STEPS_PER_MM:.// .At Temperature:.%d.Warming Nozzle:.start.Z endstop not hit - hard fault..Y endstop not hit - hard fault..X endstop not hit - hard fault..Serial Error: checksum without line number. Checksum: %d, line received: %s.Serial Error: line number without checksum. Linenumber: %ld, line received: %s.Serial Error: checksum mismatch. Remote (%d) not equal to local (%d), line received: %s.SerialError: Linenumber (%ld) is not last + 1 (%ld), line received: %s.Dud G code: G%d.Dud M code: M%d.Echo: %s.// X endstop inverted( change ENDSTOP_OPTO_TYPE to ENDSTOP_OPTO_TYPE_NORMAL ) or sensor triggered.//Y endstop inverted (change ENDSTOP_OPTO_TYPE toENDSTOP_OPTO_TYPE_NORMAL ) or sensor triggered.// Z endstop inverted ( change ENDSTOP_OPTO_TYPEto ENDSTOP_OPTO_TYPE_NORMAL) orsensor triggered.HINT: If youroptos are all electrically connected right , and the sensors are not blocked ... then you are geting the above message/s because you have not defined the opto correctly in theconfiguration.h.tThe usual Symptom, if you leave your opto/s incorrectly configured is that XY&Z steppers will only turn one way , but the Extruder stepper will turn either.//still not stepping? check ENABLE_PIN_STATE if it should be inverting (it is) .// X-endstop-pin-raw-reading (X_MIN_PIN): .// Y-endstop-pin-raw-reading (Y_MIN_PIN): .// Z-endstop-pin-raw-reading (Z_MIN_PIN): .// temp is .// Temperature reading is likely invalid ( >250 ).//Temperature reading is likely invalid ( < 5 ).// Validate done ( press reset on the arduino/sanguino/mega to re-run ) ...?.........& \

We can see that about 2900 of 4096 bytes of RAM of the atmega644 is wasted for strings store.

The output of
$ avr-objdump -t -j .bss FiveD_GCode_Interpreter.cpp.elf | sort
command is the following:

00800ba6 g .bss 00000000 __bss_start

00800ba6 g O .bss 00000002 ex

00800ba6 l d .bss 00000000 .bss

00800ba8 g O .bss 00000001 extruder_in_use

00800ba9 g O .bss 00000032 talker

00800bdb g O .bss 00000008 cdda

00800be3 g O .bss 00000001 head

00800be4 g O .bss 00000001 tail

00800be5 g O .bss 00000001 led

00800be6 g O .bss 00000002 interruptBlink

00800be8 g O .bss 00000014 where_i_am

00800bfc g O .bss 00000014 zeroHit

00800c10 g O .bss 00000001 endstop_hits

00800c11 g O .bss 00000001 nonest

00800c12 g O .bss 00000080 cmdbuffer

00800c92 g O .bss 00000001 serial_count

00800c93 g O .bss 00000001 comment

00800c94 g O .bss 00000014 fp

00800ca8 g O .bss 00000014 sp

00800cbc g O .bss 0000003e gc

00800cfa l O .bss 00000024 _ZL3ex0

00800d1e l O .bss 0000011b _ZL10talkToHost

00800e39 l O .bss 000000ab _ZL5cdda0

00800ee4 l O .bss 000000ab _ZL5cdda1

00800f8f l O .bss 000000ab _ZL5cdda2

0080103a l O .bss 000000ab _ZL5cdda3

008010e5 g O .bss 00000004 timer0_overflow_count

008010e9 g O .bss 00000004 timer0_clock_cycles
008010ed g O .bss 00000004 timer0_millis

008010f1 g O .bss 00000084 rx_buffer

00801175 g O .bss 00000084 rx_buffer1

008011f9 g O .bss 00000013 Serial

0080120c g O .bss 00000013 Serial1

0080121f g O .bss 00000002 errno

00801221 g .bss 00000000 __bss_end

Here we can see that the table ends at 0x1221 offset while the maximum RAM address for the atmega644 is 0x10ff. Also, I've modified the arduino to produce the output compatible with AVR Studio 4 and uploaded the FiveD_GCode_Interpreter.cpp.elf to AVR Studio. I looked at Memory window and defined that memory looks like avr-objdump shows. You can see the screenshots in memory1 and memory2 files. The screenshots were taken with breakpoint at the beginning of the setup function. The stack pointer was 0x10f6. We can see that it's place of the rx_buffer variable.

Before looking deep to the code, I've tried several setups. One of behaviors I've described in my previous topic. Another was described by Poller here [forums.reprap.org] and Grogyan here [forums.reprap.org] and someone else, but I can't find the topic now. The infinite stststststst response of the firmware caused by stack that was at place of timer0_clock_cycles
and timer0_overflow_count variables which are modified in a interrupt.

The problem does not exists with Arduino Mega, because atmega1280 has 8kb of RAM but if the firmware development will go the same way the RAM will end for atmega1280 too.


Solution:
I've placed all strings to the flash or pgm memory. Now the output of the avr-objdump -s -j .data FiveD_GCode_Interpreter.cpp.elf command looks like this:

Contents of section .data:

800100 205c0020 00212100 6f6b0072 73200020 \. .!!.ok.rs .

800110 543a0020 423a0020 433a2058 3a002059 T:. B:. C: X:. Y

800120 3a00205a 3a002045 3a00302e 31004669 :. Z:. E:.0.1.Fi

800130 76654400 32303130 31303233 00687474 veD.20101023.htt

800140 70253341 2f2f7265 70726170 2e6f7267 p%3A//reprap.org

800150 004d656e 64656c00 31004a75 6c203330 .Mendel.1.Jul 30

800160 20323031 31203135 3a35363a 31300031 2011 15:56:10.1

800170 2e38002f 2f20002e 003f06ff ff010000 .8.// ...?......

800180 0000b62d ...-


The command avr-objdump -t -j .bss FiveD_GCode_Interpreter.cpp.elf states that the section starts at 0x184 and ends at 0x8ff. The size of the firmware increased on less than 1kb and the length is 29220 bytes now.

I've defined some helper functions and macros and the code looks like this (for example):

pgm_sprintf( retnum, "%ul", num );
or
Serial.println(pgm_get_string("V: no endstops enabled ( please enable at least one)"));

See pgm_utils.pde and pgm_utils.h for more details.

The last example shows that there is pgm_get_string function call is necessary until the Sanguino core library will changed.

There is the modified firmware in attachments.



Thanks for all who've read this. I believe that it will be useful.
Attachments:
open | download - avr_objdump_s_j_data_FiveD_GCode_Interpreter_cpp_elf_output (10.4 KB)
open | download - memory1.png (70.4 KB)
open | download - memory2.png (45.6 KB)
open | download - FiveD_GCode_Interpreter.tar.gz (46.6 KB)
The firmware branch is dead. So many people experiencing the problem and nothing happens. It's sadly.
Re: The latest host software does not start with Gen3 electronics. Bug report
August 07, 2011 05:05AM
Great work, Anton. I'd be glad to invite you to hack on Teacup. Teacup uses all flash-stored strings already, and chimes in at about 14 kB, with a feature set equal to the "official" Firmware. No C++, no sweat smiling smiley


Generation 7 Electronics Teacup Firmware RepRap DIY
     
Sorry, only registered users may post in this forum.

Click here to login