Booting from SD card

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
nikhiledutech
Posts: 118
Joined: Wed Dec 27, 2017 8:52 am

Booting from SD card

Post by nikhiledutech » Mon Apr 30, 2018 7:07 am

Hello,

I am currently using STM32F4 disc board with micropython. I want to boot from SD card. So what steps I have to follow.

At present the following line of code are present in boot.py file.

Code: Select all


# boot.py -- run on boot-up
# can run arbitrary Python, but best to keep it minimal

import machine
import pyb
#pyb.main('main.py') # main script to run after this one
#pyb.usb_mode('VCP+MSC') # act as a serial and a storage device
#pyb.usb_mode('VCP+HID') # act as a serial device and a mouse

Do i need to uncomment anything ?
Or
I can directly copy boot.py and main.py file in my sd card, and it will automaticly boot from SD Card.

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Booting from SD card

Post by dhylands » Mon Apr 30, 2018 4:58 pm

That's correct. If you create a file called SKIPSD in the internal flash then it won't boot from the sdcard, otherwise it will boot from the sdcard.

User avatar
marfis
Posts: 215
Joined: Fri Oct 31, 2014 10:29 am
Location: Zurich / Switzerland

Re: Booting from SD card

Post by marfis » Mon Apr 30, 2018 7:04 pm

SKIPSD - that is a nice piece of information, thanks!

nikhiledutech
Posts: 118
Joined: Wed Dec 27, 2017 8:52 am

Re: Booting from SD card

Post by nikhiledutech » Wed May 02, 2018 4:35 am

Hey,

At present my PYB flash drive have main.py , boot.py , pybcdfc.inf and readme file.

I have copied all the files to SD card, and tried to boot from SD Card but it didn't boot from SD Card.


Any suggestions ?

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Booting from SD card

Post by Roberthh » Wed May 02, 2018 7:58 am

Take care that the SD card has only one (1) partition with a FAT file system. Some OSes add hidden partitions, which I found to confuse the PyBoard.

nikhiledutech
Posts: 118
Joined: Wed Dec 27, 2017 8:52 am

Re: Booting from SD card

Post by nikhiledutech » Wed May 02, 2018 11:59 am

There is only one partion with FAT file system.

i forget to tell,
I am using STM32F407 disc board which don't have any onboard SD card slot. I have mounted discovery board on another application specific interfacing kit, having MMC card slot.

I have copied the both main.py and boot.py in sd card and inserted in MMC Slot. Still i am unable to boot from SD Card.

Still there any way to boot from SD card. Cant we manually mount sd card.

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Booting from SD card

Post by Roberthh » Wed May 02, 2018 12:18 pm

At least you can have main.py on the SD card, if you mount th sd card in your flash based boot.py and tell MP via pyb.main() to use main.py or any other script instead from the SD card.

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Booting from SD card

Post by dhylands » Wed May 02, 2018 3:33 pm

OK - The STM32F4DISC board definition doesn't enable the sdcard by default.

I think that you'd need to add some definitions to the mpconfigboard.h file:

Code: Select all

#define MICROPY_HW_HAS_SDCARD       (1)

Code: Select all

// SD card detect switch
#define MICROPY_HW_SDCARD_DETECT_PIN        (pin_A8)
#define MICROPY_HW_SDCARD_DETECT_PULL       (GPIO_PULLUP)
#define MICROPY_HW_SDCARD_DETECT_PRESENT    (GPIO_PIN_RESET)
(The last 3 are just from the PYBV11 mpconfigboard.h you may need to customize)

Totally booting from the sdcard will only work if micropython if the board detects the sdcard. As @Roberthh mentions, you could also mount the sdcard in boot.py and then boot the remainder.

nikhiledutech
Posts: 118
Joined: Wed Dec 27, 2017 8:52 am

Re: Booting from SD card

Post by nikhiledutech » Thu May 03, 2018 12:06 pm

Hey,

I added the necessary definitions and it successfully booted from SD Card.

But here is a issue which i face in boot.py file. When i copy paste the below mentioned code in main,py and execute it works very well.

But when i copy this code in a new file " xyz.py" in SD Card. And add the line pyb.main('xyz.py') in boot.py file it give me error of "" SyntaxError: invalid syntax "" .

The error appears in the defined function.

Why there is change in behavior of execution of code when its executed from main.py and when its executed via boot.py? Did anyone bumped into same problem ?

Code: Select all


from pyb import UART

uart = UART(6, 9600)		#baudrate = 9600


#main function
def main():	
	#Writing string of charachter over UART
	uart.write(b"ABCD ")		#String of Charachters ransmitted


#Calling main function
main()

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Booting from SD card

Post by Roberthh » Thu May 03, 2018 12:10 pm

Check the file for a mix of tab and space. And may add the full path in the call of pyb.main.

Post Reply