One of my board had low voltage issue and it seems caused G400 running extra slow. The low voltage issue is resolved but I want to add check in firmware should this happen in future we can display it as an error.
I read the Atmel-11055F-ATARM-SAM9X35-Datasheet_31-Aug-15, on page 195 it lists the register CKGR_MCFR should contain main clock cycle count so I can easily calculate it with the formula:
fMAINCK = (MAINF * fSLCK) / 16 (Where frequency is in MHz)
This is my code to get the register value:
var CKGR_MCFR = 0xFFFFFC24;
var reg = new Register(CKGR_MCFR);
var va = reg.Value;
var reg1 = new Register(CKGR_MCFR);
var va2 = reg1.Value;
Both va & va2 are 0x118FC. The bit 16 is 1 which indicate MAINF is reliable. The MAINF = 0x18FC = 6396.
6396 * 0.032768 / 16 = 13.099008MHz
The result is far off from the G400 actual running frequency which should be 400MHz. I also checked the crystal on G400 board is 12.000MHz so the 13.09MHz couldn’t be referring to the crystal frequency.
I am little puzzled how is the main clock frequency is calculated.
Still one strange thing is sometimes I got fMAINCK = 12MHz and some other times 13MHz. If the fMAINCK is 13MHz this will results fMCK = 433MHz, 33MHz higher than the standard.
On the 13MHz times I checked the register it is indeed the external crystal instead of the internal RC is providing the main clock.
It looks like the G400 module uses SJK 12.000 crystal. According to the datasheet http://biakom.com/pdf/SJK_Catalog.pdf the H6 series should have at most 50ppm frequency error. For a 12MHz crystal it means 12 * 0.005 = 0.06MHz of frequency error should be in the allowance range.