Skip to content

Commit 75a6525

Browse files
Pull request #27: MCU16GITHUB-886 implement unlock sequence
Merge in MCU16CE/dspic33-dsc-bootloader-code-examples from ~C71668/dspic33-dsc-bootloader-code-examples:MCU16GITHUB-886-implement-unlock-sequence to feature/MCU16GITHUB-842-add-the-icsp-inhibit-feature * commit '9067b9fd5a92253ca3d6630649dc530420a2a05b': Changed valid command received statement Testing MCC generated post build with chmod addition. Reverting previous change to post-build step. post-build step update to leave in mcc generated content Updated post build step * Terminal line now clears when invalid character is entered. * Terminal shows the user entering valid lock sequence. * Refactored for clarity. Refactor to allow 10 characters over UART. Simplified the use of the ternary operator. changed function names according to coding guidelines. Changed slash direction in postBuild.sh to fix build issues. missing change in post build step. Modified post-build line to fix build issues. Removed yml files. Removed unnecessary lines * Refactor. * Characters user enters are now displayed to the user. Added more details to the warning. Cleaned up menu implementation Working implementation with window reset on incorrect character. * Added icsp inhibit projects * Added code to check if user has sent UNLOCK Command over UART.
2 parents 987e60a + 9067b9f commit 75a6525

39 files changed

+4619
-0
lines changed
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

secure_boot_and_secure_firmware_upgrade_over_canfd/icsp_inhibit.X/icsp_inhibit.mc3

Lines changed: 326 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
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 <stdio.h>
23+
#include <string.h>
24+
#include <stdbool.h>
25+
26+
#define WINDOW_SIZE 10
27+
#define UNLOCK_COMMAND "LOCKDEVICE"
28+
29+
// Function prototypes
30+
static void ClearTerminalScreen(void);
31+
static void ClearTerminalLine(void);
32+
static void MoveCursor(int row);
33+
static void HideCursor(void);
34+
static void PrintWarning(void);
35+
static void AppendCharToWindow(char receivedChar, char *window, int *windowIndex);
36+
static void ProcessReceivedChar(char receivedChar, char *window, int *windowIndex);
37+
static void ResetWindowOnMismatch(char *window, int *windowIndex);
38+
static void CheckForUnlockCommand(char *window, int *windowIndex);
39+
40+
int main(void)
41+
{
42+
char window[WINDOW_SIZE + 1] = {0};
43+
int windowIndex = 0;
44+
45+
SYSTEM_Initialize();
46+
ClearTerminalScreen();
47+
PrintWarning();
48+
while (1)
49+
{
50+
if (UART1_IsRxReady())
51+
{
52+
char receivedChar = UART1_Read();
53+
ProcessReceivedChar(receivedChar, window, &windowIndex);
54+
CheckForUnlockCommand(window, &windowIndex);
55+
}
56+
}
57+
}
58+
59+
static void ClearTerminalScreen(void)
60+
{
61+
printf("\033[2J");
62+
}
63+
64+
static void ClearTerminalLine(void)
65+
{
66+
printf("\33[2K\r");
67+
}
68+
69+
static void MoveCursor(int row)
70+
{
71+
printf("\033[%d;0f", row);
72+
}
73+
74+
static void HideCursor(void)
75+
{
76+
printf("\033[?25l");
77+
}
78+
79+
static void PrintWarning(void)
80+
{
81+
MoveCursor(1);
82+
printf("Type LOCKDEVICE to enable the ICSP Inhibit feature.");
83+
MoveCursor(3);
84+
printf("WARNING: THIS PERMANENTLY DISABLES DIRECT PROGRAMMING OF THE BOARD.");
85+
}
86+
87+
static void ProcessReceivedChar(char receivedChar, char *window, int *windowIndex)
88+
{
89+
bool isCharValid = (*windowIndex < strlen(UNLOCK_COMMAND)) && (receivedChar == UNLOCK_COMMAND[*windowIndex]);
90+
91+
if (isCharValid)
92+
{
93+
AppendCharToWindow(receivedChar, window, windowIndex);
94+
MoveCursor(10);
95+
printf("%s", window);
96+
}
97+
else
98+
{
99+
ResetWindowOnMismatch(window, windowIndex);
100+
}
101+
}
102+
103+
static void AppendCharToWindow(char receivedChar, char *window, int *windowIndex)
104+
{
105+
window[(*windowIndex)++] = receivedChar;
106+
window[*windowIndex] = '\0';
107+
}
108+
109+
static void ResetWindowOnMismatch(char *window, int *windowIndex)
110+
{
111+
MoveCursor(10);
112+
ClearTerminalLine();
113+
MoveCursor(5);
114+
ClearTerminalLine();
115+
printf("Invalid character entered. Try again.");
116+
*windowIndex = 0;
117+
memset(window, 0, WINDOW_SIZE + 1);
118+
}
119+
120+
static void CheckForUnlockCommand(char *window, int *windowIndex)
121+
{
122+
if (strncmp(window, UNLOCK_COMMAND, *windowIndex) == 0 && *windowIndex == strlen(UNLOCK_COMMAND))
123+
{
124+
MoveCursor(5);
125+
ClearTerminalLine();
126+
printf("ICSP Programming/Debugging permanently disabled. \n");
127+
MoveCursor(10);
128+
ClearTerminalLine();
129+
*windowIndex = 0;
130+
memset(window, 0, WINDOW_SIZE + 1);
131+
}
132+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
2+
/**
3+
@Generated 16-bit Bootloader Source File
4+
5+
@Company:
6+
Microchip Technology Inc.
7+
8+
@File Name:
9+
app_code_protect.c
10+
11+
@Summary:
12+
This is the app_code_protect.c file generated using 16-bit Bootloader
13+
14+
@Description:
15+
This header file provides implementations for driver APIs for all modules selected in the GUI.
16+
Generation Information :
17+
Product Revision : 16-bit Bootloader - 1.25.0
18+
Device : dsPIC33CK1024MP710
19+
The generated drivers are tested against the following:
20+
Compiler : XC16 v1.36B
21+
MPLAB : MPLAB X v5.15
22+
*/
23+
/*
24+
Copyright (c) [2012-2024] Microchip Technology Inc.
25+
26+
All rights reserved.
27+
28+
You are permitted to use the accompanying software and its derivatives
29+
with Microchip products. See the Microchip license agreement accompanying
30+
this software, if any, for additional info regarding your rights and
31+
obligations.
32+
33+
MICROCHIP SOFTWARE AND DOCUMENTATION ARE PROVIDED "AS IS" WITHOUT
34+
WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT
35+
LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE, NON-INFRINGEMENT
36+
AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP OR ITS
37+
LICENSORS BE LIABLE OR OBLIGATED UNDER CONTRACT, NEGLIGENCE, STRICT
38+
LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR OTHER LEGAL EQUITABLE
39+
THEORY FOR ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES INCLUDING BUT NOT
40+
LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES,
41+
OR OTHER SIMILAR COSTS.
42+
43+
To the fullest extend allowed by law, Microchip and its licensors
44+
liability will not exceed the amount of fees, if any, that you paid
45+
directly to Microchip to use this software.
46+
47+
THIRD PARTY SOFTWARE: Notwithstanding anything to the contrary, any
48+
third party software accompanying this software is subject to the terms
49+
and conditions of the third party's license agreement. To the extent
50+
required by third party licenses covering such third party software,
51+
the terms of such license will apply in lieu of the terms provided in
52+
this notice or applicable license. To the extent the terms of such
53+
third party licenses prohibit any of the restrictions described here,
54+
such restrictions will not apply to such third party software.
55+
*/
56+
57+
#include <xc.h>
58+
59+
#if (__XC16_VERSION__ < 1050)
60+
#error "The code protection/CodeGuard feature of this bootloader requires features only found in XC16 version 1.50 or later. Update to a newer version of the XC16 compiler."
61+
#endif
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/**
2+
@Generated 16-bit Bootloader Source File
3+
4+
@Company:
5+
Microchip Technology Inc.
6+
7+
@File Name:
8+
application_header_requirements.c
9+
10+
@Summary:
11+
This is the application_header_requirements.c file generated using 16-bit Bootloader
12+
13+
@Description:
14+
This header file provides implementations for driver APIs for all modules selected in the GUI.
15+
Generation Information :
16+
Product Revision : 16-bit Bootloader - 1.25.0
17+
Device : dsPIC33CK1024MP710
18+
The generated drivers are tested against the following:
19+
Compiler : XC16 v1.36B
20+
MPLAB : MPLAB X v5.15
21+
*/
22+
/*
23+
Copyright (c) [2012-2024] Microchip Technology Inc.
24+
25+
All rights reserved.
26+
27+
You are permitted to use the accompanying software and its derivatives
28+
with Microchip products. See the Microchip license agreement accompanying
29+
this software, if any, for additional info regarding your rights and
30+
obligations.
31+
32+
MICROCHIP SOFTWARE AND DOCUMENTATION ARE PROVIDED "AS IS" WITHOUT
33+
WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT
34+
LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE, NON-INFRINGEMENT
35+
AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP OR ITS
36+
LICENSORS BE LIABLE OR OBLIGATED UNDER CONTRACT, NEGLIGENCE, STRICT
37+
LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR OTHER LEGAL EQUITABLE
38+
THEORY FOR ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES INCLUDING BUT NOT
39+
LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES,
40+
OR OTHER SIMILAR COSTS.
41+
42+
To the fullest extend allowed by law, Microchip and its licensors
43+
liability will not exceed the amount of fees, if any, that you paid
44+
directly to Microchip to use this software.
45+
46+
THIRD PARTY SOFTWARE: Notwithstanding anything to the contrary, any
47+
third party software accompanying this software is subject to the terms
48+
and conditions of the third party's license agreement. To the extent
49+
required by third party licenses covering such third party software,
50+
the terms of such license will apply in lieu of the terms provided in
51+
this notice or applicable license. To the extent the terms of such
52+
third party licenses prohibit any of the restrictions described here,
53+
such restrictions will not apply to such third party software.
54+
*/
55+
56+
#include <xc.h>
57+
58+
#if (__XC16_VERSION__ < 1060)
59+
#error "The scripts generated to sign, or help sign, the application image require MPLAB XC16 version 1.60 or later. Install MPLAB XC16 version 1.60 and add it to the system path."
60+
#endif
61+

0 commit comments

Comments
 (0)