Skip to content

Commit f93615c

Browse files
yashatmicrochipdavidflowers
authored andcommitted
Pull request #42: Added ICSP functionality to a separate module
Merge in MCU16CE/dspic33-dsc-bootloader-code-examples from ~C71668/dspic33-dsc-bootloader-code-examples:MCU16GITHUB-939-create-icsp-inhibit-module to feature/MCU16GITHUB-842-add-the-icsp-inhibit-feature * commit '49cb7edf09996d1706e759c7fde1f91f2d2c49e3': * 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
2 parents b675ff9 + 49cb7ed commit f93615c

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

secure_boot_and_secure_firmware_upgrade_over_canfd/icsp_inhibit.X/icsp_inhibit.c

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,31 @@
2020
*/
2121

2222
#include <stdbool.h>
23+
#include <string.h>
24+
#include "mcc_generated_files/flash/flash.h"
25+
#include "mcc_generated_files/flash/flash_types.h"
2326

24-
static bool icspEnabled = false;
27+
#define ICSP_INHIBIT_WRITE_LOCK_ADDRESS 0x0801034
28+
29+
static flash_data_t inhibitKeys[4] =
30+
{
31+
0x00006D63UL, 0x00000000UL, 0x00006870UL, 0x00000000UL
32+
};
2533

26-
//temp stubs - replace with real implementation
2734
bool ICSP_INHIBIT_IsEnabled(void)
2835
{
29-
return icspEnabled;
36+
static const 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;
3044
}
3145

32-
bool ICSP_INHIBIT_Enable()
46+
void ICSP_INHIBIT_Enable()
3347
{
34-
icspEnabled = true;
48+
FLASH_WordWrite(0x801034, &inhibitKeys[0], FLASH_UNLOCK_KEY);
49+
FLASH_WordWrite(0x801038, &inhibitKeys[2], FLASH_UNLOCK_KEY);
3550
}

secure_boot_and_secure_firmware_upgrade_over_canfd/icsp_inhibit.X/icsp_inhibit.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@
2525
#include <stdbool.h>
2626

2727
bool ICSP_INHIBIT_IsEnabled(void);
28-
bool ICSP_INHIBIT_Enable(void);
28+
void ICSP_INHIBIT_Enable(void);
2929

3030
#endif

secure_boot_and_secure_firmware_upgrade_over_canfd/icsp_inhibit.X/main.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ static bool errorPresent = false;
6262
int main(void)
6363
{
6464
const char* keyword = "LOCKDEVICE";
65-
6665
SYSTEM_Initialize();
6766

6867
if(WasLoadedByBootloader() == false)
@@ -234,4 +233,4 @@ static uint32_t GetResetAddress()
234233
static bool WasLoadedByBootloader()
235234
{
236235
return (GetResetAddress() < BOOT_CONFIG_PROGRAMMABLE_ADDRESS_LOW);
237-
}
236+
}

0 commit comments

Comments
 (0)