Jane Medium : Write the python Script program , It can be automatically generated MicroPython Internal execution procedures , With the help of STM32-BOOTLOADER adopt REPL send out MicroPython, from MicroPython Finish right SD In the card main.py Empty or update files . This requires the original main.py Can return to REPL, And STM32-BOOTLOADER Cooperate with the download program . Otherwise it needs to pass USB SD The card reader / writer is complete for SD In the card main.py Modification of .
key word
: MicroPython,MM32F3277,mainpy
stay Design with SD Card MM32F3277 MicroPython Experiment board Tested with SD Card MM32F3277 MicroPython Experiment board . The circuit is portable MicroPython From MindMotion Su Yong (2021-11-5 edition ), Confirm after power on SDIO Whether the port is connected SD card ( Now this version needs SD The capacity of the card is greater than 4Gb), And detect whether there is main.py file . If you find main.py, Start execution main.py.
about SD card main.py The file of , Often need another SD The card reader has the functions of writing and deleting by the computer . The following tests whether you can use MicroPython Software completion for main.py Modification and stored procedure .
▲ chart 1.1.1 Reading and writing SD card USB Connecting socket
In the current version , There is no direct support for SD Instructions for deleting files in the card . However, with the help of the write function , The original main.py Empty the file .
First , Use SD card USB Reader writer , stay SD Write a test... Into the card main.py Program .
from machine import Pin
import utime
for _ in range(10):
print(_)
utime.sleep_ms(100)
The test circuit is after the upper point , Will execute first main.py, Showing 10 After a number , Retreat to REPL state .
[Y] sdcard ready.
[Y] file system on sdcard ready.
[Y] run the main.py on disk ...
0
1
2
3
4
5
6
7
8
9
[Y] done. 1
MicroPython v1.16 on 2021-11-05; MB_F3270 with MM32F3277G7P
>>>
Write a test program for SD In the card main.py To empty .
from machine import Pin
import utime
with open('main.py', 'w') as f:
f.write('')
Reset MicroPython...
Wait for MicroPython coming back...
Download MicroPython : 22 lines/507 characters.
Begin to download program...
-------------------------------------------------------------------------
0
>>>
Power on to execute , Here is the display information . You can see , here MicroPython
Although... Was detected main.py
The existence of , But because of main.py
It's an empty file , So go straight back to REPL .
[Y] sdcard ready.
[Y] file system on sdcard ready.
[Y] run the main.py on disk ...
[Y] done. 1
MicroPython v1.16 on 2021-11-05; MB_F3270 with MM32F3277G7P
>>>
Write files to SD In the card main.py, The program to be written needs to be programmed into an executable program , Well main.py The procedure is MicroPython open main.py Parameters to be written later .
Here's what needs to be done in SD Card write main.py Code .
from machine import Pin
import utime
for _ in range(10):
print(_)
utime.sleep_ms(100)
To write Python Script program pymain.py. Its function :
#!/usr/local/bin/python
# -*- coding: gbk -*-
#============================================================
# PYMAIN.PY -- by Dr. ZhuoQing 2021-11-07
#
# Note:
#============================================================
from head import *
from tsmodule.tsstm32 import *
#------------------------------------------------------------
pastestr = ''
if len(sys.argv) == 1:
tspcopyclipboard()
pastestr = clipboard.paste().replace('\r', '').replace('\n', '\\n')
writestr = 'with open("main.py", "w") as f:\n f.write("%s")\n\n'%pastestr
clipboard.copy(writestr)
stm32cmd("MPDLD")
tspfocuswindow("TEASOFT:1")
printf('\a')
#------------------------------------------------------------
# END OF FILE : PYMAIN.PY
#============================================================
Use TEASOFT Edit downloaded main.py Program , Do the following pymain Program .
After testing , The above process meets the design function .
Complete the above functions , need MicroPython Can return to REPL Talent . If the original main.py It's a dead cycle , Cannot have external conditions to return to REPL, Then the above procedure cannot complete the work . Only through USB SD The reader / writer completes for main.py The removal of .
Ed Yes python Script program , It can be automatically generated MicroPython Internal execution procedures , With the help of STM32-BOOTLOADER adopt REPL send out MicroPython, from MicroPython Finish right SD In the card main.py Empty or update files .
This requires the original main.py Can return to REPL, And STM32-BOOTLOADER Cooperate with the download program . Otherwise it needs to pass USB SD The card reader / writer is complete for SD In the card main.py Modification of .
#!/usr/local/bin/python
# -*- coding: gbk -*-
#============================================================
# PYMAIN.PY -- by Dr. ZhuoQing 2021-11-07
#
# Usage:
# pymain * # Clear main.py content
# pymain # Write the current edit file into micropython main.py
#
# Note:
#============================================================
from head import *
from tsmodule.tsstm32 import *
#------------------------------------------------------------
pastestr = ''
if len(sys.argv) == 1:
tspcopyclipboard()
pastestr = clipboard.paste().replace('\r', '').replace('\n', '\\n')
printf("Write the main.py code.")
else:
printf("Clear MicroPython main.py.")
writestr = 'with open("main.py", "w") as f:\n f.write("%s")\n\n'%pastestr
clipboard.copy(writestr)
stm32cmd("MPDLD")
tspfocuswindow("TEASOFT:1")
printf('\a')
#------------------------------------------------------------
# END OF FILE : PYMAIN.PY
#============================================================
■ Links to related literature :
● Related chart Links :