Hi,
I am trying to write to EEPROM without involvement of CPU, as it provides a convenient way of preparing devices. I am erasing the flash memory and trying to write to the EEPROM via a J-Link.
I have tried different scenarios to understand what the problem can be. First of all, I can successfully write to EEPROM from the CPU (i.e. when using the SDK). I can also write to the EEPROM by J-Link when I keep the clock and power configurations that CPU sets. However, I am not able to write to the EEPROM when I attempt to erase and reset the CPU and do all the required power/clock configurations through J-Link. I was wondering if anyone can point what configuration I am missing.
Here is a pseudocode showing how I communicate to J-Link to configure the device and write to the EEPROM. In the last line, the bit never gets set indicating an unsuccessful write to the EEPROM (or probably the fact that something has not been configured properly). Can you check whether I am doing the configuration correctly?
ADDRESS_AHBCLKCTRL0 = 0x40000200
ADDRESS_MAINCLKSELA = 0x40000280
ADDRESS_MAINCLKSELB = 0x40000284
ADDRESS_SYSPLLCLKSEL = 0x40000290
ADDRESS_AHBCLKDIV = 0x40000380
ADDRESS_SYSPLLCTRL = 0x40000580
ADDRESS_SYSPLLNDEC = 0x40000588
ADDRESS_SYSPLLPDEC = 0x4000058C
ADDRESS_PDRUNCFG0 = 0x40000610
ADDRESS_PDRUNCFGCLR0 = 0x40000630
ADDRESS_PRESETCTRL0 = 0x40000100
ADDRESS_PRESETCTRLSET0 = 0x40000120
ADDRESS_PRESETCTRLCLR0 = 0x40000140
ADDRESS_CMD = 0x40014000
ADDRESS_RWSTATE = 0x40014008
ADDRESS_WSTATE = 0x40014010
ADDRESS_CLKDIV = 0x40014014
ADDRESS_INTSTAT = 0x40014FE0
ADDRESS_INTSTATCLR = 0x40014FE8
ADDRESS_EEPROM_BASE = 0x40108000
# Clock configurations for main_clk
# Select Free running oscillator (FRO) 12 MHz for main clock source
write_word(ADDRESS_PDRUNCFGCLR0, 1 << 4) # Ensure FRO is running
write_word(ADDRESS_MAINCLKSELA, 0)
write_word(ADDRESS_MAINCLKSELB, 0)
# System clock and AHB clock control register
ahbclkctrl0 = read_word(ADDRESS_AHBCLKCTRL0)
write_word(ADDRESS_AHBCLKCTRL0, ahbclkctrl0 | (1 << 9)) # Enable EEPROM
# Set EEPROM peripheral reset
write_word(ADDRESS_PRESETCTRLSET0, (1 << 9)) # Reset
--> Wait until bit 9 in ADDRESS_PRESETCTRL0 is set
write_word(ADDRESS_PRESETCTRLCLR0, (1 << 9)) # Clear the reset
--> Wait until bit 9 in ADDRESS_PRESETCTRL0 is cleared
# Set EEPROM clock
write_word(ADDRESS_CLKDIV, 3)
# Set the wait states for read and write
write_word(ADDRESS_RWSTATE, 0x00000A0A)
write_word(ADDRESS_WSTATE, 0x000A0A0A)
# Write
write_word(ADDRESS_INTSTATCLR, 1 << 2) # Clear program operation finished interrupt status
eeprom_address = ADDRESS_EEPROM_BASE
write_word(eeprom_address, b"\x01")
write_word(ADDRESS_CMD, 0x00000110) # Trigger an erase/program operation
--> Wait until bit 2 in ADDRESS_INTSTAT is set