Shop OBEX P1 Docs P2 Docs Learn Events
Prop2 Flash loader — Parallax Forums

Prop2 Flash loader

Hi All

Here's a program to load your code from flash on your P2_ES eval boards.

Simply include your .obj file at the end of the program and it will be stored into the flash along with a loader.
Make sure the "FLASH" switch is on.

:)

«13

Comments

  • Hi Brian,

    This is good. I don't think I've heard anyone officially using flash yet.

    Can you tell us how fast it is to boot from flash if you already know or can test it easily, e.g. time from the rising edge of reset to start of small app booting from flash to toggle a pin? I am still waiting to hear if it is slow or fast, and if fast, just how fast.

    Roger.

  • roglohrogloh Posts: 5,122
    edited 2019-01-17 01:18
    Be good to know how fast for the smallest app to boot, as well as an app that takes up the full amount of memory space (~512k), then we will know if it makes sense for some two stage booter in order to shave off time, assuming it runs from RC clock initially but could be switched to faster XTAL frequency early.
  • I'll try and get some figures asap.
    The ROM booter detects the flash and loads 1024 bytes (my loader) into hub.
    If the checksum = 'Prop' then the code starts.
    My loader then loads the code from flash to hub and then starts it.
  • Is there a typo in line 51?
    subr	pa,##$706F7250 'Proo'
    
  • pmrobert wrote: »
    Is there a typo in line 51?
    subr	pa,##$706F7250 'Proo'
    
    Nope, wouldn't work if was wrong.
    It is a little endian format value.

    From the docs
    c) If the sum is "Prop" ($706F7250)
    
  • ozpropdev wrote: »
    pmrobert wrote: »
    Is there a typo in line 51?
    subr	pa,##$706F7250 'Proo'
    
    Nope, wouldn't work if was wrong.
    It is a little endian format value.

    From the docs
    c) If the sum is "Prop" ($706F7250)
    

    I think he was referring to the typo in the comment: 'Proo' instead of 'Prop'
  • I think the comment has a typo. should be 'Prop', not 'Proo'

    Code is good to go! :)
  • Ah, oops!
    I'm way to focused on the PASM I didn't even notice the typo in the comment. :lol:
    Apologies @pmrobert
  • RaymanRayman Posts: 13,800
    Looks like this could be automated with a little change...
    Leave off the code that determines "size" and the size long and the objs and then compile.
    Then, you append this binary with one long of the obj size and then the obj binary.
    Right?
  • cgraceycgracey Posts: 14,133
    Could one of you please do an experiment where a deterministic program boots from flash and simply reports a GETRND value? Just want to be sure that it is unique on every boot/reset.
  • ozpropdevozpropdev Posts: 2,791
    edited 2019-01-19 00:23
    cgracey wrote: »
    Could one of you please do an experiment where a deterministic program boots from flash and simply reports a GETRND value? Just want to be sure that it is unique on every boot/reset.

    Chip
    I ran some test code and here's the results of 8 power cycles reading GETRND.
    900A7C38
    82978328
    802AC61C
    9E469A93
    33932B60
    07E48F98
    94C9E978
    1C82203A
    
    and here's the result og 8 resets.
    AD8F1ABA
    01D55FA1
    077E0D35
    BFDEC64F
    BC5FC38E
    8E952B7B
    16EA4E8E
    D6F060B3
    

    Looks Ok. :)

  • evanhevanh Posts: 15,126
    I just love GETNIB/SETNIB and their ALTxx prefixes!

    Leave the terminal running, move the WAIT to after send so tx finishes, and add a HUBSET reset to make it repeat indefinitely ...
    		orgh	$400
    		org
    stage1	
    
    		getrnd	value1
    		getrnd	value2
    		getrnd	value3
    		getrnd	value4
    
    		hubset	##clk | %1111_10_00	'enable crystal+PLL, stay in 20MHz+ mode
    		waitx	##20_000_000/100	'wait ~10ms for crystal+PLL to stabilize
    		hubset	##clk | %1111_10_11	'now switch to PLL running at 180 MHz
    
    		wrpin	#%1_11110_0,#tx_pin
    		wxpin	##nco | 7,#tx_pin
    		dirh	#tx_pin
    
    		mov     value,value1
    		call	#send_hex8		'show result
    		mov     value,value2
    		call	#send_hex8
    		mov     value,value3
    		call	#send_hex8
    		mov     value,value4
    		call	#send_hex8
    		call	#newline
    		waitx	##sys_clk / 100		'allow time for tx to complete
    		hubset  ##%0001<<28             'hard reset
    		jmp	#$
    
    newline		mov	pa,#13
    		call	#send_char
    		mov	pa,#10
    send_char	rdpin	pb,#tx_pin wc
    	if_c	jmp	#send_char
    		wypin	pa,#tx_pin
    		ret	wcz
    
    send_hex8	mov	countx,#8
    .loop		getnib	pa,value,#7
    		cmp	pa,#9 wcz
    	if_a	add	pa,#"A"-10
    	if_be	add	pa,#"0"
    		call	#send_char
    		rol	value,#4
    		djnz	countx,#.loop
    space		mov	pa,#" "
    		jmp	#send_char
    
    value		res	1
    value1		res	1
    value2		res	1
    value3		res	1
    value4		res	1
    countx		res	1
    

    And data dump attached :)
  • evanhevanh Posts: 15,126
    edited 2019-01-19 01:31
    I've got a problem re-flashing though. I have to temporarily make P59 pull-up to get an update to take. This stops the existing repeated resets occurring while still having the flash connected. Presumably the fast cycling auto-reset is interfering with the USB reset sequence.

  • cgraceycgracey Posts: 14,133
    edited 2019-01-19 01:48
    Ozpropdev and Evanh, thank you very much for testing this.

    It looks okay, doesn't it?
  • evanhevanh Posts: 15,126
    cgracey wrote: »
    It looks okay, doesn't it?

    First glance looks great. Probably should do some binning or something ... that's actual work.

  • Hi,

    I can't test this. First, I set the "Flash" and P95DN switches. Then I load the program using Spin 2 GUI. However, if any of those switches is set, I get a message that it can't find a P2. That, plus the inability to boot from the SD, makes me think that my board is not working correctly.

    Kind regards, Samuel Lourenço
  • evanhevanh Posts: 15,126
    Changed the emitting to pure binary and piped it straight into Practrand. All looks good for short run:
    evanh@controlled:~/hoard/coding/rng_testing$ ./RNG_test.unchanged stdin -multithreaded -te 1 -tf 2 -tlmin 1KB </dev/serial/by-id/usb-Parallax_Inc._Propeller_P2-EVAL-ES_P2EEL5T-if00-port0 
    RNG_test using PractRand version 0.93
    RNG = RNG_stdin, seed = 0x17c88820
    test set = expanded, folding = extra
    
    rng=RNG_stdin, seed=0x17c88820
    length= 1 kilobyte (2^10 bytes), time= 0.4 seconds
      Test Name                         Raw       Processed     Evaluation
      DC6-6x2Bytes-1                    R=  +4.7  p = 0.016     unusual          
      DC6-5x4Bytes-1                    R= +12.2  p =  9.4e-5   suspicious       
      ...and 12 test result(s) without anomalies
    
    rng=RNG_stdin, seed=0x17c88820
    length= 2 kilobytes (2^11 bytes), time= 0.7 seconds
      Test Name                         Raw       Processed     Evaluation
      FPF-14+6/4:all                    R=  -6.1  p =1-4.7e-3   unusual          
      ...and 18 test result(s) without anomalies
    
    rng=RNG_stdin, seed=0x17c88820
    length= 4 kilobytes (2^12 bytes), time= 18.5 seconds
      no anomalies in 56 test result(s)
    
    rng=RNG_stdin, seed=0x17c88820
    length= 8 kilobytes (2^13 bytes), time= 25.8 seconds
      no anomalies in 114 test result(s)
    
    rng=RNG_stdin, seed=0x17c88820
    length= 16 kilobytes (2^14 bytes), time= 40.4 seconds
      no anomalies in 179 test result(s)
    
    rng=RNG_stdin, seed=0x17c88820
    length= 32 kilobytes (2^15 bytes), time= 69.7 seconds
      no anomalies in 246 test result(s)
    
    rng=RNG_stdin, seed=0x17c88820
    length= 64 kilobytes (2^16 bytes), time= 128 seconds
      no anomalies in 316 test result(s)
    
    rng=RNG_stdin, seed=0x17c88820
    length= 128 kilobytes (2^17 bytes), time= 245 seconds
      no anomalies in 367 test result(s)
    
    ^C
    
  • cgraceycgracey Posts: 14,133
    evanh wrote: »
    cgracey wrote: »
    It looks okay, doesn't it?

    First glance looks great. Probably should do some binning or something ... that's actual work.

    No, I don't think that would mean anything. The PRNG is running, being what it is, and we just need to know that it started up with a unique value.
  • cgraceycgracey Posts: 14,133
    edited 2019-01-19 02:44
    samuell wrote: »
    Hi,

    I can't test this. First, I set the "Flash" and P95DN switches. Then I load the program using Spin 2 GUI. However, if any of those switches is set, I get a message that it can't find a P2. That, plus the inability to boot from the SD, makes me think that my board is not working correctly.

    Kind regards, Samuel Lourenço

    I don't know about the timing of Spin2 GUI, but if you set the flash switch on with the others off, you should be able to download from PNut.

    Samuel, it's possible there could be something wrong with your board. We tested every pin on the chip, but we didn't test the flash or the SD socket. If there is anything wrong, it ought to be apparent by visual inspection. Look at the flash and SD card SMT components through a magnifier and see if everything looks okay.
  • samuellsamuell Posts: 554
    edited 2019-01-19 02:57
    Thanks Chip,

    Personally, I had many problems with solder bridges that stay hidden under capacitors and resistors (0805s), when soldering with solder paste and hot air. I'll do an inspection tomorrow and some measurements as well, to see if the switches are having an effect. A simple test I could do is to measure P59 with both of its switches on. If the switches are OK, I should measure around 1.65V there.

    By the way, I should mention that I can read the contents of the SD card under TAQOZ (although, I only tried the DIR command). On another note, where can I get PNut?

    Kind regards, Samuel Lourenço
  • evanhevanh Posts: 15,126
    edited 2019-01-19 03:13
    samuell wrote: »
    I can't test this. First, I set the "Flash" and P95DN switches. Then I load the program using Spin 2 GUI. However, if any of those switches is set, I get a message that it can't find a P2. That, plus the inability to boot from the SD, makes me think that my board is not working correctly.

    The FLASH switch is needed on for all flash ops. Try turning on P59 Up. I can make it program with both P59 Up and Down on together.
  • Sorry
    I program the flash with both P59 switches off and 'FLASH' on.
    After programming I set P69 pulldown on for fast SPI boot.
    For all my testing I use Pnut.
  • Cluso99Cluso99 Posts: 18,066
    evanh wrote: »
    I just love GETNIB/SETNIB and their ALTxx prefixes!
    ...

    Thanks for the tip. I may be able to use it in the ROM Monitor for the next silicon :wink:

    evan
    Here is your code (untested) using...
    1. Hopefully a standard method to set the xtal frequency. (note I didn't decode your divide/multiply/divide to get 180MHz)
    2. Using the Serial ROM Monitor to display your results.
    '' RR20190119   001     mod to use the monitor serial routines
    
    CON
      _XTALFREQ     = 20_000_000                                    ' crystal frequency
      _XDIV         = 4             '\                              '\ crystal divider                      to give 5.0MHz
      _XMUL         = 72            '| 180MHz                       '| crystal / div * mul                  to give 360MHz
      _XDIVP        = 2             '/                              '/ crystal / div * mul /divp            to give 180MHz
      _XOSC         = %10                                   '15pF   ' %00=OFF, %01=OSC, %10=15pF, %11=30pF
      _XSEL         = %11                                   'XI+PLL ' %00=rcfast(20+MHz), %01=rcslow(~20KHz), %10=XI(5ms), %11=XI+PLL(10ms)
      _XPPPP        = ((_XDIVP>>1) + 15) & $F                       ' 1->15, 2->0, 4->1, 6->2...30->14
      _CLOCKFREQ    = _XTALFREQ / _XDIV * _XMUL / _XDIVP            ' internal clock frequency                
      _SETFREQ      = 1<<24 + (_XDIV-1)<<18 + (_XMUL-1)<<8 + _XPPPP<<4 + _XOSC<<2  ' %0000_000e_dddddd_mmmmmmmmmm_pppp_cc_00  ' setup  oscillator
      _ENAFREQ      = _SETFREQ + _XSEL                                             ' %0000_000e_dddddd_mmmmmmmmmm_pppp_cc_ss  ' enable oscillator
    '------------------------------------------------------------------------------------------------
      _baud         = 115_200
      _bitper       = (_clockfreq / _baud) << 16 + 7          ' 115200 baud, 8 bits
      _txmode       = %0000_0000_000_0000000000000_01_11110_0 'async tx mode, output enabled for smart output
      _rxmode       = %0000_0000_000_0000000000000_00_11111_0 'async rx mode, input  enabled for smart input
    '------------------------------------------------------------------------------------------------
      rx_pin        = 63            ' pin serial receiver
      tx_pin        = 62            ' pin serial transmitter
    '------------------------------------------------------------------------------------------------
    
    ''============[ ROM MONITOR Equates]=============================================================
      _HUBBUF       = $FC000        ' overwrite Booter      (used as serial receive buffer, etc)
      _SerialInit      = $fcab8     ' Serial Initialise     (lmm_x & lmm_bufad must be set first)
      _HubTxCR         = $fcae4     ' Sends <cr><lf>        (overwrites lmm_x)
      _HubTx           = $fcaf0     ' Sends lmm_x           (can be up to 4 bytes)
      _HubHex8         = $fcb28     ' Sends lmm_x as Hex char(s) after setting lmm_f as 8 hex chars
    ''-------[ COG LMM parameters, etc ]-------------------------------------------------------------
      lmm_x         = $1e0          ' parameter passed to/from LMM routine (typically a value)
    ''-----------------------------------------------------------------------------------------------
      value         = lmm_x
    
    DAT
                    orgh    $400
                    org
    stage1  
    
                    getrnd  value1
                    getrnd  value2
                    getrnd  value3
                    getrnd  value4
    
    '+-------[ Set Xtal ]----------------------------------------------------------+ 
    ''              hubset  ##clk | %1111_10_00     'enable crystal+PLL, stay in 20MHz+ mode
    ''              waitx   ##20_000_000/100        'wait ~10ms for crystal+PLL to stabilize
    ''              hubset  ##clk | %1111_10_11     'now switch to PLL running at 180 MHz
                    hubset  #0                              ' set 20MHz+ mode
                    hubset  ##_SETFREQ                      ' setup oscillator
                    waitx   ##20_000_000/100                ' ~10ms
                    hubset  ##_ENAFREQ                      ' enable oscillator
    '+-----------------------------------------------------------------------------+
    
    '+-------[ Start Serial ]------------------------------------------------------+ 
    ''              wrpin   #%1_11110_0,#tx_pin
    ''              wxpin   ##nco | 7,#tx_pin
    ''              dirh    #tx_pin
                    mov     lmm_bufad,        ##_HUBBUF     ' locn of hub buffer for serial routine 
                    mov     lmm_x,            ##_bitper     ' sets serial baud
                    call    #_SerialInit                    ' initialise serial
    '+-----------------------------------------------------------------------------+
    
    '+-------[ Send Serial ]-------------------------------------------------------+ 
                    mov     value,value1
                    call    #send_hex8              'show result
                    mov     value,value2
                    call    #send_hex8
                    mov     value,value3
                    call    #send_hex8
                    mov     value,value4
                    call    #send_hex8
    
    ''              call    #newline
                    call    #_hubTxCR                       
    
                    waitx   ##sys_clk / 100         'allow time for tx to complete
                    hubset  ##%0001<<28             'hard reset
                    jmp     #$
    '+-----------------------------------------------------------------------------+
    {{
    newline         mov     pa,#13
                    call    #send_char
                    mov     pa,#10
    send_char       rdpin   pb,#tx_pin wc
            if_c    jmp     #send_char
                    wypin   pa,#tx_pin
                    ret     wcz
    
    send_hex8       mov     countx,#8
    .loop           getnib  pa,value,#7
                    cmp     pa,#9 wcz
            if_a    add     pa,#"A"-10
            if_be   add     pa,#"0"
                    call    #send_char
                    rol     value,#4
                    djnz    countx,#.loop
    space           mov     pa,#" "
                    jmp     #send_char
    }}
    send_hex8       call    #_hubHex8
                    mov     lmm_x,#" "
                    call    #_hubTx
                    ret                       
    '+-----------------------------------------------------------------------------+
    
    ''value         res     1                 'use lmm_x
    value1          res     1
    value2          res     1
    value3          res     1
    value4          res     1
    ''countx        res     1
    

    There are a couple of other tricks that I will put up on the Tricks and Traps thread...
    ' convert nibble to ASCII hex char using only the C flag
                    getnib  x,value,#7              '\ either extracts only lower nibble
                    and     x,#$0F                  '/
                    
                    or      x,#"0"
                    cmp     x,#";"            wc    ' : -> A etc
            if_nc   add     x,#7                    
    
  • ozpropdevozpropdev Posts: 2,791
    edited 2019-01-19 04:37
    Cluso99 wrote: »
    ' convert nibble to ASCII hex char using only the C flag
                    getnib  x,value,#7              '\ either extracts only lower nibble
                    and     x,#$0F                  '/
                    
                    or      x,#"0"
                    cmp     x,#";"            wc    ' : -> A etc
            if_nc   add     x,#7                    
    

    The AND after the GETNIB is not required.
    Also the #";" should be #":"
    ' convert nibble to ASCII hex char using only the C flag
                    getnib  x,value,#7              '\ either extracts only lower nibble
                    
                    or      x,#"0"
                    cmp     x,#":"            wc    ' : -> A etc
            if_nc   add     x,#7                    
    
    [/quote]


  • evanhevanh Posts: 15,126
    Oops, I've answered in the tricks comments topic - https://forums.parallax.com/discussion/comment/1461963/#Comment_1461963

  • Cluso99Cluso99 Posts: 18,066
    edited 2019-01-19 11:52
    Yes, typo “;” should be “:”. The comment was correct. That’s what I get for retyping instead of cutting and pasting from working code :(

    As for the AND, it’s an either GETNIB or AND, not both.
  • Hi,

    I've tested the switches, and they appear to work correctly. The measured voltages make sense.
    evanh wrote: »
    samuell wrote: »
    I can't test this. First, I set the "Flash" and P95DN switches. Then I load the program using Spin 2 GUI. However, if any of those switches is set, I get a message that it can't find a P2. That, plus the inability to boot from the SD, makes me think that my board is not working correctly.

    The FLASH switch is needed on for all flash ops. Try turning on P59 Up. I can make it program with both P59 Up and Down on together.
    Thanks evanh! That worked while programming with Spin 2 GUI. I get the program loaded up and apparently running. P56 blinks, although it doesn't show anything on the terminal yet.
    ozpropdev wrote: »
    Sorry
    I program the flash with both P59 switches off and 'FLASH' on.
    After programming I set P69 pulldown on for fast SPI boot.
    For all my testing I use Pnut.
    Thanks! That worked well with PNut.

    Kind regards, Samuel Lourenço
  • evanhevanh Posts: 15,126
    edited 2019-01-19 22:03
    samuell wrote: »
    evanh wrote: »
    Try turning on P59 Up. I can make it program with both P59 Up and Down on together.
    Thanks evanh! That worked while programming with Spin 2 GUI. I get the program loaded up and apparently running. P56 blinks, although it doesn't show anything on the terminal yet.
    Next step is turn P59 Up off again and press the reset button.
  • samuellsamuell Posts: 554
    edited 2019-01-20 05:26
    evanh wrote: »
    samuell wrote: »
    evanh wrote: »
    Try turning on P59 Up. I can make it program with both P59 Up and Down on together.
    Thanks evanh! That worked while programming with Spin 2 GUI. I get the program loaded up and apparently running. P56 blinks, although it doesn't show anything on the terminal yet.
    Next step is turn P59 Up off again and press the reset button.
    Strange, after pressing reset, with P59 Up already in the off position, P56 blinks no more. If I set P59 Down off, leaving FLASH on, and then reset again, I can't load TAQOZ. This should mean that the program is loaded from the flash, but not showing information on the terminal. This also happens if I turn P59 Down on again.

    What could be the issue here?

    Kind regards, Samuel Lourenço
Sign In or Register to comment.