Skip to content

Commit 188a29b

Browse files
committed
Pull request #43: Feature/MCU16GITHUB-842 merge to develop
Merge in MCU16CE/dspic33-dsc-bootloader-code-examples from ~C12109/dspic33-dsc-bootloader-code-examples:feature/MCU16GITHUB-957-improve-the-icsp-inhibit-ui-ux to develop * commit 'cb1424816cdf3e0b80a4e28a60d6444d1a177c27': (51 commits) Fix build warnings. Missing header include. Invalid const usage. * added c library for warning * used a #define for icsp lock address * changed variable to static const revert file path in confi xml Added ICSP functionality to a separate module Point to file performing inhibit in README Update wording Add BR Fix spelling Rename file Add images to README Add images Select correct debugging port. remove .yml files. Add *.yml to gitignore. Edit images Add README only allow alphanumeric input keys. disable the ICSP enable for safety during development of demo. refactor and enable bootloader detection refactor update functionality ...
2 parents 63cf864 + cb14248 commit 188a29b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+6301
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
*.ko
1010
*.obj
1111
*.elf
12+
*.yml
1213

1314
# Excluding documentation output directories
1415
#docs/
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
#
2+
# There exist several targets which are by default empty and which can be
3+
# used for execution of your targets. These targets are usually executed
4+
# before and after some main targets. They are:
5+
#
6+
# .build-pre: called before 'build' target
7+
# .build-post: called after 'build' target
8+
# .clean-pre: called before 'clean' target
9+
# .clean-post: called after 'clean' target
10+
# .clobber-pre: called before 'clobber' target
11+
# .clobber-post: called after 'clobber' target
12+
# .all-pre: called before 'all' target
13+
# .all-post: called after 'all' target
14+
# .help-pre: called before 'help' target
15+
# .help-post: called after 'help' target
16+
#
17+
# Targets beginning with '.' are not intended to be called on their own.
18+
#
19+
# Main targets can be executed directly, and they are:
20+
#
21+
# build build a specific configuration
22+
# clean remove built files from a configuration
23+
# clobber remove all built files
24+
# all build all configurations
25+
# help print help mesage
26+
#
27+
# Targets .build-impl, .clean-impl, .clobber-impl, .all-impl, and
28+
# .help-impl are implemented in nbproject/makefile-impl.mk.
29+
#
30+
# Available make variables:
31+
#
32+
# CND_BASEDIR base directory for relative paths
33+
# CND_DISTDIR default top distribution directory (build artifacts)
34+
# CND_BUILDDIR default top build directory (object files, ...)
35+
# CONF name of current configuration
36+
# CND_ARTIFACT_DIR_${CONF} directory of build artifact (current configuration)
37+
# CND_ARTIFACT_NAME_${CONF} name of build artifact (current configuration)
38+
# CND_ARTIFACT_PATH_${CONF} path to build artifact (current configuration)
39+
# CND_PACKAGE_DIR_${CONF} directory of package (current configuration)
40+
# CND_PACKAGE_NAME_${CONF} name of package (current configuration)
41+
# CND_PACKAGE_PATH_${CONF} path to package (current configuration)
42+
#
43+
# NOCDDL
44+
45+
46+
# Environment
47+
MKDIR=mkdir
48+
CP=cp
49+
CCADMIN=CCadmin
50+
RANLIB=ranlib
51+
52+
53+
# build
54+
build: .build-post
55+
56+
.build-pre:
57+
# Add your pre 'build' code here...
58+
59+
.build-post: .build-impl
60+
# Add your post 'build' code here...
61+
62+
63+
# clean
64+
clean: .clean-post
65+
66+
.clean-pre:
67+
# Add your pre 'clean' code here...
68+
# WARNING: the IDE does not call this target since it takes a long time to
69+
# simply run make. Instead, the IDE removes the configuration directories
70+
# under build and dist directly without calling make.
71+
# This target is left here so people can do a clean when running a clean
72+
# outside the IDE.
73+
74+
.clean-post: .clean-impl
75+
# Add your post 'clean' code here...
76+
77+
78+
# clobber
79+
clobber: .clobber-post
80+
81+
.clobber-pre:
82+
# Add your pre 'clobber' code here...
83+
84+
.clobber-post: .clobber-impl
85+
# Add your post 'clobber' code here...
86+
87+
88+
# all
89+
all: .all-post
90+
91+
.all-pre:
92+
# Add your pre 'all' code here...
93+
94+
.all-post: .all-impl
95+
# Add your post 'all' code here...
96+
97+
98+
# help
99+
help: .help-post
100+
101+
.help-pre:
102+
# Add your pre 'help' code here...
103+
104+
.help-post: .help-impl
105+
# Add your post 'help' code here...
106+
107+
108+
109+
# include project implementation makefile
110+
include nbproject/Makefile-impl.mk
111+
112+
# include project make variables
113+
include nbproject/Makefile-variables.mk
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<picture>
2+
<source media="(prefers-color-scheme: dark)" srcset="../images/microchip_logo_white_red.png">
3+
<source media="(prefers-color-scheme: light)" srcset="../images/microchip_logo_black_red.png">
4+
<img alt="Microchip Logo." src="../images/microchip_logo_black_red.png">
5+
</picture>
6+
7+
## Secure Boot and Secure Firmware Upgrade over CAN-FD for dsPIC33C DSCs Demo - ICSP Inhibit
8+
---
9+
> **_!!WARNING!!_**
10+
**Running the icsp_inhibit.X application and following the steps outlined in the resulting console will PERMANENTLY DISABLE direct programming and debugging of the board. For additional information, see section 5.5: Flash OTP by ICSP Write Inhibit of the [dsPIC33CK1024MP708 Family Data Sheet](https://ww1.microchip.com/downloads/aemDocuments/documents/MCU16/ProductDocuments/DataSheets/dsPIC33CK1024MP710-Family-Data-Sheet-DS70005496.pdf).**
11+
12+
---
13+
14+
## Introduction
15+
This project contains an application which, when programmed properly via the bootloader, **PERMANENTLY** locks Flash memory from any ICSP programming/erase operations. Once programmed, ICSP inhibit cannot be deactivated. See [icsp_inhibit.c](./icsp_inhibit.c) to view the code performing the lock.
16+
17+
All tool setup and programming instructions for the bootloader and application are the same as those used in boot.X and app.X, however the icsp_inhibit.X project will be used in place of app.X referenced in the README.md file in the top-level folder. For additional details on tool setup and how to run the demo, see the [README.md](../README.md) file in the top-level folder.
18+
19+
**NOTE: The ICSP inhibit functionality can only be programmed via bootloader. Direct download of the icsp_inhibit.X application will prevent the ICSP inhibit feature from being installed.**
20+
21+
## Running the Demo
22+
23+
#### Building the Bootloader
24+
* See the [README.md](../README.md) file in the top-level folder.
25+
26+
#### Building the ICSP Inhibit Application
27+
* See the [README.md](../README.md) file in the top-level folder. **NOTE: The icsp_inhibit.X application does not utilize a blinking LED to indicate the application is running**
28+
29+
#### Loading the Application
30+
* See the [README.md](../README.md) file in the top-level folder.
31+
**NOTE: The ICSP inhibit functionality will only be programmed once the steps in Locking the Device have been completed successfully. The steps listed in this section (Loading the Application) will not permanentley alter the device**
32+
**NOTE: When prompted in the instructions, utilize the hex file located at icsp_inhibit.X/dist/default/production/icsp_inhibit.X.production.hex**
33+
**NOTE: The icsp_inhibit.X application does not utilize a blinking LED to indicate the application is running**
34+
35+
#### Locking the Device
36+
1. Open a terminal emulator program such as Tera Term and connect to the COM port used by the device. If the COM port is unknown:
37+
1. Open UBHA.
38+
2. Select "UART" from the protocol drop down selection box.<br>
39+
![UBHA UART](./images/UBHA_UART.png)
40+
3. Select the “Settings->Serial” option from the top menu.<br>
41+
![Serial Settings](./images/UBHA_Settings.png)
42+
4. With the micro-USB cable connected to port J1 of the Development Board, click the COM Port dropdown and note the COM ports listed.<br>
43+
![COM Ports](./images/UBHA_COM_Ports.png)
44+
5. Unplug the micro-USB cable from port J1 and click the Refresh button in the Port Settings next to the COM Port dropdown.
45+
6. Click the COM Port dropdown and note which COM port is missing. This is the port that is being used by the device.
46+
2. Hit the MCLR button located in the middle of the board. Text should appear in the console indicating the ICSP inhibit application is running. <br>
47+
![MCLR Button](./images/MCLR_Button.png)<br>
48+
![ICSP Program Start](./images/ICSP_Start_Screen.png)
49+
3. **!!NOTE: THE FOLLOWING WILL PERMANENTLY LOCK THE DEVICE, DISABLING PROGRAMMING AND DEBUGGING.** In all CAPS type, "LOCKDEVICE" and hit enter. Flash memory is locked from any ICSP programming/erase operations. <br>
50+
![ICSP Locked](./images/ICSP_Lock.png)
51+
52+
## Trademarks
53+
54+
MPLAB® is a registered trademark of Microchip Technology Inc. All other trademarks are the property of their respective owner.
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
© [2024] Microchip Technology Inc. and its subsidiaries.
3+
4+
Subject to your compliance with these terms, you may use Microchip
5+
software and any derivatives exclusively with Microchip products.
6+
You are responsible for complying with 3rd party license terms
7+
applicable to your use of 3rd party software (including open source
8+
software) that may accompany Microchip software. SOFTWARE IS ?AS IS.?
9+
NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS
10+
SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT,
11+
MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
12+
WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
13+
INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY
14+
KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF
15+
MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE
16+
FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP?S
17+
TOTAL LIABILITY ON ALL CLAIMS RELATED TO THE SOFTWARE WILL NOT
18+
EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR
19+
THIS SOFTWARE.
20+
*/
21+
22+
#include <stdbool.h>
23+
#include <string.h>
24+
#include "mcc_generated_files/flash/flash.h"
25+
#include "mcc_generated_files/flash/flash_types.h"
26+
27+
#define ICSP_INHIBIT_WRITE_LOCK_ADDRESS 0x0801034
28+
29+
static flash_data_t inhibitKeys[4] =
30+
{
31+
0x00006D63UL, 0x00000000UL, 0x00006870UL, 0x00000000UL
32+
};
33+
34+
bool ICSP_INHIBIT_IsEnabled(void)
35+
{
36+
static flash_data_t dataInFlash[4];
37+
FLASH_Read(0x801034, 4, dataInFlash);
38+
39+
if(memcmp(inhibitKeys, dataInFlash, sizeof(inhibitKeys)) == 0)
40+
{
41+
return true;
42+
}
43+
return false;
44+
}
45+
46+
void ICSP_INHIBIT_Enable()
47+
{
48+
FLASH_WordWrite(0x801034, &inhibitKeys[0], FLASH_UNLOCK_KEY);
49+
FLASH_WordWrite(0x801038, &inhibitKeys[2], FLASH_UNLOCK_KEY);
50+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
© [2024] Microchip Technology Inc. and its subsidiaries.
3+
4+
Subject to your compliance with these terms, you may use Microchip
5+
software and any derivatives exclusively with Microchip products.
6+
You are responsible for complying with 3rd party license terms
7+
applicable to your use of 3rd party software (including open source
8+
software) that may accompany Microchip software. SOFTWARE IS ?AS IS.?
9+
NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS
10+
SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT,
11+
MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
12+
WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
13+
INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY
14+
KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF
15+
MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE
16+
FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP?S
17+
TOTAL LIABILITY ON ALL CLAIMS RELATED TO THE SOFTWARE WILL NOT
18+
EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR
19+
THIS SOFTWARE.
20+
*/
21+
22+
#ifndef ICSP_INHIBIT_H
23+
#define ICSP_INHIBIT_H
24+
25+
#include <stdbool.h>
26+
27+
bool ICSP_INHIBIT_IsEnabled(void);
28+
void ICSP_INHIBIT_Enable(void);
29+
30+
#endif

0 commit comments

Comments
 (0)