Skip to content

Commit f61017c

Browse files
committed
Fix masking and move to correct function
1 parent e2e6fe9 commit f61017c

File tree

1 file changed

+6
-4
lines changed
  • secure_boot_and_secure_firmware_upgrade_over_canfd/app.X

1 file changed

+6
-4
lines changed

secure_boot_and_secure_firmware_upgrade_over_canfd/app.X/main.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
THIS SOFTWARE.
2020
*/
2121
#include "mcc_generated_files/system/system.h"
22+
#include "mcc_generated_files/system/pins.h"
2223
#include "mcc_generated_files/flash/flash.h"
2324
#include "mcc_generated_files/flash/flash_types.h"
2425
#include "mcc_generated_files/boot/boot_config.h"
@@ -37,7 +38,8 @@
3738
* The GOTO instruction contains two 24 bit words, the first of which contains
3839
* the lower 15 bits of the address and the second of which contains the upper
3940
* 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.
41+
* parses the two words in order to determine the reset address. The opcode bits
42+
* in the GOTO instruction are masked.
4143
*
4244
* Refer to https://ww1.microchip.com/downloads/en/DeviceDoc/70000157g.pdf for
4345
* additional details on the GOTO instruction format.
@@ -46,12 +48,12 @@ uint32_t GetResetAddress()
4648
{
4749
flash_data_t flashData[2];
4850
FLASH_Read(0x000000, 2, flashData);
49-
return (flashData[1]<<16) | flashData[0];
51+
return (((flashData[1] & 0x0000007F)<<16) | (flashData[0] & 0x0000FFFE));
5052
}
5153

5254
bool WasLoadedByBootloader()
5355
{
54-
return ((GetResetAddress() & 0x0000FFFF) < BOOT_CONFIG_PROGRAMMABLE_ADDRESS_LOW);
56+
return (GetResetAddress() < BOOT_CONFIG_PROGRAMMABLE_ADDRESS_LOW);
5557
}
5658

5759
int main(void) {
@@ -62,7 +64,7 @@ int main(void) {
6264
{
6365
if (WasLoadedByBootloader())
6466
{
65-
// ICSP Inhibit
67+
IO_RE6_SetHigh();
6668
}
6769
}
6870
}

0 commit comments

Comments
 (0)