Stack overflow when responding to usb_attach_cb event

⚠️
Hi there.. thanks for coming to the forums. Exciting news! we’re now in the process of moving to our new forum platform that will offer better functionality and is contained within the main Dialog website. All posts and accounts have been migrated. We’re now accepting traffic on the new forum only - please POST any new threads at//www.wsdof.com/support. We’ll be fixing bugs / optimising the searching and tagging over the coming days.
4 posts / 0 new
Last post
alarner
Offline
Last seen:1 month 2 weeks ago
加入:2017-05-27 02:11
Stack overflow when responding to usb_attach_cb event

I have a function which responds when the USB of my device is attached.

void usb_attach_cb(void) { printf("usb_attach_cb\n"); ActionDispatcher *actionDispatcher = ActionDispatcher::Instance(); uint8_t data = 1; actionDispatcher->dispatch(ActionType_UsbStatusChange, &data, 1); }

This code works fine but if I add a printf statement to the dispath function that is called I get a stack overflow

vApplicationStackOverflowHook USBC

Is there a way to increase the stack size to avoid this issue?

Device:
PM_Dialog
Offline
Last seen:9 hours 13 min ago
工作人员
加入:2018-02-08 11:03
Hi alarner,

Hi alarner,

It is not recommended to call the printf function inside to a callback function. The best practice for this is to create a task and when the usb_attach_cb is triggered, the task with the printf should be triggered. Otherwise, you should increase the number of bytes (stack_size) which will be allocated to the stack of the task that you are using.

Thanks, PM_Dialog

alarner
Offline
Last seen:1 month 2 weeks ago
加入:2017-05-27 02:11
Thank you for the reply.

Thank you for the reply. Where might I find a code example that demonstrates increasing the number of bytes allocated to the stack?

PM_Dialog
Offline
Last seen:9 hours 13 min ago
工作人员
加入:2018-02-08 11:03
Hi alarner,

Hi alarner,

You could check any of our BLE examples of the SDK. For example, please check the pxp_reporter example and in the main.f you will find “PXP Reporter” task. So, that you have to do is to change the number of bytes to allocate to the stack of the task from the OS_TASK_CREATE() API.

Thanks, PM_Dialog