Skip to content

Commit 6f318a8

Browse files
Added ICSP functionality to a separate module
1 parent b675ff9 commit 6f318a8

File tree

4 files changed

+21
-8
lines changed

4 files changed

+21
-8
lines changed

secure_boot_and_secure_firmware_upgrade_over_canfd/icsp_inhibit.X/icsp_inhibit.c

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

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

24-
static bool icspEnabled = false;
26+
static flash_data_t inhibitKeys[4] =
27+
{
28+
0x00006D63UL, 0x00000000UL, 0x00006870UL, 0x00000000UL
29+
};
2530

26-
//temp stubs - replace with real implementation
2731
bool ICSP_INHIBIT_IsEnabled(void)
2832
{
29-
return icspEnabled;
33+
static flash_data_t dataInFlash[4];
34+
FLASH_Read(0x801034, 4, dataInFlash);
35+
36+
if(memcmp(inhibitKeys, dataInFlash, sizeof(inhibitKeys)) == 0)
37+
{
38+
return true;
39+
}
40+
return false;
3041
}
3142

32-
bool ICSP_INHIBIT_Enable()
43+
void ICSP_INHIBIT_Enable()
3344
{
34-
icspEnabled = true;
45+
FLASH_WordWrite(0x801034, &inhibitKeys[0], FLASH_UNLOCK_KEY);
46+
FLASH_WordWrite(0x801038, &inhibitKeys[2], FLASH_UNLOCK_KEY);
3547
}

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+
}

secure_boot_and_secure_firmware_upgrade_over_canfd/icsp_inhibit.X/nbproject/configurations.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,8 @@
358358
value="${memories.instruction.ram.ranges}"/>
359359
<property key="memories.programmemory" value="true"/>
360360
<property key="memories.programmemory.ranges" value="0-afeff"/>
361+
<property key="programmerToGoFilePath"
362+
value="C:/work/repos/dspic33-dsc-bootloader-code-examples/secure_boot_and_secure_firmware_upgrade_over_canfd/icsp_inhibit.X/debug/default/icsp_inhibit_ptg"/>
361363
<property key="programoptions.donoteraseauxmem" value="false"/>
362364
<property key="programoptions.eraseb4program" value="true"/>
363365
<property key="programoptions.pgmentry.voltage" value="low"/>

0 commit comments

Comments
 (0)