aboutsummaryrefslogtreecommitdiff
path: root/contrib/loaders/flash/xmc1xxx/xmc1xxx.S
blob: dfe7d3f41ef602d14be8c24ab40ab4602285d5bc (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
/*
 * Infineon XMC1000 flash
 *
 * Copyright (c) 2016 Andreas Färber
 *
 * Based on XMC1100 AA-Step Reference Manual
 *
 * License: GPL-2.0+
 */

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

#define NVMSTATUS	0x00
#define NVMPROG		0x04
#define NVMCONF		0x08

#define NVMSTATUS_BUSY		(1 << 0)
#define NVMSTATUS_VERR_NOFAIL	(0x0 << 2)
#define NVMSTATUS_VERR_MASK	(0x3 << 2)

#define NVMPROG_ACTION_IDLE			0x00
#define NVMPROG_ACTION_WRITE_CONTINUOUS		0xA1
#define NVMPROG_ACTION_PAGE_ERASE_CONTINUOUS	0xA2
#define NVMPROG_ACTION_VERIFY_CONTINUOUS	0xE0

#define NVMCONF_HRLEV_NR	(0x0 << 1)
#define NVMCONF_HRLEV_HRE	(0x2 << 1)
#define NVMCONF_HRLEV_MASK	(0x3 << 1)

#define NVM_WORD_SIZE	4
#define NVM_BLOCK_SIZE	(4 * NVM_WORD_SIZE)
#define NVM_PAGE_SIZE	(16 * NVM_BLOCK_SIZE)

	.macro busy_wait, nvmbase, tmp, tmp2
1:
	ldrh	\tmp, [\nvmbase, #NVMSTATUS]
	movs	\tmp2, #NVMSTATUS_BUSY
	ands	\tmp, \tmp, \tmp2
	cmp	\tmp, \tmp2
	beq	1b

	.endm