Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix nuc126 buffer copy with IAR #1024

Merged
merged 2 commits into from
Aug 18, 2021
Merged

Fix nuc126 buffer copy with IAR #1024

merged 2 commits into from
Aug 18, 2021

Conversation

HiFiPhile
Copy link
Collaborator

@HiFiPhile HiFiPhile commented Aug 16, 2021

Describe the PR
DCD buffer copy doesn't work correctly with IAR, after investigation IAR use optimized STM/LDM instructions in memcpy but there must be some access restrictions on USB buffer just like STM32 fsdev.

Use byte copy just like StdDriver.

And fix a warning.

@@ -153,7 +158,7 @@ static void dcd_in_xfer(struct xfer_ctl_t *xfer, USBD_EP_T *ep)
else
#endif
{
memcpy((uint8_t *)(USBD_BUF_BASE + ep->BUFSEG), xfer->data_ptr, bytes_now);
usb_memcpy((uint8_t *)(USBD_BUF_BASE + ep->BUFSEG), xfer->data_ptr, bytes_now);
Copy link
Owner

@hathach hathach Aug 17, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to be honest, I feel a bit odd about this change, would it work if we cast the buffer with volatile uint8_t* instead of uint8_t*

PS: maybe the usb buffer is byte access only, I will try to check the datasheet later on to confirm this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

volatile doesn't work as Error[Pe167]: argument of type "uint8_t volatile *" is incompatible with parameter of type "void *"

In fact read setup packet from buffer with memcpy (LDM instruction) works, only write doesn't work.

I read the manual, it didn't mention the access type.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked the manual as well, it is not mentioned. But It is very likely that USB SRAM is byte access. So yeah, this PR is spot on and needed.
https://github.com/majbthrd/nuc_driver/blob/master/nuc126/StdDriver/inc/usbd.h#L524

Only 1 request, would you mind adding an comment at this line and usb_memcpy below to explain the reason something like although it is not mentioned in manual, but the USB SRAM seems to only support byte access and memcpy could possibly do it by words etc ...

@@ -101,6 +101,11 @@ static void usb_detach(void)
USBD->SE0 |= USBD_SE0_SE0_Msk;
}

static void usb_memcpy(uint8_t *dest, uint8_t *src, uint16_t size)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor but maybe make this function inline

Copy link
Owner

@hathach hathach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realized that dcd nuc120 is very similar to nuc121, and therefore also apply the same changes to it as well. This should be ready to merged once ci passed.

PS: due to the dcd similarity, I open #1029 as reminder to merge them together to make it easier to maintain in the future.

@hathach hathach merged commit 3a24895 into hathach:master Aug 18, 2021
@HiFiPhile
Copy link
Collaborator Author

I've spotted another issue of device stopped functioning after PC reboot with set address failure.
Clear assigned_address in dcd_reset() maybe fixed it but not well tested.

@hathach
Copy link
Owner

hathach commented Aug 18, 2021

assigned_address can actually changed to use the dcd_edpt0_status_complete(). other port also use this for set_address(). I think the API is added after the nuc port. I could do this but I need to find the nuc board in my drawer first :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants