Teensy 3.2 with OctoWS2811, can I swap out the Teensy 3.2 for Teensy 4.0?

Status
Not open for further replies.

chris.nz

Well-known member
I have a project that's about 15k lines of code, using a Teensy 3.2 and OctoWS2811 board to control around 700 LEDs. My code is using FastLED 3.4.0 and OctoWS2811 1.4.0 to drive the LEDs.

I also have various other modules/components connected, as follows:

Bluetooth module (Rx pin 0, Tx pin 1)
APDS-9960 Gesture sensor (interrupt on pin 17, SDA0/SCL0 on pins 18 & 19)
MAX9814 Microphone (pin 23)
Rotary Encoder (pins 24, 25, 33)
Potentiometer (pin 26)
Flame sensor (pin 27)
Alcohol sensor (pin 28)
Planned future use (pins 29, 30, 31)

I want to upgrade the project to use a Teensy 4.0 instead of 3.2, primarily because my current codebase uses 99.3% of available space on the 3.2, but also because I could do with the additional CPU power. I understand I'll need to update to the latest Github verison of OctoWS2811 (as per https://www.searle.me.uk/2021/05/19/teensy-4-with-fastled/). I'm also aware that any code (e.g. LED patterns) tied to the CPU's clock frequency will need tweaking. Other than that, am I right in thinking that I can swap in the Teensy 4.0 and everything should work fine?
 
You will need to get this FastLED, or install 1.56-beta3 (when it's published... should be a matter of days).

https://github.com/PaulStoffregen/FastLED

If you haven't already tried setting Tools > Boards to Teensy 4.0 and click Verify, at least give that a quick try. If you're running low on code space, you might find that Teensy 4.0 only helps if you add FLASHMEM to several functions that take a lot of code space, since ITCM RAM is used to speed up code execution.
 
Thanks Paul. I'm using CLion with PlatformIO, so updated my platformio.ini config as follows:
Code:
board = teensy40
lib_deps =
  https://github.com/PaulStoffregen/FastLED
  https://github.com/PaulStoffregen/OctoWS2811
My project didn't quite build successfully with that change. For some reason the analog pin #defines (PIN_A0, PIN_A1, ...) and constants (A0, A1, ...) from pins_arduino.h were no longer being recognised in my code. I changed my code to just use the equivalent digital pin integer values directly (e.g. 26 instead of A15) and the project then built fine. Note that keeping the new FastLED and OctoWS2811 libraries, but reverting the board to teensy31, did still compile OK with the analog pins.

Thanks for the pointer regarding FLASHMEM/ITCM RAM. Building my project with teensy32 logs the following:
Code:
RAM:   [==        ]  21.5% (used 14108 bytes from 65536 bytes)
Flash: [==========]  98.3% (used 257796 bytes from 262144 bytes)
Building with teensy40 instead logs:
Code:
teensy_size: Memory Usage on Teensy 4.0:
teensy_size:   FLASH: code:116712, data:88860, headers:8440   free for files:1817604
teensy_size:    RAM1: variables:107200, code:114672, padding:16400   free for local variables:286016
teensy_size:    RAM2: variables:25792  free for malloc/new:498496
Am I right in thinking that ITCM RAM is the same thing as RAM1, and is 512KB? If so I should be fine, but appreciate I might have to tag startup code etc with FLASHMEM, and maybe move some static data into RAM2 with DMAMEM if things do get tight again. [EDIT: looks like that isn't correct, I've just found https://forum.pjrc.com/threads/58863-FASTRUN-feature-on-Teensy-4-0 and https://forum.pjrc.com/threads/57326-T4-0-Memory-trying-to-make-sense-of-the-different-regions which explain the memory+flash layout clearly. ITCM is allocated in 32KB blocks, and some of the 512KB will need to be kept aside for DTCM]

All in all it looks like I should be able to upgrade to the 4.0 pretty easily, so I'll likely order one in the near future and give it a go.
 
Last edited:
Status
Not open for further replies.
Back
Top