Hello,
I am trying to access the VBAT register like this:
#define VBATREGISTERFILE_BYTE0 (*((volatile uint8_t*) (0x4003E000)))
VBATREGISTERFILE_BYTE0 = 0xaa; // some value for testing.
When it comes to the assignement/access of the VBAT Register File a hardfault occurs.
I am using the same syntax and logic for accessing the SystemRegisterFile and that works just fine.
I have a custom board and supplied 3V3 to the VBAT pin, the over power pins are supplied with 3v3 also. (I read up that low voltage on VBAT may prevent from accessing the register)
The RTC is running with an external crystal just fine in the background and gets initialized with a proper time even before VBAT Register Access is attempted.
Do you have any ideas on this?
Thanks in advance.
Solved! Go to Solution.
Hello,
thank you for your fast reponse. I tried it today and figured out it works with
CLOCK_EnableClock(kCLOCK_Rtc_Rf0);
It seems I did some error while manually configuring this register.
Thanks!
When I first saw this, I had a number of questions and I think @ErichStyger & @mjbcswitzerland have kind of answered them but I still am curious about:
Comments?
Myke
The K22 doesn't have VBAT register files - in fact very few Kinetis parts do.
These registers are preserved across power cycles (when VBAT is present) and in all very low power modes and can be written and read as bytes, half words or long words.
The clock must be gated for reads/writes not to hard fault and this has to be enabled after every reset/power cycle.
Attached is a FRDM-KL82Z binary that can be loaded to such a board and VBAT register files tested as follows (either on its LPUART VCOM connection at 115kBaud or on its USB device connection as CDC class). Here I use the I/O menu to do memory reads, write etc., whereby the first thing that needs to be done is
"mm 4004803c l 60000031" to enable the VBAT clock gate (the 0x40000000 is set since it is initially 0 in SIM_SCGC6)
Below is a test session where reads and writes of different sizes are verified (it started after a watchdog reset due to previously trying to read a VBAT register without the clock gated to it (hard fault).
Regards
Mark
Console session:
Hello, world... FRDM-KL82Z [WDOG]
Kinetis Unique ID: 0x10710000750a003e0014100735194e45
Static memory = 0x00000c74
OS Heap use = 0x0359 from 0x3000
Initial stack margin 0x000141ec
Enumerated [1]
Serial number: 00
Software version V1.4.012
Device identification: KINETIS
Main menu
===================
1 Configure LAN interface
2 Configure serial interface
3 Go to I/O menu
4 Go to administration menu
5 Go to overview/statistics menu
6 Go to USB menu
7 Go to I2C menu
8 Go to utFAT disk interface
9 FTP/TELNET commands
a CAN commands
help Display menu specific help
quit Leave command mode
3
Input/Output menu
===================
up go to main menu
md Memory Display [address] [<l>|<w>|<b>] [num]
mm Memory Modify [address] [<l>|<w>|<b>] [val]
mf Memory Fill [address] [<l>|<w>|<b>] [val] [num]
sd Storage Display {as md}
sm Storage Modify {as mm}
sf Storage Fill {as mf}
se Storage Erase [address] [len-hex]
dma DMA transfer [src][dst][len]
lp_cnt Read LPTMR CNT
dac DAC [ref] [hex]
save Save port setting as default
help Display menu specific help
quit Leave command mode
#mm 4004803c l 60000031
Write - OK
#md 4003e000 l 4
Memory Display
0x4003e000 12345678 00000000 00000000 00000000 .4Vx............
#mm 4003e000 l 0
Write - OK
md 4003e000 l 4
Memory Display
0x4003e000 00000000 00000000 00000000 00000000 ................
#mf 4003e000 l 12345678 4
Fill - OK
md 4003e000 l 4
Memory Display
0x4003e000 12345678 12345678 12345678 12345678 .4Vx.4Vx.4Vx.4Vx
#md 4003e000 b 16
Memory Display
0x4003e000 78 56 34 12 78 56 34 12 78 56 34 12 78 56 34 12 xV4.xV4.xV4.xV4.
#mm 4003e000 l 0
Write - OK
md 4003e000 b 16
Memory Display
0x4003e000 00 00 00 00 78 56 34 12 78 56 34 12 78 56 34 12 ....xV4.xV4.xV4.
md 4003e000 l 4
Memory Display
0x4003e000 00000000 12345678 12345678 12345678 .....4Vx.4Vx.4Vx
#mm 4003e000 b 25
Write - OK
md 4003e000 l 4
Memory Display
0x4003e000 00000025 12345678 12345678 12345678 ...%.4Vx.4Vx.4Vx
mm 4003e000 w 1234
Write - OK
md 4003e000 l 4
Memory Display
0x4003e000 00001234 12345678 12345678 12345678 ...4.4Vx.4Vx.4Vx
#md 4003e000 b 16
Memory Display
0x4003e000 34 12 00 00 78 56 34 12 78 56 34 12 78 56 34 12 4...xV4.xV4.xV4.
#mm 4003e003 b aa
Write - OK
md 4003e000 b 16
Memory Display
0x4003e000 34 12 00 aa 78 56 34 12 78 56 34 12 78 56 34 12 4...xV4.xV4.xV4.
mm 4003e002 w 7654
Write - OK
md 4003e000 b 16
Memory Display
0x4003e000 34 12 54 76 78 56 34 12 78 56 34 12 78 56 34 12 4.TvxV4.xV4.xV4.
Hey @mjbcswitzerland
Thanx for the taking the time to explain. I was looking at the SIM_SCGC6 register and thinking that this is what @marcwillem was trying to write to.
Cheers!
Hi @marcwillem ,
yes, the lack of VBAT supply voltage could cause a hard fault. The other thing to check
Not sure about that 0x4003E000 address: is this a writeable location?
Is your RTC clocked (clock gates?)?
I hope this helps,
Erich
Hi
Regards
Mark