20.5 Self programming
The Flash in Tiny104 does not support Read-While-Write, and cannot be read during an erase or write operation. Therefore, the CPU will halt execution.
The device provides a Self-Programming mechanism for downloading and uploading program code by the MCU itself. Only WORD_WRITE and PAGE_ERASE commands are supported in self-programming. The CPU can execute Page Erase and Word Write in the NVM code memory section to perform programming operations.
Assembly Code Example |
The sequence for entering self-programming mode is given below (r19 can be any register): ; set CCP ldi r19, 0xe7 out CCP, r19 The software then has to perform the desired self-programming operation within 4 clock cycles. Example of the complete code to perform page erase: ; erase page ; set the page address pointer ldi ZL, 0xE1 ldi ZH, 0x43 ; set NVMCMD to page erase ldi temp, 0b011000 out NVMCMD, temp ; set CCP to enter program mode ldi r19, 0xe7 out CCP, r19 ; trigger the erase operation (within four clock cycles) ldi temp, 0x00 st Z+, temp ; required for proper CPU halting nop nop |