You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

79 lines
2.7 KiB

  1. /***************************************************************************
  2. * Copyright (C) 2006 by Magnus Lundin *
  3. * lundin@mlu.mine.nu *
  4. * *
  5. * Copyright (C) 2008 by Spencer Oliver *
  6. * spen@spen-soft.co.uk *
  7. * *
  8. * This program is free software; you can redistribute it and/or modify *
  9. * it under the terms of the GNU General Public License as published by *
  10. * the Free Software Foundation; either version 2 of the License, or *
  11. * (at your option) any later version. *
  12. * *
  13. * This program is distributed in the hope that it will be useful, *
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  16. * GNU General Public License for more details. *
  17. * *
  18. * You should have received a copy of the GNU General Public License *
  19. * along with this program; if not, write to the *
  20. * Free Software Foundation, Inc., *
  21. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
  22. ***************************************************************************/
  23. .text
  24. .syntax unified
  25. .cpu cortex-m3
  26. .thumb
  27. .thumb_func
  28. /*
  29. * Params :
  30. * r0 = workarea start
  31. * r1 = workarea end
  32. * r2 = target address
  33. * r3 = count (32bit words)
  34. *
  35. * Clobbered:
  36. * r4 = pFLASH_CTRL_BASE
  37. * r5 = FLASHWRITECMD
  38. * r7 - rp
  39. * r8 - wp, tmp
  40. */
  41. write:
  42. ldr r4, pFLASH_CTRL_BASE
  43. ldr r5, FLASHWRITECMD
  44. wait_fifo:
  45. ldr r8, [r0, #0] /* read wp */
  46. cmp r8, #0 /* abort if wp == 0 */
  47. beq exit
  48. ldr r7, [r0, #4] /* read rp */
  49. cmp r7, r8 /* wait until rp != wp */
  50. beq wait_fifo
  51. mainloop:
  52. str r2, [r4, #0] /* FMA - write address */
  53. add r2, r2, #4 /* increment target address */
  54. ldr r8, [r7], #4
  55. str r8, [r4, #4] /* FMD - write data */
  56. str r5, [r4, #8] /* FMC - enable write */
  57. busy:
  58. ldr r8, [r4, #8]
  59. tst r8, #1
  60. bne busy
  61. cmp r7, r1 /* wrap rp at end of buffer */
  62. it cs
  63. addcs r7, r0, #8 /* skip loader args */
  64. str r7, [r0, #4] /* store rp */
  65. subs r3, r3, #1 /* decrement word count */
  66. cbz r3, exit /* loop if not done */
  67. b wait_fifo
  68. exit:
  69. bkpt #0
  70. pFLASH_CTRL_BASE: .word 0x400FD000
  71. FLASHWRITECMD: .word 0xA4420001