Kinetis KL82: Cannot access VBAT register

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Kinetis KL82: Cannot access VBAT register

Jump to solution
1,014 Views
marcwillem
Contributor II

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.

0 Kudos
1 Solution
1,007 Views
mjbcswitzerland
Specialist V
6 Replies
959 Views
marcwillem
Contributor II

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!

0 Kudos
990 Views
myke_predko
Senior Contributor III

@marcwillem 

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:

  1. Is the register explicitly writable?  When I look at the RM it looks like it is, but with Mark's post there is a reference which seems to imply (but not explicitly state) that the register can't be written to.  Further confusing the issue is that the register bit reference screen shot provided by Mark clearly shows a "W" indicating that the register bits are writeable.  
    1. When I look another device (I had the RM open for the MK22FN1M0Axxx12) for this register there isn't the same message as what Mark quotes - so can I assume that on this part the register is writeable?  
    2. So how do you determine whether or not a register is writeable in a reasonably efficient manner?  Personally, I think it should be spelled out explicitly in the RM at the location of the register.  
  2. You are referencing the register as a "uint8_t" type - shouldn't it be "uin32_t" as it is a 32bit register?  I would think that in the actual hardware register write bits 8 through 31 would be loaded with zero. 
    1. I believe the actual register datapaths are all 32bits and cannot handle 8 or 16 bit writes and i would be very suprised if the compiler was smart enough to recognize that this is a register write and it should read the register and OR bits 8 through 31 wtih the new value for the lower 8 bits before doing the write.  

Comments?  

0 Kudos
981 Views
mjbcswitzerland
Specialist V

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.



979 Views
myke_predko
Senior Contributor III

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!

0 Kudos
1,012 Views
ErichStyger
Senior Contributor V

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

0 Kudos
1,008 Views
mjbcswitzerland
Specialist V

Hi

mjbcswitzerland_0-1609408199263.png

 

mjbcswitzerland_1-1609408215667.png

Regards

Mark