CCP error in AU manual?

Go To Last Post
2 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The manual for the AU series says CCP (Configuration Change Protection) must be used with the LPM instruction when reading fuses and signature row.

This seems to be wrong. What am I missing? I use pgm_read_byte() to read the User and Production signature rows without using CPP, and it works fine with my Xmega128au chips. None of the examples I've seen on the internet that shows pgm_read_byte() and the __LPM macro it calls shows CCP being used.

Well, I see that using CCP disables interrupts for the duration of the CCP enable period. Maybe that can be beneficial?

In the AVR911 bootloader (Bandtank etc.) sp_driver.s, I see reading the signature rows and fuses without using CCP. I'm not an expert with the AVR assembler, but that seems to be the case.

; ---
; This routine reads the user signature byte given by the index in R25:R24.
;
; Input:
;     R25:R24 - Byte index.
;
; Returns:
;     R24 - Signature byte.
; ---

.section .text
.global SP_ReadUserSignatureByte

SP_ReadUserSignatureByte:
	ldi	r20, NVM_CMD_READ_USER_SIG_ROW_gc  ; Prepare NVM command in R20.
	rjmp	SP_CommonLPM                       ; Jump to common LPM code.



; ---
; This routine is called by several other routines, and contains common code
; for executing an LPM command, including the return statement itself.
;
; Note that R24 is used for returning results, even if the
; C-domain calling function expects a void.
;
; Input:
;     R25:R24 - Low bytes of Z pointer.
;     R20     - NVM Command code.
;
; Returns:
;     R24     - Result from LPM operation.
; ---

.section .text

SP_CommonLPM:
	movw	ZL, r24             ; Load index into Z.
	sts	NVM_CMD, r20        ; Load prepared command into NVM Command register.
	lpm	r24,Z
	ret

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I guess it's wrong. If you read 33.11.2.12-14

Quote:
33.11.2.12 Erase User Signature Row
The erase user signature row command is used to erase the user signature row.
1. Load the NVM CMD register with the erase user signature row command.
2. Execute the SPM instruction. This requires the timed CCP sequence during self-programming.
The BUSY flag in the NVM STATUS register will be set, and the CPU will be halted until the erase operation is finished.
The user signature row is NRWW.
33.11.2.13 Write User Signature Row
The write signature row command is used to write the flash page buffer into the user signature row.
1. Set up the NVM CMD register to write user signature row command.
2. Execute the SPM instruction. This requires the timed CCP sequence during self-programming.
The BUSY flag in the NVM STATUS register will be set until the operation is finished, and the CPU will be halted during
the write operation. The flash page buffer will be cleared during the command execution after the write operation, but the
CPU is not halted during this stage.
33.11.2.14 Read User Signature Row / Production Signature Row
The read user signature row and read production signature (calibration) row commands are used to read one byte from
the user signature row or production signature (calibration) row.
1. Load the Z-pointer with the byte address to read.
2. Load the NVM CMD register with the read user signature row / production signature (calibration) row command
3. Execute the LPM instruction.
The destination register will be loaded during the execution of the LPM instruction.
To ensure that LPM for reading flash will be executed correctly it is advised to disable interrupt while using either of these
commands.
the CCP is only mentioned for erase and write, not for read. But I guess that 4 cycle disable of interrupts when you write CCP could be useful even if the CCP write isn't needed.