Skip to content

Commit 8bb91d6

Browse files
committed
Fix MISRA violation and add comments for required violations
1 parent 98011ce commit 8bb91d6

File tree

2 files changed

+25
-9
lines changed

2 files changed

+25
-9
lines changed

dspic33a_bootloader_and_firmware_upgrade_demo/boot.X/mdfu/mdfu_firmware_update.c

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -93,18 +93,34 @@ bool MDFU_FirmwareUpdateVerifyImage(void)
9393
}
9494

9595
void MDFU_FirmwareUpdateStartApplication(void)
96-
{
97-
int (*user_application)(void);
98-
96+
{
9997
/* This is probably being replaced at some point by __builtin__setIVTBASE() but is not currently supported */
10098
/* This also assumes that the first block of memory in the application is the reset/ivt table which may not always be true if there is an application header */
10199
PACCON1bits.IVTBASEWR = 1;
102100
IVTBASE = MDFU_CONFIG_APPLICATION_RESET_ADDRESS;
103101
PACCON1bits.IVTBASEWR = 0;
104102

105-
uint32_t *resetVectorPtr = (uint32_t *)MDFU_CONFIG_APPLICATION_RESET_ADDRESS;
106-
uint32_t resetVector = *resetVectorPtr;
107-
108-
user_application = (int(*)(void))resetVector;
109-
user_application();
103+
/* cppcheck-suppress misra-c2012-11.4
104+
*
105+
* (Rule 11.4) ADVISORY: A conversion should not be performed between a
106+
* pointer to object and an integer type
107+
*
108+
* Reasoning: This is required for the bootloader to jump to the application
109+
* code. The reset vector is stored at a fixed address, and this cast is
110+
* necessary to read it.
111+
*/
112+
uint32_t resetVector = *((const uint32_t *)MDFU_CONFIG_APPLICATION_RESET_ADDRESS);
113+
114+
/* cppcheck-suppress misra-c2012-11.4
115+
*
116+
* (Rule 11.4) ADVISORY: A conversion should not be performed between a
117+
* pointer to object and an integer type
118+
*
119+
* Reasoning: This is required for the bootloader to jump to the application
120+
* code. The application entry point is stored in the reset vector and must
121+
* be cast to a function pointer.
122+
*/
123+
int (*user_application)(void) = (int (*)(void))resetVector;
124+
125+
(void)user_application();
110126
}

dspic33a_secure_boot/boot.X/mdfu/mdfu_partition_executable.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ static enum MDFU_PARTITION_STATUS Run(void)
243243
* pointer to object and an integer type
244244
*
245245
* Reasoning: This is required for the bootloader to jump to the executable
246-
* code. The application entry point is stored in the reset vector and must
246+
* code. The executable entry point is stored in the reset vector and must
247247
* be cast to a function pointer.
248248
*/
249249
int (*user_executable)(void) = (int (*)(void))resetVector;

0 commit comments

Comments
 (0)