Fatal error in compile, but program loaded anyway {SOLVED]

Been happily trying various things with my STM32F401RE board. Then noticed a fatal error flash by, and the program did not load. It looked like it did, but it didn’t. I didn’t figure this out until I noticed the output of a print command in the monitor, and I had deleted the print statement from the program, so it was either uploading an older version, or not uploading anything. Linux Mint 19.3, Zerynth 2.4.1.

UPDATE
I have found that it is only one program that causes this error. A few others I have tried, like a simple blinky and an adc read do not do it. So it’s something in my program. Plan A right now is to delete stuff until the error goes away, then try to figure out what heck I have done. I’ll report back when I have some results.
:-\

UPDATE 2
Well that didn’t take long. It didn’t like a particular construct I was using. I’m using a python dictionary to select a function to execute. like this.

def pMainPage(btnId, modelId):
    print("entered pMainPage(btnId):", btnId)
    modelName = nx.getText(0, modelId) # get model name
    getBtnId = { 2: pMainbUpdate,
                 3: pMainbFly,
                 4: pMainbRangeCheck,
                 5: pMainbModelSelect }
    return (getBtnId.get(btnId)(modelId, modelName))

This calls the specified function for the id of the button passed to the function. Works a treat and, to my way of thinking, is neater than a string of “elif” clauses. But that’s just me.
HOWEVER, in order to create a scope limitation around the functions and the calling function, I put the whole mess inside another dummy function. This way I figured I could use the same variable names (i.e. btnId for button id) in the other cases as well. So it looked like this:

def pMainScope():

    def pMainbUpdate(modelName):
        print("pMain bUpdate newValue:", modelName)
        nx.setText("pUpdateModel", "tTitle", modelName) # set model name in update screen
        s2.write("page pUpdateModel" + myTerm) # display model update screen
        return(0)
    
    def pMainbFly(modelId, modelName):
        print("pMain bFly newValue:", modelName)
        nx.setText("pFly", "tTitle", modelName) # already have model name in inValue
        if modelId < 3:
            nx.setPicId("pFly", "bHome", modelId)
        else:
            nx.setPicId("pFly", "bHome", modelId - 3)
       ... and so on, down to and including the function shown above. 

When I removed the enclosing function definition the problem went away.

Solved

Here’s the output.

Loading settings...
Switched to auto mode
Ready!
Ok
Checking for updates...
[info] Searching for /home/ian/zerynth/Taranis_Single_Stick/__builtins__.py
[info] Searching for /home/ian/.zerynth2/dist/r2.4.1/stdlib/__builtins__.py
[info] ########## STEP 0 - first pass
[info] Compiling module: __main__ @ /home/ian/zerynth/Taranis_Single_Stick/main.py
[info] Searching for /home/ian/zerynth/Taranis_Single_Stick/__builtins__.py
[info] Searching for /home/ian/.zerynth2/dist/r2.4.1/stdlib/__builtins__.py
[info] Compiling module: __builtins__ @ /home/ian/.zerynth2/dist/r2.4.1/stdlib/__builtins__.py
[info] Searching for /home/ian/zerynth/Taranis_Single_Stick/streams.py
[info] Searching for /home/ian/.zerynth2/dist/r2.4.1/stdlib/streams.py
[info] Compiling module: streams @ /home/ian/.zerynth2/dist/r2.4.1/stdlib/streams.py
[info] Searching for /home/ian/zerynth/Taranis_Single_Stick/NextionCommands.py
[info] Compiling module: NextionCommands @ /home/ian/zerynth/Taranis_Single_Stick/NextionCommands.py
[info] Searching for /home/ian/zerynth/Taranis_Single_Stick/screenDict.py
[info] Compiling module: screenDict @ /home/ian/zerynth/Taranis_Single_Stick/screenDict.py
[info] Searching for /home/ian/zerynth/Taranis_Single_Stick/ProcessPage.py
[info] Compiling module: ProcessPage @ /home/ian/zerynth/Taranis_Single_Stick/ProcessPage.py
[info] ########## STEP 0 - second pass
[info] Compiling module: __main__ @ /home/ian/zerynth/Taranis_Single_Stick/main.py
[info] Searching for /home/ian/zerynth/Taranis_Single_Stick/__builtins__.py
[info] Searching for /home/ian/.zerynth2/dist/r2.4.1/stdlib/__builtins__.py
[info] Compiling module: __builtins__ @ /home/ian/.zerynth2/dist/r2.4.1/stdlib/__builtins__.py
[info] Searching for /home/ian/zerynth/Taranis_Single_Stick/streams.py
[info] Searching for /home/ian/.zerynth2/dist/r2.4.1/stdlib/streams.py
[info] Compiling module: streams @ /home/ian/.zerynth2/dist/r2.4.1/stdlib/streams.py
[info] Searching for /home/ian/zerynth/Taranis_Single_Stick/NextionCommands.py
[info] Compiling module: NextionCommands @ /home/ian/zerynth/Taranis_Single_Stick/NextionCommands.py
[info] Searching for /home/ian/zerynth/Taranis_Single_Stick/screenDict.py
[info] Compiling module: screenDict @ /home/ian/zerynth/Taranis_Single_Stick/screenDict.py
[info] Searching for /home/ian/zerynth/Taranis_Single_Stick/ProcessPage.py
[info] Compiling module: ProcessPage @ /home/ian/zerynth/Taranis_Single_Stick/ProcessPage.py
[fatal] Unexpected exception
Traceback (most recent call last):
  File "/home/ian/.zerynth2/dist/r2.4.1/ztc/compiler/astwalker.py", line 120, in visit_Import
    mod = self.hooks.getModuleCode(alias.name)
  File "/home/ian/.zerynth2/dist/r2.4.1/ztc/compiler/compiler.py", line 154, in getModuleCode
    return self.modules[name]
KeyError: 'ProcessPage'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/home/ian/.zerynth2/dist/r2.4.1/ztc/compiler/compilercmd.py", line 80, in _zcompile
    binary, reprs = compiler.compile()
  File "/home/ian/.zerynth2/dist/r2.4.1/ztc/compiler/compiler.py", line 515, in compile
    self.compileModule(self.mainfile)
  File "/home/ian/.zerynth2/dist/r2.4.1/ztc/compiler/compiler.py", line 470, in compileModule
    mc.visit(tree)
  File "/home/ian/.zerynth2/sys/python/lib/python3.5/ast.py", line 245, in visit
    return visitor(node)
  File "/home/ian/.zerynth2/dist/r2.4.1/ztc/compiler/astwalker.py", line 103, in visit_Module
    self.code.addCode(self.visit(stmt))
  File "/home/ian/.zerynth2/sys/python/lib/python3.5/ast.py", line 245, in visit
    return visitor(node)
  File "/home/ian/.zerynth2/dist/r2.4.1/ztc/compiler/astwalker.py", line 122, in visit_Import
    self.hooks.importHook(alias.name,node.lineno,self.filename)
  File "/home/ian/.zerynth2/dist/r2.4.1/ztc/compiler/compiler.py", line 170, in importHook
    self.compileModule(name,line,filename)
  File "/home/ian/.zerynth2/dist/r2.4.1/ztc/compiler/compiler.py", line 470, in compileModule
    mc.visit(tree)
  File "/home/ian/.zerynth2/sys/python/lib/python3.5/ast.py", line 245, in visit
    return visitor(node)
  File "/home/ian/.zerynth2/dist/r2.4.1/ztc/compiler/astwalker.py", line 107, in visit_Module
    self.generateCodeObjs()
  File "/home/ian/.zerynth2/dist/r2.4.1/ztc/compiler/astwalker.py", line 853, in generateCodeObjs
    fcode.addCode(self.genCodeList(node.body))
  File "/home/ian/.zerynth2/dist/r2.4.1/ztc/compiler/astwalker.py", line 92, in genCodeList
    listcode.append(self.visit(cc))
  File "/home/ian/.zerynth2/sys/python/lib/python3.5/ast.py", line 245, in visit
    return visitor(node)
  File "/home/ian/.zerynth2/dist/r2.4.1/ztc/compiler/astwalker.py", line 810, in visit_FunctionDef
    code.addCode(OpCode.BUILD_TUPLE(len(cellvars)))
UnboundLocalError: local variable 'cellvars' referenced before assignment
[info] Searching for device af406b2da1a9355a65335ee005a1e0214af88f6c with alias zs:st_nucleof401re:af406b2da1a9355a65335ee005a1e0214af88f6c
[info] Checking layout...
[info] No active layout found
[info] Searching for vm...
[info] Starting temporary probe...
[info] Checking probe health...
[info] Starting OpenOCD...
GNU MCU Eclipse 64-bits Open On-Chip Debugger 0.10.0+dev-00487-gaf359c18 (2018-05-12-19:25)
Licensed under GNU GPL v2
For bug reports, read
 http://openocd.org/doc/doxygen/bugs.html
Info : auto-selecting first available session transport "hla_swd". To override use 'transport select '.
Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
adapter speed: 2000 kHz
adapter_nsrst_delay: 100
none separate
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Info : Unable to match requested speed 2000 kHz, using 1800 kHz
Info : Unable to match requested speed 2000 kHz, using 1800 kHz
Info : clock speed 1800 kHz
Info : STLINK v2 JTAG v28 API v2 SWIM v17 VID 0x0483 PID 0x374B
Info : using stlink api v2
Info : Target voltage: 3.273448
Info : stm32f4x.cpu: hardware has 6 breakpoints, 4 watchpoints
Info : Listening on port 3333 for gdb connections
[info] Checking probe health...
[info] Ok
Info : accepting 'telnet' connection on tcp/4444
Info : accepting 'telnet' connection on tcp/4444
Info : dropped 'telnet' connection
Info : Unable to match requested speed 2000 kHz, using 1800 kHz
Info : Unable to match requested speed 2000 kHz, using 1800 kHz
adapter speed: 1800 kHz
target halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x080019b0 msp: 0x20000800
0x0801fc00: 00000016 
0x0801fc04: 636e4735 
0x0801fc08: 6b32514b 
0x0801fc0c: 4a576c52 
0x0801fc10: 2d494d35 
0x0801fc14: 36686865 
0x0801fc18: 00007776 
0x0801fc1c: 00000000 
[info] Info : dropped 'telnet' connectionWaiting temporary probe...
Info : accepting 'telnet' connection on tcp/4444
shutdown command invoked
Info : dropped 'telnet' connection
[info] Stopped temporary probe...
[info] Linking bytecode...
[info] File /home/ian/.zerynth2/tmp/fw.bin saved
[info] Starting temporary probe...
[info] Checking probe health...
[info] Starting OpenOCD...
GNU MCU Eclipse 64-bits Open On-Chip Debugger 0.10.0+dev-00487-gaf359c18 (2018-05-12-19:25)
Licensed under GNU GPL v2
For bug reports, read
 http://openocd.org/doc/doxygen/bugs.html
Info : auto-selecting first available session transport "hla_swd". To override use 'transport select '.
Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
adapter speed: 2000 kHz
adapter_nsrst_delay: 100
none separate
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Info : Unable to match requested speed 2000 kHz, using 1800 kHz
Info : Unable to match requested speed 2000 kHz, using 1800 kHz
Info : clock speed 1800 kHz
Info : STLINK v2 JTAG v28 API v2 SWIM v17 VID 0x0483 PID 0x374B
Info : using stlink api v2
Info : Target voltage: 3.278203
Info : stm32f4x.cpu: hardware has 6 breakpoints, 4 watchpoints
Info : Listening on port 3333 for gdb connections
[info] Checking probe health...
[info] Ok
Info : accepting 'telnet' connection on tcp/4444
Info : dropped 'telnet' connection
Info : accepting 'telnet' connection on tcp/4444
Info : Unable to match requested speed 2000 kHz, using 1800 kHz
Info : Unable to match requested speed 2000 kHz, using 1800 kHz
adapter speed: 1800 kHz
target halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x080019b0 msp: 0x20000800
Info : Unable to match requested speed 8000 kHz, using 4000 kHz
Info : Unable to match requested speed 8000 kHz, using 4000 kHz
adapter speed: 4000 kHz
** Programming Started **
auto erase enabled
Info : device id = 0x10016433
Info : flash size = 512kbytes
target halted due to breakpoint, current mode: Thread 
xPSR: 0x61000000 pc: 0x20000044 msp: 0x20000800
wrote 131072 bytes from file /home/ian/.zerynth2/tmp/tmpiwvlgw8i/tmp.bin in 2.900203s (44.135 KiB/s)
** Programming Finished **
** Verify Started **
target halted due to breakpoint, current mode: Thread 
xPSR: 0x61000000 pc: 0x2000002e msp: 0x20000800
verified 16128 bytes in 0.074483s (211.458 KiB/s)
** Verified OK **
** Resetting Target **
Info : Unable to match requested speed 2000 kHz, using 1800 kHz
Info : Unable to match requested speed 2000 kHz, using 1800 kHz
adapter speed: 1800 kHz
Info : dropped 'telnet' connection
Info : accepting 'telnet' connection on tcp/4444
[info] Waiting temporary probe...
shutdown command invoked
Info : dropped 'telnet' connection
[info] Stopped temporary probe...
[info] Done
1 Like