PDA

View Full Version : TeensyLoader seems to choke on large .hex files



dhylands
01-04-2014, 07:04 AM
I'm trying to port micropython to the Teensy 3.1.

My micropython.elf file looks like:


micropython.elf: file format elf32-little

Sections:
Idx Name Size VMA LMA File off Algn
0 .text 000211a0 00000000 00000000 00008000 2**3
CONTENTS, ALLOC, LOAD, READONLY, CODE
1 .ARM.exidx 00000008 000211a0 000211a0 000291a0 2**2
CONTENTS, ALLOC, LOAD, READONLY, DATA
2 .usbdescriptortable 000000a0 1fff8000 1fff8000 00038000 2**2
ALLOC
3 .usbbuffers 00000360 1fff80a0 1fff80a0 00038000 2**0
ALLOC
4 .data 00000664 1fff8400 000211a8 00030400 2**2
CONTENTS, ALLOC, LOAD, DATA
5 .bss 00000580 1fff8a64 0002180c 00030a64 2**2
ALLOC
6 .ARM.attributes 0000002f 00000000 00000000 00030a64 2**0
CONTENTS, READONLY
7 .comment 0000003b 00000000 00000000 00030a93 2**0
CONTENTS, READONLY
8 .debug_frame 000016a0 00000000 00000000 00030ad0 2**2
CONTENTS, READONLY, DEBUGGING


When I call


/home/dhylands/arduino-1.0.5/hardware/tools/teensy_post_compile -file="micropython" -path="/home/dhylands/micropython/micropython/teensy" -tools="/home/dhylands/arduino-1.0.5/hardware/tools"
Teensy Loader could not find the file micropython


And teensy loader gui reports micropython.hex (unreadble).

The Verbose log from TeensyLoader shows:


23:55:35: remote connection opened
23:55:35: remote cmd: "comment: Teensyduino 1.18-rc1 - LINUX64"
23:55:35: remote cmd: "dir:/home/dhylands/micropython/micropython/teensy/"
23:55:35: remote cmd: "file:micropython.hex"
23:55:35: ihex: parse error line 8193

23:55:35: remote connection closed

line 8193 appears to be where the second 64K block ends and the third begins (line 8193 is the line before the :02... line)


:10FFE0006E206E616D653E20657870656374656432
:10FFF000206174206D6F73742025642061726775B1
:020000022000DC
:100000006D656E74732C20676F74202564004D50ED
:100010005F4F424A5F49535F545950452873656C9E


I used the following command to create the .hex file:


/home/dhylands/arduino-1.0.5/hardware/tools/arm-none-eabi/bin/arm-none-eabi-objcopy -O ihex -R .eeprom "micropython.elf" "micropython.hex"


Does teensy loader only support 128K ?

Dave Hylands

LenSamuelson
01-04-2014, 02:34 PM
Hi Dave,

I've been using the linux-only loader for my somewhat Arduino-independent work, and made a small modification to the code that ostensibly supports the Teensy 3.1. I added an else-if block to support the 256 kbyte flash capacity, leaving the code otherwise unmodified.




} else if (strcasecmp(arg+6, "mk20dx128") == 0) {
code_size = 131072;
block_size = 1024;
} else if (strcasecmp(arg+6, "mk20dx256") == 0) {
code_size = 262144;
block_size = 1024;
} else {
die("Unknown MCU type\n");
}


The compilation command line I use is also simple. The resulting executable runs so quickly that (I just noticed that) I didn't bother to compile it with the optimizer.


gcc -o lxload256 -DUSE_LIBUSB load_linux_only.c -lusb

Funny that you're porting MicroPython... I backed it too, both to support Damien's work and to get access to the code and to try porting it to the Teensy 3.1. I've recently become rather loaded with day-job responsibilities and haven't started it. I would enjoy hearing what challenges you are running into.

dhylands
01-04-2014, 04:36 PM
Hi Len,

Thanks. It seems to be failing with the same error message (no surprise there), but at least now that I have source I can debug the problem.

The port has been relatively straight forward so far. The biggest issue I've faced is that micropython is pure C code, and the Arduino support code for the teensy is C++. So I'm using main.cpp and the biggest issue is some clash over the use of bool. I've hacked around it using a #define and a tweak to one of the micropython files.

The cleaner solution would be to take the "essence" out of the Arduino support stuff and code it as C, but for now I think its easier to just use it as-is.

The unix port of micropython compiled and ran out of the box. I actually started with that because it was simpler than the STM port. Both the unix and STM ports seem to assume a microSD card for importing modules from, so I'll probably need to figure that part out eventually.

Once I get the repl loop working (no I/O support - just the basic python support), I'll make a fork and commit.

dhylands
01-04-2014, 05:07 PM
Hi Len,

I got the loader working with the following additional changes:


2404 >diff ~/Downloads/load_linux_only.c load_linux_only.c
270a271,272
> libusb_teensy_handle = open_usb_device(0x16C0, 0x0483); // testing only
> if (libusb_teensy_handle) return 1;
772c774
< #define MAX_MEMORY_SIZE 0x20000
---
> #define MAX_MEMORY_SIZE 0x40000

With this loader, I have to press the button on my Teensy 3.1, whereas with the GUI version I don't.

Do you (or anyboy else) know what needs to be done to get it to work like the GUI one?

PaulStoffregen
01-04-2014, 08:41 PM
Opps, looks like this is indeed a bug. I'll work on a fix this weekend.

PaulStoffregen
01-24-2014, 09:28 PM
Just a quick followup on this old thread. This bug was fixed in 1.18-rc2 (http://forum.pjrc.com/threads/24796-Teensyduino-1-18-Release-Candidate-2-Available).

ftrias
10-15-2015, 01:32 AM
Sorry to revive an old thread, but this tripped me up for a few days with a very large hex file. On Github, teensy_loader_cli.c has


809: #define MAX_MEMORY_SIZE 0x20000

But should it have the following to fully support the Teensy 3.1 & 3.2?


809: #define MAX_MEMORY_SIZE 0x40000