Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(PeriphDrivers): Fix -Wcast-align warning for MAX78000 & MAX78002 SYS Drivers #706

Merged
merged 4 commits into from
Aug 17, 2023

Conversation

Jake-Carter
Copy link
Contributor

@Jake-Carter Jake-Carter commented Aug 11, 2023

Pull Request Template

Description

This PR fixes the -Wcast-align errors for the MAX78000 & MAX78002 USN calculations. Our AES struct enforces 32-bit data alignment, so this solution uses an intermediate buffer and memcpy's out to the user's buffers.

- CC /home/jakecarter/repos/fork/msdk/Libraries/CMSIS/../PeriphDrivers/Source/SYS/sys_ai85.c
/home/jakecarter/repos/fork/msdk/Libraries/CMSIS/../PeriphDrivers/Source/SYS/sys_ai85.c: In function 'MXC_SYS_GetUSN':
/home/jakecarter/repos/fork/msdk/Libraries/CMSIS/../PeriphDrivers/Source/SYS/sys_ai85.c:120:29: warning: cast increases required alignment of target type [-Wcast-align]
  120 |         aes_req.inputData = (uint32_t *)usn;
      |                             ^
/home/jakecarter/repos/fork/msdk/Libraries/CMSIS/../PeriphDrivers/Source/SYS/sys_ai85.c:121:30: warning: cast increases required alignment of target type [-Wcast-align]
  121 |         aes_req.resultData = (uint32_t *)check_csum;
      |                              ^

Test Program

// project.mk
PROJ_CFLAGS += -Wcast-align -Werror
// main.c
#include "mxc_sys.h"

int main(void) {
    uint8_t usn[MXC_SYS_USN_LEN];
    uint8_t checksum[MXC_SYS_USN_CSUM_FIELD_LEN];

    int err = MXC_SYS_GetUSN(usn, checksum);
    if (err)
        printf("USN error: %i\n", err);

    printf("USN: 0x");
    for (int i = 0; i < MXC_SYS_USN_LEN; i++) {
        printf("%x", usn[i]);
    }
    printf("\n");
    printf("Checksum: 0x%x\n", checksum[0] | (checksum[1] << 8));

   return 0;
}
  • MA78000 (PASS):
USN: 0xa184932241e4effdaee9bc
Checksum: 0xbce9
  • MAX78002 (PASS):
USN: 0xa186889024015501ce32f7
Checksum: 0xf732

Checklist Before Requesting Review

  • PR Title follows correct guidelines.
  • Description of changes and all other relevant information.
  • (Optional) Link any related GitHub issues using a keyword
  • (Optional) Provide info on any relevant functional testing/validation. For API changes or significant features, this is not optional.

@github-actions github-actions bot added MAX78000 Related to the MAX78000 (AI85) MAX78002 Related to the MAX78002 (AI87) labels Aug 11, 2023

MXC_FLC_LockInfoBlock(MXC_INFO0_MEM_BASE);

if (usn != NULL)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check for a null pointer is redundant.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Jacob-Scheiffler
Copy link
Contributor

Are we gonna see this warning on other parts as well?

@Jake-Carter
Copy link
Contributor Author

Are we gonna see this warning on other parts as well?

Not by default. We should eventually apply this to the other micros, but at a low priority

@Jake-Carter Jake-Carter merged commit 79c58c7 into analogdevicesinc:main Aug 17, 2023
9 checks passed
@Jake-Carter Jake-Carter deleted the fix/usn-wcast branch August 17, 2023 17:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
MAX78000 Related to the MAX78000 (AI85) MAX78002 Related to the MAX78002 (AI87)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants