colin howard

AN2720SW - Some feedback

Discussion created by colin howard on Jan 9, 2008
Latest reply on Jan 14, 2008 by bigmac
Hi All

The "Codewarrior Stationery" version of AN2720SW (or at least the one I found on the forum) has a few errors and/or bits of misleading coding. From flash.c:

    FSTAT |= (FSTAT_PVIOL|FSTAT_ACCERR);   /* Clear any errors  */

There are a couple of variations on the above in the code, and I think these should all be replaced with
which is how it is done in some other places in the code.  There are two reasons for this, (1) The |= assignment causes a read/modify/write sequence which can inadvertently clear other flags, (2) The FSTAT_PVIOL and FSTAT_ACCERR are the bit members of the struct - doing a bit-wise OR of them doesn't really make sense (and I don't consider myself a complete C guru but I think the behaviour of such a bit-wise OR, as opposed to a logical OR, might be undefined)

    FCLKDIV |= fclk_val | FCLKDIV_PRDIV8_MASK;

The |= assignment look suspect - why or in the old value?  Will work OK (since out of reset FCLKDIV is zero and it is a write once register) but it looks like bad coding.

So, does anyone know of a post 09/09/2004 version of this code?