SPI Flash for PyBoard
SPI Flash for PyBoard
Hello,
I have designed several boards using the STM32F405 and run a slightly modified version of uPython 1.3.
I have added 2M and 16M external serial flash and have libraries to access them. But I can only do this using OS libraries within the Python environment.
Is there a plan, or a way to use external Flash with uPython 1.3 on an STM32F405/7 as main flash so that it enumerates as a disk drive? Right now the size in the internal flash is relatively small by comparison. To me, this is the only weakness of the PyBoard. Even so, it's the best implementation of MicroPython I've seen.
I started some development on a STM32F407 Discovery board using ST's CubeIDE. This board as a 2MB serial flash. The demo software includes USB file support so when you connect it to USB, it enumerates as a 2MB flash card. Internal flash is not used for file storage (similar as some Circuit Python boards).
Thanks,
I have designed several boards using the STM32F405 and run a slightly modified version of uPython 1.3.
I have added 2M and 16M external serial flash and have libraries to access them. But I can only do this using OS libraries within the Python environment.
Is there a plan, or a way to use external Flash with uPython 1.3 on an STM32F405/7 as main flash so that it enumerates as a disk drive? Right now the size in the internal flash is relatively small by comparison. To me, this is the only weakness of the PyBoard. Even so, it's the best implementation of MicroPython I've seen.
I started some development on a STM32F407 Discovery board using ST's CubeIDE. This board as a 2MB serial flash. The demo software includes USB file support so when you connect it to USB, it enumerates as a 2MB flash card. Internal flash is not used for file storage (similar as some Circuit Python boards).
Thanks,
Re: SPI Flash for PyBoard
Yes, this can be done in your mpconfigboard.h
Have a look at, for example, the PYBD_SF2 board. The way this works is that you have:
- Internal flash (main firmware)
- External spiflash 1 (sw qspi, filesystem, exposed over USB)
- External spiflash 2 (memory mapped using hw qspi, additional firmware)
The key details:
- stm32/storage.c provides the pyb.Flash class (which is also used for USB MSC) on top of a block device
- stm32/flash.c provides a driver for the internal flash
- stm32/flashbdev.c provides a block device using the internal flash driver
-stm32/spibdev.c provides a block device driver for external spiflash
So PYBD_SF2 sets MICROPY_HW_ENABLE_INTERNAL_FLASH_STORAGE to disable flashbdev.c, but instead provides the MICROPY_HW_BDEV_ macros using the spibdev implementation (otherwise these macros would default to using flashbdev.c's implementation).
Re: SPI Flash for PyBoard
Thanks! That sounds pretty easy.
Then internal flash is only used for kernel and frozen code/applications as a .dfu object. Is this correct?
If so, then what is purpose of stm32/flash.c for internal flash? Is internal flash still available as a flash file device?
Also, I assume s/w qspi is internal 4-bit but serializes to single data line (since STM32F405/7 does not have h/w qspi).
Brad
Then internal flash is only used for kernel and frozen code/applications as a .dfu object. Is this correct?
If so, then what is purpose of stm32/flash.c for internal flash? Is internal flash still available as a flash file device?
Also, I assume s/w qspi is internal 4-bit but serializes to single data line (since STM32F405/7 does not have h/w qspi).
Brad
Re: SPI Flash for PyBoard
Yep, exactly.
It will be unused if you're not using flashbdev.c (the linker will GC the unused symbols during linking).
Yep, I was describing how it works on the PYBD, but yeah take a look at (say) STM32L476DISC/mpconfigboard.h for a L4 board that is doing (I think) exactly what you want.
Re: SPI Flash for PyBoard
So I had some success! I have a full 16MB with V1.13.
Next, I got a fresh clone of the repo for V1.14 and it compiles the non-external-flash without any problems.
However, when I enable the external flash, it fails. This doesn't happen with V1.13.
Problem seems to be with bdev.c (which I borrowed from /boards/STM32L476. I've also attached the configuration file and and bdev.c (Note that changing line #8 in mpconfigboard.h had no effect)
Any ideas?
Next, I got a fresh clone of the repo for V1.14 and it compiles the non-external-flash without any problems.
However, when I enable the external flash, it fails. This doesn't happen with V1.13.
Problem seems to be with bdev.c (which I borrowed from /boards/STM32L476. I've also attached the configuration file and and bdev.c (Note that changing line #8 in mpconfigboard.h had no effect)
Any ideas?
- Attachments
-
- Desktop.zip
- (921 Bytes) Downloaded 151 times
Re: SPI Flash for PyBoard
The cache was made optional in v1.14. See https://github.com/micropython/micropython/pull/6704
FWIW -- the steps to figure this out:
- See that .cache is set in other boards (like the one you copied), so it must be valid.
- Look at the definition of the mp_spiflash_config_t struct
- See that .cache is guarded by MICROPY_HW_SPIFLASH_ENABLE_CACHE
- This is enabled on the working board.
- Do a git blame on that line (added Dec 2020).
Re: SPI Flash for PyBoard
So I added #define MICROPY_HW_SPIFLASH_ENABLE_CACHE (1) to mpconfigboard.h.
Mostly compiled until it got to the end: It's all a bit odd. I can successfully build STM32L476DISC.
Mostly compiled until it got to the end: It's all a bit odd. I can successfully build STM32L476DISC.
Re: SPI Flash for PyBoard
No matter what I try, I just can't get my board to compile with V1.14. So for now, I'll just keep using V1.13.
Re: SPI Flash for PyBoard
This means that:
- You've compiled with support for LFS
- You haven't enabled MICROPY_HW_BDEV_SPIFLASH_EXTENDED
The reason STM32L476DISC works is that it does not enable LFS.
Take a look at either PYBD_SF2 or F769DISC for an example.