-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathREADME
More file actions
165 lines (122 loc) · 4.76 KB
/
Copy pathREADME
File metadata and controls
165 lines (122 loc) · 4.76 KB
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
A basic serial mode ISP programmer for Nuvoton N76E003, under Linux
This program is released under the GPL v2 or later license. See
COPYING.
Requirements
============
A Nuvoton N76E003 development board with UART pins, already programmed
with the Nuvoton LDROM that provides ISP programming. For instance,
that one:
https://www.electrodragon.com/product/n76e003-mini-development-board/
Some of the blue breakout boards available on aliexpress also have the
ISP bootloader, but sellers do not advertise it.
A board without the ISP capability will need to be flashed with an
LDROM bootloader, which can be achieved by using NU-Link device or by
a gpio capable device running linux (see the last section for a link.)
A PC with a serial port, or some USB-to-UART adapter, such as a CP2102
or CH341A. Ideally this adapter is able to power the chip at 3.3V and
has a DTR line.
Connection
==========
Connect the board to the host UART like this:
GND <--> GND
RX <--> TX
TX <--> RX
DTR <--> Reset Pin (either P20 or RST), optional
3.3V <--> 3.3V
The ISP module will start if the chip sees a specific connect packet
on its serial port 0 within a few milliseconds after powering up. If
it doesn't get the packet, it will boot normally.
For that to happen, start nvtispflash, which will begin polling the
chip through the serial device. The board must then be somehow rebooted.
The best way is to let nvtispflash automatically reboot the board by
triggering the DTR line. The following conditions must be met:
- DTR is connected
- The RPD bit is set to 1 in the chip config, meaning P20 is the
reset pin and not just a regular pin.
If these conditiona are not met, there are 2 other ways to boot the
board in ISP mode.
If the RPD bit is set to 1, a reset button, if present, will be able
to reset the board.
- Start nvtispflash
- press the reset button
If this doesn't work, disconnect the 3.3V line and:
- Start nvtispflash
- reconnect the 3.3V line
That last method might be the only one that works on a new
board. After that, the RPD bit can bet set with the following command,
which makes repeat programming easier, provided DTR is connected too:
nvtispflash -c rpd=1
Usage
=====
ISP programmer for Nuvoton N76E003
Options:
--serial-device, -d serial device to use. Defaults to /dev/ttyUSB0
--config, -c enable or disable some config options
--aprom-file, -a binary APROM file to flash
--remain-isp, -r remain in ISP mode when exiting
--read-serial, -s read serial output after programming
iHEX files must be converted to binary first. SDCC provides the makebin
tool for that purpose:
makebin -p prog.ihx prog.bin
The file will be flashed at offset 0, which is the start address of
the chip.
Flashing the whole 14Kb shouldn't take more than a few seconds.
Config bits can be changed as well. For safety, only one is currently
supported. The option "--config rpd=1" will enable the RESET pin,
while setting it to 0 will disable it.
Example
=======
$ ./nvtispflash -a blink.bin
Ready to connect
Connected
FW version: 0x27
Device is N76E003
Config:
LOCK: 1
RPD: 0
OCDEN: 0
OCDPWM: 1
CBS: 0
LDSIZE: LDROM=4K, APROM=14K
CBORST:1
BOIAP:1
CBOV:3
CBODEN:1
WDTEN:15
Flashing APROM with blink.bin
sending block of 48 bytes
sending block of 56 bytes
sending block of 56 bytes
sending block of 56 bytes
sending block of 20 bytes
Done
Rebooting to APROM
Caveats
=======
Only the N76E003 is supported although other Nuvoton chips could be.
There is no error recovery. If an error happens, the program will bail
out.
nvtispflash will not work on big-endian machines. Some byte swapping
work would be needed.
Programming the config is partially supported. Programming the data
section is not supported at this moment, but should not be difficult
to add.
Sometimes programming will fail, with the ISP not responding, or
falling behind. As the communication protocol is not robust, it's
easier to stop and restart nvtispflash.
External resources
==================
A similar program written in python, as well as a bootloader flashing
software using a gpio capable device such as a Raspberry Pi:
https://github.com/steve-m/N76E003-playground.git
An easy to build blink and uart test programs can be found in the
following project:
https://github.com/erincandescent/libn76
The official BSP
https://github.com/OpenNuvoton/N76E003-BSP
That BSP includes the source code for the LDROM bootloader in
Sample_Code/ISP_UART0/Source.
The official BSP converted for SDCC usage, but with no Makefile:
https://github.com/danchouzhou/N76E003-SDCC
Nuvoton's own ISP, with its windows source code:
https://github.com/OpenNuvoton/ISPTool