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")
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