cancel
Showing results for 
Search instead for 
Did you mean: 

STM32H563vit6 unaligned access on USBX initialization

stst9180
Associate III

I generated code for STM32H563VIT6 via CubeMX with USBD MSC enabled.

When I now run the software, I get an unaligned memory access error within:

 

static void USBD_FrameWork_MSCDesc(USBD_DevClassHandleTypeDef *pdev,

uint32_t pConf, uint32_t *Sze)

 

in the MACRO:

 

__USBD_FRAMEWORK_SET_EP((pdev->tclasslist[pdev->classId].Eps[1].add),

(USBD_EP_TYPE_BULK),

(uint16_t)(pdev->tclasslist[pdev->classId].Eps[1].size),

(0U), (0U));

 

which is disassembled to:

676 __USBD_FRAMEWORK_SET_EP((pdev->tclasslist[pdev->classId].Eps[1].add),
08005d9a: adds r3, r4, r1
08005d9c: mov.w r12, #7
08005da0: strb.w r12, [r4, r1]
08005da4: movs r4, #5
08005da6: strb r4, [r3, #1]
08005da8: ldr r4, [r0, #4]
08005daa: mov.w r12, #92 ; 0x5c
08005dae: mla r4, r12, r4, r0
08005db2: ldrb.w r4, [r4, #42] ; 0x2a
08005db6: strb r4, [r3, #2]
08005db8: movs r4, #2
08005dba: strb r4, [r3, #3]
08005dbc: ldr r4, [r0, #4]
08005dbe: mla r4, r12, r4, r0
08005dc2: ldrh r4, [r4, #44] ; 0x2c
08005dc4: strh r4, [r3, #4]   <- unaligned access interrupt here
08005dc6: ldrb r0, [r0, #0]
08005dc8: cmp r0, #1

The packed struct is at an unaligned memory location but the Cortex-M33 manual states that unaligned access is allowed for the strh instruction .

Does one have an Idea where this may orginate from?

Regards Pascal

6 REPLIES 6
stst9180
Associate III

Hi guys,

after a few more digging it seems that the bug is created by the STM32CubeMX as the "ux_device_descriptors.h" seems to orginate from here.

 

Currently I've work-arounded it by hand-editing the macro like:

 

uint16_t maxPacketSize = (epsize); \

memcpy(&pEpDesc->wMaxPacketSize, &maxPacketSize, sizeof(uint16_t)); \

 

Unfortunately our goal is to re-generate cubemx code during the build-process

which would not work with hand-edited / patched stuff very well.

 

Regards Pascal

Hi,

If you know, what you want to change - and sure, your right :)   

-> can edit in the repo , where cube puzzles code together 

-> (..)/STM32Cube/Repository/STM32Cube_FW_H5_V1.1.1/Middlewares/ST/usbx/common/usbx_device_classes/

+

Look in debug setting: whats set for :: exception on unaligned...

AScha3_0-1708419187207.png

 

If you feel a post has answered your question, please click "Accept as Solution".

This one is not set as on your picture.

I also checked up the corresponding core-register of the cpu, the irq on unalingend is also not set here.

Nevertheless it's firing such an IRQ.

FBL
ST Employee

Hello @stst9180 

You mean wMaxPacketSize field is a 16-bit value and should be aligned on a 2-byte boundary. 

pDevDesc->bMaxPacketSize = (uint16_t)USBD_MAX_EP0_SIZE;

Would you please share a failing project to confirm the issue? Also specify your toolchain being used.

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.


I'm out of offce with limited access to my emails.
Happy New Year!

Hello FBL,

While generating the test-project i found out the following:

The issue is only appearing when the MPU is enabled in the CORTEX_M33 tab.

As this was not done by me manually, some initialization of our project seems to have done this.

The MPU settings are also attached and in the testproj.ioc

For now we may live with a completely disabled MPU.

If this is done the unaligned access does not lead to problems.

Regards

Pascal