Jul 13, 2021
01:48 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Jul 13, 2021
01:48 AM
Hello!
I am trying to rewrite my code from other MCU to TC234. And when i try to cast Can bus data to (uint16_t) like this:
- uint16_t var = *(uint16_t*)pCanData;
CPU goes to IfxCpu_Trap_instructionError(). And the same happends if i try to write field of casted struct like this:
Header_t *pxHeader = (Header_t *)byteArrayGetData(&pCtx->byteArray);
pCtx->sessionCnt = pxHeader->sessions;
What i do wrong, or TC234 can't do this operations?
I am trying to rewrite my code from other MCU to TC234. And when i try to cast Can bus data to (uint16_t) like this:
- uint16_t var = *(uint16_t*)pCanData;
CPU goes to IfxCpu_Trap_instructionError(). And the same happends if i try to write field of casted struct like this:
Header_t *pxHeader = (Header_t *)byteArrayGetData(&pCtx->byteArray);
pCtx->sessionCnt = pxHeader->sessions;
What i do wrong, or TC234 can't do this operations?
Solved! Go to Solution.
- Tags:
- IFX
1 Solution
Jul 13, 2021
03:38 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Jul 13, 2021
03:38 AM
You can change the definition e.g. uint8_t canData[8] IFX_ALIGN(IFX_ALIGN_16), then canData[0] is 16 bit aligned.
Same works for the byteArray. If you add an IFX_ALIGN(IFX_ALIGN_32) then the struct is 32 bit aligned.
Maybe there is also a compiler option to use always 32 bit address for begin of structs and fields. Please check the compiler documentation for such a setting if exist.
Same works for the byteArray. If you add an IFX_ALIGN(IFX_ALIGN_32) then the struct is 32 bit aligned.
Maybe there is also a compiler option to use always 32 bit address for begin of structs and fields. Please check the compiler documentation for such a setting if exist.
4 Replies
Jul 13, 2021
02:11 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Jul 13, 2021
02:11 AM
This will be happen when e.g. pCanData is not 16 bit aligned. Check the TIN of the trap, I expect it is 4 (ALN - Data Address Alignment).
Same occurs with the struct. You must make sure that the address of the byteArray is 32 bit aligned.
Same occurs with the struct. You must make sure that the address of the byteArray is 32 bit aligned.
Jul 13, 2021
02:31 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Jul 13, 2021
02:31 AM
Thank you for answering!
TIN of the trap is realy 4. If I understand it right uint8_t canData[8] most be 16bit aligned;
so it's no way to do forward cast from canData to uint16_t like this
*(uint16_t*)&canData[0], the only way is used bit shift - (canData[0] | canData[1] << 😎
howeever how can I sure that adress of byteArray is 32 bit aligned? Is that some compiler setting? Or I most create all structures with padding.
TIN of the trap is realy 4. If I understand it right uint8_t canData[8] most be 16bit aligned;
so it's no way to do forward cast from canData to uint16_t like this
*(uint16_t*)&canData[0], the only way is used bit shift - (canData[0] | canData[1] << 😎
howeever how can I sure that adress of byteArray is 32 bit aligned? Is that some compiler setting? Or I most create all structures with padding.
Jul 13, 2021
03:38 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Jul 13, 2021
03:38 AM
You can change the definition e.g. uint8_t canData[8] IFX_ALIGN(IFX_ALIGN_16), then canData[0] is 16 bit aligned.
Same works for the byteArray. If you add an IFX_ALIGN(IFX_ALIGN_32) then the struct is 32 bit aligned.
Maybe there is also a compiler option to use always 32 bit address for begin of structs and fields. Please check the compiler documentation for such a setting if exist.
Same works for the byteArray. If you add an IFX_ALIGN(IFX_ALIGN_32) then the struct is 32 bit aligned.
Maybe there is also a compiler option to use always 32 bit address for begin of structs and fields. Please check the compiler documentation for such a setting if exist.
Jul 13, 2021
03:52 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Jul 13, 2021
03:52 AM
Thank you for answer!
This widget could not be displayed.