Skip to content

Commit 21b6b1d

Browse files
committed
block ICSP inhibit when programmed directly: MCU16GITHUB-959
1 parent 0ecf88a commit 21b6b1d

File tree

1 file changed

+27
-3
lines changed
  • secure_boot_and_secure_firmware_upgrade_over_canfd/icsp_inhibit.X

1 file changed

+27
-3
lines changed

secure_boot_and_secure_firmware_upgrade_over_canfd/icsp_inhibit.X/main.c

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,12 @@
1818
EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR
1919
THIS SOFTWARE.
2020
*/
21-
21+
22+
/* WARNING: THIS PROJECT WHEN BOOTLOADED WILL CAUSE THE DEVICE TO NO LONGER
23+
BE PROGRAMMABLE VIA AN EXTERNAL PROGRAMMER. Programming this project in
24+
directly should not allow programming to be disabled. A keyword must also
25+
be typed into the terminal console for the programming disable to occur. */
26+
2227
#include <stdio.h>
2328
#include <string.h>
2429
#include <stdbool.h>
@@ -41,15 +46,28 @@ static void ResetWindowOnMismatch(char *window, int *windowIndex);
4146
static void CheckForUnlockCommand(char *window, int *windowIndex);
4247
static uint32_t GetResetAddress();
4348
static bool WasLoadedByBootloader();
49+
static void PrintBootloaderRequired(void);
4450

4551
int main(void)
4652
{
4753
char window[WINDOW_SIZE + 1] = {0};
4854
int windowIndex = 0;
4955

5056
SYSTEM_Initialize();
57+
HideCursor();
5158
ClearTerminalScreen();
59+
60+
if(WasLoadedByBootloader() == false)
61+
{
62+
PrintBootloaderRequired();
63+
64+
while(1)
65+
{
66+
}
67+
}
68+
5269
PrintWarning();
70+
5371
while (1)
5472
{
5573
if (UART1_IsRxReady())
@@ -84,11 +102,17 @@ static void HideCursor(void)
84102
static void PrintWarning(void)
85103
{
86104
MoveCursor(1);
87-
printf("Type LOCKDEVICE to enable the ICSP Inhibit feature.");
88-
MoveCursor(3);
105+
printf("Type LOCKDEVICE to enable the ICSP Inhibit feature.\r\n\r\n");
89106
printf("WARNING: THIS PERMANENTLY DISABLES DIRECT PROGRAMMING OF THE BOARD.");
90107
}
91108

109+
static void PrintBootloaderRequired(void)
110+
{
111+
MoveCursor(1);
112+
printf("NO BOOTLOADER DETECTED!\r\n\r\n");
113+
printf("Because programming will be permanently disabled, \r\na bootloader is required to run this demo. \r\nPlease see the readme.md for more information.");
114+
}
115+
92116
static void ProcessReceivedChar(char receivedChar, char *window, int *windowIndex)
93117
{
94118
bool isCharValid = (*windowIndex < strlen(UNLOCK_COMMAND)) && (receivedChar == UNLOCK_COMMAND[*windowIndex]);

0 commit comments

Comments
 (0)