SPI downgrade and a fix

Any bugs you encounter with Flowcode should be discussed here.
Post Reply
mnfisher
Valued Contributor
Posts: 955
http://meble-kuchenne.info.pl
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 104 times
Been thanked: 508 times

Flowcode v10 SPI downgrade and a fix

Post by mnfisher »

A bug that has been reported before - and a simple fix for it.... It might not occur often in the wild...

If you have a cal_spi component and export the properties to top level in an esp32 flowchart - 'downgrading' the program to Arduino Uno (or others) doesn't work correctly - the list of pre-scaler options remains as for the esp32.

Saving/reloading doesn't fix this.

So - a simple python batch file that corrects the chart for you.

You'll need to install BeautifulSoup and lxml ('pip install beautifulsoup4' and 'pip install lxml' at a python command prompt)

Save the following as fix_spi.py (or name of your choice.py)

Code: Select all

#!python3

from bs4 import BeautifulSoup as bs
from sys import argv


def Read(fname):
    global xml
    with open (fname, "r") as f:
        xml = bs(f.read(), 'lxml')
    

if len(argv) < 2 :
    print("Usage 'fix_spi.py infile outfile'")
else:
    Read(argv[1]+ ".fcfx")
    pr = xml.findAll("property")
    for p in pr:
        if p['name'] == 'Prescale':
            p['filter'] = "004Fosc/4\r\n016Fosc/16\r\n064Fosc/64"
    ofn = ""
    if len(argv) > 2:
        ofn = argv[2]
    else:
        ofn = argv[1] + "_spi"
    ofn = ofn + ".fcfx"
    with open(ofn, 'w') as out:
        out.write(str(xml.body.next))
    print("Finished")
Then to fix a program - type

fix_spi.py prog [output]

This will read prog.fcfx and write it out as either prog_spi.fcfx or output.fcfx (if output = prog then it will overwrite the file)

And you should then be able to open and edit the program (you'll need to set Prescaler)

I haven't tried it - but this may affect 'downgrades' to other MCUs - and you might need to alter p['filter'] = "... to suit..

Martin

Post Reply