cancel
Showing results for 
Search instead for 
Did you mean: 

sw4stm32 doesn't like the project generated by STMCubeMx v5.3

Spaced Cowboy
Associate III

Specifically, for a STM32F723, with the HS USB PHY enabled, it's giving me an error in

HAL_StatusTypeDef USB_WritePacket(USB_OTG_GlobalTypeDef *USBx, uint8_t *src, uint8_t ch_ep_num, uint16_t len, uint8_t dma)
{
  uint32_t USBx_BASE = (uint32_t)USBx;
  uint32_t *pSrc = (uint32_t *)src;
  uint32_t count32b, i;
 
  if (dma == 0U)
  {
    count32b = ((uint32_t)len + 3U) / 4U;
    for (i = 0U; i < count32b; i++)
    {
      USBx_DFIFO((uint32_t)ch_ep_num) = *((__packed uint32_t *)pSrc);
      pSrc++;
    }
  }
 
  return HAL_OK;
}

... where it's the __packed that's causing the problem. The same thing is true for the USB_ReadPacket immediately below the above in stm32f7xx_ll_usb.c

I'm not sure what the effect of removing the __packed will be (presumably it's there for a reason!) but after freshly generating the project, a build produces:

../Drivers/STM32F7xx_HAL_Driver/Src/stm32f7xx_ll_usb.c: In function 'USB_WritePacket':
../Drivers/STM32F7xx_HAL_Driver/Src/stm32f7xx_ll_usb.c:958:53: error: expected ')' before 'uint32_t'
       USBx_DFIFO((uint32_t)ch_ep_num) = *((__packed uint32_t *)pSrc);
                                                     ^~~~~~~~
../Drivers/STM32F7xx_HAL_Driver/Src/stm32f7xx_ll_usb.c:958:64: error: expected ')' before 'pSrc'
       USBx_DFIFO((uint32_t)ch_ep_num) = *((__packed uint32_t *)pSrc);
                                                                ^~~~
../Drivers/STM32F7xx_HAL_Driver/Src/stm32f7xx_ll_usb.c: In function 'USB_ReadPacket':
../Drivers/STM32F7xx_HAL_Driver/Src/stm32f7xx_ll_usb.c:987:16: error: expected ')' before 'uint32_t'
     *(__packed uint32_t *)pDest = USBx_DFIFO(0U);
                ^~~~~~~~
../Drivers/STM32F7xx_HAL_Driver/Src/stm32f7xx_ll_usb.c:987:5: warning: statement with no effect [-Wunused-value]
     *(__packed uint32_t *)pDest = USBx_DFIFO(0U);
     ^~~~~~~~~~~~~~~~~~~
../Drivers/STM32F7xx_HAL_Driver/Src/stm32f7xx_ll_usb.c:987:27: error: expected ';' before 'pDest'
     *(__packed uint32_t *)pDest = USBx_DFIFO(0U);
                           ^~~~~
../Drivers/STM32F7xx_HAL_Driver/Src/stm32f7xx_ll_usb.c:980:12: warning: unused variable 'USBx_BASE' [-Wunused-variable]
   uint32_t USBx_BASE = (uint32_t)USBx;
            ^~~~~~~~~
make: *** [Drivers/STM32F7xx_HAL_Driver/Src/stm32f7xx_ll_usb.o] Error 1

Removing the __packed attribute from both calls makes it compile cleanly.

3 REPLIES 3
Spaced Cowboy
Associate III

This time around I'm trying to generate a build for ST's own STM32F723E-DISCO board, selected defaults, chose sw4stm32. I thought I might have better luck with an official board from ST.

Nope. Same problem.

So after much searching, I found the reason for this - it seems that STCube defines __packed surrounded with quotes, which is simply wrong. It can be fixed by selecting the project, going to Project -> Properties -> C/C++ General -> Symbols : Remove quotes around __packed and __weak

At which point, the build will fail because it can't find os_tick.h. Great. Ok "find" to the rescue, get the path and configure it in Project -> Properties -> C/C++ General -> Includes : Add Drivers/CMSIS/RTOS2/Include

At which point it fails saying it can't find RTE_Components.h. Ok, another find. Ah - there's lots of them...

find . -name RTE_Components.h               ./Drivers/CMSIS/NN/Examples/ARM/arm_nn_examples/cifar10/RTE/_ARMCM0/RTE_Components.h
./Drivers/CMSIS/NN/Examples/ARM/arm_nn_examples/cifar10/RTE/_ARMCM3/RTE_Components.h
./Drivers/CMSIS/NN/Examples/ARM/arm_nn_examples/cifar10/RTE/_ARMCM4_FP/RTE_Components.h
./Drivers/CMSIS/NN/Examples/ARM/arm_nn_examples/cifar10/RTE/_ARMCM7_SP/RTE_Components.h
./Drivers/CMSIS/NN/Examples/ARM/arm_nn_examples/gru/RTE/_ARMCM0/RTE_Components.h
./Drivers/CMSIS/NN/Examples/ARM/arm_nn_examples/gru/RTE/_ARMCM3/RTE_Components.h
./Drivers/CMSIS/NN/Examples/ARM/arm_nn_examples/gru/RTE/_ARMCM4_FP/RTE_Components.h
./Drivers/CMSIS/NN/Examples/ARM/arm_nn_examples/gru/RTE/_ARMCM7_SP/RTE_Components.h
./Drivers/CMSIS/NN/NN_Lib_Tests/nn_test/RTE/_ARMCM0/RTE_Components.h
./Drivers/CMSIS/NN/NN_Lib_Tests/nn_test/RTE/_ARMCM3/RTE_Components.h
./Drivers/CMSIS/NN/NN_Lib_Tests/nn_test/RTE/_ARMCM4_FP/RTE_Components.h
./Drivers/CMSIS/NN/NN_Lib_Tests/nn_test/RTE/_ARMCM7_SP/

So let's assume it's the one in ./Drivers/CMSIS/NN/NN_Lib_Tests/nn_test/RTE/_ARMCM7_SP - and add that path to Project -> Properties -> C/C++ General -> Includes as well...

And then it fails with "Drivers/CMSIS/NN/NN_Lib_Tests/nn_test/RTE/_ARMCM7_SP/RTE_Components.h:17:29: fatal error: ARMCM7_SP.h: No such file or directory"

Ok, well it's got me there, doing a 'find . -name ARMCM7_SP.h' returns nothing, nada, zilch, zero point...

At this point I have to give up. This is the latest version of STMCube and it's just generating very broken code. Sigh.

Joerg Wagner
Senior III

Simply remove in your Project Properties > C/C++ Build > Settings > MCU GCC Compiler > Preprocessor > Defined Symbols the line

__packed__="__attribute__((__packed__))"

I also added the line USE_USB_FS.

This solved my problem to use USB sticks.

Pavel A.
Evangelist III

Could anybody explain what exactly does __attribute__((packed)) for pointers?

Is it just a reminder for a programmer that the pointer or structure members are not aligned?

Or the compiler will actually generate code to access unaligned data by bytes and reassemble?

-- pa