Skip to content
Frank edited this page Apr 6, 2020 · 26 revisions

Compiler explorer

Godbolt is a useful tools which shows you the Assembler-code of short code snippets. You can compare different compiler versions, too.

Additional files:

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:

  1. Add a line to boards.txt:

teensy40.build.command.nm=arm-none-eabi-gcc-nm

  1. 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 Toolchain

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:

  1. 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"
  2. 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
  3. Extract it to the new directory - choose overwrite to overwrite the old version (additionnal files from the original version will stay)
  4. Edit bords.txt. There is a line teensy40.build.toolchain=arm/bin/ - change that to teensy40.build.toolchain=arm9/bin/
  5. done :)

Broken objdump for M7 (Teensy 4)

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

Clone this wiki locally