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.25k stars 19.23k forks source link

[BUG] Cannot mount SD card on my computer with the latest Marlin, SKR 1.3 #14318

Closed hudja closed 4 years ago

hudja commented 5 years ago

archive.zip

Hi,

I just installed the latest Marlin bugfix, the one with Square Wave feature, and I cannot mount SD card on my Mac anymore via USB. The board I am using is SKR 1.3. I plug SD card into the board card reader. I can connect to the printer using terminal (pronterface or s3d) and control it. The settings I am using worked fine with the previous release (downloaded on 29.05), and I also tried to downgrade firmware and can confirm that with old firmware SD support is back to normal.

One thing I noticed is that with the latest release the card is automatically mounted in the printer, when I turn it on. On the previous release, I need to click 'Init SD card' to mount it in the printer. Releasing SD card in the printer menu on the latest release does not mount it on Mac.

The relevant code which worked fine with the previous release is: configuration.h:

#define SERIAL_PORT -1

#define BAUDRATE 250000

configuration_adv.h

  #ifdef TARGET_LPC1768
    //#define LPC_SD_LCD          // Use the SD drive in the external LCD controller.
    #define LPC_SD_ONBOARD      // Use the SD drive on the control board. (No SD_DETECT_PIN. M21 to init.)
    //#define LPC_SD_CUSTOM_CABLE // Use a custom cable to access the SD (as defined in a pins file).
    //#define USB_SD_DISABLED     // Disable SD Card access over USB (for security).
    #if ENABLED(LPC_SD_ONBOARD)
      #define USB_SD_ONBOARD    // Provide the onboard SD card to the host as a USB mass storage device.
    #endif
  #endif

I also attach archive of both config files from previous (SD card mounted successfully) and current (faulty SD card) releases.

Thanks!

shitcreek commented 5 years ago

Latest version has some bugs. The SD card auto mounting at startup is being worked on. This might be a related issue. I'm using an older commit for now.

gloomyandy commented 5 years ago

Trying to reproduce this now (and work out what is going wrong). I suspect that the USB sharing code has got part way through making the SD card available to the host when the card "disappears" due to it being mounted by the new init code. I'm not really sure why that should stop the Mac from trying to mount it again though when it is released. Can you try releasing the card and then unplugging/replugging the USB cable, does the card show up on the Mac then?

gloomyandy commented 5 years ago

@shitcreek did you see this problem as well? Do you use a Mac or a PC?

gloomyandy commented 5 years ago

Hmm I can't reproduce this problem using either a Windows PC or a Linux system (rPi). I do see on Linux that things get very messy when Marlin boots though and I suspect that perhaps the Mac sees this and just decides to ignore the drive from then on.

So if anyone has a Mac and is seeing this problem can you try something for me. In the file: Marlin/src/HAL/HAL_LPC1768/main.cpp can you locate the lines that look like this....

  #if DISABLED(USB_SD_DISABLED)
    MSC_SD_Init(0);                         // Enable USB SD card access
  #endif

and change them to look like this...

  #if DISABLED(USB_SD_DISABLED)
    //MSC_SD_Init(0);                         // Enable USB SD card access
  #endif

then rebuild and try this new firmware build. Let me know if this fixes the problem.

hudja commented 5 years ago

Hi, I tried both release SD card and reconnect printer, and your code fix. Both does not work.

MarkMan0 commented 5 years ago

Try disabling USB_SD_ONBOARD. It works for me like that for some reason.

  #ifdef TARGET_LPC1768
    //#define LPC_SD_LCD          // Use the SD drive in the external LCD controller.
    #define LPC_SD_ONBOARD      // Use the SD drive on the control board. (No SD_DETECT_PIN. M21 to init.)
    //#define LPC_SD_CUSTOM_CABLE // Use a custom cable to access the SD (as defined in a pins file).
    //#define USB_SD_DISABLED     // Disable SD Card access over USB (for security).
    #if ENABLED(LPC_SD_ONBOARD)
      //#define USB_SD_ONBOARD    // Provide the onboard SD card to the host as a USB mass storage device.
    #endif
  #endif
hudja commented 5 years ago

MarkMan0, do I need to use the fixed code from above also?

Grogyan commented 5 years ago

@MarkMan0 that would defeat the ability to use the onboard SD to be seen from external host programs, like OctoPrint

gloomyandy commented 5 years ago

Actually disabling USB_SD_ONBOARD will end up with both Marlin and your PC/Mac accessing the SD card at the same time, which may work some of the time but will almost certainly at some point end up with a corrupt SD card. It is interesting that it works though.

Can any one else confirm that the above fix I posted does not work on a Mac? As far as I can see it should work fine.

@hudja I am very surprised that releasing the SD card from the menu and then unplugging and re-attaching the printer did not work. That situation is pretty much identical to what happened with the old code. Is there any chance you have other config changes?

Grogyan commented 5 years ago

@MarkMan0 I'm surprised it even worked for you like this, it doesn't for me, thus, have to ensure the USB_SD_ONBOARD is enabled

hudja commented 5 years ago

I can confirm, it also works for me with:

#ifdef TARGET_LPC1768
    //#define LPC_SD_LCD          // Use the SD drive in the external LCD controller.
    #define LPC_SD_ONBOARD      // Use the SD drive on the control board. (No SD_DETECT_PIN. M21 to init.)
    //#define LPC_SD_CUSTOM_CABLE // Use a custom cable to access the SD (as defined in a pins file).
    //#define USB_SD_DISABLED     // Disable SD Card access over USB (for security).
    #if ENABLED(LPC_SD_ONBOARD)
      //#define USB_SD_ONBOARD    // Provide the onboard SD card to the host as a USB mass storage device.
    #endif
  #endif

and

#if DISABLED(USB_SD_DISABLED)
    MSC_SD_Init(0);                         // Enable USB SD card access
  #endif

I can connect with Pronterface and see SD card.

gloomyandy commented 5 years ago

Seriously that is not a very safe configuration. Please don't use it, it is certainly not a fix for this problem.

@hudja With your old (working firmware), can you confirm that doing the following works....

  1. Boot your printer.
  2. SD card should appear on your Mac
  3. Choose init SD from the menu, SD card should disappear from the Mac
  4. Choose Release Sd from the menu, SD card should again be available to the Mac In particular please check step 4 does that work for you?
gloomyandy commented 5 years ago

Oh and what if anything are you doing on the Mac to mount the SD card? Does it just appear or do you need to do something?

gloomyandy commented 5 years ago

Also if you are doing this testing using the SD card that came free with the SKR board please try using a different SD card. That "free" card seems to cause all sorts of odd things to happen when you switch between Marlin and PC access.

hudja commented 5 years ago

Seriously that is not a very safe configuration. Please don't use it, it is certainly not a fix for this problem.

@hudja With your old (working firmware), can you confirm that doing the following works....

  1. Boot your printer.
  2. SD card should appear on your Mac

Yes.

  1. Choose init SD from the menu, SD card should disappear from the Mac

Yes.

  1. Choose Release Sd from the menu, SD card should again be available to the Mac

No, it does not reappear. Reconnecting USB cable also does not help. I need to turn off/on the printer to get it back.

Concerning your other question, I do not need to do anything. Mac sees and mounts it automatically.

I am using other (not free) SD card, which was working fine for long time now.

hudja commented 5 years ago
  1. Choose init SD from the menu, SD card should disappear from the Mac

Yes.

Correction. After turning printer on, I can see the SD card and contents. I 'Init SD card'. I can still see SD card on Mac in Finder, but it is empty now, no contents. I click 'Release', contents reappear on Mac. I click 'Init' again. Contents disappear on Mac, and only after some time I can see that card was also released on Mac.

gloomyandy commented 5 years ago

@hudja If your drive does not re-appear at step 4 then something is not working correctly. That is the same problem that you are seeing now because with the current code you will in effect always be going from the state of Marlin having the card mounted to Marlin no longer having it mounted.

If you have any other SD cards please try them with the above test, this is exactly the situation I have seen many times before with the "free" SD card. Most of the time it works fine but when you switch from Marlin access to pc/Mac access you get this sort of problem. Perhaps your current SD card is triggering a similar issue? I am not saying this is not a problem, but I'd rather try and solve one at a time!

hudja commented 5 years ago

I am afraid to plug in my 128Gb and 256Gb cards into it :) Will buy a small new one later today and try it.

gloomyandy commented 5 years ago

@hudja just seen your correction so if after doing the Init SD you wait until the card is no longer seen on the Mac, does doing a release on the printer make the drive come back again on the Mac or is it lost for ever?

Ah yes I wouldn't plug a large SD card in there! An 8Gb or 16Gb card is probably the best to try! Thanks for doing this.

hudja commented 5 years ago

It behaves strangely. When I init, I can still see SD card in Finder, but it is empty. When I release, contents of SD card reappear in Finder (I can still see card as mounted all the time). And only after few init/release cycles, the Mac says that card was unsafely removed and card disappears from the Finder. This is all on the previous Marlin release.

gloomyandy commented 5 years ago

If you do an Init SD and then wait a few minutes before you do the release what happens? If you do an Init SD and then do nothing for a long time do you ever get any sort of message? Does the card remain visible?

hudja commented 5 years ago

It is behaving erratically. Now, it takes about 20-30 seconds on the first Init for Mac to throw out an error 'Disc not ejected properly'. Also it takes (and took before) quite long time to mount it after printer turn on, up to 30 seconds.

forkoz commented 5 years ago

So this is the offending commit: https://github.com/MarlinFirmware/Marlin/commit/eb1c9113c23869b839abb63b7a43f84d13ed603c

Maybe

#if ENABLED(SDIO_SUPPORT) && !PIN_EXISTS(SD_DETECT)

needs another qualifier for boards using the eeprom.dat file or just a straight setting is needed.

gloomyandy commented 5 years ago

Hmm that is all very strange.

If you have chance can you retest the latest software with the change that I gave above (comment out, the call to MSC_SD_Init(0); then rebuild and flash to the printer. Then can you try the following... 1.Boot the printer - what happens is the SD card visible in any way on the Mac?

  1. Select release SD card - what happens? If you wait a few minutes does anything change?
  2. Select Init SD - what happens does anything change?

Thanks again for your help.

gloomyandy commented 5 years ago

@forkoz that line only relates to boards that use SDIO SD card readers which is not the case here. The "problem" is the changes made to ultralcd.cpp which basically means that on boot Marlin will always try and mount the SD card, before these changes if there was no SD detect pin then it would not try and mount the card until you told it to with Init SD or whatever.

But really going back to the way things were is not the best solution if we can avoid it. There are good reasons to mount the SD card if we can. Also it seems to work fine with Linux and Windows, unfortunately that is not the case with the Mac. Which of course is the one machine type I don't have easy access to!

gloomyandy commented 5 years ago

So if there is anyone else with a Mac and an LPC1768 based printer out there I would very much appreciate some help testing this case.

hudja commented 5 years ago

ok, will test after getting a new card. btw, why this is not the safe solution (I do not use octopi)?

#ifdef TARGET_LPC1768
    //#define LPC_SD_LCD          // Use the SD drive in the external LCD controller.
    #define LPC_SD_ONBOARD      // Use the SD drive on the control board. (No SD_DETECT_PIN. M21 to init.)
    //#define LPC_SD_CUSTOM_CABLE // Use a custom cable to access the SD (as defined in a pins file).
    //#define USB_SD_DISABLED     // Disable SD Card access over USB (for security).
    #if ENABLED(LPC_SD_ONBOARD)
      //#define USB_SD_ONBOARD    // Provide the onboard SD card to the host as a USB mass storage device.
    #endif
  #endif
gloomyandy commented 5 years ago

Because you now have two file systems (the one in your printer and the one on your PC) accessing the disk at a block level at the same time. one will not know anything about the changes made by the other. So if you copy a file to the disk from your Mac it may not show up on the list of files on the printer unless you do a refresh. Even worse if your printer and your Mac both write to the disk (and your printer may do this if you delete a file, or are using something like power loss recovery) then you will have a corrupt SD card as both will have updated the low level file structure without knowing that the other has also done the same.

You may get away with it for a while, but it is not safe as a general solution.

thinkyhead commented 5 years ago

Over at #14325 I have modified the patch so that Marlin won't try to mount the outboard SD card if the onboard SD card is at all USB-accessible. Please test the patch to make sure it does the right thing for your setup.

hudja commented 5 years ago

Hi, sorry for the late reply. Took little bit longer to get a new card than expected. I am using new 16Gb sandisc ultra formatted in FAT. I can confirm previous behaviour. It takes about 20s until card is mounted on mac on printer boot up. When I click 'init' on printer, it takes up to a minute for Mac to show 'Disc not ejected properly' error. After I click 'release' on printer, the card is not re-mounted on Mac. I need to restart printer to re-mount it. I am using the latest OS X Mojave.

thinkyhead commented 5 years ago

Try a low-level format on your SD card to see if it then mounts more quickly.

hudja commented 5 years ago

15 seconds to mount on boot. Could you please point me to exact change I need to do from https://github.com/MarlinFirmware/Marlin/pull/14325?

gloomyandy commented 5 years ago

15 to 20s sounds about right. Windows/Mac/Linux systems all seem to like to read all of the system structures (like the file allocation table) when they mount an SD card, this can be many hundreds (sometimes thousands) of blocks.

What version of Marlin did you use for the above tests? If you want to try the latest changes just use the current state of the code in #14325.

Could you also try the following for me (on the Marlin version you used for the above tests and if possible on the PR version) ...

  1. Boot Marlin (SD card should be mounted by your Mac)
  2. On the Mac eject the SD card to unmount it.
  3. On Marlin do Init SD
  4. On Marlin do Release SD What happens? Does the Mac remount the SD card? Do you get any sort of error message from the Mac?

Thanks again for your help with this.

gloomyandy commented 5 years ago

@VanessaE This is what should happen with your configuration files as posted (you have things setup to shared the onboard reader between USB and Marlin) and an SD card in the onboard reader (please don't use the "free" SD card that comes with the board). Boot your printer. You should see dmesg activity on your Linux system about the SD card over USB, it may or may not get automounted, but should be available for mounting. If you go to the LCD then the SD card should not be visible, but the InitSD menu item should be there. If you choose InitSD then you should see the SD card become unavailable from Linux and available to Marlin. Release SD should reverse this process. In this mode the SD detect pins are not used so removing/inserting the SD card is probably not a good idea. With this configuration the LCD card reader should not be active (and it should probably not have a card in it).

That's what I see with rPi 3B+ (and the equivalent on a WIndows PC). I don't have a system running Buster.

If you change SDCARD_CONNECTION to be LCD then the onboard SD reader should be made available to your PC (again the SD detect pin will not be used, so best to start the printer with the card inserted). The LCD reader should be used by Marlin (and the SD detect pins for that reader should be active). In this mode the SD card menu options should have no effect on the card seen by the PC.

I assume you have not made any other changes other than to Configuration.h and Configuration_Adv.h files? In particular with the current version of Marlin do not comment out the calls to MSC_SD_Init(0). Is USB working at all to your PC from the board? Do you see the CDC serial device get created and can you talk to the board via it?

VanessaE commented 5 years ago

Ok, I feel stupid now. It was just a cabling error (no data was getting through). Easy fix, sorry for the false report.

#define SDCARD_CONNECTION LCD indeed works as you describe (the PC sees/mounts the onboard card, and Marlin sees the LCD's card), so you can ignore the entirety of my previous comment (deleted anyway to reduce clutter).

**** EDIT: Some commentary moved to #14485

I assume you have not made any other changes other than to Configuration.h and Configuration_Adv.h files?

Don't really need to answer this now since I fixed my derp, :smiley: but, for this round of tinkering, I started from a clean clone, then imported my Configuration*.h settings, my thermistor table (see #14258), and the usual one-line change to platformio.ini that makes Atom's "-->" button work. There are no other changes.

gloomyandy commented 5 years ago

Glad you have resolved the SD issue! As to the others I think you should create a new issue for each of them. I've not seen either problem (but I have a different configuration), but my thoughts are....

Beeping, none of my setups have ever beeped on startup (even when using the same display as you). I suspect that it may be a combination of the exact version of the display (which beeper is used, any pullups etc.), the pin the board has selected for the beeper and possibly the bootloader (it may be setting the state of that pin differently to others). But it sounds annoying and should really be addressed if possible!

The MINTEMP Bed issue. I am pretty sure this is down to the way that the LPC176x HAL has additional filtering on the ADCs to reduce noise. The way this is currently implemented means that you need to have performed a certain number of reads for the temperature to settle at the actual value. I think in the past the checks on temperature were not activated until you printed, but a few months ago they got turned on when the printer boots. When the change was first made lots of folks hit problems. A sort of fix is currently in place using THERMAL_PROTECTION_GRACE_PERIOD which means that there is a short delay (at boot) before readings are delivered. However this is not really a very good fix (IMO) as it does not really address the actual problem (because it is based on time, not the number of actual readings taken). This means that if something else (like reading the SD card) uses up that grace period (and so the extra readings don't happen), you get this error again. You could try changing the setting from 1000 to say 5000 to see if that helps (the setting is in HAL_LPC1768/hal.h I think).

AnHardt commented 5 years ago

Beeping. Could be. Most bootloaders use a LED for making their state visible (debugging). If that pin is connected to the beeper one could get the described pattern - until Marlin takes over and inits its beeper.

ManuelMcLure commented 5 years ago

The long beep at startup is unfortunately a hardware issue. The beeper will sound until the LCD gets initialized, which doesn't happen until the bootloader gives control to Marlin, so there's nothing Marlin can do to disable the beeper.

However, there is a simple hardware change that can be done to disable the beep on startup - see #13965 for details.

VanessaE commented 5 years ago

Sounds good, then we're just down to that bogus "crash" (see #14485)

cinealfa commented 5 years ago

This thread veered somewhat, is the issue resolved with mounting the sd card?

gloomyandy commented 5 years ago

As far as I can tell there is not currently a problem when using Linux or Windows, there could possibly be a problem when using a Mac, but I have no way of testing that.

It could just be that the Mac does not like the SD card disappearing on it. It could be that you need to eject the card from the Mac before trying to use it via Marlin (probably a good idea anyway). It may be that there is some magic USB MSC status that we could return that would keep the Mac happy (or at least convince it to try mounting the card again later, which both Windows and Linux seem happy to do), but as far as I can tell we are returning the correct status (we basically say that the card has been removed).

So ideally this needs more input from a Mac user (and perhaps from a Marlin developer with a Mac).

lrpirlet commented 5 years ago

Hi @hudja

Hi, sorry for the late reply. Took little bit longer to get a new card than expected. I am using new 16Gb sandisc ultra formatted in FAT.

In order for a mac to share a SD disk with windows, the format MUST be exFAT... Please confirm that your SD is exFAT formated... or that your sc card is read write on BOTH MAC and Windows, implying exFAT…

FAT16 formated implies an SDSC (Secure Digital Standard Capacity) card with a capacity up to 2 GB maximum... see https://en.wikipedia.org/wiki/SD_card

hudja commented 5 years ago

Sorry for the silence, my mac is broken and I am waiting for the replacement now. Cannot confirm nor check anything immediately, will test latet.

lrpirlet commented 5 years ago

OK, what I mean is the following…. exFAT is NOT supported in MARLIN (Marlin support FAT32)… So, you should be able to read in the printer an SD card formatted under windows using FAT32, Hopefully your mac is able to write on this sd card…

DO NOT use a card formated for or in a camera (it uses exFAT format)… Do use a machine running a Microsoft OS to format the card (as FAT32 is Microsoft defined and documented standard)

boelle commented 5 years ago

@hudja is the issue still there?

boelle commented 5 years ago

line 1071 explains things pretty good :-D

 * :[ 'LCD', 'ONBOARD', 'CUSTOM_CABLE' 
boelle commented 5 years ago

i assume you have #define SDSUPPORT, its a strange one.

But then again i also have the re-arm (not a clone/ripoff) so its a totally different case

Evg33 commented 5 years ago

I use #define STARTUP_COMMANDS "M22" in Configuration_adv.h

http://marlinfw.org/docs/gcode/M022.html

boelle commented 5 years ago

@hudja is this still an issue?

boelle commented 5 years ago

Lack of Activity This issue is being closed due to lack of activity. If you have solved the issue, please let us know how you solved it. If you haven't, please tell us what else you've tried in the meantime, and possibly this issue will be reopened.