Hi, Rodrigo,
Regarding the set_pll function:
command[0] = 4000;
command[1] = 4000;
command[2] = CPU_FREQ_EQU;
command[3] = 0;
(*rom)->pWRD->set_pll(command, result);
It appears that above parameters are incorrect.
Pls refer to Fig 12 in UM10398.pdf, the first parameter0 command[0] is the system PLL input frequency, depending on the SYSPLLCLKSEL reg setting, it can be irc_osc_clk(12MHz) or sys_osc_clk(it is dependent on the external crystal frequency on the XTALIN/XTALOUT pins), in default, it is 12MHz instead of 4000(4MHz) I think. The parameter1 is expected system clock (in kHz), I do not think it is 4MHz, it should be for example 50MHz, the value is 50000.,
BTW, if you want to set up the main clock frequency as 4MHz, you do not need to use pll, you can use the 12MHz irc_osc_clk(12Mhz) as main clock, use the CLOCK DIVIDER to get 4MHz with 3 divider, the system clock will be 4MHz, it is okay.
Hope it can help you
BR
Xiangjun rong