0

try to run Python on SD with STM32F405
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

try to run Python on SD with STM32F405

by ALTENTB on Thu Sep 16, 2021 5:39 am

We're using a STM32F405 Express microcontroller in order to develop a machine learning algorithm. It consists in a python main code (315kB) and pyton libraries (about 1GB including 400MB tensoflow library).
Since there is no room enough to load sofware into microcontroller memory is it possible to use SD card ? If so can you explain us the procedure to run our code in SD card ?

Thank you for your help

B.R.

ALTENTB

ALTENTB
 
Posts: 2
Joined: Thu Sep 16, 2021 5:35 am

Re: try to run Python on SD with STM32F405

by jerryn on Thu Sep 16, 2021 6:22 am

Here is a code example that will mount the SDCard and add it to your path so you can just import modules from the SDCard.
Code: Select all | TOGGLE FULL SIZE
import os
import board
import sdioio
import storage
import sys
sd = sdioio.SDCard(clock=board.SDIO_CLOCK,command=board.SDIO_COMMAND,data=board.SDIO_DATA,frequency=25000000)
vfs = storage.VfsFat(sd)
storage.mount(vfs, '/sd')
sys.path.append("/sd")
sys.path.append("/sd/lib")


So if you put a file neame hello.py on the SDCard, you can now just use
import hello
You can also put files int a folder named "lib" on the SDCard and they will be found by "import"

However, I expect you will have trouble running code that complex since you will likely still run out of RAM.

Note: I do not represent Adafruit. Just trying to help.

jerryn
 
Posts: 1549
Joined: Sat Sep 14, 2013 9:05 am

Re: try to run Python on SD with STM32F405

by ALTENTB on Thu Sep 16, 2021 8:33 am

Thank you for your quick answer :)
We meet another issue : it seems MicroPython doesn't allow to use all libraries we need : we use python libraries which are not included in MicroPython. We Don't know if we can use a Full python workspaceon these boards.
B.R.

ALTENTB
 
Posts: 2
Joined: Thu Sep 16, 2021 5:35 am

Re: try to run Python on SD with STM32F405

by jerryn on Thu Sep 16, 2021 8:44 am

The above example was for CircuitPython, not MicroPython. I'm sorry if I misunderstood your request.
As I noted, the main limitation will be the amount of RAM available on the board. I doubt you'll be able to use may of the standard Python libraries.

jerryn
 
Posts: 1549
Joined: Sat Sep 14, 2013 9:05 am

Re: try to run Python on SD with STM32F405

by tannewt on Thu Sep 16, 2021 2:00 pm

It sounds to me like you want a single board computer running CPython on Linux. Microcontrollers can't really do anything in the 10+ MB range.

tannewt
 
Posts: 2631
Joined: Thu Oct 06, 2016 8:48 pm

Please be positive and constructive with your questions and comments.