cancel
Showing results for 
Search instead for 
Did you mean: 

Is it OK to use "__PACKED" other than "__packed" in "cmsis_armcc.h"

FLiu.11
Associate II

I found that I have to change the define "__PACKED" to "__packed" in "cmsis_armcc.h"; otherwise, the following code in "stm32h7xx_II_usb.c" will crash on the second call to this function, if the "len" in the first call is 7 ( or might be other none 32-bit aligned number). I am wondering whether I do not configure the compiler correctly. It is Keil Compiler Version 5.

/**

 * @brief USB_ReadPacket : read a packet from the RX FIFO

 * @param USBx Selected device

 * @param dest source pointer

 * @param len Number of bytes to read

 * @retval pointer to destination buffer

 */

void *USB_ReadPacket(USB_OTG_GlobalTypeDef *USBx, uint8_t *dest, uint16_t len)

{

 uint32_t USBx_BASE = (uint32_t)USBx;

 uint32_t *pDest = (uint32_t *)dest;

 uint32_t i;

 uint32_t count32b = ((uint32_t)len + 3U) / 4U;

 for (i = 0U; i < count32b; i++)

 {

   __UNALIGNED_UINT32_WRITE(pDest, USBx_DFIFO(0U));

   pDest++;

 }

 return ((void *)pDest);

}

1 REPLY 1

Aligment control and data packing are non-standard thus compiler-dependent features. In other words, you might be better off asking this question at Keil.

The strange thing is, that Keil==ARM, so I'd expect ARM headers be good for Keil.

There may be compiler settings impacting its behaviour when it comes to the very details.

JW