Skip to content

stm32 USB sanitycheck failures with sdk 0.10.0-beta2 #13237

Closed
@galak

Description

@galak
Collaborator

Seeing a number of sanitycheck failures due the following warning when building with the newer gcc in sdk 0.10.0-beta:

/home/galak/git/zephyr/ext/hal/st/stm32cube/stm32f4xx/drivers/src/stm32f4xx_ll_usb.c: In function 'USB_WritePacket':
/home/galak/git/zephyr/ext/hal/st/stm32cube/stm32f4xx/drivers/src/stm32f4xx_ll_usb.c:886:7: error: 'packed' attribute ignored for type 'uint32_t *' {aka 'unsigned int *'} [-Werror=attributes]
       USBx_DFIFO(ch_ep_num) = *((__packed uint32_t *)src);
       ^~~~~~~~~~
/home/galak/git/zephyr/ext/hal/st/stm32cube/stm32f4xx/drivers/src/stm32f4xx_ll_usb.c: In function 'USB_ReadPacket':
/home/galak/git/zephyr/ext/hal/st/stm32cube/stm32f4xx/drivers/src/stm32f4xx_ll_usb.c:912:5: error: 'packed' attribute ignored for type 'uint32_t *' {aka 'unsigned int *'} [-Werror=attributes]
     *(__packed uint32_t *)dest = USBx_DFIFO(0U);
     ^
cc1: all warnings being treated as errors

Reproduce:

./scripts/sanitycheck -T samples/subsys/usb/cdc_acm -l

Activity

added
bugThe issue is a bug, or the PR is fixing a bug
area: USBUniversal Serial Bus
on Feb 10, 2019
added this to the v1.14.0 milestone on Feb 10, 2019
galak

galak commented on Feb 10, 2019

@galak
CollaboratorAuthor

Not sure what the proper workaround for this. Not clear to me why the cast to (__packed uint32_t *) is even there.

In previous similar issue, I fixed this with UNALIGNED_GET() see commit 93d0f8c.

Whatever fix will probably need to be applied to all these cases:

ext/hal/st/stm32cube/stm32f1xx/drivers/src/stm32f1xx_ll_usb.c:    USBx_DFIFO(ch_ep_num) = *((__packed uint32_t *)src);
ext/hal/st/stm32cube/stm32f1xx/drivers/src/stm32f1xx_ll_usb.c:    *(__packed uint32_t *)dest = USBx_DFIFO(0);
ext/hal/st/stm32cube/stm32f2xx/drivers/src/stm32f2xx_ll_usb.c:      USBx_DFIFO(ch_ep_num) = *((__packed uint32_t *)src);
ext/hal/st/stm32cube/stm32f2xx/drivers/src/stm32f2xx_ll_usb.c:    *(__packed uint32_t *)dest = USBx_DFIFO(0U);
ext/hal/st/stm32cube/stm32f4xx/drivers/src/stm32f4xx_ll_usb.c:      USBx_DFIFO(ch_ep_num) = *((__packed uint32_t *)src);
ext/hal/st/stm32cube/stm32f4xx/drivers/src/stm32f4xx_ll_usb.c:    *(__packed uint32_t *)dest = USBx_DFIFO(0U);
ext/hal/st/stm32cube/stm32f7xx/drivers/src/stm32f7xx_ll_usb.c:      USBx_DFIFO((uint32_t)ch_ep_num) = *((__packed uint32_t *)pSrc);
ext/hal/st/stm32cube/stm32f7xx/drivers/src/stm32f7xx_ll_usb.c:    *(__packed uint32_t *)pDest = USBx_DFIFO(0U);
ext/hal/st/stm32cube/stm32l4xx/drivers/src/stm32l4xx_ll_usb.c:    USBx_DFIFO((uint32_t)ch_ep_num) = *((__packed uint32_t *)pSrc);
ext/hal/st/stm32cube/stm32l4xx/drivers/src/stm32l4xx_ll_usb.c:    *(__packed uint32_t *)pDest = USBx_DFIFO(0U);
erwango

erwango commented on Feb 11, 2019

@erwango
Member

What about using CMSIS defines ?

__UNALIGNED_UINT32_READ
__UNALIGNED_UINT32_WRITE

Downloading sdk_ng, so I haven't been able to test.
Though, since available in cmsis pack, these should be easier to propagate in Cube releases

galak

galak commented on Feb 11, 2019

@galak
CollaboratorAuthor

This makes the warnings go away for me, please look to see its correct and I think you can make the change for the other driver instances:

diff --git a/ext/hal/st/stm32cube/stm32f2xx/drivers/src/stm32f2xx_ll_usb.c b/ext/hal/st/stm32cube/stm32f2xx/drivers/src/stm32f2xx_ll_usb.c
index a0e37e8afd..e9872e3d2d 100644
--- a/ext/hal/st/stm32cube/stm32f2xx/drivers/src/stm32f2xx_ll_usb.c
+++ b/ext/hal/st/stm32cube/stm32f2xx/drivers/src/stm32f2xx_ll_usb.c
@@ -768,7 +768,7 @@ HAL_StatusTypeDef USB_WritePacket(USB_OTG_GlobalTypeDef *USBx, uint8_t *src, uin
     count32b =  (len + 3U) / 4U;
     for (i = 0U; i < count32b; i++, src += 4U)
     {
-      USBx_DFIFO(ch_ep_num) = *((__packed uint32_t *)src);
+      USBx_DFIFO(ch_ep_num) = __UNALIGNED_UINT32_READ(src);
     }
   }
   return HAL_OK;
@@ -794,7 +794,7 @@ void *USB_ReadPacket(USB_OTG_GlobalTypeDef *USBx, uint8_t *dest, uint16_t len)
 
   for ( i = 0U; i < count32b; i++, dest += 4U )
   {
-    *(__packed uint32_t *)dest = USBx_DFIFO(0U);
+    __UNALIGNED_UINT32_WRITE(dest, USBx_DFIFO(0U));
 
   }
   return ((void *)dest);
erwango

erwango commented on Feb 11, 2019

@erwango
Member

Tested ok on nucleo_f429zi.
Will submit internal ST issues and make fixes in cube packages

added a commit that references this issue on Feb 11, 2019
99e5761

8 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

area: USBUniversal Serial BusbugThe issue is a bug, or the PR is fixing a bugplatform: STM32ST Micro STM32priority: mediumMedium impact/importance bug

Type

Projects

No projects

Relationships

None yet

    Development

    No branches or pull requests

      Participants

      @ydamigos@finikorg@galak@loicpoulain@erwango

      Issue actions

        stm32 USB sanitycheck failures with sdk 0.10.0-beta2 · Issue #13237 · zephyrproject-rtos/zephyr