Skip to content

Fix write buffer issues#170

Open
madhogs wants to merge 1 commit intojoeycastillo:mainfrom
madhogs:write_buffer_fix
Open

Fix write buffer issues#170
madhogs wants to merge 1 commit intojoeycastillo:mainfrom
madhogs:write_buffer_fix

Conversation

@madhogs
Copy link
Contributor

@madhogs madhogs commented Dec 15, 2025

3 changes:

  1. Flush the write buffer first if it is full rather than overwrite data
  2. Fix bug in write loop causing it to exit early
  3. Fix some inconsistent line endings in filesystem.c

This fixes the issue of the output being incorrect when outputting text over the serial connection. Part of #58
Catting large files and also the help function now outputs correctly every time:

swsh> ?                                                                                                   
Command List:                                                                                             
 ?      print command list                                                                                
 help   print command list                                                                                
 flash  reboot to UF2 bootloader                                                                          
 ls     usage: ls [PATH]                                                                                  
 cat    usage: cat <PATH>                                                                                 
 b64encode      usage: b64encode <PATH>                                                                   
 df     print filesystem free space                                                                       
 rm     usage: rm [PATH]                                                                                  
 format usage: format YES                                                                                 
 echo   usage: echo TEXT {>,>>} FILE                                                                      
 stress test CDC write; usage: stress [LEN] [DELAY_MS]

I have tested this on my sensorwatch pro using the serial connection and when in normal watch mode.

@madhogs madhogs changed the title Fix write buffer issues, flush when full and stop write loop exiting early Fix write buffer issues Dec 15, 2025
@Hylian
Copy link
Contributor

Hylian commented Dec 15, 2025

It looks like you're retracing my steps in the original PR. 😛

Unfortunately, I don't recommend merging this PR, as we really should be servicing TinyUSB from outside the app loop context, as commented in the linked issue.

If you'd like to give it a shot yourself, I'd be happy to give pointers. Otherwise, I can try and find some time this week to put up a fix.

@madhogs
Copy link
Contributor Author

madhogs commented Dec 16, 2025

It looks like you're retracing my steps in the original PR. 😛

Could you please explain what you mean, did you try these changes previously and they weren't needed?

Unfortunately, I don't recommend merging this PR, as we really should be servicing TinyUSB from outside the app loop context, as commented in the linked issue.

I agree that this doesn't fix the interactive use over the serial connection but these are both valid data loss bugs that need fixing, no? This pr does fix issues when outputting large amount of text.

If you'd like to give it a shot yourself, I'd be happy to give pointers. Otherwise, I can try and find some time this week to put up a fix.

I'm not sure I understand the required changes enough to implement it myself.
If you have time to put up a fix that would be amazing, the previous repo worked very well after your PR 😄 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants