How can I make a program permanent on a Nucleo-L432KC #14460
Replies: 15 comments 3 replies
-
On the linker file from the 256k flash it has there's 26k reserved to flash user storage, you can send files to it using shell ( I like to use thonny to send, edit and execute) or usb storage and import it from boot.py or main.py to execute ir automatically. There's too 2 spi buses that you can add a spi flash if you need store more than 26k data. |
Beta Was this translation helpful? Give feedback.
-
You can save files on "/flash" drive, it appears that you are trying to
save on "/" root
Em sáb., 11 de mai. de 2024 11:56, garryp4 ***@***.***>
escreveu:
… I have had no success with Thonny, rshell, or mpfshell. How exactly is it
done?
Here is mpfshell:
E:\MicroPython\Original File>dir
Volume in drive E has no label.
Volume Serial Number is 76FE-FFD3
Directory of E:\MicroPython\Original File
05/07/2024 10:07 AM
.
05/07/2024 10:07 AM ..
04/14/2024 10:27 AM .idea
04/14/2024 10:29 AM 305 boot.py
05/07/2024 10:07 AM 290 MAIN.PY
04/15/2024 09:07 AM 1,025,250 PYBV11-20240222-v1.22.2.hex
3 File(s) 1,025,845 bytes
3 Dir(s) 478,395,441,152 bytes free
E:\MicroPython\Original File>mpfshell com9
Connected to pyboard
** Micropython File Shell v0.9.3, ***@***.*** **
-- Running on Python 3.12 using PySerial 3.5 --
mpfs [/]> put boot.py
Failed to create file: boot.py
mpfs [/]>
Here is rshell:
E:\MicroPython\Original File>rshell -p com9
Traceback (most recent call last):
File "", line 198, in _run_module_as_main
File "", line 88, in
*run_code File "e:\python312\scripts\rshell.exe_main*.py", line 4, in
File "E:\Python312\Lib\site-packages\rshell\command_line.py", line 1, in
import rshell.main
File "E:\Python312\Lib\site-packages\rshell\main.py", line 80, in
import readline
ModuleNotFoundError: No module named 'readline'
E:\MicroPython\Original File>
Here is Thonny error:
PROBLEM IN THONNY'S BACK-END: Exception while handling 'write_file'
(OSError: Could not open file /main.py for writing, output:
Traceback (most recent call last):
File "", line 4, in
OSError: [Errno 19] ENODEV).
See Thonny's backend.log for more info.
You may need to press "Stop/Restart" or hard-reset your MicroPython device
and try again.
Process ended with exit code 1.
This code from Thonny executes on the NUCLEO-L432KC fine, I just can't
store it in the Micro memory so it executes when it powers up:
import machine
import time
Define LED pin
LED_PIN = machine.Pin('PB3', machine.Pin.OUT)
Main loop while True:
# Turn LED on
LED_PIN.on()
# Delay for 1 second
time.sleep(.2)
# Turn LED off
LED_PIN.off()
# Delay for 1 second
time.sleep(.2)
The NUCLEO-L432KC does not have a memory card slot. I chose this NUCLEO
because it has a smaller micro. The circuit I will build doesn't need many
pins.
Thanks
—
Reply to this email directly, view it on GitHub
<#14460 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AK4TXJ66WAJBKQ6MXIN4G53ZBYWRBAVCNFSM6AAAAABHPP5AJGVHI2DSMVQWIX3LMV43SRDJONRXK43TNFXW4Q3PNVWWK3TUHM4TGOJWGIZDE>
.
You are receiving this because you commented.Message ID:
***@***.***
com>
|
Beta Was this translation helpful? Give feedback.
-
how can I do that? Thonny only has an option for 'This Computer and Mycropython Device. I tried this in mpfshell: E:\MicroPython\Original File>mpfshell com9 ** Micropython File Shell v0.9.3, sw@kaltpost.de ** mpfs [/]> put main.py /flash Failed to create file: /flash mpfs [/]> |
Beta Was this translation helpful? Give feedback.
-
Three official tool for this sort of thing is mpremote
If this doesn't work, the filesystem on the device might need reformatting. https://docs.micropython.org/en/latest/reference/filesystem.html
|
Beta Was this translation helpful? Give feedback.
-
This is from the Command Prompt: E:\MicroPython\Original File>So in Thonny I entered this and ran it: STM32import os, vfs, pyb and got this error:
MPY: sync filesystems I really do appreciate your help. I am so used to writing my code in basic, compiling, and flashing a hex file. |
Beta Was this translation helpful? Give feedback.
-
Ok, I don't use thonny, not sure if it's broken things. The instructions I pasted are for the current / latest micropython, Try this
|
Beta Was this translation helpful? Give feedback.
-
I get an error. Pasted from the Command Prompt window: E:\Python312\Scripts>mpfshell com9 ** Micropython File Shell v0.9.3, sw@kaltpost.de ** mpfs [/]> help Documented commands (type help ):EOF cd exec get lcd lpwd md mput mrm put pwd rm mpfs [/]> repl *** Exit REPL with Ctrl+Q *** MicroPython v1.22.2 on 2024-02-22; NUCLEO-L432KC with STM32L432KC
|
Beta Was this translation helpful? Give feedback.
-
I did a REPL to verify the serial connection is good: E:\Python312\Scripts>mpfshell com9 ** Micropython File Shell v0.9.3, sw@kaltpost.de ** mpfs [/]> repl *** Exit REPL with Ctrl+Q ***MicroPython
mpfs [/]> ^Z E:\Python312\Scripts> |
Beta Was this translation helpful? Give feedback.
-
I looked up what options I have with 'import os'. I found I can do some commands but not all. I'm not sure what it means tho. Another paste from the Command window: E:\Python312\Scripts>mpfshell com9 ** Micropython File Shell v0.9.3, sw@kaltpost.de ** mpfs [/]> repl *** Exit REPL with Ctrl+Q ***
|
Beta Was this translation helpful? Give feedback.
-
Now more information. I also happen to have a NUCLEO-G0B1RE. After loading the Micropython hex from GitHub, I opened Thonny and found that boot.py and main.py were already files on the micro. There is no external memory on this NUCLEO so the files need to be on the micro. Is andrewleech correct with"missing is a new module that your micropython must not have yet."? |
Beta Was this translation helpful? Give feedback.
-
As mentioned please try to post command prompt stuff in backticks to format them in a readable way. From the commands I previously suggested, remove the line That os.getenv command you tried doesn't exist on micropython devices, there's no environment as such there. Only desktop / unix port would have access to an environment. |
Beta Was this translation helpful? Give feedback.
-
I did read the three backticks but was using the apostrophe. My mistake. Anyway, here is the attempt. After the 'REPL' I did a reset on the board just to make sure it was connected and gave response. Then a print to make sure Micropython was alive. Then, as suggested by andrewleech, I skipped the unmount command. You can see VfsLfs2 upset it. E:\Python312\Scripts>mpfshell com9 ** Micropython File Shell v0.9.3, sw@kaltpost.de ** mpfs [/]> repl *** Exit REPL with Ctrl+Q ***
The reason I'm using the L432KC flavor is the circuit I intend to build once I learn enough does not need even close to 64 pins. It would not even use 32 pins. And I need to keep the real estate to a minimum. I really do appreciate the help. |
Beta Was this translation helpful? Give feedback.
-
Ah ok, looking at that board config it's a bit old, has LFS1 enabled but not 2 Can try again with VfsLfs1 instead or VfsFat is also probably enabled, though it's not as robust as LFS |
Beta Was this translation helpful? Give feedback.
-
That did it! I flashed a program that blinks the LED, power cycled it, and the LED is flashing. Thank you both so much. Now to get on with learning micropython. How can I tell how much flash memory there is? |
Beta Was this translation helpful? Give feedback.
-
Use os.statvfs("/flash") that will return drive stats, use block size and
free blocks stats to calc free space on device.
Em seg., 13 de mai. de 2024 12:20, garryp4 ***@***.***>
escreveu:
… That did it! I flashed a program that blinks the LED, power cycled it, and
the LED is flashing.
Thank you both so much. Now to get on with learning micropython. How can I
tell how much flash memory there is?
—
Reply to this email directly, view it on GitHub
<#14460 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AK4TXJ7MFPERF5VHR7JCQWLZCDK33AVCNFSM6AAAAABHPP5AJGVHI2DSMVQWIX3LMV43SRDJONRXK43TNFXW4Q3PNVWWK3TUHM4TIMRSGQ3TE>
.
You are receiving this because you commented.Message ID:
***@***.***
com>
|
Beta Was this translation helpful? Give feedback.
-
I am new to Micropython and trying to learn how to make a program permanent on the micro memory so it executes when powered on, The last 15 or so years I have built a number of circuits based on 8 bit Microchip PIC's and programmed in Basic. None of the circuits needed more horsepower than the 8 bit micro's. Now I need more horsepower so bought a Nucleo-l432kc to learn on. I have Micropython loaded using the STCube programmer and can do REPL all day. So far I have spent about 4 days trying to find how to make a file system on the micro so I can load main.py and execute it when it's powered on. I have tried rshel, mpfshell, storing on the micro with Thonny, os.mount, but have not gotten anywhere. Am I even approaching this the correct way?
Any help would be greatly appreciated.
Beta Was this translation helpful? Give feedback.
All reactions