Skip to content

Commit 1274bf9

Browse files
committed
Revert changes in app and add to icsp project
1 parent c70559c commit 1274bf9

File tree

12 files changed

+1158
-110
lines changed

12 files changed

+1158
-110
lines changed

secure_boot_and_secure_firmware_upgrade_over_canfd/app.X/app.mc3

Lines changed: 2 additions & 44 deletions
Large diffs are not rendered by default.

secure_boot_and_secure_firmware_upgrade_over_canfd/app.X/main.c

Lines changed: 6 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -19,51 +19,20 @@
1919
THIS SOFTWARE.
2020
*/
2121
#include "mcc_generated_files/system/system.h"
22-
#include "mcc_generated_files/flash/flash.h"
23-
#include "mcc_generated_files/flash/flash_types.h"
24-
#include "mcc_generated_files/boot/boot_config.h"
22+
#include "mcc_generated_files/system/pins.h"
2523

2624
/*
2725
Main application
2826
*/
2927

30-
/* The following code finds the address used by GOTO instruction programmed
31-
* at the reset vector in order to determine whether or not the application
32-
* was downloaded directly or via the bootloader (i.e. if the address within the
33-
* GOTO instruction is within the bootloader or application), as the ICSP
34-
* inhibit functionality is only permitted if the application was
35-
* downloaded via the bootloader.
36-
*
37-
* The GOTO instruction contains two 24 bit words, the first of which contains
38-
* the lower 15 bits of the address and the second of which contains the upper
39-
* 7 bits. The following code reads the GOTO address at the reset vector and
40-
* parses the two words in order to determine the reset address. The opcode bits
41-
* in the GOTO instruction are masked.
42-
*
43-
* Refer to https://ww1.microchip.com/downloads/en/DeviceDoc/70000157g.pdf for
44-
* additional details on the GOTO instruction format.
45-
*/
46-
static uint32_t GetResetAddress()
47-
{
48-
flash_data_t flashData[2];
49-
FLASH_Read(0x000000, 2, flashData);
50-
return (((flashData[1] & 0x0000007F)<<16) | (flashData[0] & 0x0000FFFE));
51-
}
52-
53-
static bool WasLoadedByBootloader()
54-
{
55-
return (GetResetAddress() < BOOT_CONFIG_PROGRAMMABLE_ADDRESS_LOW);
56-
}
57-
5828
int main(void) {
29+
unsigned int counter = 0;
5930

6031
SYSTEM_Initialize();
61-
62-
while (1)
63-
{
64-
if (WasLoadedByBootloader())
65-
{
66-
// ICSP Inhibit
32+
33+
while (1) {
34+
if ((counter++ % 0x8000) == 0) {
35+
IO_RE9_Toggle();
6736
}
6837
}
6938
}

secure_boot_and_secure_firmware_upgrade_over_canfd/app.X/nbproject/configurations.xml

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,6 @@
1010
<logicalFolder name="boot" displayName="boot" projectFiles="true">
1111
<itemPath>mcc_generated_files/boot/boot_config.h</itemPath>
1212
</logicalFolder>
13-
<logicalFolder name="flash" displayName="flash" projectFiles="true">
14-
<itemPath>mcc_generated_files/flash/flash.h</itemPath>
15-
<itemPath>mcc_generated_files/flash/flash_interface.h</itemPath>
16-
<itemPath>mcc_generated_files/flash/flash_types.h</itemPath>
17-
<itemPath>mcc_generated_files/flash/flash_hardware.h</itemPath>
18-
</logicalFolder>
1913
<logicalFolder name="system" displayName="system" projectFiles="true">
2014
<itemPath>mcc_generated_files/system/interrupt.h</itemPath>
2115
<itemPath>mcc_generated_files/system/dmt.h</itemPath>
@@ -31,20 +25,6 @@
3125
</logicalFolder>
3226
</logicalFolder>
3327
</logicalFolder>
34-
<logicalFolder name="ExternalFiles"
35-
displayName="Important Files"
36-
projectFiles="true">
37-
<logicalFolder name="MCC Generated Files"
38-
displayName="MCC Generated Files"
39-
projectFiles="true">
40-
<logicalFolder name="boot" displayName="boot" projectFiles="true">
41-
<itemPath>mcc_generated_files/boot/postBuild.bat</itemPath>
42-
<itemPath>mcc_generated_files/boot/combineAppAndBootloaderHex.bat</itemPath>
43-
</logicalFolder>
44-
</logicalFolder>
45-
<itemPath>Makefile</itemPath>
46-
<itemPath>app.mc3</itemPath>
47-
</logicalFolder>
4828
<logicalFolder name="LinkerScript"
4929
displayName="Linker Files"
5030
projectFiles="true">
@@ -64,12 +44,6 @@
6444
<itemPath>mcc_generated_files/boot/memory_partition.S</itemPath>
6545
<itemPath>mcc_generated_files/boot/app_code_protect.c</itemPath>
6646
</logicalFolder>
67-
<logicalFolder name="flash" displayName="flash" projectFiles="true">
68-
<logicalFolder name="src" displayName="src" projectFiles="true">
69-
<itemPath>mcc_generated_files/flash/src/flash.c</itemPath>
70-
<itemPath>mcc_generated_files/flash/src/flash_asm.s</itemPath>
71-
</logicalFolder>
72-
</logicalFolder>
7347
<logicalFolder name="system" displayName="system" projectFiles="true">
7448
<logicalFolder name="src" displayName="src" projectFiles="true">
7549
<itemPath>mcc_generated_files/system/src/system.c</itemPath>
@@ -86,6 +60,20 @@
8660
</logicalFolder>
8761
<itemPath>main.c</itemPath>
8862
</logicalFolder>
63+
<logicalFolder name="ExternalFiles"
64+
displayName="Important Files"
65+
projectFiles="false">
66+
<logicalFolder name="MCC Generated Files"
67+
displayName="MCC Generated Files"
68+
projectFiles="true">
69+
<logicalFolder name="boot" displayName="boot" projectFiles="true">
70+
<itemPath>mcc_generated_files/boot/postBuild.bat</itemPath>
71+
<itemPath>mcc_generated_files/boot/combineAppAndBootloaderHex.bat</itemPath>
72+
</logicalFolder>
73+
</logicalFolder>
74+
<itemPath>Makefile</itemPath>
75+
<itemPath>app.mc3</itemPath>
76+
</logicalFolder>
8977
</logicalFolder>
9078
<projectmakefile>Makefile</projectmakefile>
9179
<confs>
@@ -95,7 +83,7 @@
9583
<targetDevice>dsPIC33CK1024MP710</targetDevice>
9684
<targetHeader></targetHeader>
9785
<targetPluginBoard></targetPluginBoard>
98-
<platformTool>pkob4hybrid</platformTool>
86+
<platformTool>noID</platformTool>
9987
<languageToolchain>XC16</languageToolchain>
10088
<languageToolchainVersion>2.10</languageToolchainVersion>
10189
<platform>3</platform>

secure_boot_and_secure_firmware_upgrade_over_canfd/icsp_inhibit.X/icsp_inhibit.mc3

Lines changed: 44 additions & 2 deletions
Large diffs are not rendered by default.

secure_boot_and_secure_firmware_upgrade_over_canfd/icsp_inhibit.X/main.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
#include <stdio.h>
2323
#include <string.h>
2424
#include <stdbool.h>
25+
#include "mcc_generated_files/flash/flash.h"
26+
#include "mcc_generated_files/flash/flash_types.h"
27+
#include "mcc_generated_files/boot/boot_config.h"
2528

2629
#define WINDOW_SIZE 10
2730
#define UNLOCK_COMMAND "LOCKDEVICE"
@@ -36,6 +39,8 @@ static void AppendCharToWindow(char receivedChar, char *window, int *windowIndex
3639
static void ProcessReceivedChar(char receivedChar, char *window, int *windowIndex);
3740
static void ResetWindowOnMismatch(char *window, int *windowIndex);
3841
static void CheckForUnlockCommand(char *window, int *windowIndex);
42+
static uint32_t GetResetAddress();
43+
static bool WasLoadedByBootloader();
3944

4045
int main(void)
4146
{
@@ -129,4 +134,32 @@ static void CheckForUnlockCommand(char *window, int *windowIndex)
129134
*windowIndex = 0;
130135
memset(window, 0, WINDOW_SIZE + 1);
131136
}
137+
}
138+
139+
/* The following code finds the address used by GOTO instruction programmed
140+
* at the reset vector in order to determine whether or not the application
141+
* was downloaded directly or via the bootloader (i.e. if the address within the
142+
* GOTO instruction is within the bootloader or application), as the ICSP
143+
* inhibit functionality is only permitted if the application was
144+
* downloaded via the bootloader.
145+
*
146+
* The GOTO instruction contains two 24 bit words, the first of which contains
147+
* the lower 15 bits of the address and the second of which contains the upper
148+
* 7 bits. The following code reads the GOTO address at the reset vector and
149+
* parses the two words in order to determine the reset address. The opcode bits
150+
* in the GOTO instruction are masked.
151+
*
152+
* Refer to https://ww1.microchip.com/downloads/en/DeviceDoc/70000157g.pdf for
153+
* additional details on the GOTO instruction format.
154+
*/
155+
static uint32_t GetResetAddress()
156+
{
157+
flash_data_t flashData[2];
158+
FLASH_Read(0x000000, 2, flashData);
159+
return (((flashData[1] & 0x0000007F)<<16) | (flashData[0] & 0x0000FFFE));
160+
}
161+
162+
static bool WasLoadedByBootloader()
163+
{
164+
return (GetResetAddress() < BOOT_CONFIG_PROGRAMMABLE_ADDRESS_LOW);
132165
}
Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
2+
/**
3+
* FLASH Generated Driver Header File
4+
*
5+
* @file flash.h
6+
*
7+
* @ingroup Flash Driver
8+
*
9+
* @brief This is the generated driver header file for the FLASH driver
10+
*
11+
* @skipline @version Firmware Driver Version 1.1.0
12+
*
13+
* @skipline @version PLIB Version 3.2.1
14+
*
15+
* @skipline Device : dsPIC33CK1024MP710
16+
*/
17+
18+
/*
19+
© [2024] Microchip Technology Inc. and its subsidiaries.
20+
21+
Subject to your compliance with these terms, you may use Microchip
22+
software and any derivatives exclusively with Microchip products.
23+
You are responsible for complying with 3rd party license terms
24+
applicable to your use of 3rd party software (including open source
25+
software) that may accompany Microchip software. SOFTWARE IS ?AS IS.?
26+
NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS
27+
SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT,
28+
MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
29+
WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
30+
INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY
31+
KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF
32+
MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE
33+
FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP?S
34+
TOTAL LIABILITY ON ALL CLAIMS RELATED TO THE SOFTWARE WILL NOT
35+
EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR
36+
THIS SOFTWARE.
37+
*/
38+
39+
#ifndef FLASH_HARDWARE_H
40+
#define FLASH_HARDWARE_H
41+
42+
#include <xc.h>
43+
#include <stdint.h>
44+
#include <stdbool.h>
45+
#include "flash_types.h"
46+
47+
/**
48+
@ingroup flashdriver
49+
@brief Defines FLASH Flash PC unit size
50+
*/
51+
#define FLASH_PC_UNIT_SIZE 2U
52+
/**
53+
@ingroup flashdriver
54+
@brief Defines FLASH unlock key value
55+
*/
56+
#define FLASH_UNLOCK_KEY 0x00AA0055
57+
/**
58+
@ingroup flashdriver
59+
@brief Defines FLASH write row size in instruction counts
60+
*/
61+
#define FLASH_WRITE_ROW_SIZE_IN_INSTRUCTIONS 128U
62+
/**
63+
@ingroup flashdriver
64+
@brief Defines FLASH write row size in PC counts
65+
*/
66+
#define FLASH_WRITE_ROW_SIZE_IN_PC_UNITS (FLASH_WRITE_ROW_SIZE_IN_INSTRUCTIONS * FLASH_PC_UNIT_SIZE)
67+
/**
68+
@ingroup flashdriver
69+
@brief Defines FLASH erase page size in instruction counts
70+
*/
71+
#define FLASH_ERASE_PAGE_SIZE_IN_INSTRUCTIONS 1024U
72+
/**
73+
@ingroup flashdriver
74+
@brief Defines FLASH erase page size in PC counts
75+
*/
76+
#define FLASH_ERASE_PAGE_SIZE_IN_PC_UNITS (FLASH_ERASE_PAGE_SIZE_IN_INSTRUCTIONS * FLASH_PC_UNIT_SIZE)
77+
/**
78+
@ingroup flashdriver
79+
@brief Defines if FLASH has ECC
80+
*/
81+
#define FLASH_HAS_ECC 1
82+
/**
83+
@ingroup flashdriver
84+
@brief Defines FLASH erase page mask value
85+
*/
86+
#define FLASH_ERASE_PAGE_MASK (~(FLASH_ERASE_PAGE_SIZE_IN_PC_UNITS - 1U))
87+
/**
88+
@ingroup flashdriver
89+
@brief Defines FLASH odd address mask value
90+
*/
91+
#define FLASH_ODD_ADDRESS_MASK 1U
92+
/**
93+
@ingroup flashdriver
94+
@brief Defines FLASH error mask value
95+
*/
96+
#define FLASH_ERROR_MASK 0x2100
97+
98+
/**
99+
* @ingroup flashdriver
100+
* @brief This routine erases a page indicated by the page aligned address.
101+
* @param[in] address - Flash page aligned address.
102+
* @return bool - Returns True if operation successful else returns false.
103+
*/
104+
bool FLASH_ErasePage(flash_adr_t address, flash_key_t unlockKey);
105+
106+
/* The address in the Read and Write word functions below must be even */
107+
108+
/**
109+
* @ingroup flashdriver
110+
* @brief This routine reads a 24 bit instruction from the indicated address in flash.
111+
* @param[in] address - Flash address.
112+
* @return uint32_t - 24 bit data.
113+
*/
114+
uint32_t FLASH_ReadWord24(flash_adr_t address);
115+
116+
117+
/**
118+
* @ingroup flashdriver
119+
* @brief This routine reads a 16 bit instruction from the indicated address in flash.
120+
* @param[in] address - Flash address.
121+
* @return uint16_t - 16 bit data.
122+
*/
123+
uint16_t FLASH_ReadWord16(flash_adr_t address);
124+
125+
126+
/**
127+
* @ingroup flashdriver
128+
* @brief This routine writes two 24 bit instructions to the indicated address in flash.
129+
* @param[in] address - Flash address.
130+
* @param[in] data1 - First 24 bit data to be written(First word).
131+
* @param[in] data2 - Second 24 bit data to be written(Second word).
132+
* @return bool - Returns true if operation is successful else returns false.
133+
*/
134+
bool FLASH_WriteDoubleWord24(flash_adr_t address, flash_data_t Data0, flash_data_t Data1, flash_key_t unlockKey);
135+
136+
137+
/**
138+
* @ingroup flashdriver
139+
* @brief This routine writes two ,16 bit instructions to the indicated address in flash.
140+
* @param[in] address - Flash address.
141+
* @param[in] data1 - First 16 bit data to be written(First word).
142+
* @param[in] data2 - Second 16 bit data to be written(Second word).
143+
* @return bool - Returns true if operation is successful else returns false.
144+
*/
145+
bool FLASH_WriteDoubleWord16(flash_adr_t flashAddress, uint16_t Data0, uint16_t Data1, flash_key_t unlockKey);
146+
147+
148+
/* Program the flash one row at a time. */
149+
150+
151+
/**
152+
* @ingroup flashdriver
153+
* @brief
154+
* This routine writes a single row of data from the location given in *data to the flash location in address.
155+
* Since the flash is only 24 bits wide all data in the upper 8 bits of the source will be lost.The address in
156+
* *data must be row aligned.
157+
* @param[in] address - Flash address.
158+
* @param[in] *data - Address of the data to be written.
159+
* @return bool - Returns true if operation is successful else returns false.
160+
*/
161+
bool FLASH_WriteRow24(flash_adr_t flashAddress, flash_data_t *data, flash_key_t unlockKey);
162+
163+
164+
/**
165+
* @ingroup flashdriver
166+
* @brief
167+
* This routine writes a single row of data from the location given in *data to the flash location in address.
168+
* Each 16 bit source data word is stored in the lower 16 bits of each flash entry and the upper 8 bits of the
169+
* flash is not programmed.The address in *data must be row aligned.
170+
* @param[in] address - Flash address.
171+
* @param[in] *data - Address of the data to be written.
172+
* @return bool - Returns true if operation is successful else returns false.
173+
*/
174+
bool FLASH_WriteRow16(flash_adr_t address, uint16_t *data, flash_key_t unlockKey);
175+
176+
177+
/**
178+
* @ingroup flashdriver
179+
* @brief This routiner returns the page offset the given flash address.
180+
* @param[in] address - Flash address.
181+
* @return uint32_t - returns offset.
182+
*/
183+
uint16_t FLASH_ErasePageOffsetGet(flash_adr_t address);
184+
185+
186+
/**
187+
* @ingroup flashdriver
188+
* @brief This routine returns the page aligned address for a given flash address..
189+
* @param[in] address - Flash address.
190+
* @return uint32_t - Returns page aligned flash address.
191+
*/
192+
uint32_t FLASH_ErasePageAddressGet(flash_adr_t address);
193+
194+
#endif /* FLASH_HARDWARE_H */

0 commit comments

Comments
 (0)