The specific issue is that systick_set_clocksource is horribly broken.

Basically there is one bit in STK_CTRL that determines either AHB or AHB/8
for the clock source, and that is bit 2. Current code is this:

void systick_set_clocksource(uint8_t clocksource)
{
    if (clocksource < 2) {
        STK_CSR |= clocksource;
    }
}

Which if the value passed is 0 or 1 will either do nothing (|= 0) or again
set bit 1 (STK_CTRL_TICKINT) or CSR_TICKINT both CSR and CTRL are used to
identify the same register.

The correct value (STK_CSR_CLKSOURCE_AHB or STK_CTRL_CLKSOURCE_AHB) is
correctly defined as 1 << STK_{CSR|CTRL}_CLKSOURCE_LSB which is 1 << 2 or
0x4 but the set clocksource call will not actually set the clock source
because the if clause is looking for a value less than 2. Presumably it
should either:
       look for EXACTLY either 4 or 0 since those are the only two
            if (clocksource == STK_CSR_CLKSOURCE_AHB) {
                  STK_CSR |= clocksource;
            }

       define a new constant where 1 becomes 4 and 0 remains 0
           if (clocksource < 2) {
                   STK_CSR |= clocksource << STK_CSR_CLOCKSOURCE_LSB;
           }

I slightly prefer the first (it is more future proof) but either will do.

The question is this, do I simply report it and wait for someone to fix it?
Or do I send a pull request with the fix? or should change it in my copy of
the repo and try to push it back (I expect that would fail). Guidance here
is welcome.

--Chuck
------------------------------------------------------------------------------
Rapidly troubleshoot problems before they affect your business. Most IT 
organizations don't have a clear picture of how application performance 
affects their revenue. With AppDynamics, you get 100% visibility into your 
Java,.NET, & PHP application. Start your 15-day FREE TRIAL of AppDynamics Pro!
http://pubads.g.doubleclick.net/gampad/clk?id=84349351&iu=/4140/ostg.clktrk
_______________________________________________
libopencm3-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/libopencm3-devel

Reply via email to