USB Serial component with HID bootloader compatibility

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 5.
To post in this forum you must have a registered copy of Flowcode 5 or higher.

Moderator: Benj

Post Reply
GTF
Posts: 170
Joined: Sat Dec 10, 2011 7:21 pm
Location: Canada
Has thanked: 20 times
Been thanked: 52 times
Contact:

USB Serial component with HID bootloader compatibility

Post by GTF »

I recently tried adding this component to an old V5 project that is used with a HID bootloader. I am connecting the USB after my program is running. If connected at boot, it will trigger bootloader mode as expected. Sometimes I have been able to make a connection, but then any small change to my program will result in the serial comm not working after the rebuild. The device actually enters bootloader mode instead. My program does use the same input that is used to trigger bootloader mode at startup, but I don't see how this could happen unless a reset has occurred. Could the USB serial component cause a reset? WDT is not enabled. config is set in bootloader.

edit: Possibly a RAM issue? I noticed that my FC program requires 97.4% of available RAM after adding the USB Serial component. It was only 13.7% before adding the component and a few data sends. Just adding the component alone with no Macros adds 70% to RAM usage. RAM usage for the bootloader(Diolan) is 44% according to MPLAB. This is on a 18F14K50.(768 bytes RAM)

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: USB Serial component with HID bootloader compatibility

Post by Benj »

Hello,

I have reduced the size of the incoming and outgoing buffers from 128 bytes to 32 bytes. Hopefully everything should still work ok but you should now have more RAM memory to play with.

Let me know how you get on.
USB_Serial.fcpx
(15.99 KiB) Downloaded 513 times
If this works ok then I will try and make the buffer size a bit more dynamic via a property so it's easier to change the amount of RAM used by the buffers.

Shortening the device name and manufacturer strings should also help to reduce RAM usage.

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: USB Serial component with HID bootloader compatibility

Post by Benj »

This seems to be working well.

The TX and RX buffers can now be edited using the new component properties. You should be able to reduce the buffer sizes down from the default 64 to 8 without any problems.
USB_Serial.fcpx
(16.12 KiB) Downloaded 508 times
To install the new component simply copy the file to your "Flowcode 6/Components" directory and restart Flowcode.

Let me know how you get on.

GTF
Posts: 170
Joined: Sat Dec 10, 2011 7:21 pm
Location: Canada
Has thanked: 20 times
Been thanked: 52 times
Contact:

Re: USB Serial component with HID bootloader compatibility

Post by GTF »

Thanks Benj. I will have to rebuild this project in V6 and let you know.

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: USB Serial component with HID bootloader compatibility

Post by Benj »

Aha sorry,

I missed that you were using v5. You could do the changes in v5 using the custom code option to edit the defines function of the USB serial component.

Right click the USB component and select Custom Code.

Click the Defines function and click Edit code.

These are the default lines of code.

Code: Select all

		#define CDC_TX_BUFFER_SIZE 	64
		#define CDC_RX_BUFFER_SIZE 	64
And here are my suggested changes to reduce memory usage.

Code: Select all

		#define CDC_TX_BUFFER_SIZE 	8
		#define CDC_RX_BUFFER_SIZE 	8

GTF
Posts: 170
Joined: Sat Dec 10, 2011 7:21 pm
Location: Canada
Has thanked: 20 times
Been thanked: 52 times
Contact:

Re: USB Serial component with HID bootloader compatibility

Post by GTF »

Benj wrote:Aha sorry,

I missed that you were using v5. You could do the changes in v5 using the custom code option to edit the defines function of the USB serial component.

Right click the USB component and select Custom Code.

Click the Defines function and click Edit code.

These are the default lines of code.

Code: Select all

		#define CDC_TX_BUFFER_SIZE 	64
		#define CDC_RX_BUFFER_SIZE 	64
And here are my suggested changes to reduce memory usage.

Code: Select all

		#define CDC_TX_BUFFER_SIZE 	8
		#define CDC_RX_BUFFER_SIZE 	8
Thanks. I'll try that first.

GTF
Posts: 170
Joined: Sat Dec 10, 2011 7:21 pm
Location: Canada
Has thanked: 20 times
Been thanked: 52 times
Contact:

Re: USB Serial component with HID bootloader compatibility

Post by GTF »

That freed up another 17% RAM. Did a little testing and it seems I start having issues if FC/Boost C reported RAM usage gets over 80%.

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: USB Serial component with HID bootloader compatibility

Post by Benj »

Did you try also reducing the size of the USB Device Name and Manufacturer strings. I think this should also help to drop the RAM usage a bit.

Are you initialising your variables to a known value before you use them?

Also are you using any arrays? could it be you are going outside the bounds of the array?

These two bugs are known to cause the types of RAM issues your having.

GTF
Posts: 170
Joined: Sat Dec 10, 2011 7:21 pm
Location: Canada
Has thanked: 20 times
Been thanked: 52 times
Contact:

Re: USB Serial component with HID bootloader compatibility

Post by GTF »

Benj wrote:Did you try also reducing the size of the USB Device Name and Manufacturer strings. I think this should also help to drop the RAM usage a bit.
No I didn't, but I have now and that yields another 10% drop in RAM usage.

Are you initialising your variables to a known value before you use them?
Yes, they all initialize to 0.

Also are you using any arrays? could it be you are going outside the bounds of the array?
No arrays

These two bugs are known to cause the types of RAM issues your having.
Not sure how the USB RAM is taken into account in the usage calculation?

GTF
Posts: 170
Joined: Sat Dec 10, 2011 7:21 pm
Location: Canada
Has thanked: 20 times
Been thanked: 52 times
Contact:

Re: USB Serial component with HID bootloader compatibility

Post by GTF »

Seems to be working well now even after make some changes and adding functionality. Still with about 28% RAM free.

Appeared to be somehow affected by an output(C4=LED) on PortC, but I cannot pinpoint it. The bootloader trigger input is C2. My code uses C2/AN6 as an analog input. Bootloader clears ANSEL/ANSELH, sets TRISC, then tests C2.

Post Reply