Access ATXMega8E5 Flash from Host CPU

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

Sorry for what may be a noob question, but I've literally had this problem dropped in my lap.

 

We have an ATXMega8E5 hanging off an IMX6 host CPU that using the XMEGA for its TWI and QDEC.  That's all running fine, but now the task is to read the user_signature row from the XMEGA flash from the IMX6 and I don't know how to access the flash memory.  Is there an app note or the like that can show me?  I don't mind reading, just don't know where to start looking.  I had the XDF project that set up the TWI and QDEC, so I can add the extra stuff there to expose the flash address space.

 

Thanks.

 

Matt

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

First question ought to be: How do the host and the slave communicate?

 

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

Last Edited: Thu. Feb 1, 2018 - 09:27 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If you want to dabble in the dark world of ASF then this page:

 

http://asf.atmel.com/docs/latest...

 

shows the use of the Atmel supplied nvm_read_user_signature_row() function.

 

The downside is that to call that 1 function ASF typically adds about 50 header files and a whole raft of code to your project (and sorry if I am being a bit negative and that's not true in this isolated case!). For an 8K micro this might be significant.

 

However what you could do is create a completely standalone project in AS7 using ASF to add just NVM access and then study all the code to see what's actually at the core of doing it.

 

The alternative I guess would simply be to read about the NVM Controller in one of the two E5 datasheets and just program the things directly using the low level info.

 

BTW a google suggests that AVR1316 may have some info about reading the sig row (though that is not the direct focus of that app note).

 

EDIT: Apparently the functions in 1316 include:

/*! \brief Read user signature at given index.
 *
 *  This function reads one byte from the user signature row.
 *
 *  \param index  Index of the byte in the user signature row.
 *
 *  \retval User signature byte
 */
uint8_t SP_ReadUserSignatureByte(uint16_t index);

EDIT2: found it on the new look Microchip site:

 

http://www.microchip.com//wwwApp...

EDIT3: so the implementation is actually in the .S file:

; ---
; 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.

but clearly that's really dependent on:

; ---
; 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

So all this might show that it only actually takes a few opcodes to achieve the functionality.

 

However what I can't tell you (without more study) is whether you can simply call SP_ReadUserSignatureByte() directrly with no other prior setup? For all I know there might be some kind of SP_Init() you need to call first that gets the whole system rolling? Suggest you study the words and code in AVR1316

Last Edited: Fri. Feb 2, 2018 - 10:41 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The AVR1316 code is a bit buggy in places but basically works. A better option is to steal the ASF code and just ditch all the other crap it tries to add to your project.

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

mojo-chan wrote:
A better option is to steal the ASF code
Is that really "better"? Do you mean just from the point of view of bug avoidance?

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

clawson wrote:

mojo-chan wrote:

A better option is to steal the ASF code

 

Is that really "better"? Do you mean just from the point of view of bug avoidance?

 

Yeah, it's slightly less buggy than the app note code.

 

From memory the main issue with the app note is that it doesn't restore registers properly, maybe the NVM.CTRL one or one of the CPU registers. Anyway, under some circumstances it can cause issues.

 

Having said that I think I fixed it in this copy I made: https://github.com/kuro68k/kboot...

 

Or I might have forgotten... If I remember or someone reminds me next week I'll check against some known fixed production code.