Marlin: RuntimeError: deque mutated during iteration:

keep getting this error. been tryn for days to get this fixed…maybe someone here can help me out

my set up…ender 3 v2. skr mini e3 v3 main board, pheatus dragonfly BMS hotend, bl touch…tryn to get the platformio.ini to compile. and its fight me tooth and nail

the error

Verbose mode can be enabled via -v, --verbose option

CONFIGURATION: Redirecting...

PLATFORM: ST STM32 (6.1.1) > STM32F103RC (48k RAM. 256k Flash)

HARDWARE: STM32F103RCT6 72MHz, 48KB RAM, 512KB Flash

DEBUG: Current (blackmagic) External (blackmagic, jlink, stlink)

PACKAGES:

  • framework-arduinoststm32-maple @ 2.10000.200103 (1.0.0)

  • tool-stm32duino @ 1.0.2

  • toolchain-gccarmnoneeabi @ 1.70201.0 (7.2.1)

Converting Marlin.ino

LDF: Library Dependency Finder → Library Dependency Finder (LDF) — PlatformIO latest documentation

LDF Modes: Finder ~ chain, Compatibility ~ soft

Found 38 compatible libraries

Scanning dependencies…

Dependency Graph

|-- LiquidCrystal @ 1.5.0

|-- TMCStepper @ 0.7.1

|-- Adafruit MAX31865 library @ 1.1.0

|-- U8glib-HAL @ 0.4.1

|-- Arduino-L6470 @ 0.8.0

|-- SlowSoftI2CMaster @ 1.0.0

|-- LiquidTWI2 @ 1.2.7

|-- SailfishLCD @ 0.0.0+20230708193619

|-- SoftwareSerialM @ 1.0.0

|-- STM32ADC @ 1.0

|-- EEPROM

|-- Wire @ 1.0

|-- USBComposite for STM32F1 @ 0.91

|-- Servo(STM32F1) @ 1.1.2

Building in release mode

RuntimeError: deque mutated during iteration:

File “C:\Users\Aidan.platformio\penv\lib\site-packages\platformio\builder\main.py”, line 182:

env.SConscript(env.GetExtraScripts(“post”), exports=“env”)

File “C:\Users\Aidan.platformio\packages\tool-scons\scons-local-4.5.2\SCons\Script\SConscript.py”, line 598:

return _SConscript(self.fs, *files, **subst_kw)

File “C:\Users\Aidan.platformio\packages\tool-scons\scons-local-4.5.2\SCons\Script\SConscript.py”, line 285:

exec(compile(scriptdata, scriptname, ‘exec’), call_stack[-1].globals)

File “C:\Marlin\BTT-SKR-MINI-V3-For-ENDER-3-PRO-with-BLTouch–master\buildroot\share\PlatformIO\scripts\STM32F103RC_SKR_MINI.py”, line 6:

for define in env[‘CPPDEFINES’]:

please help me out

You use outdated Marlin Firmware. Please update to the latest https://marlinfw.org/

Gonna try it thjs morning, in the case of this fixing me…i love u dude, your my fn hero rn, superman cape and all

Your a mfkn rockstar ivan… i just needed pointed in the right direction…thank you eminencly

The real reason is that in Marlin/buildroot/share/PlatformIO/scripts/marlin.py the iterated environment is getting modified during the iteration in the replace_define() function, update it as follows and the error will be gone:

def replace_define(field, value):
	found_define = None
	for define in env['CPPDEFINES']:
		if define[0] == field:
			found_define = define
			break
	if found_define:
		env['CPPDEFINES'].remove(found_define)
	env['CPPDEFINES'].append((field, value))

I’m writing this, to help people facing this error, because sometimes (as I do now) you need to go back and compile an older version of Marlin to solve when a bug is introduced (bisect)…

3 Likes

Thanks @eoyilmaz for your help. I’m exactly in the situation you describe.

I don’t have the Marlin/buildroot/share/PlatformIO/scripts/marlin.py file in my environment. I’m configuring the 2.0.7.2 version of Marlin. Do you think you can help me ?

Thank you !!

What is the error message saying?

It’s exactly the same message than describes at the beginning of this topic.

The error message should tell you in which file it occurred, e.g. above buildroot\share\PlatformIO\scripts\STM32F103RC_SKR_MINI.py”, line 6.

See also Unable to build Marlin code for SKR Mini E3 v1.2 STM32F103RC_btt - #5 by zz-jaybuck-zz and Trying to compile Marlin 2.1.2 for Ender 3 SKR Mini v2.0 board - #9 by maxgerhardt.

Is it the “STM32F103RC_SKR_MINI.py” file your build script is complaining about, I’m not on 2.0.x and I don’t see that file (and I don’t have that motherboard either), but I’m guessing as the error message is complaining about a line number that is relatively close to the begining of the file it should be an import statement to “marlin.py” and it should be about the “replace_define” function again, try searching for the “marlin.py” file and replace that function with my suggestion…

Hello.
I try to recompile an old Marlin version 2.0.5.3… And the script generating the error is not the same one, but STM32F103VE_longer.py.

I tried to change the script to include the modification above, but obviously, I did something wrong. It compiles, but Marlin does not boot once the code is flashed…

Original code to be modified :

import os
Import("env")

# Relocate firmware from 0x08000000 to 0x08010000
for define in env['CPPDEFINES']:
    if define[0] == "VECT_TAB_ADDR":
        env['CPPDEFINES'].remove(define)
env['CPPDEFINES'].append(("VECT_TAB_ADDR", "0x08010000"))

custom_ld_script = os.path.abspath("buildroot/share/PlatformIO/ldscripts/STM32F103VE_longer.ld")
for i, flag in enumerate(env["LINKFLAGS"]):
    if "-Wl,-T" in flag:
        env["LINKFLAGS"][i] = "-Wl,-T" + custom_ld_script
    elif flag == "-T":
        env["LINKFLAGS"][i + 1] = custom_ld_script

And what I did, which might be wrong…

import os
Import("env")

# Relocate firmware from 0x08000000 to 0x08010000

def replace_define(field, value):
    found_define = None
    for define in env['CPPDEFINES']:
        if define[0] == "VECT_TAB_ADDR":
            found_define = define
            break
    if found_define:
        end['CPPDEFINES'].remove(found_define)
    env['CPPDEFINES'].append(("VECT_TAB_ADDR", "0x08010000"))

custom_ld_script = os.path.abspath("buildroot/share/PlatformIO/ldscripts/STM32F103VE_longer.ld")
for i, flag in enumerate(env["LINKFLAGS"]):
    if "-Wl,-T" in flag:
        env["LINKFLAGS"][i] = "-Wl,-T" + custom_ld_script
    elif flag == "-T":
        env["LINKFLAGS"][i + 1] = custom_ld_script

@eoyilmaz @ivankravets please have a look!!!
TMC drivers do not compile on 2.1.2, and on 2.1.2.1 it does compile I have X OK, and Y not ok, therefore I would like to go back to what worked!!!

Thank you for any help.

So you changed the inline execution of the code

To be a function, that is in never called?

That’s not the same at all. You would need to replace the block with just

# Relocate firmware from 0x08000000 to 0x08010000
for define in env['CPPDEFINES'].copy():
    if define[0] == "VECT_TAB_ADDR":
        env['CPPDEFINES'].remove(define)
env['CPPDEFINES'].append(("VECT_TAB_ADDR", "0x08010000"))

you have a couple of typos and @maxgerhardt 's code should work

Hi gentlemen,

Well, I just tried to make it look like the right thing, and got it awfully wrong!
Seems there is an exact description of the problem there, and the fix… Unable to build Marlin code for SKR Mini E3 v1.2 STM32F103RC_btt - #5 by zz-jaybuck-zz

With all that… fingers crossed.

Thanks a lot.

And I can confirm : IT WORKS, and now, I can also confirm that 2.0.5.3 with its old trinamic driver works…
2.1.2 : Unable to link to the trinamic lib,
2.1.2.1 : same config compiles, but trinamic drivers fail… and stepper get all sorts of strange setup.

Gosh, no warning, no errors, and all I get in M122 is that one of the stepper fails… but with the old libs, it works. It will remain like that!!!

Thanks a lot for the help. What looks simple to you is super hard for me.

Hello,

Im a bit new to re-compiling Marlin code for my Tevo Tornado Gold printer. I have done it a few time to add certain functionalities but now I getting these errors that I believe are related to this thread. All Im trying to do it enable the Host_Action_Commands and re-compile. Would someone be able to assist?
eoyilmaz

Warning! Ignore unknown configuration option monitor_flags in section [env]
Warning! src_filter configuration option in section [env:include_tree] is deprecated and will be removed in the next release! Please use build_src_filter instead
Warning! src_filter configuration option in section [env:DUE] is deprecated and will be removed in the next release! Please use build_src_filter instead
Warning! src_filter configuration option in section [env:esp32] is deprecated and will be removed in the next release! Please use build_src_filter instead
Warning! src_build_flags configuration option in section [env:linux_native] is deprecated and will be removed in the next release! Please use build_src_flags instead
Warning! src_filter configuration option in section [env:linux_native] is deprecated and will be removed in the next release! Please use build_src_filter instead
Warning! src_build_flags configuration option in section [env:simulator_windows] is deprecated and will be removed in the next release! Please use build_src_flags instead
Warning! src_filter configuration option in section [env:SAMD51_grandcentral_m4] is deprecated and will be removed in the next release! Please use build_src_filter instead
Warning! src_filter configuration option in section [env:malyan_M300] is deprecated and will be removed in the next release! Please use build_src_filter instead
Warning! src_filter configuration option in section [env:STM32F103CB_malyan] is deprecated and will be removed in the next release! Please use build_src_filter instead
Warning! src_filter configuration option in section [env:teensy31] is deprecated and will be removed in the next release! Please use build_src_filter instead
Warning! src_filter configuration option in section [env:teensy35] is deprecated and will be removed in the next release! Please use build_src_filter instead
Warning! src_filter configuration option in section [env:teensy36] is deprecated and will be removed in the next release! Please use build_src_filter instead
Warning! src_filter configuration option in section [env:teensy41] is deprecated and will be removed in the next release! Please use build_src_filter instead