Shop OBEX P1 Docs P2 Docs Learn Events
To ORGH or not to ORGH? — Parallax Forums

To ORGH or not to ORGH?

rjo__rjo__ Posts: 2,114
edited 2019-04-08 03:56 in Propeller 2
I am using P123(A9), and I'm wondering if this occurs just on the A9 or whether it also occurs in silicon.

While updating my PropCam code from P2v14, which worked fine, I ran into a hiccup using coginit and cogstop.

To illustrate, I have taken Chip's 640x480 8bpp example and added my coginit after his hubset instruction.

DAT		org
'
' Setup

			    hubset	#$FF			'set clock to 80MHz
				
			    coginit #2,##@PropCam_Acq


and then after his code added:
org
PropCam_Acq              
                     
			                        'nop                      'if this is first instruction everything fine
						'waitx ##80_000_000   'if this is first instruction ... no display
                                                'cogid camera_number  'if this is first instruction ... bad lut
						'cogstop #2            'if this is first instruction ... bad lut
           
temploop   				jmp #temploop
camera_number   res 1


I get various results depending upon the first instruction after PropCam_Acq. as explained in the code.


«134

Comments

  • RaymanRayman Posts: 14,646
    edited 2019-04-07 21:17
    Maybe code has to be after $400 or something...

    Try using an ORGH in your section...

    You need an ORG too...
  • rjo__rjo__ Posts: 2,114
    I've tried various combinations of org and orgh, before and after the label.

    org $400 gives me … "cog origin exceeds limit"


  • rjo__rjo__ Posts: 2,114
    the whole thing is a mystery to me... but it really seems odd that anything in Cog 2 should have an effect on the LUT of cog 1...

    I tried moving my coginit after the lut had loaded, but it made no difference.


  • cgraceycgracey Posts: 14,152
    Rjo__,

    I don't see anything in your code that looks wrong. I will try this out later when I'm at my computer.

    Do you see anywhere in the code where maybe some RAM is being used for workspace that might overwrite your tiny program that goes into cog 2?
  • rjo__rjo__ Posts: 2,114
    Chip,

    I don't see anything. Maybe v32i didn't load correctly. I'll trying the PX route again.

  • I remember that fasttspin now puts the clock frequency into low memory, is that maybe overwriting your code?

    just guessing,

    Mike
  • rjo__rjo__ Posts: 2,114
    Reflashing with px didn't solve it.
  • rjo__rjo__ Posts: 2,114
    Does this happen on P2-ES?
  • yes fastspin does now put something in lower memory of the P2, I think 3 or four longs, Taqoz uses the same locations and P2gcc also.

    Pnut does not.


    Mike
  • RaymanRayman Posts: 14,646
    edited 2019-04-07 22:40
    Sorry, I meant like this:
    DAT 'Start of HyperRAM test code
            orgh  0
            org   0
    

    I think orgh puts it over $400
  • YanomaniYanomani Posts: 1,524
    edited 2019-04-07 22:49
    rjo__ wrote: »
    Does this happen on P2-ES?

    As for the P2-ES, any time you need to start the PLL (or change its frequency) the WAITX interval is mandatory; PLL needs to stabilize, before it can be allowed to drive Sysclk.

    Using the following code snippet, extracted form from RJSM's Hyperram code, as an example:
                    hubset  #0                              ' set 20MHz+ mode
                    hubset  ##_SETFREQ                      ' setup oscillator
                    waitx   ##20_000_000/100                ' ~10ms
                    hubset  ##_ENAFREQ                      ' enable oscillator
    

    A procedure like the one above is of general usage, and no one has reported any bug related to it.
  • Only thinking aloud: did you verified the assembler-generated binary image of your code?

    Since you are not using any debug facilities, if some lazy slug did found its way under the doors, it can be seating at the wrong place, unnoticed.
  • Try this
    	orgh	$400
    	org
    
    PropCam_Acq              
    
  • RaymanRayman Posts: 14,646
    edited 2019-04-07 23:18
    Was just looking at what I've been doing lately...
    Seems I just waste the first $400, so don't have to think about it...
    My code starts out like this:
    DAT 'Start of HyperRAM test code
    orgh  0
    org   0
    '+-------[ Set Xtal ]----------------------------------------------------------+ 
    ' RJA:  New for real P2
                    hubset  #0                              ' set 20MHz+ mode
                    hubset  ##_SETFREQ                      ' setup oscillator
                    waitx   ##20_000_000/100                ' ~10ms
                    hubset  ##_ENAFREQ                      ' enable oscillator
    '+-----------------------------------------------------------------------------+        
                    coginit   #Serial_Cog,##@SerialStart
                    coginit   #HyperRam_Cog,##@HyperInit
                    coginit   #VGA_Cog,##@VGA_Driver 'this one has to be last as overwrites this cog
    endStart
                    jmp #endStart
    

    Then, the other cog code just starts with this:
    DAT 'VGA_Driver   'vsync and hsync normally low
    orgh
    org 0        
    VGA_Driver
    
  • rjo__rjo__ Posts: 2,114
    Brian and Ray,

    That was it... in addition to the fact that I used # rather than ## in the coginit... had changed it while I was messing around and then forgot I changed it.

    Thanks everyone...

    wow... a day of worrying about absolutely nothing:)
  • Tired? Perhaps a bit of relaxing distraction...

    Maybe it could be trained, to wander at your monitor's screen, searching for missing #s, then filling the blanks, with their tracks.

    Given the actual stage of my sight capabilities, its 8"-long body will help me to don't foot-step on its head.

    https://nationalgeographic.com.au/australia/new-hot-pink-slug-found-in-australia.aspx

    Henrique :lol:
  • rjo__rjo__ Posts: 2,114
    lol

    Then we would have one slug correcting another slug.

    I don't get why we have single #'s. Doesn't a ## work whenever a # does?

    And about this orgh business... what?

    I didn't need orgh before and I was pounding my P2v... up til v14 after which I really did get distracted for a while.

    (These are mostly rhetorical question, since I probably won't understand the answers:)




  • evanhevanh Posts: 15,915
    msrobots wrote: »
    yes fastspin does now put something in lower memory of the P2, I think 3 or four longs, Taqoz uses the same locations and P2gcc also.

    Pnut does not.
    It's actually loadp2 that does the filling during download. And it requires a specific switch, -PATCH, to activate it. So it should only happen to code that is aware and making use of the feature.
  • evanhevanh Posts: 15,915
    edited 2019-04-08 03:36
    First downloaded code (first booting code) must rely on powerup/reset clock selection being RCFAST. This what you see when using loadp2's -SINGLE switch. So as long as DTR is being toggled to reset the Prop on each download, then -SINGLE and -PATCH are effectively exclusive of each other. Or, -PATCH only makes sense when used in conjunction with -CHIP.
  • rjo__rjo__ Posts: 2,114
    edited 2019-04-08 03:52
    Evanh et al,

    SO.... originally I fixed my problem by using an Org only instruction and then inserting a NOP instruction at the beginning of my code section... thinking that there was a timing issue.
    This worked fine, but it bothered me.

    Then I tried inserting a waitx instead of a NOP at the beginning of the code section and it failed (no matter how large or small I made the wait period.)

    Why does inserting a NOP solve the problem if the problem is that I wasn't using ORGH?

    See what I mean?


  • evanhevanh Posts: 15,915
    edited 2019-04-08 04:08
    Mike might have a point. If you are inadvertently activating the patching then, with a NOP, it will only overwrite doVga routine, but with a WAITX ## it will hit the COGINIT as well.

    EDIT: Err, loadp2 only fills 3 of the 4 allotted longwords, so COGINIT would be safe. I'll have a look at your code ...
  • evanhevanh Posts: 15,915
    PropCam_Acq needs an ORG to tell the assembler that it'll be executing as cogexec at address 0. Without that the second cog will go unpredictable when the JMP branches off to never-never-land.
  • twice :lol: :

    You're not alone. I'm all for the slugs and snails. Let the spins for the Props; I'm just a "linear" wandering being.

    Sure, we do understand the answers; each one has its own share of responsibility, by letting computers get where they are, now.

    Five++ decades doing hardware, four++++ coding, and I always feel amissed, dealing with the several syntaxes I've passed by.

    Many times I get myself wondering why and when I did lose sight of my first 400 Series Compucorp programmable calculator (4 kB of memory, 56-bit mantissa, 8-bit exponent, both signed), where I did learn, with a lot of fun, and also a ton of limitations concerning code&data organization, almost 80% of what I can do with the right processor.

    Propellers are my best bets, to recover all the time and joy I did lost, so far.
  • rjo__rjo__ Posts: 2,114
    I did as Yanomani suggested... with everything in there including an image, I could not make sense of anything.
    So, I commented out everything having to do with VGA and images and toggled PNUT into PASM view.

    with org and nop ... but  without orgh $400
    
    
    this code combination did not screw up the VGA in the original example
    
    OBJ bytes:      32
    
    _CLKMODE: 00
    _CLKFREQ: 00B71B00
    
    00000- 00 FE 65 FD 00 00 00 FF 10 04 EC FC FC FF 9F FD   '..e.............'
    00010- 00 00 00 00 01 06 60 FD FC FF 9F FD 00 00 00 00   '......`.........'
    
    ******************************************************************
    without orgh $400
    and without NOP at beginning ... this doesn't work correctly
    
    
    TYPE: 4B   VALUE: 00000050   NAME: INTENSITY
    TYPE: 4C   VALUE: 4C989680   NAME: FCLK
    TYPE: 4C   VALUE: 4BBEBC20   NAME: FPIX
    TYPE: 4C   VALUE: 4E200000   NAME: FSET
    TYPE: 4B   VALUE: 00000000   NAME: VSYNC
    TYPE: 56   VALUE: 0030000C   NAME: NEVERENDING
    TYPE: 56   VALUE: 00000010   NAME: PROPCAM_ACQ
    TYPE: 56   VALUE: 00100014   NAME: TEMPLOOP
    TYPE: 57   VALUE: 00200018   NAME: CAMERA_NUMBER
    
    OBJ bytes:      32
    
    _CLKMODE: 00
    _CLKFREQ: 00B71B00
    
    00000- 00 FE 65 FD 00 00 00 FF 10 04 EC FC FC FF 9F FD   '..e.............'
    00010- 01 04 60 FD FC FF 9F FD 00 00 00 00 00 00 00 00   '..`.............'
    
    *************************************************
    *************************************************
    [b]with org and orgh $400[/b]
    and NOP  ... works as God intended
    
    TYPE: 4B   VALUE: 00000050   NAME: INTENSITY
    TYPE: 4C   VALUE: 4C989680   NAME: FCLK
    TYPE: 4C   VALUE: 4BBEBC20   NAME: FPIX
    TYPE: 4C   VALUE: 4E200000   NAME: FSET
    TYPE: 4B   VALUE: 00000000   NAME: VSYNC
    TYPE: 56   VALUE: 0030000C   NAME: NEVERENDING
    TYPE: 56   VALUE: 00000400   NAME: PROPCAM_ACQ
    TYPE: 56   VALUE: 00200408   NAME: TEMPLOOP
    TYPE: 57   VALUE: 0030040C   NAME: CAMERA_NUMBER
    
    OBJ bytes:   1,056
    
    _CLKMODE: 00
    _CLKFREQ: 00B71B00
    
    00000- 00 FE 65 FD 02 00 00 FF 00 04 EC FC FC FF 9F FD   '..e.............'
    00010- 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   '................'
    00020- 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   '................'
    00030- 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   '................'
    00040- 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   '................'
    00050- 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   '................'
    00060- 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   '................'
    00070- 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   '................'
    00080- 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   '................'
    00090- 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   '................'
    000A0- 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   '................'
    000B0- 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   '................'
    000C0- 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   '................'
    000D0- 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   '................'
    000E0- 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   '................'
    000F0- 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   '................'
    00100- 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   '................'
    00110- 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   '................'
    00120- 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   '................'
    00130- 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   '................'
    00140- 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   '................'
    00150- 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   '................'
    00160- 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   '................'
    00170- 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   '................'
    00180- 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   '................'
    00190- 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   '................'
    001A0- 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   '................'
    001B0- 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   '................'
    001C0- 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   '................'
    001D0- 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   '................'
    001E0- 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   '................'
    001F0- 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   '................'
    00200- 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   '................'
    00210- 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   '................'
    00220- 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   '................'
    00230- 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   '................'
    00240- 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   '................'
    00250- 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   '................'
    00260- 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   '................'
    00270- 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   '................'
    00280- 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   '................'
    00290- 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   '................'
    002A0- 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   '................'
    002B0- 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   '................'
    002C0- 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   '................'
    002D0- 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   '................'
    002E0- 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   '................'
    002F0- 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   '................'
    00300- 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   '................'
    00310- 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   '................'
    00320- 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   '................'
    00330- 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   '................'
    00340- 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   '................'
    00350- 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   '................'
    00360- 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   '................'
    00370- 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   '................'
    00380- 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   '................'
    00390- 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   '................'
    003A0- 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   '................'
    003B0- 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   '................'
    003C0- 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   '................'
    003D0- 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   '................'
    003E0- 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   '................'
    003F0- 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   '................'
    00400- 00 00 00 00 01 06 60 FD FC FF 9F FD 00 00 00 00   '......`.........'
    00410- 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   '................'
    


    It is pretty clear... that without the ORGH, the fact that my code was not interfering with the VGA code was accidental.




  • rjo__rjo__ Posts: 2,114
    I'm left with the fact that I have never used ORGH except to load assets into Hubram… Thousands of lines of code... all working by accident.
    I am the luckiest person I know, but this would be a new record for me.


  • evanhevanh Posts: 15,915
    Oh, that'll be the relative vs absolute bug below $400. It's a bug in Pnut with the handling of relative branch addresses and the other assemblers have copied the bug, afaik. Also affects LOC instruction. It can be worked around by using #\@ or in this case moving the offending code out of the sub-$400 address range. So, again it is the JMP #temploop that will be going astray because the relative encoding is mangled.
  • evanhevanh Posts: 15,915
    That's a guess.
  • evanhevanh Posts: 15,915
    Nah, that JMP is fine. So's the COGINIT address. Shrug.
  • evanhevanh Posts: 15,915
    edited 2019-04-08 12:16
    Oh, wow, it's something to do with the RES data defines. Replace the RESs with LONGs and the ORGH isn't needed.

    And with the RESs, ORGH $400 isn't specifically needed either, $100 works too, for example.

    I've always been wary of using RES in the past. I must have bumped into this before but didn't understand it at the time. Still don't really.
  • evanhevanh Posts: 15,915
    Chip/Eric/Dave,
    That finding might be of interest to you guys. It would be good to understand if we're coding wrong or if there is a common bug in the tools.
Sign In or Register to comment.