Clockfreq, clockmode and others: Agreement for what and where
Cluso99
Posts: 18,069
in Propeller 2
What is the agreement for the placement of clockfreq and clockmode in HUB RAM?
IIRC it was $14 and $18? Which is which, what is the format, and what are the labels?
Perhaps this should be in the tricks and traps thread too???
IIRC it was $14 and $18? Which is which, what is the format, and what are the labels?
Perhaps this should be in the tricks and traps thread too???
Comments
2nd!
The need is because there's a hardware bug which can cause a lock-up if you change the clock mode. There is a work-around but it requires knowing the current clock mode. The tricks and traps thread has more details.
(Knowing the current clock frequency is also pretty useful for programs, and having it in a common location makes it possible for PASM code to get it easily.)
I've posted my code which I believe has been used by others to setup the xtal initially. Here I have already used _clockfreq and _baud, so I'd prefer something else, although it's not too late to change.
Is _CLOCKMODE set to the value of _SETFREQ below?
Postedit: changed above to be _clkfreq, _clkmode, _serbaud
Here is how I set the clock, etc
BTW It is baud, not baud rate. The definition of baud inherently means rate.
Using the RCFAST handover workaround will be fine without the first HUBSET instruction.
Using the reserved mailboxes workaround needs to actually use the prior clkmode value at the very least.
The above code is loaded by fastspin/spingui or pnut. The loader overwrites any value that may have been saved in hub $14-$18 so my code above cannot possibly know what the previous xtal mode was.
BTW I have never found a problem with this method. Perhaps that is because the same clock modes are being set as previously set???
The RCFAST handover workaround would involve the convention of the loader always changing back to RCFAST before COGINITing the loaded program. eg:
The reserved mailbox workaround method can be found in the tricks and traps - https://forums.parallax.com/discussion/comment/1466702/#Comment_1466702
The way I've been doing it is to have my binary laid out so that $14-$18 contains 0 for the clock mode and 22000000 for frequency (or some other approximation to what RCFAST is). The clock frequency changing mode looks like:
This is only ever an issue if you're changing from something other than RCFAST. If you use the ROM loader then it ends up in RCFAST so there's no problem. But loadp2's fast two-stage loader may leave the chip in a different frequency, and of course if you change mid-program then you have to use this sequence as well.
Ah, thanks. I see Chip had the same concerns with using $14 and $18 as I do. A shame. However, if Spin uses them, so will Catalina.
At least its all soft.