-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathreadme_run_demo.html
299 lines (275 loc) · 15.8 KB
/
readme_run_demo.html
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
<html>
<head>
<style>
h2 {
text-decoration: bold;
}
h3 {
text-decoration: underline;
}
ol,ul {
line-height: 200%;
}
</style>
</head>
<body lang=EN-US link=blue vlink=purple>
<table border="0" cellspacing="0" cellpadding="0">
<tr >
<th bgcolor="lightgrey">
<h2><b>DEPRECTION NOTICE:</b>This repo and associated examples are deprecated.</h2>
</th>
</tr>
<tr>
<td bgcolor="lightgrey">Please refer to the latest examples at:<br>
<a href="https://github.com/microchip-pic-avr-examples/dspic33_dsc_bootloader_code_examples">https://github.com/microchip-pic-avr-examples/dspic33_dsc_bootloader_code_examples</a>
</td>
</tr>
</table>
<h1>Bootloader Example Using the CAN Physical Layer</h1>
<h2>Introduction</h2>
This example shows how to use the pre-configured CAN demo on the dsPIC33CK256MP508 processor module for the Explorer
16/32 board.
This demo uses the ISO 15765-2 CAN Transport Protocol layer to transport custom bootloader commands over the CAN bus
as seen in the diagram below:<br>
<img src="readme_files/stack.png"><br>
<h2>Tools</h2>
<h3>Software</h3>
<ol>
<li>The unzipped example project files, boot.X and app.X</li>
<li><a href="https://www.microchip.com/mplabx">Microchip MPLAB® X version 5.40 or later</a></li>
<li><a href="https://www.microchip.com/en-us/development-tools-tools-and-software/mplab-xc-compilers">Microchip MPLAB® XC16 C compiler version 1.60 or later</a></li>
<li><a href="https://www.microchip.com/16-bit-Bootloader">Unified Bootloader Host Application v1.17.0 or later</a></li>
<li>Microchip MPLAB® Code Configurator version v4.0.1 or later (optional – for code configuration)</li>
<li>16-bit Bootloader MCC module version 1.18.3 or later (optional – for code configuration)</li>
<li>The drivers for the selected Peak CAN protocol analyzer/protocol generator (available at <a href="https://www.peak-system.com/Home.59.0.html?&L=1">https://www.peak-system.com/Home.59.0.html?&L=1</a>)</li>
</ol>
<h3>Hardware</h3>
<ol>
<li>Explorer 16/32 Demo board</li>
<li>dsPIC33CK256MP508 Processor module</li>
<li>A programmer/debugger of choice</li>
<li>A Peak CAN protocol analyzer/protocol generator. A PCAN-USB FD was used for development of this demo
(https://www.peak-system.com/PCAN-USB-FD.365.0.html?&L=1).</li>
<li>A CAN cable</li>
<li>An MCP2542 click board (https://www.mikroe.com/mcp2542-click) or another appropriate CAN transceiver click
board.
It is important that this is just a transceiver and not a CAN-to-SPI/UART converter chip.</li>
<li>A micro USB cable, a USB-Type C cable, or a 9v power adapter for the Explorer 16/32 (for powering the board).
</li>
</ol>
<h2>Running the Demo</h2>
<h3>Hardware Configuration</h3>
<ol>
<li>With the Explorer 16/32 detached from any power source, programmer, or USB connection:</li>
<ol type="a">
<li>Connect the dsPIC33CK256MP508 processor module into the socket on the Explorer 16/32 such that the notched
edge is
in the top left corner matching the silk screen on the Explorer 16/32</li>
<li>Connect the MCP2542 daughter board into the mikroBUS™ A slot.</li>
</ol>
<li>Connect the programmer to the Explorer 16/32</li>
<li>Connect the Peak analyzer/generator to your computer.</li>
<li>Connect the Peak analyzer/generator to the MCP2543 daughter board with the CAN cable.</li>
<li>Power the board using either USB cable or the 9 volt adapter plug.</li>
</ol>
<img src="readme_files/hardware.jpg"><br><br>
<h3>Programming the Bootloader</h3>
<ol>
<li>Open the boot.x project in MPLAB® X</li>
<li>Press the “Make and Program” button on the top bar.</li>
<img src="readme_files/program.png"><br><br>
<li>Select the appropriate programmer if prompted.</li>
<li>The project should compile and program successfully.</li>
<li>Verify the D3 LED is solid on the Explorer 16/32. This indicates the bootloader is running.</li>
</ol>
<h3>Building the Application</h3>
<ol>
<li>Open the app.X project in MPLAB® X
<li>Press the “Clean and Build Project” button on the top bar.
<b>NOTE</b>: Make sure not to hit the program button. This will program the application code over the bootloader
that was
just programmed.
<img src="readme_files/compile.png"><br><br>
<li>The project should compile cleanly. app.X/dist/default/production/app.X.production.hex should be generated.
<li>Verify that the D3 LED is still solid.
<ol type="a">
<li>If the D3 LED is blinking instead of D3 solid, then the application code was programmed instead of only
compiled.
Go back to the “Programming the Bootloader” stage and re-program the bootloader.
</li>
</ol>
</ol>
<h3>Loading the Application</h3>
<ol>
<li>Open the Universal Bootloader Host Application tool (UBHA)</li>
<img src="readme_files/ubha.jpg"><br><br>
<li>Select the “PIC24/dsPIC” option from the “Device Architecture” selection drop down</li>
<img src="readme_files/pic24f.png"><br><br>
<li>Select “CAN” from the protocol drop down selection box:</li>
<img src="readme_files/can.png"><br><br>
<li>Select the “Settings->CAN” option from the top menu</li>
<img src="readme_files/settings.png"><br><br>
<li>Select the Peak protocol analyzer being used and the appropriate CAN configuration settings and press “Apply”
when
done. By default, the configuration for the demo are the following:</li>
<ol type="a">
<li>Nominal bit rate: 125 kbits/sec</li>
<li>Host to device ID: 0xA1</li>
<li>Device to host ID: 0xA2</li>
</ol>
<img src="readme_files/settings_can.jpg"><br><br>
<li>Press the “Read Device Settings” button.</li>
<ol type="a">
<li>The Application start address and Application end address fields should have updated. If it did not or if you
get a
communication error, please go back to the “Programming the Bootloader” stage to make sure the bootloader was
programmed correctly.
</li>
</ol>
<img src="readme_files/read_device.png"><br><br>
<li>Load the application hex file by selecting “File->Open/Load File (*.hex)”</li>
<ol type="a">
<li>Select the file generated in the previous section: app.X/dist/default/production/app.X.production.hex
</li>
</ol>
<img src="readme_files/open.png"><br><br>
<li>Press “Program Device”. The application should program erase, program and readback verify correctly.</li>
<ol type="a">
<li>After a few seconds, D3 should be blinking.</li>
</ol>
</ol>
<h2>Customizing the Bootloader Project</h2>
The bootloader project can be opened in MCC and new modules can be added and configured as they normally would in MCC.
Additionally, the parameters in the Bootloader:Bootloader module can be re-configured.
<h3>Changing the CAN bitrate</h3>
The CAN bitrate of the bootloader can be easily changed. By default the bitrate is set to 125 kbits/second. To change
the bitrate, do the following:
<ol>
<li>Open the bootloader project.</li>
<li>Open the MCC plug-in by clicking on the MCC icon in the tool bar of MPLAB X.</li>
<img src="readme_files/mcc.png"><br><br>
<li>Select the CAN1 module from the project resources pane on the left navigation pane. This will open the CAN1
module settings in the main configuration window.</li>
<img src="readme_files/can1.png"><br><br>
<li>Expand the "Step 2: Nominal Bit Rate Settings" pane and make the desired bit rate changes.</li>
<img src="readme_files/bitrate.png"><br><br>
<li>Re-generate the project by pressing the generate button in the project resources pane.</li>
<img src="readme_files/generate.png"><br><br>
<li>Re-build/program the bootloader into the board.</li>
<img src="readme_files/program.png"><br><br>
<li>Re-open the settings window in the UBHA program.</li>
<img src="readme_files/settings.png"><br><br>
<li>Change the nominal bit rate to match what was selected in MCC. <b>NOTE:</b> The Peak analyzer/generator is
limited to what bit rates it can generate so not all bit rates possible by the micro-controller can be realized by
this hardware generator. You are limited to the bit rates listed in the UBHA selection window.</li>
<ol type="a">
<li>When the bit rate has been changed, press apply.</li>
</ol>
<img src="readme_files/settings_can.jpg"><br><br>
<li>You can now press the program button or read device settings button as before and the device should now be
communicating using the new bit rate selected.</li>
</ol>
<h3>Changing the Host to Device ID</h3>
This is changing the message ID of the messages sent from the PC bootloader host to the target board. Currently the same message ID must be used for both ISO 15765-2 message and flow control frames. To change the message ID used from host to device, do the following:
<ol>
<li>Open the bootloader project.</li>
<li>Open the MCC plug-in by clicking on the MCC icon in the tool bar of MPLAB X.</li>
<img src="readme_files/mcc.png"><br><br>
<li>Select the CAN1 module from the project resources pane on the left navigation pane. This will open the CAN1
module settings in the main configuration window.</li>
<img src="readme_files/can1.png"><br><br>
<li>Expand the "Step 5: Filter Object Settings" pane.</li>
<img src="readme_files/filter.png"><br><br>
<li>Change the message ID in the Message ID section to the desired value. In this example we changed it from 0xA1 to 0xA5.</li>
<img src="readme_files/filter_a5.png"><br><br>
<li>Re-generate the project by pressing the generate button in the project resources pane.</li>
<img src="readme_files/generate.png"><br><br>
<li>Re-build/program the bootloader into the board.</li>
<img src="readme_files/program.png"><br><br>
<li>Re-open the settings window in the UBHA program.</li>
<img src="readme_files/settings.png"><br><br>
<li>Change the "Host to Device ID" field to match the value used in the MCC filter object settings, in this example 0xA5.</li>
<img src="readme_files/host_to_device_a5.png"><br><br>
<ol type="a">
<li>When the message ID has been changed, press apply.</li>
</ol>
<li>You can now press the program button or read device settings button as before and the device should now be
communcicating using the new message IDs from the host to the device.</li>
</ol>
<h3>Changing the Device To Host ID</h3>
This is changing the message ID of the messages sent from the the target board back to the PC host. Currently the same message ID must be used for both ISO 15765-2 message and flow control frames. To change the message ID used from device to host, do the following:
<ol>
<li>Open the bootloader project.</li>
<li>Open the can_tp_config.h file in the "Headers/MCC Generated Files" section of the MPLAB X project.</li>
<img src="readme_files/config_header.png"><br><br>
<li>Change the values for the CAN_TP_MESSAGE_ID_DATA and CAN_TP_MESSAGE_ID_FLOW_CONTROL to the desired value. In this example it is changed from 0xA2 to 0xA4.<br><b>NOTE:</b> Due to a constraint in the UBHA hos program, the same message ID must be used for both the data and flow control messages. Please make these two values the same.</li>
<img src="readme_files/config_header_a4.png"><br><br>
<li>Re-build/program the bootloader into the board.</li>
<img src="readme_files/program.png"><br><br>
<li>Re-open the settings window in the UBHA program.</li>
<img src="readme_files/settings.png"><br><br>
<li>Change the "Device To Host ID" field to match the value used in can_tp_config.h file, in this example 0xA4.</li>
<img src="readme_files/device_to_host_a4.png"><br><br>
<ol type="a">
<li>When the message ID has been changed, press apply.</li>
</ol>
<li>You can now press the program button or read device settings button as before and the device should now be
communicating using the new message IDs from the device to the host.</li>
</ol>
<h3>Using Extended (29-bit) CAN IDs</h3>
The ISO 15765-2 specification says that the communication pair should use the same format IDs when talking to each other. Thus we need to change settings in both the host application and the firmware to add support for extended IDs.
<ol>
<li>Open the bootloader project.</li>
<li>Open the can_tp_config.h file in the "Headers/MCC Generated Files" section of the MPLAB X project.</li>
<img src="readme_files/config_header.png"><br><br>
<li>Change the value CAN_TP_MESSAGE_ID_IS_EXTENDED from false to true. If this definition doesn't exist, define it and set the value to true. This will change all the messages from the device to the host to extended ID messages.
<img src="readme_files/extended_device_to_host.png"><br><br>
<li>Open the MCC plug-in by clicking on the MCC icon in the tool bar of MPLAB X.</li>
<img src="readme_files/mcc.png"><br><br>
<li>Select the CAN1 module from the project resources pane on the left navigation pane. This will open the CAN1
module settings in the main configuration window.</li>
<img src="readme_files/can1.png"><br><br>
<li>Expand the "Step 5: Filter Object Settings" pane.</li>
<img src="readme_files/filter.png"><br><br>
<li>Modify the filter from "0xA1" to "0xA1x". The trailing "x" indicates that this is an extended address.</li>
<img src="readme_files/extended_filter.png"><br><br>
<li>Re-generate the project by pressing the generate button in the project resources pane.</li>
<img src="readme_files/generate.png"><br><br>
<li>Re-build/program the bootloader into the board.</li>
<img src="readme_files/program.png"><br><br>
<li>Re-open the settings window in the UBHA program.</li>
<img src="readme_files/settings.png"><br><br>
<li>Change the "Message Format" field to extended (29-bit) mode.</li>
<img src="readme_files/can_settings_extended.png"><br><br>
<ol type="a">
<li>When the mode had been changed, press apply.</li>
</ol>
<li>You can now press the program button or read device settings button as before and the device should now be
communicating using the new message IDs from the device to the host.</li>
</ol>
<h2>Customizing the Application Project</h2>
The application MCC configuration can be opened and modules can be added or modified as desired.
<h2>Known Limitations</h2>
<ul>
<li>Only CAN classic is supported. For CAN-FD support, use the CAN-FD demo as a starting point instead.</li>
</ul>
<h2>Terminology</h2>
<b>ISO 15765-2 / CAN-TP / ISO-TP</b>
<p>
ISO 15765-2 is a transport protocol layer designed for usage with the CAN bus. The original CAN bus specification
allows for up to 8 bytes of data to be in a single frame. Larger messages need to be fragmented into smaller frames
for transmission on the CAN bus. ISO 15765-2 defines a protocol for fragmenting larger messages and sending them
over the CAN bus. It also incorporates flexibility in handling the data transmission through the use of flow control
packets to control the frequency of when packets arrive as well allowing to pause the transmission of a message
until the receiver is ready to receive the message.</p>
<b>MCC</b>
<p>Microchip’s MPLAB® Code Configurator tool. This tool helps configure and generate source code for peripherals and
libraries.</p>
<b>UBHA - Unified Bootloader Host Application</b>
<p>The PC application used to send the firmware update and verification commands
from the PC to the board to complete the firmware update.</p>
<h2>Trademarks</h2>
MPLAB® is a registered trademark of Microchip Technology Inc. All other trademarks are the property of their
respective owner.
</body>
</html>