prjbrook

tiny85 burns buf to pg 67 in flash

Jul 4th, 2014
277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.82 KB | None | 0 0
  1. ;tiny85flash0.asm avr stufio 4. Flashes 64 byte buffer into page 67 of tiny85.Works but code is messy.
  2. ;tn85SelfProg2. Erase worked in simulation. Got do_spm going. There's a difference between lds and out for spmcsr
  3. ;Test self prog program for Tiny 85. Just want to put a page
  4. ; of random data into flash
  5.  
  6.  
  7.  
  8. .include "tn85def.inc"
  9. .equ tab_size = 64
  10. .def spmcsr_val=r18
  11. .def buf_ctr = r19
  12. .def counterReg = r17
  13.  
  14. .DSEG
  15. var1: .BYTE 1 ; reserve 1 byte to var1
  16. table: .BYTE tab_size ; reserve tab_size bytes
  17.  
  18. .CSEG
  19. ;--------------set up stack
  20. ldi r16,low(RAMEND)
  21. out spl, r16
  22. ldi r16, high(RAMEND)
  23. out sph,r16
  24.  
  25. rjmp test_tableToFlashBuffer
  26.  
  27. ;----------stack done
  28. ;ldi r30,0xc0 ;load the starting page address into Z
  29. ;ldi r31,0x01 ; z=01c0 means PC page is page 7 0b111
  30. ldi r30,0xc0 ;
  31. ldi r31,0x10 ; z=$10c0 page 67, byte 0
  32. ldi r16, 0x51
  33. mov r0, r16 ; r1:r0 is 0xa150
  34. ldi r16, 0xa1
  35. mov r1, r16
  36. ;-----------now erase page----------
  37. ldi spmcsr_val,0x03 ;this is the page erase command
  38. rcall do_spm
  39. ;-------------page erased----------
  40.  
  41. ;---------now fill buffer with 64 bytes coming from r0,r1---
  42. nop
  43. push r30
  44. ldi buf_ctr, 32 ;number of temp buf insertions
  45. write_buf:
  46. ldi spmcsr_val,01 ;this is write r0:r1 to temp buffer
  47. rcall do_spm ;two bytes written, now what?
  48. inc r30
  49. inc r30 ;bump up z for next write
  50. dec buf_ctr
  51. brne write_buf ;loop 32 times
  52. nop ;when here have written to temp buf and z points to next page
  53. pop r30 ;get z-pointer back after 64 inc's
  54. ;----------buffer now filled and z-ptr points to start of page------
  55.  
  56. ;---------------now do page write----------------
  57. ldi spmcsr_val, 0x05 ;command that writes temp buffer to flash. 64 bytes
  58. rcall do_spm
  59. nop ; page now written. z still points to start of this page
  60.  
  61. here: rjmp here
  62. ;----------------------------------------------------------------
  63. fillBuf:
  64. ldi ZL,low(table) ;table is my buffer
  65. ldi ZH, high(table) ;Z now points to table
  66. ldi counterReg,64 ;64 bytes in buffer
  67. ldi r16,$30
  68. storeB0:
  69. st z+,r16
  70. inc r16
  71. dec counterReg
  72. brne storeB0
  73.  
  74. ; rjmp here
  75. ret
  76. ;----------------------------------------------------------
  77.  
  78. do_spm:
  79. ;lds r16,SPMCSR
  80. in r16,SPMCSR
  81. andi r16,1
  82. cpi r16,1
  83. breq do_spm
  84. mov r16,spmcsr_val
  85. out SPMCSR,r16
  86. spm
  87. ret
  88. ;-------------------------------------------------------------------
  89. tableToFlashBuffer: ;send the 64 bytes, 32 words to flash page <-- Z pnts there.
  90. push r30 ;save for later spm work.
  91. ldi XL,low(table) ;X pnts to table that contains the 64 bytes.
  92. ldi XH, high(table)
  93. ;assume Z is already pointing to correct flash start of page.
  94. ldi buf_ctr,32 ;send 32 words
  95. sendr0r1:
  96. ld r16, x+ ;get first byte
  97. mov r0,r16 ; into r0
  98. ld r16, x+ ; and get the second of the pair into
  99. mov r1,r16 ; into r1
  100. ldi spmcsr_val,01 ;set up for write into spare buffer flash page
  101. rcall do_spm ;that's r0,r1 gone in.
  102. inc r30
  103. inc r30
  104. dec buf_ctr ;done 32 times?
  105. brne sendr0r1
  106. pop r30 ;for next spm job
  107. ret
  108. ;--------------------------------------------------------------------------
  109. erasePage: ; assume Z points to start of a flash page. Erase it.
  110. ldi spmcsr_val,0x03 ;this is the page erase command
  111. rcall do_spm
  112. ret
  113. ;------------------------------------------------------------------
  114. writePage:
  115. ldi spmcsr_val, 0x05 ;command that writes temp buffer to flash. 64 bytes
  116. rcall do_spm
  117. nop ; page now written. z still points to start of this page
  118. ret
  119. ;---------------------------------------------------------------
  120. test_tableToFlashBuffer:
  121. rcall fillBuf
  122. ldi ZH, $10
  123. ldi ZL,$c0 ;z=$01c0. Start of page 67.
  124. rcall erasePage
  125. rcall tableToFlashBuffer
  126. rcall writePage
  127. herettt:
  128. rjmp herettt
Advertisement
Add Comment
Please, Sign In to add comment