Content originally posted in LPCWare by alindvall on Fri Nov 16 00:40:47 MST 2012
I have seen the same problem on LPC4357 on 4.60. I talked to Keil's support and got the following answer:
For your information, the problem was in the lpc43xx_cgu.c file:
--------------
(CGU_REG_BRANCH_STATUS(Clock) & CGU_BRANCH_STATUS_ENABLE_MASK)
in case of armcc CGU_BRANCH_STATUS_ENABLE_MASK is
#define CGU_BRANCH_STATUS_ENABLE_MASK 0x01
and CGU_REG_BRANCH_STATUS is:
#define CGU_REG_BRANCH_STATUS(x)
(*(uint32_t*)(CGU_CGU_ADDR+CGU_PERIPHERAL_Info[x].RegBranchOffset+0))
Seems like, because CGU_REG_BRANCH_STATUS(Clock) is not volatile, compiler loads only a byte
from this address, which is ok, as only 8 bit get tested. Other bits don't care.
But this address is in SFR space and byte access might be a problem, so wrong data is loaded.
To fix this, make CGU_REG_BRANCH_STATUS(Clock) dereferencing a volatile address:
#define CGU_REG_BRANCH_STATUS(x) (*(volatile
uint32_t*)(CGU_CGU_ADDR+CGU_PERIPHERAL_Info[x].RegBranchOffset+0))
----------------
When applying the fix to the CGU_REG_BRANCH_STATUS define I found that I had to do the same with the CGU_PER_BRANCH_STATUS define.