-
Notifications
You must be signed in to change notification settings - Fork 5
Godbolt is a useful tools which shows you the Assembler-code of short code snippets. You can compare different compiler versions, too.
- https://godbolt.org/z/i4dL_i (GCC 5.4, AVR - Teensy 2.x)
- https://godbolt.org/z/y4oh33 (GCC 5.4.1, Arm-Cortex M0+ - Teensy LC)
- https://godbolt.org/z/uVo6fG (GCC 5.4.1, Arm-Cortex M4 - Teensy 3.x)
- https://godbolt.org/z/Qc5dNE (GCC 5.4.1, Arm-Cortex M7 - Teensy 4)
Teensyduino produces additional files, which are useful if you want to dig more in to the internals or for optimizing.
In principle this should be possible with any of the build systems. Teensyduino creates an .LST and a .SYM file in the build directory.
There is nothing that can't be improved - the generated .SYM file is a bit confusing because the tool nm is not used. But we can easily change that:
Example for Teensy 4:
- Add a line to boards.txt:
teensy40.build.command.nm=arm-none-eabi-gcc-nm
- Add a line to platform.txt:
recipe.hooks.postbuild.4.pattern="{compiler.path}stdout_redirect" "{build.path}/{build.project_name}.symnm" "{compiler.path}{build.toolchain}{build.command.nm}" -n -S --defined-only -C "{build.path}/{build.project_name}.elf"
Now when we do a new build, an additional .symnm file is created, which is clearer and sorted -- and therefore easier to read.
Newer Toolchains are not always better. The one Teensyduino uses is quite old - but good. If you want to try a newer one, that's easyly doable:
- There is a directory "arm" under Arduino/hardware/tools - copy the whole directory and name it i.e. "arm9" - in result, you should have two directories now, "arm" and "arm9"
- Download (the zip-file) a newer toolchain from https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-rm/downloads
- Extract it to the new directory - choose overwrite to overwrite the old version (additionnal files from the original version will stay)
- Edit bords.txt. There is a line
teensy40.build.toolchain=arm/bin/
- change that toteensy40.build.toolchain=arm9/bin/
- done :)
The objdump for the current GCC is broken and emitts more or less unreadable lst files. Copying an objdump from a newer (GCC 9) toolchain to the GCC folder fixes this. Here the output of a working objdump
00000060 <setup>:
#include "Arduino.h"
void setup()
{
pinMode(LED_BUILTIN,OUTPUT);
60: movs r1, #1
62: movs r0, #13
64: b.w 150 <pinMode>
00000068 <loop>:
return (CORE_PIN13_PINREG & CORE_PIN13_BITMASK) ? 1 : 0;
68: ldr r3, [pc, #36] ; (90 <loop+0x28>)
6a: ldr r2, [r3, #8]
6c: tst.w r2, #8
CORE_PIN13_PORTCLEAR = CORE_PIN13_BITMASK;
70: mov.w r2, #8
return (CORE_PIN13_PINREG & CORE_PIN13_BITMASK) ? 1 : 0;
74: bne.n 82 <loop+0x1a>
}
void loop()
{
digitalWriteFast(LED_BUILTIN,!digitalReadFast(LED_BUILTIN));
delay(500);
76: mov.w r0, #500 ; 0x1f4
CORE_PIN13_PORTSET = CORE_PIN13_BITMASK;
7a: str.w r2, [r3, #132] ; 0x84
7e: b.w 94 <delay>
82: mov.w r0, #500 ; 0x1f4
CORE_PIN13_PORTCLEAR = CORE_PIN13_BITMASK;
86: str.w r2, [r3, #136] ; 0x88
8a: b.w 94 <delay>
8e: nop
90: .word 0x42004000
See https://forum.pjrc.com/threads/58814-Code-generated-for-Teensy40?p=224844&viewfull=1#post224844
Teensy is a PJRC trademark. Notes here are for reference and will typically refer to the ARM variants unless noted.