USB Serial component with HID bootloader compatibility
Moderator: Benj
-
- 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
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)
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)
- 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
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.
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.
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.
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.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
- 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
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.
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.
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.
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.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- 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
Thanks Benj. I will have to rebuild this project in V6 and let you know.
- 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
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.
And here are my suggested changes to reduce memory usage.
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
Code: Select all
#define CDC_TX_BUFFER_SIZE 8
#define CDC_RX_BUFFER_SIZE 8
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- 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
Thanks. I'll try that first.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.
And here are my suggested changes to reduce memory usage.Code: Select all
#define CDC_TX_BUFFER_SIZE 64 #define CDC_RX_BUFFER_SIZE 64
Code: Select all
#define CDC_TX_BUFFER_SIZE 8 #define CDC_RX_BUFFER_SIZE 8
-
- 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
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%.
- 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
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.
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.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- 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
Not sure how the USB RAM is taken into account in the usage calculation?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.
-
- 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
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.
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.