UART Bootloader HOST S/W error

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
lock attach
Attachments are accessible only for community members.
PAB
Level 2
Level 2
First like given Welcome!

I made a program with the help of uart bootloader host application.

i want to add security key feature.

I inherit the security key feature from the USB bootloader host project.

https://www.cypress.com/documentation/application-notes/an73503-psoc-usb-hid-bootloader

The software runs fine without  Security key.

But when i enable security key feature in software, by checking a checkbox.

pastedImage_5.png

I got this Exception.

pastedImage_2.png

i tried a lot of different options  but didn't work at all.

0 Likes
1 Solution
DheerajK_81
Moderator
Moderator
Moderator
First comment on KBA First comment on blog 5 questions asked

Hello,

I was able to recreate the issue you are facing. This error usually occurs when you access unmanaged code like BootLoader_Utils.dll in this case in a manner that's not expected like wrong parameters etc.

I programmed the UART Bootloader project and checked if everything works using the Bootloader Host tool. Does it work for you?

pastedImage_0.png

Once I verified everything was fine, I then ran your application. When I click "Load" without security being enabled, I get the following error message. Not sure if you made any modifications to the UART Bootloader PSoC Creator.

pastedImage_0.png

I then enabled "Security" and was able to see the issue you are facing. The stack trace is as shown below:

"   at UART_PROGRAMER.Bootload_Utils.CyBtldr_Program(String file, Byte[] securityKey, CyBtldr_CommunicationsData& comm, CyBtldr_ProgressUpdate update)\r\n   at UART_PROGRAMER.Form1.BG_Work_DoWork(Object sender, DoWorkEventArgs e) in C:\\Users\\ddka\\Documents\\TechnicalSupport\\CDC\\2020\\Q1\\Thread52977\\UART_PROGRAMER\\UART_PROGRAMER\\Form1.cs:line 298\r\n   at System.ComponentModel.BackgroundWorker.OnDoWork(DoWorkEventArgs e)\r\n   at System.ComponentModel.BackgroundWorker.WorkerThreadStart(Object argument)\r\n   at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Object[]& outArgs)\r\n   at System.Runtime.Remoting.Messaging.StackBuilderSink.AsyncProcessMessage(IMessage msg, IMessageSink replySink)\r\n   at System.Runtime.Remoting.Proxies.AgileAsyncWorkerItem.DoAsyncCall()\r\n   at System.Runtime.Remoting.Proxies.AgileAsyncWorkerItem.ThreadPoolCallBack(Object o)\r\n   at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(Object state)\r\n   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)\r\n   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)\r\n   at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()\r\n   at System.Threading.ThreadPoolWorkQueue.Dispatch()\r\n   at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()"

From the error, I think it might have something to do with calling DLL APIs from the Background Worker. There was a similar issue reported on the Microsoft Forum. Not sure if this is the root of the problem but probably where you can start debugging from.

Might, be helpful to check what the best way to invoke a DLL call from within a background worker would be. Also, since programming shouldn't be interrupted, if there might be another thread running, you can use a mutex lock or a critical section for that part of code.

I'll keep debugging and keep you posted on the developments.

Hope this helps!

Regards,

Dheeraj

View solution in original post

0 Likes
3 Replies
DheerajK_81
Moderator
Moderator
Moderator
First comment on KBA First comment on blog 5 questions asked

Hello,

I was able to recreate the issue you are facing. This error usually occurs when you access unmanaged code like BootLoader_Utils.dll in this case in a manner that's not expected like wrong parameters etc.

I programmed the UART Bootloader project and checked if everything works using the Bootloader Host tool. Does it work for you?

pastedImage_0.png

Once I verified everything was fine, I then ran your application. When I click "Load" without security being enabled, I get the following error message. Not sure if you made any modifications to the UART Bootloader PSoC Creator.

pastedImage_0.png

I then enabled "Security" and was able to see the issue you are facing. The stack trace is as shown below:

"   at UART_PROGRAMER.Bootload_Utils.CyBtldr_Program(String file, Byte[] securityKey, CyBtldr_CommunicationsData& comm, CyBtldr_ProgressUpdate update)\r\n   at UART_PROGRAMER.Form1.BG_Work_DoWork(Object sender, DoWorkEventArgs e) in C:\\Users\\ddka\\Documents\\TechnicalSupport\\CDC\\2020\\Q1\\Thread52977\\UART_PROGRAMER\\UART_PROGRAMER\\Form1.cs:line 298\r\n   at System.ComponentModel.BackgroundWorker.OnDoWork(DoWorkEventArgs e)\r\n   at System.ComponentModel.BackgroundWorker.WorkerThreadStart(Object argument)\r\n   at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Object[]& outArgs)\r\n   at System.Runtime.Remoting.Messaging.StackBuilderSink.AsyncProcessMessage(IMessage msg, IMessageSink replySink)\r\n   at System.Runtime.Remoting.Proxies.AgileAsyncWorkerItem.DoAsyncCall()\r\n   at System.Runtime.Remoting.Proxies.AgileAsyncWorkerItem.ThreadPoolCallBack(Object o)\r\n   at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(Object state)\r\n   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)\r\n   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)\r\n   at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()\r\n   at System.Threading.ThreadPoolWorkQueue.Dispatch()\r\n   at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()"

From the error, I think it might have something to do with calling DLL APIs from the Background Worker. There was a similar issue reported on the Microsoft Forum. Not sure if this is the root of the problem but probably where you can start debugging from.

Might, be helpful to check what the best way to invoke a DLL call from within a background worker would be. Also, since programming shouldn't be interrupted, if there might be another thread running, you can use a mutex lock or a critical section for that part of code.

I'll keep debugging and keep you posted on the developments.

Hope this helps!

Regards,

Dheeraj

0 Likes
PAB
Level 2
Level 2
First like given Welcome!

Hello DheerajK_81

Did you try to debug the software.

if you find any thing it will be helpful.

Thanks and Regards

Paras.

0 Likes
DheerajK_81
Moderator
Moderator
Moderator
First comment on KBA First comment on blog 5 questions asked

Hello Paras,

Like I mentioned in the previous interaction please try running Bootloader Host tool from Cypress and checking if everything works. That will make it clear there is no error from the PSoC side.

Once it does, implement the suggestions I mentioned, it should solve your issue:

Might, be helpful to check what the best way to invoke a DLL call from within a background worker would be. Also, since programming shouldn't be interrupted, if there might be another thread running, you can use a mutex lock or a critical section for that part of code.

Following links can be helpful:

Make thread-safe calls to controls - Windows Forms | Microsoft Docs

https://www.c-sharpcorner.com/UploadFile/1d42da/thread-safe-calls-with-backgroundworker-class-in-C-S...

Regards,

Dheeraj

0 Likes