Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fail SD mounting with no SPI re-init #19226

Merged

Conversation

rhapsodyv
Copy link
Member

@rhapsodyv rhapsodyv commented Sep 1, 2020

Description

sd2card.init uses SPI_SD_INIT_RATE, not SPI_SPEED. The removed line set the spi speed to wrong velocity and the SD stop working. Even if correct, that spiInit dont need stay there, as is the calling code the responsability to put spi in the right state before the use.

Benefits

Fixes #19223

It removes the false "SD Init Fail" when booting a printer without a SD card.

Related Issues

#19223

…et the spi speed to wrong velocity and the SD stop working. Even if correct, that spiInit dont need stay there, as is the calling code the responsability to put spi in the right state before the use.
@rhapsodyv rhapsodyv changed the title Remove extra and invalid spiInit Fix SDCard Mount false "fail" and extra/invalid spiInit Sep 1, 2020
@thisiskeithb
Copy link
Member

It removes the false "SD Init Fail" when booting a printer without a SD card.

Thanks! This also addresses the comments left on #19064

@rhapsodyv
Copy link
Member Author

rhapsodyv commented Sep 1, 2020

Doing more research, I found that spiInit is totally wrong, as it assume that the SD is SPI... but a lot of SD uses SDIO with no spi involved ...

The bug it fixes, is because that SPI init defaults to SPI 1, that are the same pins as used for creality_v4 end stops:

// endstops on Creality v4
#define X_STOP_PIN                          PA5
#define Y_STOP_PIN                          PA6
#define Z_STOP_PIN                          PA7

// spi default pins
#ifndef SCK_PIN
  #define SCK_PIN  PA5
#endif
#ifndef MISO_PIN
  #define MISO_PIN PA6
#endif
#ifndef MOSI_PIN
  #define MOSI_PIN PA7
#endif
#ifndef SS_PIN
  #define SS_PIN   PA4
#endif

@rhapsodyv rhapsodyv changed the title Fix SDCard Mount false "fail" and extra/invalid spiInit Fix SDCard Mount false "fail" and extra/invalid spiInit for SD using SDIO, and pins conflict with Creality board Sep 1, 2020
@thinkyhead thinkyhead changed the title Fix SDCard Mount false "fail" and extra/invalid spiInit for SD using SDIO, and pins conflict with Creality board Fail SD mounting with no SPI re-init Sep 1, 2020
@thinkyhead thinkyhead merged commit e3d8556 into MarlinFirmware:bugfix-2.0.x Sep 1, 2020
@mikemerryguy
Copy link
Contributor

mikemerryguy commented Sep 2, 2020

line 386 I changed from (cardreader.cpp)
else if (marlin_state != MF_INITIALIZING)
to
else if (marlin_state == MF_INITIALIZING)
and now I get my ready message vs SD INIT FAIL on boot with no SD
with SD I can print from SD
without I can attach SD as normal and print as normal.

@thisiskeithb
Copy link
Member

thisiskeithb commented Sep 2, 2020

@mikemerryguy: Which board/LCD/SDCARD_CONNECTION setting?

I tested this on a few printers:

With a BTT002 on a MK3S with a REPRAP_DISCOUNT_SMART_CONTROLLER (no motherboard-based SD card reader), no errors displayed on boot when no SD card is present in the LCD-based SD card slot.

With an SKR Mini E3 V2 on an Ender-3 with a CR10_STOCKDISPLAY (no LCD-based SD card reader), "SD Init Fail" is displayed on boot when no SD card is present in the motherboard-based SD card slot.

With an SKR Mini E3 V1.2 on an Ender-3 with a CR10_STOCKDISPLAY (no LCD-based SD card reader), "SD Init Fail" is displayed on boot when no SD card is present in the motherboard-based SD card slot.

With an SKR 1.4 on an Biqu B1 with a REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER and SDCARD_CONNECTION set to ONBOARD, "SD Init Fail" is displayed on boot when no SD card is present in the motherboard-based SD card slot.

With an SKR 1.4 on an Biqu B1 with a REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER and SDCARD_CONNECTION set to LCD, no errors are displayed on boot when no SD card is present in either the motherboard or LCD-based SD card slot.

Copy link
Contributor

@mikemerryguy mikemerryguy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mikemerryguy: Which board/LCD/SDCARD_CONNECTION setting?

I tested this on a few printers:

With a BTT002 on a MK3S with a REPRAP_DISCOUNT_SMART_CONTROLLER (no motherboard-based SD card reader), no errors displayed on boot when no SD card is present in the LCD-based SD card slot.

With an SKR Mini E3 V2 on an Ender-3 with a CR10_STOCKDISPLAY (no LCD-based SD card reader), "SD Init Fail" is displayed on boot when no SD card is present in the motherboard-based SD card slot.

With an SKR 1.4 on an Biqu B1 with a REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER and SDCARD_CONNECTION set to ONBOARD, "SD Init Fail" is displayed on boot when no SD card is present in the motherboard-based SD card slot.

With an SKR 1.4 on an Biqu B1 with a REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER and SDCARD_CONNECTION set to LCD, no errors are displayed on boot when no SD card is present in either the motherboard or LCD-based SD card slot.

I am using Skr mini e3 1.2 with CR10 stock display settings on an ENDER 3

as per facebook I think the issue is deeper in marlin_state or MF_INITIZLIZING but it DID work for my setup!

@rhapsodyv
Copy link
Member Author

Changing to == MF_INITIZLIZING will only hide the problem... If you are getting SD Init Fail with "!=" and not with "==" is because the sd init code has being called after the what marlin define as "boot sequence".

When I send that PR, I was just focused in solving the spiInit problem, that was conflicting with creality board and was totally wrong there.

But, as you and @thisiskeithb are reporting, maybe the entire "if not mount, show fail" is wrong...

I will review the sd init code.

@mikemerryguy
Copy link
Contributor

@rhapsodyv Yes, I do think its deeper, I just was reporting it worked for now, and as I said, hopefully we get it sorted, I did not dig deeper, I am ehhhh basic programming level haha made some stuff, but never deep into a firmware!!!
Thanks for looking into it!

@rhapsodyv
Copy link
Member Author

What is happening is:

In the marlin boot marlin_state is MF_INITIZLIZING, it call card.mount(). If fail, it will not show any message.

After all boot sequence, marlin_state became MF_RUNNING. So, all calls to card.mount() now on will show the message.

The issue is, that in the marlin main loop, it always calls: card.manage_mediaI(). This function compares the current card insertion state with the last state from the previews calls.

The problem is: some boards don't have the SD_DETECT_PIN. So, the marlin code always consider that the SD was inserted and try mount it every time.

It appears to be in the boot sequence, but isn't. The card.mount is called every second (or so), and will try mount and give fail message always if the board don't have SD_DETECT_PIN.

So, my suggestion is: only show that ui.set_status_P(GET_TEXT(MSG_SD_INIT_FAIL), -1); if the board have SD_DETECT_PIN...
Without that, it will always and forever show that "SD Init Fail", until you insert a SD...

@rhapsodyv
Copy link
Member Author

@mikemerryguy take a look in this PR #19236

thinkyhead pushed a commit to thinkyhead/Marlin that referenced this pull request Sep 2, 2020
@mikemerryguy
Copy link
Contributor

mikemerryguy commented Sep 2, 2020

@rhapsodyv
@thisiskeithb
what you think?
it compiled!!!
didn't test yet!!!

if (flag.mounted)
cdroot();
else if (marlin_state != MF_INITIALIZING)
#if defined (SD_DETECT_PIN)
ui.set_status_P(GET_TEXT(MSG_SD_INIT_FAIL), -1);
#endif

fix from #19236 works perfect, thanks guys!

@th3dstudio
Copy link

Can confirm this fixes the endstop with no SD card inserted issue on the V4.2.7 boards.

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

Successfully merging this pull request may close these issues.

5 participants