cybootloaderutils throwing AccessViolationException when opening connection. Trying to track down cause.

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

cross mob
KyTr_1955226
Level 6
Level 6
250 sign-ins 10 likes given 50 solutions authored

Hi all,

I'm working on trying a create multi-protocol (UART and USB HID) bootloader host application in C#, using .NET Core 3.1/WPF.  I'm hitting a roadblock where attempting to call CyBtldr_Program() always results in an AccessViolationException being thrown.

After some digging, the exception is thrown inside CyBtldr_StartBootloadOperation at the line:

err = g_comm->OpenConnection();

pastedImage_0.png

Looks like possibly an issue with the communication functions not getting passed through/referenced properly?  I'm not much of an application developer, so if it's something obvious I'm probably missing it.

I've attached the entire VS2019 solution that includes both the application as well as the CyBootloaderUtils project.  The application itself is a bit messy and incomplete.  The HID USB loader has not been tested at all yet.  I am running into this issue attempting to load via serial port interface.  CyBootloaderUtils is being built from the source code included in PSoC Creator 4.3.

I have also included the Creator 4.3 workspace targeting the PSoC5LP onboard a CY8CKIT-050 that I am using to test the bootloader.

Might anyone have an idea as to what's going on here?

0 Likes
1 Solution

Glad to hear that you got it working. It would be nice if you could also share your work here so that other users can also benefit from it!

Check my previous post, there's a link to the thread where I documented the whole process and shared the project.

Here it is again for anyone hunting for it:

Running Dev Diary: Creating a managed .NET Bootloader Utilities library

View solution in original post

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

Can you try targeting the .NET Framework version 3.5 in the Project Properties and checking if it works?

net_framework.png

In the above screenshot, my platform toolset is v141 because I'm using VS 2017, in your case since it is VS 2019, v142 is fine. Don't change that.

I could only import the CyBootloaderUtils project. I get this error when trying to import the application project:

pastedImage_2.png

Looks like VS Studio 2017 doesn't WPF applications targeting .NET Core 3 from what I found here. Should try it out on VS 2019.

Meanwhile, let me know if specifying the .NET Target Framework solves the problem for you.

Regards,

Dheeraj

0 Likes

Hi Dheeraj,

Thanks for the Target Framework tip.

I found the ".NET Target Framework Version" option under Advanced > C++/CLI Properties.

It had nothing in the field, and it looks like the setting only takes effect if "Common Language Runtime Support" is set.  So I set it to ".NET Core Runtime Support (/clr:netcore)"

Now I need a TargetFramework value that actually works.  Most things I try either result in a "Not Recognized" Error thrown on build.

Setting "netcoreapp3.0" for some reason throws the following (it thinks I'm targeting 3.5?):

Error    NETSDK1045    The current .NET SDK does not support targeting .NET Core 3.5.  Either target .NET Core 3.1 or lower, or use a version of the .NET SDK that supports .NET Core 3.5.

pastedImage_2.png

pastedImage_3.png

Not sure why it thinks netcoreapp3.1 == .NET Core 3.5...

*sigh*

Visual Studio problems...

0 Likes

After a little more prodding, and getting it to actually recognize my Target Framework setting, it looks like there's an incompatibility?

the /MT option does not work when a common language runtime is selected.

pastedImage_0.png

0 Likes

The reason I asked you try that is because a user had a similar problem and it was solved after using .NET Framework 3.5. You can find that thread here: USB bootloader dll

I'm not able to open the WPF application for some reason, the project load fails.

Anyways, regarding the error, revert back the changes and try these steps:

(1) In Solution Explorer, open the right-click menu for the WPF project and then choose Properties.

(2) In the left column of the Properties window, choose the Application tab.

(3) Change the .NET Framework to 3.5

Repeat the same steps for the BootloaderUtils project as well.

Run the WPF application now and let me know if it works.

Regards,
Dheeraj

0 Likes

Dheeraj,

This is not an option for me in settings, this is a .NET Core project:

pastedImage_0.png

Changing to .NET Framework would likely mean having to create a new project unless I'm misunderstanding (which is possible, I'm not terribly experienced working in C#/.NET).

Reverting back to Framework also goes against the idea of what this project was for, which was mostly to experiment with trying to build a bootloader using .NET Core rather than Framework.  This is for cross-platform reasons.  .NET Core is meant to be cross-platform rather than having to use something like mono to emulate the .NET Framework on linux.

If it's not doable then it's not doable, but it's going to probably start getting annoying having the bootloader utils locked to older versions of .NET.

At this point maybe I'll just see if I can port bootloader utils to a C# managed library.

0 Likes

If you require the bootloader host application that is cross-platform, I would suggest looking at the source code of dfuh-tool which we provide with ModusToolbox. After installation, you can find it in this path: "ModusToolbox\tools_2.2\dfuh-tool\sample_code".

It is created using Qt Creator, you can modify it as per requirement. Written using C++.

Hope this helps

Regards,
Dheeraj

Hi Dheeraj,

Thanks for the tip, I will look into dfuh-tool.  I assume it follows the same bootloader protocol as the one included with Creator?

P.S. I actually did undertake porting the bootoader host utilities to C# .NET as documented in the thread below:

Running Dev Diary: Creating a managed .NET Bootloader Utilities library

Just yesterday I was able to successfully load a PSoC5 on the CY8CKIT-050 with the ported library, so it actually seems to be coming along fairly well.

0 Likes

I assume it follows the same bootloader protocol as the one included with Creator?

The dfuh-tool that comes packaged with ModusToolbox only works with PSoC6 devices. This is because it supports only .cyacd2 file format. Please look at the documentation present in the doc folder of the tool to get more information on this. Since the source code is made available, it should be fairly easy to modify it to work for .cyacd files. So, the answer is yes, its the same, but requires slight modifications to make it work for .cyacd format.

Just yesterday I was able to successfully load a PSoC5 on the CY8CKIT-050 with the ported library

Glad to hear that you got it working. It would be nice if you could also share your work here so that other users can also benefit from it!

Regards,

Dheeraj

0 Likes

Glad to hear that you got it working. It would be nice if you could also share your work here so that other users can also benefit from it!

Check my previous post, there's a link to the thread where I documented the whole process and shared the project.

Here it is again for anyone hunting for it:

Running Dev Diary: Creating a managed .NET Bootloader Utilities library

0 Likes

Thanks for sharing the project and detailing each step. This will help our community users immensely!

Regards,
Dheeraj

0 Likes