Shop OBEX P1 Docs P2 Docs Learn Events
Where is CLKFREQ set? — Parallax Forums

Where is CLKFREQ set?

J^3J^3 Posts: 121
edited 2012-05-18 20:56 in Propeller 1
Sorry for the newb question, but I am assuming the user still has control of the PLL and whether or not the prop is using an external crystal or the internal RC Oscillator. I looked into propeller.h and found the macro clkset, but couldn't find where it is being used.

Thanks in advance.

Comments

  • pedwardpedward Posts: 1,642
    edited 2012-05-18 00:25
    It's a configuration parameter set by the propeller-load program. The program looks for the symbol in the binary while it's loading and substitutes the proper clock speed for the board profile you are loading.
  • David BetzDavid Betz Posts: 14,516
    edited 2012-05-18 05:43
    pedward wrote: »
    It's a configuration parameter set by the propeller-load program. The program looks for the symbol in the binary while it's loading and substitutes the proper clock speed for the board profile you are loading.
    Actually, that isn't completely true. CLKFREQ is a special case as is CLKMODE since there are already defined places for those values in the hub address space. CLKFREQ is set based on the corresponding value for the selected board configuration file and placed in location zero in hub memory, the same place where it is placed by the Spin compiler. The same applies to CLKMODE. The linker script provides symbols for both of these values but the loader doesn't look them up at load time. This setting of CLKFREQ and CLKMODE at load time rather than compile or link time was done to allow the same ELF file to be loaded into different boards with different values for those settings.
  • pedwardpedward Posts: 1,642
    edited 2012-05-18 11:34
    So you are saying the loader doesn't look up the symbols, but it does set them?

    I know what you are getting at. The symbols are hardcoded in the address space, so the loader just sets them based on the hardcoded locations.

    Sometimes an exact explanation can cloud the bigger picture. While they are hardcoded locations, the mechanism is the same for all config variables from the user/programmer perspective.
  • David BetzDavid Betz Posts: 14,516
    edited 2012-05-18 12:17
    pedward wrote: »
    So you are saying the loader doesn't look up the symbols, but it does set them?

    I know what you are getting at. The symbols are hardcoded in the address space, so the loader just sets them based on the hardcoded locations.

    Sometimes an exact explanation can cloud the bigger picture. While they are hardcoded locations, the mechanism is the same for all config variables from the user/programmer perspective.
    Well, there really is a difference. The symbols for CLKFREQ and CLKMODE exist independant of any programmer definitions of those symbols. In fact, if you try to define them yourself you'll get errors because they are already defined by the runtime library. Other symbols like _cfg_txpin are only patched if the user defines a global symbol with that name. If the user doesn't define those symbols they won't exist in the linked program. This is to prevent precious hub space from being used for parameters that the user doesn't need.
  • J^3J^3 Posts: 121
    edited 2012-05-18 17:19
    David Betz wrote: »
    CLKFREQ is set based on the corresponding value for the selected board configuration file and placed in location zero in hub memory.

    Thanks for the replies.

    Based on the above, my understanding is that the CLKFREQ gets set in the board configuration file. Is this correct? Also, what if I want to use a current board configuration, but want to run the clock at a different speed? Do I have to edit the board configuration file or can I do it in the code?
  • David BetzDavid Betz Posts: 14,516
    edited 2012-05-18 20:56
    J^3 wrote: »
    Thanks for the replies.

    Based on the above, my understanding is that the CLKFREQ gets set in the board configuration file. Is this correct? Also, what if I want to use a current board configuration, but want to run the clock at a different speed? Do I have to edit the board configuration file or can I do it in the code?
    You can override any value from the board configuration file with a command line option to the loader. For instance, -Dclkfreq=96000000 or -Dclkfreq=96mhz will set the clock frequency to 96mhz independent of what is in the board configuration file.
Sign In or Register to comment.