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.
 
 
 
 
 
 

73 lines
2.7 KiB

  1. /***************************************************************************
  2. * Copyright (C) 2014 by Angus Gratton *
  3. * Derived from stm32f1x.S:
  4. * Copyright (C) 2011 by Andreas Fritiofson *
  5. * andreas.fritiofson@gmail.com *
  6. * Copyright (C) 2013 by Roman Dmitrienko *
  7. * me@iamroman.org *
  8. * *
  9. * This program is free software; you can redistribute it and/or modify *
  10. * it under the terms of the GNU General Public License as published by *
  11. * the Free Software Foundation; either version 2 of the License, or *
  12. * (at your option) any later version. *
  13. * *
  14. * This program is distributed in the hope that it will be useful, *
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  17. * GNU General Public License for more details. *
  18. * *
  19. * You should have received a copy of the GNU General Public License *
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>. *
  21. ***************************************************************************/
  22. .text
  23. .syntax unified
  24. .cpu cortex-m0
  25. .thumb
  26. .thumb_func
  27. /* Written for NRF51822 (src/flash/nor/nrf51.c) however the NRF NVMC is
  28. * very generic (CPU blocks during flash writes), so this is actually
  29. * just a generic word-oriented copy routine for Cortex-M0 (also
  30. * suitable for Cortex-M0+/M3/M4.)
  31. *
  32. * To assemble:
  33. * arm-none-eabi-gcc -c cortex-m0.S
  34. *
  35. * To disassemble:
  36. * arm-none-eabi-objdump -o cortex-m0.o
  37. *
  38. * Thanks to Jens Bauer for providing advice on some of the tweaks.
  39. */
  40. /* Params:
  41. * r0 - byte count (in)
  42. * r1 - workarea start
  43. * r2 - workarea end
  44. * r3 - target address
  45. * Clobbered:
  46. * r4 - rp
  47. * r5 - wp, tmp
  48. */
  49. wait_fifo:
  50. ldr r5, [r1, #0] /* read wp */
  51. cmp r5, #0 /* abort if wp == 0 */
  52. beq exit
  53. ldr r4, [r1, #4] /* read rp */
  54. cmp r4, r5 /* wait until rp != wp */
  55. beq wait_fifo
  56. ldmia r4!, {r5} /* "*target_address++ = *rp++" */
  57. stmia r3!, {r5}
  58. cmp r4, r2 /* wrap rp at end of work area buffer */
  59. bcc no_wrap
  60. mov r4, r1
  61. adds r4, #8 /* skip rp,wp at start of work area */
  62. no_wrap:
  63. str r4, [r1, #4] /* write back rp */
  64. subs r0, #4 /* decrement byte count */
  65. bne wait_fifo /* loop if not done */
  66. exit:
  67. bkpt #0