MarlinFirmware / Marlin

Marlin is an optimized firmware for RepRap 3D printers based on the Arduino platform. Many commercial 3D printers come with Marlin installed. Check with your vendor if you need source code for your specific machine.
https://marlinfw.org
GNU General Public License v3.0
16.36k stars 19.26k forks source link

[BUG] (M20 returns empty despite files present on storage medium) #16668

Closed rlayne closed 4 years ago

rlayne commented 4 years ago

Bug Description

Issuing the M20 command is expected to return a list of files available from a mounted SD card on the controller; in this issue it only ever returns an empty list regardless of what is present on the SD card.

My Configurations

Marlin.zip 2.0.1 config (problem persists, initially observed with Marlin 1.1.4)

Steps to Reproduce

  1. Connect to printer as usual using repetier or any software with a SD card support or serial console
  2. After initialisation, issue an M20 command or try and populate the file list

Expected behavior: Marlin responds with a list of files present on the root of the SD Card

Actual behavior: Marlin responds with an entirely empty list, i.e. nothing between begin/end

Additional Information

image

Initially encountered on Marlin 1.1.4 Upgrading to Marlin 2.0.1 did not affect the issue Altering firmware config has not affected the issue:

  1. halving SPI rate
  2. turning off/on long filename support
  3. turning off/on binary transfer support

Furthermore:

  1. Correct file list is visible on the controller LCD itself and can be printed.
  2. Tried regular SD cards of <4gb, >4gb, micro SD + adapter, regular size SD, reformatted, etc. All work as expected except for the relevant issue.
  3. Issue appears agnostic to file naming patterns or folder stucture; tried most simple (1.gco) to extended character sets like kanji.
  4. Ditto for folders.
  5. FAT32 formatting with default allocation units.
  6. I have tested various combinations of gcode file extensions, removing non-gcode files, and folders (i.e. just placing files at the root of the card)
  7. I have checked the output of the M20 command using both repetier and the general serial monitor from Arduino
  8. M20 is sent as part of Repetier's initialisation on a new connection to the printer - same effect as sending the code manually.

Interesting? The SD cards always auto mount when inserted. When I try sending M21 I get Init failure. Other related commands: M28 seems to be accepted but I have no way of manually sending a transfer as repetier's UI preents this.

thisiskeithb commented 4 years ago

Can you try with the latest bugfix-2.0.x? I'm running the latest on several machines and M20 output is as expected:

Example 1:

Send: M20
Recv: Begin file list
Recv: MK3_BT~1.GCO 45855
Recv: End file list
Recv: ok

Example 2:

Send: M20
Recv: Begin file list
Recv: PLA_FU~1.GCO 18169
Recv: End file list
Recv: ok
rlayne commented 4 years ago

Can you try with the latest bugfix-2.0.x? I'm running the latest on several machines and M20 output is as expected:

Yes certainly. Assuming the configs are the same between 2.0.1 and x I'll be able to do that over the next day or so.

AnHardt commented 4 years ago

Are there any files with the extensions .g, .gco. *.gcode on the card?

Marlin does not display endings like: .exe, .bin, .hex, txt, *.log, ... just files it expects to contain g-code.

//
// Return 'true' if the item is a folder or G-code file
//
bool CardReader::is_dir_or_gcode(const dir_t &p) {
  uint8_t pn0 = p.name[0];

  if ( pn0 == DIR_NAME_FREE || pn0 == DIR_NAME_DELETED  // Clear or Deleted entry
    || pn0 == '.' || longFilename[0] == '.'             // Hidden file
    || !DIR_IS_FILE_OR_SUBDIR(&p)                       // Not a File or Directory
    || (p.attributes & DIR_ATT_HIDDEN)                  // Hidden by attribute
  ) return false;

  flag.filenameIsDir = DIR_IS_SUBDIR(&p);               // We know it's a File or Folder

  return (
    flag.filenameIsDir                                  // All Directories are ok
    || (p.name[8] == 'G' && p.name[9] != '~')           // Non-backup *.G* files are accepted
  );
}
rlayne commented 4 years ago

Are there any files with the extensions .g, .gco. *.gcode on the card?

Yes, there are always files of all three extensions on the card for testing purposes, I've also tried removing none gcode files or not, as a further test, and removing folders and just using the root of the card, too.

sjasonsmith commented 4 years ago

I tried reproducing the problem using your exact configuration with 2.0.1. I had no issues with M20 or M21.

My testing was all done with a generic serial terminal (TeraTerm), as I don't have Repetier or any other host software installed on my machine.

I tested using a Mega2560 with RAMPS 1.4. I tested first with a RepRapDiscount Full Graphics display, then again with a RepRapDiscount character display so that I could use your configs unaltered.

I tested with both cheap 128 MB Creality SD cards, as well as a quality 16 GB SanDisk card.

I even tried using the SD card from a Mac so that it would get filled up with garbage hidden files/folders, which I've seen cause issues on some other (non-Marlin) machines. It all still worked fine.

I wish I had better news for you, but I just can't observe any issues on my end.

rlayne commented 4 years ago

I wish I had better news for you, but I just can't observe any issues on my end.

Thanks a lot for going through the trouble of doing that for me. I was afraid this would be the case. The firmware version on my MKS TFT32 v4 is higher than the most recent available stock firmware. There is an FLSun splash screen on boot but other than that I don't know what else has been messed with, but whatever it is may be responsible for the error.

I'm not sure exactly how the M20 command is relayed to the MKS TFT32 board, from Marlin but assuming I can find some documentation on how it handles messaging I might try talking to it directly via GPIO... or for the sake of £30 I could just buy a replacement immediately which will likely just work.

My main motivation for wanting the sd card to operate correctly is when I print via USB, there's a chance the print will stall (print head stops, refuses further commands, marlin spams waiting for user input, ), which I haven't figured out is due to Cura temperature request spam or some USB deficiency.

sjasonsmith commented 4 years ago

How does the TFT display fit into this? From your configs, this looked like a simple RAMPS board with a RepRapDiscount character display attached, with your RAMPS connected directly to the host PC over USB.

rlayne commented 4 years ago

Ah, so then to be clear, the configs were largely copied from an original 1.1.4 distro with my printer, which also comes with a MKS TFT32 v4 where this board provides the SD CARD. It's entirely possible something is misconfigured if this isn't clear from the config.

On Sun, Jan 26, 2020 at 7:03 PM Jason Smith notifications@github.com wrote:

How does the TFT display fit into this? From your configs, this looked like a simple RAMPS board with a RepRapDiscount character display attached, with your RAMPS connected directly to the host PC over USB.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/MarlinFirmware/Marlin/issues/16668?email_source=notifications&email_token=ABINBPFRQP6DPXQ2ZHBVS7DQ7XNA5A5CNFSM4KLOOLLKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEJ53GVY#issuecomment-578532183, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABINBPAHLX7AYNGVXESBKQLQ7XNA5ANCNFSM4KLOOLLA .

boelle commented 4 years ago

will close this one as its mostly a config problem config files say its a RepRapDiscount character display but a TFT is mentioned

github-actions[bot] commented 4 years ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.