aboutsummaryrefslogtreecommitdiff
path: root/contrib/loaders/flash/stm32/stm32lx.S
blob: 7cfe48545215f4e6728faf43e1999c5c3eb48394 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/***************************************************************************
 *   Copyright (C) 2010 by Spencer Oliver                                  *
 *   spen@spen-soft.co.uk                                                  *
 *                                                                         *
 *   Copyright (C) 2011 Øyvind Harboe                                      *
 *   oyvind.harboe@zylin.com                                               *
 *                                                                         *
 *   Copyright (C) 2011 Clement Burin des Roziers                          *
 *   clement.burin-des-roziers@hikob.com                                   *
 *                                                                         *
 *   Copyright (C) 2017 Armin van der Togt                                 *
 *   armin@otheruse.nl                                                     *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 ***************************************************************************/

	.text
	.syntax unified
	.cpu cortex-m0
	.thumb

/*
Parameters
	r0 - destination address
	r1 - source address
	r2 - half pages
	r3 - bytes per half page
	r4 - flash base
Variables
	r0 - destination write pointer
	r1 - source read pointer
	r2 - source limit address
	r3 - bytes per half page
	r4 - flash base
	r5 - pages left in current half page
	r6 - temporary r/w
*/

/* offsets of registers from flash reg base */
#define STM32_FLASH_SR_OFFSET 0x18

	.thumb_func
	.global _start
_start:
	// r2 = source + half pages * bytes per half page
	muls r2, r2, r3
	add r2, r1, r2
	// Go to compare
	b test_done
write_half_page:
	// initialize pages left in current half page
	mov r5, r3
write_word:
	// load word from address in r1 and increase r1 by 4
	ldmia r1!, {r6}
	// store word to address in r0 and increase r0 by 4
	stmia r0!, {r6}
	// check for end of half page
	subs r5, r5, #4
	bne write_word
wait_busy:
	// read status register into r6, loop while bottom bit is set
	ldr r6, [r4, #STM32_FLASH_SR_OFFSET]
	lsls r6, r6, #31
	bne wait_busy
test_done:
	// compare r1 and r2, loop if not equal
	cmp	r1, r2
	bne	write_half_page

	// Set breakpoint to exit
	bkpt #0x00