This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Programming flash on ST10F269

Can anyone point me in the direction of any information/code on programming on-chip Flash. I have application note 1496 but require more information than it offers.

Parents
  • When I run the following code instead of getting the flash status register on polling I am reading the value from the flash at the address I am trying to program. Has anybody else come accross this problem ?

    uint16_t ProgramWord( uint16_t segment, uint16_t segment_offset, uint16_t data )
    {
    	uint16_t rc = 255 ;
    
    __asm{
    		BCLR	IEN
    		NOP
    		NOP
    
    		PUSH 	R5
    		PUSH 	R6
    		PUSH 	R7
    
    		MOV		R5,#01554h		;load auxilary register R5 with command address
    								;(used in command cycle 1)
    		MOV		R6,#02AA8h		;load auxilary register R6 with command address
    								;(used in command cycle 2)
    		SCXT	DPP0,#08h		;push data page pointer 0 and load it to point
    								;to segment 1
    		MOV		R7,#0A8h		;load register R7 with 1st CI enable command
    		MOV		[R5],R7			;command cycle 1
    		MOV		R7,#054h		;load register R7 with 2nd CI enable command
    		MOV		[R6],R7			;command cycle 2
    		MOV		R7,#0A0h		;load register R7 with Program Word command
    		MOV		[R6],R7			;command cycle 3
    		POP		DPP0			;restore DPP0: following addressing to the Flash
    								;will use EXTended instructions
    								;R8 contains the segment to be programmed
    								;R9 contains the segment offset address to be programmed
    								;R10 contains the data to be programmed
    		MOV		R8,#02h 		;segment
    		MOV		R9,#0000h 		;segment_offset
    		MOV		R10,#0000h 		;data
    
    		EXTS	R8,#1			;use EXTended addressing for next MOV instruction
    		MOV		[R9],R10		;command cycle 4: the E/P.C starts the execution of
    								;Programming Command
    
    		; Data-Polling after word programming :
    	Data_Polling :
    		EXTS	R8,#1			;use EXTended addressing for next MOV instruction
    		MOV		R7,[R9]			;read Flash Status register (FSB) in R7
    		MOV		debug12,R7
    		MOV		R6,R7			;save it in R6 register
    		XOR		R7,R10			;Check if FSB.7 = Data.7 (i.e. R7.7 = R10.7)
    		JNB		R7.7,Prog_OK
    								;Check if FSB.5 = 1 (Programming Error)
    		JNB		R6.5,Data_Polling
    		EXTS	R8,#1			;use EXTended addressing for next MOV instruction
    		MOV		R7,[R9]			;read Flash Status register (FSB) in R7
    
    		XOR		R7,R10			;Check if FSB.7 = Data.7 (i.e. R7.7 = R10.7)
    		JNB		R7.7,Prog_OK
    								;Programming failed: Flash remains in Write Operation.
    								;To go back to normal Read operations, a Read/Reset
    								;command must be performed
    	Prog_Error :
     		MOV 	R7, #0F0h		;load register R7 with Read/Reset command
    		EXTS	R8,#1			;use EXTended addressing for next MOV instruction
    		MOV		[R9],R7
    		MOV		rc,#00h
    
    	Prog_OK :
    
    		POP 	R5
    		POP 	R6
    		POP 	R7
    
    		BSET	IEN
    		NOP
    		NOP
    	 }
    
    	 return rc ;
    }
    

Reply
  • When I run the following code instead of getting the flash status register on polling I am reading the value from the flash at the address I am trying to program. Has anybody else come accross this problem ?

    uint16_t ProgramWord( uint16_t segment, uint16_t segment_offset, uint16_t data )
    {
    	uint16_t rc = 255 ;
    
    __asm{
    		BCLR	IEN
    		NOP
    		NOP
    
    		PUSH 	R5
    		PUSH 	R6
    		PUSH 	R7
    
    		MOV		R5,#01554h		;load auxilary register R5 with command address
    								;(used in command cycle 1)
    		MOV		R6,#02AA8h		;load auxilary register R6 with command address
    								;(used in command cycle 2)
    		SCXT	DPP0,#08h		;push data page pointer 0 and load it to point
    								;to segment 1
    		MOV		R7,#0A8h		;load register R7 with 1st CI enable command
    		MOV		[R5],R7			;command cycle 1
    		MOV		R7,#054h		;load register R7 with 2nd CI enable command
    		MOV		[R6],R7			;command cycle 2
    		MOV		R7,#0A0h		;load register R7 with Program Word command
    		MOV		[R6],R7			;command cycle 3
    		POP		DPP0			;restore DPP0: following addressing to the Flash
    								;will use EXTended instructions
    								;R8 contains the segment to be programmed
    								;R9 contains the segment offset address to be programmed
    								;R10 contains the data to be programmed
    		MOV		R8,#02h 		;segment
    		MOV		R9,#0000h 		;segment_offset
    		MOV		R10,#0000h 		;data
    
    		EXTS	R8,#1			;use EXTended addressing for next MOV instruction
    		MOV		[R9],R10		;command cycle 4: the E/P.C starts the execution of
    								;Programming Command
    
    		; Data-Polling after word programming :
    	Data_Polling :
    		EXTS	R8,#1			;use EXTended addressing for next MOV instruction
    		MOV		R7,[R9]			;read Flash Status register (FSB) in R7
    		MOV		debug12,R7
    		MOV		R6,R7			;save it in R6 register
    		XOR		R7,R10			;Check if FSB.7 = Data.7 (i.e. R7.7 = R10.7)
    		JNB		R7.7,Prog_OK
    								;Check if FSB.5 = 1 (Programming Error)
    		JNB		R6.5,Data_Polling
    		EXTS	R8,#1			;use EXTended addressing for next MOV instruction
    		MOV		R7,[R9]			;read Flash Status register (FSB) in R7
    
    		XOR		R7,R10			;Check if FSB.7 = Data.7 (i.e. R7.7 = R10.7)
    		JNB		R7.7,Prog_OK
    								;Programming failed: Flash remains in Write Operation.
    								;To go back to normal Read operations, a Read/Reset
    								;command must be performed
    	Prog_Error :
     		MOV 	R7, #0F0h		;load register R7 with Read/Reset command
    		EXTS	R8,#1			;use EXTended addressing for next MOV instruction
    		MOV		[R9],R7
    		MOV		rc,#00h
    
    	Prog_OK :
    
    		POP 	R5
    		POP 	R6
    		POP 	R7
    
    		BSET	IEN
    		NOP
    		NOP
    	 }
    
    	 return rc ;
    }
    

Children