Using USB host port to read/write USB memory (MSC)

I got also troubles with some USB memorysticks. It turned out is was not the program, but the wires from the teensy to the USB connector.
You need shielded wires or at least twisted wires and not to long.
 
I am an old man, working al lot with C in the 1980's. But I use also ChatGPT. It came to the same conclusion, it is a pointer directive not an operator.
It solved the compiler error for me. Maybe in the transfer from your program to here there was something change (autocorrection) ?
Maybe different versions of compilers ? I had lately also a problem with the keyboard on the new compiler. I had to place it now in het HID part.
It could be that the new compilers are smarter and fill in the gaps and do some correction by itself, so you get still a working end result...

Screenshot_ 2025-04-20.jpg
 
I meant syntactically. The lexer treats '*' as an operator token which means whitespace around it is ignored. So long as it isn't part of a larger operator or comment sequence (such as *= or /*, */)
 
But I use also ChatGPT. It came to the same conclusion, it is a pointer directive not an operator.
  • Be very wary of using AI for code: time after time it generates nonsense which is just plausible enough to waste a lot of your time
  • * is not a directive, it is an operator - these are two very different things
  • compilers do not correct your code for you: if you're lucky erroneous code will generate an error (if it simply can't be compiled) or a warning (if it does't "seem to make sense"); a lot of the time the compiler generates the code you asked for, but it's wrong and you don't get the expected result
Looking back to post #20 (which is nearly 2 years old now and I'm sure the poster has long since moved on), buf[BUF_SIZE-1] = (uint8_t *)'\n'; is almost certainly incorrect code. It is trying to cast a char constant to a pointer to a uint8_t, and then copy that address (10) into the buf[] array. This makes no sense: the address will be 32 bits long, and the buf[] array contains 8-bit values. Hence the warning.

Pro tip: if you get a warning, understand it, and fix your code. The case in point actually would have worked as intended, but a lot of the time warnings are very much valid.
 
Well it does not matter any more, the program is running fine without errors.
Thanks for the example, nice work.
It would be nice to have an 'write to USB memory stick' example and a "read from USB memory stick' example in the standaard examples of the Teensy 4.x examples for other people.

Again thanks for the hard work.
 
@FKS39 - I dug up some MSC examples from a while back that I used for testing MSC. Just went through them to make sure they still work. I put them up on GitHub for anybody that wants to try them out. The bench.ino and copyFilesUSB.ino give fairly good examples of read/write speeds and transfer speeds when copying files. In the copyFilesUSB folder there is zip file that needs to be unzipped and copied to a USB drive with a PC. It is the files that gets copied between the two USB drives and the SD card. The library is located here.
There are quite a few examples to show MSC usage :)

EDIT: TD1.59 and up only.
 
Back
Top