This looks like a mistake copied from the earlier n200_func.c file, which also incorrectly aligned the address to 64 bytes. The address should be masked by ~3, not ~0x3f.
This code probably works by accident since a lot of startup code seems to place the interrupt table at the start of Flash memory, so it is accidentally aligned.
EDIT: It seems that the address written to mtvec does have to be aligned to 64 bytes, or else the hardware refuses to work. So the actual bug here is that this requirement is not correctly documented for this function.
The comments for __set_exc_entry says that address should be aligned to 4 bytes, but the code itself forces alignment to 64 bytes:https://github.com/Nuclei-Software/nuclei-sdk/blob/master/NMSIS/Core/Include/core_feature_eclic.h#L757This looks like a mistake copied from the earlier n200_func.c file, which also incorrectly aligned the address to 64 bytes. The address should be masked by~3
, not~0x3f
.This code probably works by accident since a lot of startup code seems to place the interrupt table at the start of Flash memory, so it is accidentally aligned.EDIT: It seems that the address written to
mtvec
does have to be aligned to 64 bytes, or else the hardware refuses to work. So the actual bug here is that this requirement is not correctly documented for this function.https://github.com/Nuclei-Software/nuclei-sdk/blob/master/NMSIS/Core/Include/core_feature_eclic.h#L751
This comment says the address has to be aligned to 4 bytes, but it should be aligned to 64 bytes.