Due to high demand expect some shipping delays at this time, orders may not ship for 3-4 business days. On MLK Day no orders will be shipped.
0

Processing speed on Trinket M0 much slower than Feather M0 E
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Processing speed on Trinket M0 much slower than Feather M0 E

by joxl on Mon Nov 29, 2021 1:40 am

I'm working on a CircuitPython project which I started out developing on the Feather M0 Express. After getting the software sufficiently mature, I moved to a Trinket M0 which I plan to use in the final hardware build. Prior to moving to the Trinket M0, I checked the hardware specs between the Feather M0 Express and the Trinket M0 -- I was mostly concerned about the processor clock speed and the available RAM. Despite the two boards using different variants (ATSAMD21G18 on the Feather M0e, ATSAMD21E18 on the Trinket M0), as far as I can tell they're both identical from an architectural perspective (32-bit, Cortex M0+ @ 48MHz, 32KB RAM, 3.3v logic).

With this in mind, I expected my software to run more-or-less the same on the Trinket M0 as it did on the Feather M0e, but to my dismay, the Trinket M0 spins through my main loop five times slower than the Feather M0e did. The software is identical between the the two boards except for where I changed the `board.<pin>` references to accommodate the different pin layout.

Unfortunately I don't have an oscilloscope to poke around and get hardware measurements, so I can't really *verify* anything other than "my code runs way slower", which isn't entirely helpful from a troubleshooting perspective. I wanted to post here just in case this is a known "issue" where boards with nearly identical MCUs run the same code at drastically different speeds.

I would very much appreciate if anyone has insight on what might be causing the speed difference I'm seeing between these boards. Judging by hardware specs alone, it seems like it should be entirely possible to write CircuitPython code that executes at consistent speeds across both boards, but that's not what I'm observing at all.

Thanks.

_______________________________

More details...

My software is sufficiently complex that it's not trivial to just rip small parts out to identify if there's a specific "area of slowness" on the Trinket, but here are some details for context:

My application is a "digital VU meter" of sorts. The only board peripherals I'm using is a single analog pin to read the raw value from a microphone, and a single digital pin to drive a strip of 10 neopixels (of the 3-wire variant). On the Feather M0e my application refreshes the entire neopixel strip 180+ times per second. With identical code (except the IO pins used), the Trinket M0 only achieves about 36 updates per second. The pins in use on each board are as follows:

Feather M0 Express:
  • board.A1 (mic analog input)
  • board.D12 (neopixel digital output)

Trinket M0
  • board.A1 (mic analog input)
  • board.D3 (neopixel digital output)

Both boards are running recent CircuitPython 7.0.0 releases:
  • Feather M0 Express: adafruit-circuitpython-feather_m0_express-en_US-7.0.0.uf2 (SHA1: 4160abf562555ecb6e8434814c72863109bcbea5)
  • Trinket M0: adafruit-circuitpython-trinket_m0-en_US-7.0.0.uf2 (SHA1: 1bc5e0d93ad4b5f425f1d1589daa33a8e3e7eff1)

I'm using the same `neopixel.mpy` from a recent CircuitPython Bundle on both boards. On the Trinket I needed to install the `adafruit_pixelbuf.mpy` in order to instantiate a `neopixel.NeoPixel` instance (that library seems to come pre-installed on the Feather M0e firmware).

joxl
 
Posts: 25
Joined: Thu Jan 16, 2014 1:29 am

Re: Processing speed on Trinket M0 much slower than Feather

by jerryn on Mon Nov 29, 2021 1:00 pm

I'm using the same `neopixel.mpy` from a recent CircuitPython Bundle on both boards. On the Trinket I needed to install the `adafruit_pixelbuf.mpy` in order to instantiate a `neopixel.NeoPixel` instance (that library seems to come pre-installed on the Feather M0e firmware).


I suspect this is the problem. The pixelbuf module is part of the "core" for the boards with sufficient resources, but it is not included in the Trinket M0 (it is part of the "Full Build")
https://github.com/adafruit/circuitpython/blob/main/ports/atmel-samd/boards/trinket_m0/mpconfigboard.mk#L11

Executing it as a python module will be much slower.

Note: I do not represent Adafruit. This is just what I think is happening.

jerryn
 
Posts: 1630
Joined: Sat Sep 14, 2013 9:05 am

Re: Processing speed on Trinket M0 much slower than Feather

by blakebr on Mon Nov 29, 2021 2:28 pm

Joxl,

You could try this.

Get the schematics for both boards.
Find out what pins A1 and D12 actually connect to on the Feather MO Express CPU.
Find out what those pins from the Feather MO CPU connect to what pins on the Trinket MO
Load the OS that works on the Feather board to the Trinket board.
Use the bastard connection pins.
If the pins are not shared, find an A1 and D? pin pair that are and work on the Feather and test on the Trinket.
Named pins such as SCL/DCL NEOPIXEL will move too.

I know this is ugly and not very elegant but it may get you to where you want.
I to do not work for AdaFruit, so no guarantee given.

Bruce

blakebr
 
Posts: 253
Joined: Tue Apr 17, 2012 6:23 pm

Re: Processing speed on Trinket M0 much slower than Feather

by joxl on Tue Nov 30, 2021 12:30 am

I suspect this is the problem. The pixelbuf module is part of the "core" for the boards with sufficient resources, but it is not included in the Trinket M0 (it is part of the "Full Build")


Ahh, this is a really helpful tip. This certainly hints at a difference in the two boards (i.e. the OS) that could describe the behavior I'm seeing. I'll look deeper into this. Thanks @jerryn.

__________________________

Load the OS that works on the Feather board to the Trinket board.


That's a fantastic troubleshooting sequence. Certainly ugly, but if it helps me pinpoint the source of my issue, that's incredibly helpful. I'm going to give this a try. Thanks @blakebr.

joxl
 
Posts: 25
Joined: Thu Jan 16, 2014 1:29 am

Re: Processing speed on Trinket M0 much slower than Feather

by blakebr on Tue Nov 30, 2021 11:57 am

Joxl,

A possibly ever so slightly less ugly option.

Load the Feather OS to the Trinkit.
Write a small script that toggles A0.
Find what pin A0 shows up on, document.
Then try A1, A2, A3, D1, D2, D3. You get the idea, until all the Trinket pins have been found/defined.
Putting a resistor and LED on each output pin of the Trinkit may speed things up.

Bruce

I like the Pearl saying. 'If it is ugly but works, it is good.'

blakebr
 
Posts: 253
Joined: Tue Apr 17, 2012 6:23 pm

Re: Processing speed on Trinket M0 much slower than Feather

by jerryn on Tue Nov 30, 2021 6:21 pm

The Feather M0 Express build is going to be expecting and external SPI Flash for the File System. I don't think it will run properly on the Trinket M0.
Your mileage may vary ... ;-)

jerryn
 
Posts: 1630
Joined: Sat Sep 14, 2013 9:05 am

Re: Processing speed on Trinket M0 much slower than Feather

by blakebr on Tue Nov 30, 2021 7:42 pm

Jerry,

Drat!

Bruce

blakebr
 
Posts: 253
Joined: Tue Apr 17, 2012 6:23 pm

Re: Processing speed on Trinket M0 much slower than Feather

by joxl on Tue Nov 30, 2021 8:54 pm

I don't think it will run properly on the Trinket M0.


You are correct. I didn't spend any time debugging it (it was getting late), but it sure did fail hard.

For the pin reconnaissance, it wasn't too difficult to cross-reference the port source files for the two boards (feather pins.c, mpconfigboard.h and trinket pins.c, mpconfigboard.h) while using the Adafruit pinout diagrams (feather pinout, and trinket pinout) and the MCU datasheets for making sense of the pin names.

Sidenote: of course this all assumes Adafruit hasn't made any typos in their "PAxx" references anywhere. I don't think I have any probes tiny enough to reliably "fact check" via a continuity test, so the "power, pulse and probe" technique is probably the best way to be 100% certain :)

Using the board sources above, I concluded the two boards only have 3 "broken out" pins in common:
  • PA02 - A0 (DAC) pin on both boards
  • PA07 - D3 (trinket), D9 (feather, aka: BATTERY, VOLTAGE_MONITOR)
  • PA10 - D1 (feather), D13 (trinket, aka: LED)

Being as I'd rather not see the little LED flash like crazy on the Trinket, I'm using PA07 for my neopixel output on both boards and PA02 for my microphone input. Fun fact (new to me anyway), the `microcontroller.pin` module references all the pins by their "hardware name":

Code: Select all | TOGGLE FULL SIZE
>>> import microcontroller.pin
>>> microcontroller.pin.PA02
board.D1
>>> microcontroller.pin.PA07
board.D3
>>> microcontroller.pin.PA10
board.LED

My next step is to see if I can figure out how to build a .uf2 file... I'll keep you posted.

joxl
 
Posts: 25
Joined: Thu Jan 16, 2014 1:29 am

Re: Processing speed on Trinket M0 much slower than Feather

by blakebr on Tue Nov 30, 2021 9:16 pm

Joxl,

Don't discount PA10 too soon.
It may be a good troubleshooting aid during development.
You can move to PA7 when all is well and good.
IMHO

Bruce

P.S. Search "JYETech DSOShell Fully Assembled Portable Oscilloscope" for an O-Scope for about $30 to $35.

blakebr
 
Posts: 253
Joined: Tue Apr 17, 2012 6:23 pm

Re: Processing speed on Trinket M0 much slower than Feather

by blakebr on Wed Dec 01, 2021 2:55 pm

Joxl,

This chunk of code may come in handy.
You will need to import board if you have not.
Code: Select all | TOGGLE FULL SIZE
#################### Figure out what board we have ####################
Pico, Itsy, QTPy, Fthr, ANRC, Chal = False, False, False, False, False, False
brd = board.board_id # Ask the AdaFruit Circuit Python OS what board we are using
print(brd, end=" - ")
#           "12345678901234567890123456789
if  (brd == "raspberry_pi_pico"):           Pico = True # 17
elif(brd == "adafruit_qtpy_rp2040"):        QTPy = True # 20
elif(brd == "adafruit_feather_rp2040"):     Fthr = True # 23
elif(brd == "adafruit_itsybitsy_rp2040"):   Itsy = True # 25
elif(brd == "challenger_rp2040_wifi"):      Chal = True # 22
elif(brd == "challenger_nb_rp2040_wifi"):   Chal = True # 25
elif(brd == "arduino_nano_rp2040_connect"): ANRC = True # 27
else:
    while(True):
        print("Board Not Supported.")
        time.sleep(15)
        pass # raise
print("Board Supported.")
It may make it easier to move your code between boards.
The code can test which board it is running on and set the variables accordingly.

Bruce

blakebr
 
Posts: 253
Joined: Tue Apr 17, 2012 6:23 pm

Re: Processing speed on Trinket M0 much slower than Feather

by joxl on Wed Dec 01, 2021 4:51 pm

I have this instead:

Code: Select all | TOGGLE FULL SIZE
if board.board_id not in ["feather_m0_express", "trinket_m0"]:
    raise ValueError(f"unsupported board: {board.board_id}")

joxl
 
Posts: 25
Joined: Thu Jan 16, 2014 1:29 am

Re: Processing speed on Trinket M0 much slower than Feather

by blakebr on Wed Dec 01, 2021 5:32 pm

Too bad there are no emojis, I'd give you a Thumbs-Up.

Bruce

blakebr
 
Posts: 253
Joined: Tue Apr 17, 2012 6:23 pm

Please be positive and constructive with your questions and comments.