A resource burner for (not only) standalone system
We have a 16 MB flash memory on every(?) P2 board.
So instead of adding cog drivers and resources in a DAT or asm shared sections they can be stored in the flash area and loaded on demand,
There is a topic about flash and SD access at the same time: https://forums.parallax.com/discussion/175020/flash-and-microsd-in-the-same-program-how-to-flexprop#latest
First experiments with the burner using available flash object ended with unformatting the (unmounted, unused) SD card in the Edge's slot. I managed to restore the card, but it means the flash access has to be done in Mode 3 or it is not safe for a SD card and I have to add erase and write procedures to the read procedure from the topic mentioned above.
Here is the simple bitbanged Mode 3 flash object:
' A simple bitbanged SPI Mode 3 flash driver ' v. 0.02 - 2022.12.08 ' Piotr Kardasz pik33@o2.pl with a help from the P2 community ' read a block (256 bytes) from the flash ' fa - flash address, ha - hub address pub read_block(fa,ha) | bb,i org drvh #60 ' clock drvh #61 ' cs drvh #59 ' prop->flash fltl #58 ' flash->prop add fa, ##$03000000 ' 03-read outl #61 ' select the flash rep @p1, #32 ' send command+address rol fa, #1 wc outl #60 outc #59 outh #60 p1 mov pr0,#64 ' read 64 longs outl #60 fltl #59 outh #60 p3 rep @p2, #32 outl #60 rcl fa, #1 outh #60 testp #58 wc p2 rcl fa, #1 movbyts fa,#%00011011 wrlong fa, ha add ha, #4 djnz pr0, #p3 drvh #61 ' disable chip select end ' erase a 4k block at fa pub erase_block(fa) org drvh #60 ' clock drvh #61 ' cs drvh #59 ' prop->flash fltl #58 ' flash->prop mov pr0,##$06000000 ' write enable outl #61 rep @p6,#8 rol pr0,#1 wc outl #60 outc #59 outh #60 p6 nop outh #61 waitx ##$30_000 add fa, ##$20000000 ' 20-erase 4k block and fa, ##$FFFFF000 ' address has to be block aligned outl #61 ' select the flash rep @p1, #32 rol fa, #1 wc outl #60 outc #59 outh #60 p1 nop outh #61 waitx ##$30_000_000 fltl #59 ' prop->flash end pub write_block(fa,ha) org drvh #60 ' clock drvh #61 ' cs drvh #59 ' prop->flash fltl #58 ' flash->prop mov pr0,##$06000000 outl #61 rep @p6,#8 rol pr0,#1 wc outl #60 outc #59 outh #60 p6 nop outh #61 waitx ##$30_000 add fa, ##$02000000 ' 02 - write 256 bytes block outl #61 ' select the flash rep @p1, #32 rol fa, #1 wc outl #60 outc #59 outh #60 p1 mov pr1,#256 p3 rdbyte pr0,ha shl pr0,#24 rep @p2,#8 rol pr0, #1 wc outl #60 outc #59 outh #60 p2 add ha,#1 djnz pr1,#p3 outh #61 waitx ##3_000_000 fltl #59 ' prop->flash drvh #60 end
The burner now burns the HDMI cog driver, font and sprites definition. In the final version I want to have any possible stuff needed for a standalone system: audio drivers, samples, etc.
Comments
Very cool.
Can you give a example how to load the HDMI driver from Spin and/or (better) PASM once it is in the Flash, and have you some sort of Directory/Index in mind?
Very useable idea, I like it much.
Enjoy!
Mike
No, I have no directory, I only prepared a flash memory map
I am now in the process of rewriting the spin code, but this works:
A perecompiled cog code is loaded now from the flash instead of attaching it as DAT section.
This $70000 is the unused memory. Used for testing, the proper way is to allocate 4k of memory, do job, then free it.
This driver uses also a font definitions. In the current state 3 definitions are attached as DAT. I can now preload one of them from the flash on demand and not keeping all of them in the hub.
PSRAM 32 MB driver for P2-EC32MB added to the burner. Burns at $860000. Attached psram_flash.spin2 is a modified version of the high level PSRAM driver file that loads it from the flash instead of using a PASM/Spin driver source code. It uses $7F000 as a temporary storage, but any HUB RAM can do, you need only to adjust the driver address variable
driverAddr:= $7F020
which is HUB RAM driver start+$20. Afer the driver is started, the HUB RAM can be discarded and reused