View previous topic :: View next topic |
Author |
Message |
enniom
Joined: 20 Oct 2009 Posts: 537
|
Posted: Sun Dec 07, 2014 2:33 am Post subject: Is it possible to write XMEGA Fuse Bits? |
|
|
Hello Forum,
The BASCOM help describes reading the Fuse Bits and reading/writing the Lock Bits for XMEGA.
This sample writes the Lock Bits:
Code: | Sub Write_lockbits(lockbyte As Byte)
Nvm_data0 = Lockbyte
Nvm_data1 = 0
Nvm_data2 = 0
Nvm_cmd = &H08 'Load the NVM CMD register with the Write Lock Bit command
Cpu_ccp = &HD8 '0xD8 IOREG Protected IO register (this disables interrupts for 4 cycles)
Nvm_ctrla.0 = 1 'Non-Volatile Memory Command Execute
Bitwait Nvm_status.7 , Reset
Nvm_cmd = 0
End Sub |
I did find this snippet which, I assume, writes FuseByte in MEGA chips, but I am reluctant to experiment with it as I may make the XMEGA chip unusable.
Code: |
'DISABLE_JTAG:
IN R24, MCUCR
!SET
BLD R24, 7
!OUT MCUCR, R24
!OUT MCUCR, R24
|
I imagine there might be a "Nvm_cmd" to write FuseByte0..5 - but I have not been able to find it.
I would like to change the EESave and BootRST settings (maybe others) from within the Bootloader if possible.
Thanks in advance for any help.
Ennio
(BASCOM-AVR version : 2.0.7.7 ) |
|
Back to top |
|
|
reinhars
Joined: 29 Nov 2009 Posts: 114
|
Posted: Tue Dec 09, 2014 11:09 am Post subject: |
|
|
From Datasheet: 8077H–AVR–12/09
Quote: |
4.4 Fuses and Lockbits
The Fuses are used to set important system function and can only be written from an external
programming interface. The application software can read the fuses. The fuses are used to con-
figure reset sources such as Brown-out Detector and Watchdog, Start-up configuration, JTAG
enable and JTAG user ID.
The Lock bits are used to set protection level on the different flash sections. They are used to
block read and/or write access of the code. Lock bits can be written from en external program-
mer and from the application software to set a more strict protection level, but not to set a less
strict protection level. Chip erase is the only way to erase the lock bits. The lock bits are erased
after the rest of the flash memory is erased.
An unprogrammed fuse or lock bit will have the value one, while a programmed flash or lock bit
will have the value zero.
Both fuses and lock bits are reprogrammable like the Flash Program memory. |
You can read and write lockbits with your bootloader. You can read and NOT write the fuses from your bootloader. I use to check for the right fuses im my bootloader and stop AVR if the fuses are wrong. |
|
Back to top |
|
|
enniom
Joined: 20 Oct 2009 Posts: 537
|
Posted: Tue Dec 09, 2014 1:46 pm Post subject: |
|
|
Thank-you Reinhars for your help.
It seems as if the FuseBit checks you make in the Bootloader are similar to what I wanted to do ... I was hoping to also be able to change them too in the Bootloader.
The Quote you posted makes it clear. |
|
Back to top |
|
|
Deanus
Joined: 26 May 2006 Posts: 188 Location: Adelaide
|
Posted: Mon Dec 15, 2014 9:15 am Post subject: |
|
|
Hi Reinhars,
This is interesting, as it states in the data sheet section that you have provides that the fuses can be read but not written from within the program, but not 2 minutes ago, I read the " LCD TAmega32 16PU no display " article and it states (second to last post)
"Or disable the jtag in your code with DISABLED JTAG at the beginning of your code.
Is this a compiler command used at programming stage, or is it a command that operates from withing your program.
Since the programmer is attached at the time of writing to the chip, I assume that the compiler is writing the fuse bits even though you don't specifically say "write the fuses", would this be correct.
Dean |
|
Back to top |
|
|
Evert :-)
Joined: 18 Feb 2005 Posts: 2156
|
Posted: Mon Dec 15, 2014 9:32 am Post subject: |
|
|
Hi Dean,
You can't change the fuse bits from the within the program ( 8bit avr). With Disabled jtag you can overwrite the jtag fuse bit temporarily.
If you disable the jtag with the fuse bit it's disabled forever, until you reset the fuse bits with an isp programmer.
If you use the Disable Jtag statement the fuse bit will not changed, but the jtag will be disabled in code until the cpu is reset. Removing this line code will enable the jtag also again.
Now these days with the newer avr's there are more fuses that can be overwritten temporarily by code like Clock div, Watchdog.
I said place it at the beginning of your code because if you place it for example behind the Config display, the jtag holds still the port occupied when initializing the lcd port. _________________ www.evertdekker.com Bascom code vault |
|
Back to top |
|
|
Deanus
Joined: 26 May 2006 Posts: 188 Location: Adelaide
|
Posted: Mon Dec 15, 2014 8:17 pm Post subject: |
|
|
Hi Evert,
Thanks for the explanation, learn something new every day!
Regards
Dean |
|
Back to top |
|
|
|