Shop OBEX P1 Docs P2 Docs Learn Events
A resource burner for (not only) standalone system — Parallax Forums

A resource burner for (not only) standalone system

pik33pik33 Posts: 2,366
edited 2022-12-09 10:05 in Propeller 2

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

  • pik33pik33 Posts: 2,366
    edited 2022-12-10 08:36

    No, I have no directory, I only prepared a flash memory map

    '800000 - fonts
    '810000 - palettes and sprites
    '830000 - video drivers
    '840000 - audio drivers
    '850000 - keyboard,  mouse, joysticks, etc HID drivers
    '860000 - other drivers (PSRAM etc)
    '870000 - audio samples, 63 slots@2k+names at 87F800
    '890000 - audio envelopes, 62 slots@1k+names at 89F800
    

    I am now in the process of rewriting the spin code, but this works:

    repeat i from 0 to 15
       read_block  ($830000+256*i,$70000+256*i)
    cog:=coginit(16,$70000, @vblank_ptr)                           
    

    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.

  • pik33pik33 Posts: 2,366
    edited 2022-12-30 14:16

    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

Sign In or Register to comment.