Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Discussion options

I have an exception (memory/timeout) showing up when I include select and ssd1306 in the build with the current (pre 1.21, 20230902) code. The V1.20 version works fine for my full example, but running with the new build fails when I include both select and ssd1306. Note that framebuf is necessary, so I needed to change the code memory size. For V1.20.0 and earlier I used a custom link loader specification. For current version I used the codesize setting.
Test board:
SEEED XIAO SAMD21 using the SEEED XIAO Expansion board with OLED and other devices

The test code in testit.py

# note import select is not used
import ssd1306
from machine import I2C, Pin
print("create i2c and display")
i2c = I2C(0, scl=Pin("A5_D5"), sda=Pin("A4_D4"), freq=400000)
display = ssd1306.SSD1306_I2C(128, 64, i2c, addr=60)
display.fill(0)
display.text(" Just Text", 10,30)
display.show()
print("done")

and the manifest.py is:

include("$(PORT_DIR)/boards/manifest.py")
require("ssd1306")

I have included results using:
v1.20.0 with select and ssd1306: works
20230902 master with select and ssd1306: gives exception on instantiation of ssd1306
20230902 master without select and with ssd1306: works
I am not particularly knowledgable about select and had been using it in this case to have a non-blocking poll of keyboard for demonstration code for the XIAO Expansion board. My demonstration code ran fine for multiple XIAO form processors at V1.20.0 and I am just now checking the newer builds with this code.

Here details on builds and results:

Using version 1.20.0 I get (dumpinfo is just a script to ... dump info). This was built with:

make V=0 -j4 -C mpy/ports/samd BOARD=SEEED_XIAO_SAMD21 CFLAGS_EXTRA=-DMP_MODULE_RJS_DISPREGS=0 -DMICROPY_PY_FRAMEBUF=1 -DMICROPY_PY_BUILTINS_COMPLEX=0 -DMICROPY_PY_CMATH=0 -DMICROPY_PY_USELECT=1  LD_FILES=/work/domicropy/mybuilder/samd21x18a_48K.ld sections.ld FROZEN_MANIFEST=/work/domicropy/mybuilder/manifest.basic.py

results:

$ mpremote dumpinfo run testit.py
gc_free: 18944
gc_free: 19824
stack: 476
GC: total: 22080, used: 2320, free: 19760
 No. of 1-blocks: 30, 2-blocks: 13, max blk sz: 31, max free sz: 909
--- Sys Info ---
  platform:        samd
  version:         3.4.0; MicroPython v1.20.0 on 2023-09-03
  implementation:  (name='micropython', version=(1, 20, 0), _machine='Seeed Xiao with SAMD21G18A', _mpy=262)
  path:            ['', '.frozen', 'lib']
  unique_id:       b'\xa6@\xf1UPSKT3.1 \xff\x08\x075'
--- Modules ---
__main__          micropython       uheapq            uselect
_boot             samd              uio               ustruct
_uasyncio         ssd1306           ujson             usys
builtins          uarray            umachine          utime
framebuf          ubinascii         uos               uzlib
gc                ucollections      urandom
math              uctypes           ure
Plus any modules on the filesystem
    dir(machine)
['__class__', '__name__', '__dict__', 'ADC', 'DAC', 'DEEPSLEEP_RESET', 'HARD_RESET', 'I2C', 'PWM', 'PWRON_RESET', 'Pin', 'RTC', 'SOFT_RESET', 'SPI', 'Signal', 'SoftI2C', 'SoftSPI', 'Timer', 'UART', 'WDT', 'WDT_RESET', 'bitstream', 'bootloader', 'disable_irq', 'enable_irq', 'freq', 'idle', 'lightsleep', 'mem16', 'mem32', 'mem8', 'reset', 'reset_cause', 'soft_reset', 'time_pulse_us', 'unique_id']
    dir(mcu)
['__class__', '__name__', '__dict__', 'Flash', 'pininfo']

--- FileSyst: Size=47616   Free=19968
gc_free: 19008
gc_free: 19776
create i2c and display
done

Using master code from 20230902 1700 CDT (-5) (approx!) using select built with:

make V=0 -j4 -C mpy/ports/samd BOARD=SEEED_XIAO_SAMD21 CFLAGS_EXTRA=-DMP_MODULE_RJS_DISPREGS=0 -DMICROPY_PY_FRAMEBUF=1 -DMICROPY_PY_BUILTINS_COMPLEX=0 -DMICROPY_PY_CMATH=0 -DMICROPY_PY_SELECT=1  FROZEN_MANIFEST=/work/domicropy/mybuilder/manifest.basic.py MICROPY_HW_CODESIZE=200K

results:

$ mpremote dumpinfo run testit.py 
gc_free: 18544
gc_free: 19632
stack: 476
GC: total: 22080, used: 2512, free: 19568
 No. of 1-blocks: 31, 2-blocks: 13, max blk sz: 31, max free sz: 881
--- Sys Info ---
  platform:        samd
  version:         3.4.0; MicroPython v1.20.0-435-gc0d4c604e on 2023-09-02
  implementation:  (name='micropython', version=(1, 20, 0), _machine='Seeed Xiao with SAMD21G18A', _mpy=262)
  path:            ['', '.frozen', '/lib', 'lib']
  unique_id:       b'\xa6@\xf1UPSKT3.1 \xff\x08\x075'
--- Modules ---
__main__          collections       machine           samd
_asyncio          deflate           math              select
_boot             framebuf          micropython       ssd1306
_onewire          gc                os                struct
array             heapq             platform          sys
binascii          io                random            time
builtins          json              re                uctypes
Plus any modules on the filesystem
    dir(machine)
['__class__', '__name__', '__dict__', 'ADC', 'DAC', 'DEEPSLEEP_RESET', 'HARD_RESET', 'I2C', 'PWM', 'PWRON_RESET', 'Pin', 'RTC', 'SOFT_RESET', 'SPI', 'Signal', 'SoftI2C', 'SoftSPI', 'Timer', 'UART', 'WDT', 'WDT_RESET', 'bitstream', 'bootloader', 'deepsleep', 'dht_readinto', 'disable_irq', 'enable_irq', 'freq', 'idle', 'lightsleep', 'mem16', 'mem32', 'mem8', 'reset', 'reset_cause', 'soft_reset', 'time_pulse_us', 'unique_id']
    dir(mcu)
['__class__', '__name__', '__dict__', 'Flash', 'pininfo']

--- FileSyst: Size=49152   Free=21504
gc_free: 18800
gc_free: 19568
create i2c and display
Traceback (most recent call last):
  File "<stdin>", line 6, in <module>
  File "ssd1306.py", line 1, in __init__
  File "ssd1306.py", line 1, in __init__
  File "ssd1306.py", line 1, in init_display
  File "ssd1306.py", line 1, in show
  File "ssd1306.py", line 1, in write_data
OSError: 116

Using master code from 20230902 1700 CDT (-5) (approx!) withoutselect built with:

make V=0 -j4 -C mpy/ports/samd BOARD=SEEED_XIAO_SAMD21 CFLAGS_EXTRA=-DMP_MODULE_RJS_DISPREGS=0 -DMICROPY_PY_FRAMEBUF=1 -DMICROPY_PY_BUILTINS_COMPLEX=0 -DMICROPY_PY_CMATH=0 -DMICROPY_PY_SELECT=0 FROZEN_MANIFEST=/work/domicropy/mybuilder/manifest.basic.py MICROPY_HW_CODESIZE=200K

results:

$ mpremote dumpinfo run testit.py 
gc_free: 18544
gc_free: 19632
stack: 476
GC: total: 22080, used: 2512, free: 19568
 No. of 1-blocks: 31, 2-blocks: 13, max blk sz: 31, max free sz: 881
--- Sys Info ---
  platform:        samd
  version:         3.4.0; MicroPython v1.20.0-435-gc0d4c604e on 2023-09-02
  implementation:  (name='micropython', version=(1, 20, 0), _machine='Seeed Xiao with SAMD21G18A', _mpy=262)
  path:            ['', '.frozen', '/lib', 'lib']
  unique_id:       b'\xa6@\xf1UPSKT3.1 \xff\x08\x075'
--- Modules ---
__main__          collections       machine           samd
_asyncio          deflate           math              ssd1306
_boot             framebuf          micropython       struct
_onewire          gc                os                sys
array             heapq             platform          time
binascii          io                random            uctypes
builtins          json              re
Plus any modules on the filesystem
    dir(machine)
['__class__', '__name__', '__dict__', 'ADC', 'DAC', 'DEEPSLEEP_RESET', 'HARD_RESET', 'I2C', 'PWM', 'PWRON_RESET', 'Pin', 'RTC', 'SOFT_RESET', 'SPI', 'Signal', 'SoftI2C', 'SoftSPI', 'Timer', 'UART', 'WDT', 'WDT_RESET', 'bitstream', 'bootloader', 'deepsleep', 'dht_readinto', 'disable_irq', 'enable_irq', 'freq', 'idle', 'lightsleep', 'mem16', 'mem32', 'mem8', 'reset', 'reset_cause', 'soft_reset', 'time_pulse_us', 'unique_id']
    dir(mcu)
['__class__', '__name__', '__dict__', 'Flash', 'pininfo']

--- FileSyst: Size=49152   Free=21504
gc_free: 18800
gc_free: 19568
create i2c and display
done

You must be logged in to vote

Replies: 9 comments · 6 replies

Comment options

At the end of the build log the memory area usage is displayed. What are the figures?

You must be logged in to vote
1 reply
@ricksorensen
Comment options

I'll regenerate the logs shortly, but here are my summaries. I did increase the codesize to 216K (File system shrink to 32K) but that did not make a difference.
V1.20.0 build:

LINK build-SEEED_XIAO_SAMD21/firmware.elf
   text	   data	    bss	    dec	    hex	filename
 193504	    128	   1804	 195436	  2fb6c	build-SEEED_XIAO_SAMD21/firmware.elf
Converted to uf2, output size: 387584, start address: 0x2000
Wrote 387584 bytes to build-SEEED_XIAO_SAMD21/firmware.uf2
make: Leaving directory '/work/domicropy/mybuilder/mpy/ports/samd'
Generated  2023-09-03T09:08:46.390911
elffile:  mpy/ports/samd/build-SEEED_XIAO_SAMD21/firmware.elf last date 2023-09-03T09:08:46.320693
Flash file system: start=034000  size=00bfff
 02f460 (193632) ++++ Code Size+++
 EndBin: 031460   SpaceLeft: 002ba0
 11168(2ba0) space between file system and firmware

Current master, with select:

LINK build-SEEED_XIAO_SAMD21/firmware.elf
Memory region         Used Size  Region Size  %age Used
           FLASH:      195248 B       200 KB     95.34%
             RAM:        1928 B        32 KB      5.88%
Converted to uf2, output size: 390656, start address: 0x2000
Wrote 390656 bytes to build-SEEED_XIAO_SAMD21/firmware.uf2
make: Leaving directory '/work/domicropy/mybuilder/mpy/ports/samd'
Generated  2023-09-02T19:39:52.611856
elffile:  mpy/ports/samd/build-SEEED_XIAO_SAMD21/firmware.elf last date 2023-09-02T19:39:52.545469
Flash file system: start=034000  size=00c000
 02fab0 (195248) ++++ Code Size+++
 EndBin: 031ab0   SpaceLeft: 002550
 9552(2550) space between file system and firmware

Current master, without select:

LINK build-SEEED_XIAO_SAMD21/firmware.elf
Memory region         Used Size  Region Size  %age Used
           FLASH:      193780 B       200 KB     94.62%
             RAM:        1928 B        32 KB      5.88%
Converted to uf2, output size: 387584, start address: 0x2000
Wrote 387584 bytes to build-SEEED_XIAO_SAMD21/firmware.uf2
make: Leaving directory '/work/domicropy/mybuilder/mpy/ports/samd'
Generated  2023-09-02T20:20:38.438028
elffile:  mpy/ports/samd/build-SEEED_XIAO_SAMD21/firmware.elf last date 2023-09-02T20:20:38.367583
Flash file system: start=034000  size=00c000
 02f4f4 (193780) ++++ Code Size+++
 EndBin: 0314f4   SpaceLeft: 002b0c
 11020(2b0c) space between file system and firmware
Comment options

That does not look critical. I tried to locate where the error code 116 comes from, but did not find it yet. The MP error code go up to 115. When the error happens, was any data transferred to the display? It seems that at least the init data was sent. But from the I2C code I cannot tell where error 116 could be raised.

You must be logged in to vote
2 replies
@ricksorensen
Comment options

in <root>/py/mperrno.h is a conditional on MICROPY_USE_INTERNAL_ERRNO which is not set directly for samd. The default in mpconfig.h is 0.
If ZERO : system errno's are used - in this case #define MP_ETIMEDOUT ETIMEDOUT which is the 116.
If non-zero uPy errnos are used: #define MP_ETIMEDOUT (110) // Connection timed out is used.
Not sure what determine usage of this macro but it looks like default is system errors

@robert-hh
Comment options

Thanks. That explains it. Timeout was most likely the reason, only the error numbers did not match. It seems to be set for almost all ports. So I do the same. No impact on the code size.

Comment options

You must be logged in to vote
0 replies
Comment options

I tried to replicate the situation. I've built the binary with from today's master branch:

make V=0 -j4 BOARD=SEEED_XIAO_SAMD21 CFLAGS_EXTRA="-DMP_MODULE_RJS_DISPREGS=0 -DMICROPY_PY_FRAMEBUF=1 -DMICROPY_PY_BUILTINS_COMPLEX=0 -DMICROPY_PY_CMATH=0 -DMICROPY_PY_SELECT=1" MICROPY_HW_CODESIZE=200K

I did not have your manifest.py file, so I skipped it. But I copied ssd1306.mpy to the file system, which is empty besides that file.
The boot prompt is:
MicroPython v1.20.0-435-gc0d4c604e on 2023-09-03; Seeed Xiao with SAMD21G18A
help("modules") shows select.

Sitting on a XIAO expansion board, i2c.scan() returns [60, 81], and your test script works!

When I tried before to run the script without having it placed on the expansion board (== item at I2C 60), I got error 116. Still no clue when that one is raised.

You could try to increase the timeout in samd/machine_i2c.c, line 42. It is set ATM to 100 (ms), assuming that a MICROPY_EVENT_POLL_HOOK call takes at least 1 ms. But even for a timeout, the error code is 110.

You must be logged in to vote
2 replies
@ricksorensen
Comment options

I played with setting Frequency and HW I2C

f <= 393442 seemed to work ... at least hasn't failed yet for several samples
f in [393443,400000] give me an exception
f > 400000 seem to work ... and 400000 is a threshold for clock mode?

SoftI2C has not given that exception yet at any (reasonable) frequency I've tried < 600000

For my current testing I have the 'testit' script on the XIAO flash

I will try with a local ssd1306 mpy instead of frozen version ...

Thanks

@ricksorensen
Comment options

Rebuilt without ssd1306 frozen, got exactly the same hash for version as you had, but I still get the exception at 400000 with HW I2C. I tried multiple expansion boards and got the same results (including same frequency range behaviors.) I erased all the files and only had the testit script and ssd1306.mpy

I'll try some aura calming exercises again.

Thanks again

Comment options

I played with setting Frequency and HW I2C

That's another strange topic. The formula for the baud rate setting of the controller is:
baud = peripheral_freq / (2 * baudrate) - 5 - (rise_time * peripheral_freq) / 2
with peripheral_freq=48MHz, risetime = 200ns.
So there is value change for baud between 393_442 and 393_553, and 400_000 and 400_001, when integer arithmetic is used. But there is not reason why just the value for 400_000, which is 51, should not work, but 50 and 52 do. And why that depends on the select module being present or not.
Still unclear as well, why error 116 pops up.
Single-stepping through the code reveals nothing unexpected.

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

Yes I've seen that error 116 comes up if i2c is not properly defined or no I2C peripheral is connected. Only: I do not see in the code how this error number is set. The samd/machine_i2c only uses the error numbers 5, 19 and 110.

You must be logged in to vote
0 replies
Comment options

maybe some interplay between frozen and compiled.

That would be surprising. And not explain the behavior with varying baud rates.

You must be logged in to vote
1 reply
@ricksorensen
Comment options

Seems to be hardware/system related.
I put a logic analyzer on the I2C bus and the problem changes! My first test with v1.20.0 build f=400K worked, but f=392K gave the 116 error on write_data. I switched to most recent, and haven't see an error yet.

I disconnected the logic analyser and just left an I2C connection cable dangling off the expansiong board with open SDA/SCL (no new device) and the error goes away also. I unplug the free cable and the error comes back. The schematic shows a 4.7k pull-up resistor for SDA/SCL and that is close to what I measure.

Can't explain why I didn't see this on earlier builds, and why the fussy frequency sensitivity ... ringing on signal lines?

Comment options

I had tested the signals with an logic analyzer as well and found them perfect. Looking at them with an oscilloscope shows a slight overshoot of 900mV max, 100MHz, ~2 cycles, at the falling edge. But that is probably caused by using a standard GND clip at the probe. I see that all the time, and it does not affect the operation. The rising edge looks perfect. It's slope is slow.
Rising edge, rise time 325ns, falling egde fall time 3.22 ns.

i2c_samd21_400k

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
🔌
SAMD
Labels
None yet
2 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.