-
Notifications
You must be signed in to change notification settings - Fork 52
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
SDCard_disk_initialize always fails #6
Comments
oh, and I replaced this code with a much longer delay:
and I also do several retries. May be I have not tried every combination of all the measures above. Any hint which one I should try? |
This code was developed on a range of smoothieboards including the old v1.0 you mention and even older beta versions of the board which were never available for sale. It is in use on thousands of boards across the world and is the primary way that smoothie users update their firmware - IOW you seem to be the only one with this issue. Most other users that have problems resembling this find that simply using a different SD card solves it. The only real way to find out what's happening would be to put a 'scope on the pins and have a look, or dig into those functions and print out every byte that goes across the SPI - which is quite doable if you use (say) 2MBaud for debug serial and cut the SPI frequency down to 10kHz or less. Best of luck if you choose to go digging! I'm curious what you might find. |
thanks for answering... The main question is, what is different between the hex file in the smoothieware repo (in folder bootloader) and this repo. I could find out myself, but I cannot relate it to some version in this repo. The hex file works as bootloader with all my cards for years. This repo compiled and uploaded works in dfu mode and I can also add blinking lights, serial output etc. but it does not load firmware.bin because it does not detect any of my current cards (all of them work with the hex file). From the file date it's obvious that the hex file is not equal to the current version. So please could you please be so kind to tell me which version of this repo it is? |
what you say about printing bytes, that should be only 16 (or 24) 0xFF for the so called 'idle mode'. So nothing complicated I guess. |
As far as I know, the firmware bin in the smoothie repo been built from this repo - likely grabbed from the build server at http://triffid-hunter.no-ip.info/DFU-Bootloader.html which shows an older commit date than Smoothieware/Smoothieware@504e25e I probably should give that a poke at some stage and make sure it's working, although there's been no significant code changes in the past few years. You may need to check your toolchain, we have encountered some versions that produce very strange breakage with subtle but infuriating symptoms just like the one you describe. I've had situations where simply inserting or removing an ostensibly innocuous printf could make or break apparently unrelated code blocks, and updating or downgrading toolchain version would often sort it out entirely. If the binary from the build server works but the one you compile doesn't, the problem is almost certainly local to your system/toolchain and may require some interesting debugging to find a code change that makes it work for you and doesn't break it for anyone else. |
Thanks for the answer again... I thought of the toolchain, too. Some optimization here and there and the timing changes. Usually I follow the instructions how to compile the project, at least at first, to be sure it works. |
I installed the hex file from My compiler is gcc 6.3 (arm...), which should be quite a difference to 4.8... But I don't see a problem in the main code...may be there is something in some of the lower level code. Curious, the cmd0 command only gets 0xFF as response, if I remove/insert the card while looking at the response it sometimes changes. As a next step I'll try to use gcc 4.9 from ubuntu xenial, but have to do updates currently, so installing is not an option for today, I will probably do tomorrow. Btw. I looked in the SDcard standard...what a mess... I also found this: I think at least the basic init sequence is ok. |
ok, updates finished faster than expected. So I installed gcc-arm-none-eabi/xenial which is 4.9.3... ...and it WORKED... I'll try other versions tomorrow. I also downgraded This wasn't forced by downgrading to gcc-arm-none-eabi/xenial, so I'll also try which of the packages makes the difference. |
this combination works, so everything is current but the gcc is 4.9.3:
gcc 5.4.1 from debian stable doesn't work:
|
Wow, great detective work! So it is a toolchain issue after all.. Ideally we should have code that works with anything, but practically we need to find out what gcc-6.x doesn't like and fix it without breaking anything for 4.x. Writing the 0xFFs with CS deasserted (high) is simply a method of 1) introducing a startup delay controlled by the SPI frequency and 2) flushing any crud that might be lying around in the SD card's buffers for some reason (as noted in your link, at least 74 clocks - we send 16*8=128). Scoping the lines would give us a vastly clearer picture on what's happening with the SPI signals between the working and non-working versions. Your link suggestion https://electronics.stackexchange.com/questions/77417/what-is-the-correct-command-sequence-for-microsd-card-initialization-in-spi/238217#238217 is a great read - perhaps you could try putting some retry-delay sequences around the CMD0 and CMD8 and see if that improves things? Perhaps your newer GCC is generating code that simply does things too fast or something? I don't have a smoothieboard handy to play with at the moment - if you do end up generating a pull request, please ensure it still works as expected with the older toolchain installed by smoothie's script as well as whatever new fancy compiler you want to play with :D |
I am currently at a point where I managed to get SOFT_SPI working (I added code to force this even with hardware spi pins). I also added some delays like this:
and also added delays between several initialization lines in case the speed does matter there. I early changed SOFT_SPI to GPIO_xxx functions. May be this makes a difference, but I don't know. The behavior could point to a problem in initialization, perhaps the clock frequency is wrong? but it works with gcc 4.9.3... Currently I have no clue what could be wrong. Clock calculations result in these values:
|
I currently cannot use a scope, but I used a logic pen to verify sck, cs, mosi, miso at least are doing something senseful. Btw. for 25kHz it's:
Summary for gcc 6.3:
|
ok, I tried:
which indicates the problem is entirely related to cmd0 processing or ... perhaps generally SDCARD_cmd ... ok, next test doing the rest in hardware spi ... if I do hardware spi for the 16 x 0xFF sequence, and then software spi for cmd0 and the rest in hardware spi, cmd8 thinks it's "not an SD card?" because it's not in idle state after sending cmd8. So the failure seems to be in SDCard_cmd in general. Or it may be still SPI_write, given that the 0xFF sequence is not very critical. Now I'm running out of options, I'll better input some beer and pan cakes and a movie...tomorrow is another day... |
Well the hardware SPI driver is as simple as things can get, essentially just:
so I suppose the next step is to fill that file with printf, and/or examine the assembly generated by the non-working toolchain. It may be possible to shoe-horn the MRI debugger that smoothie uses into the bootloader, if you change the linker script to allow it to use more flash. That might be useful, then you can point GDB at it and single-step through the whole SD/SPI init section. Once we know what the actual root cause is, hopefully there'll be some obvious code change we can make so that it works with all toolchain versions |
I now have a version that works with gcc 6.3 ...but not ready yet...see at the end... Based on my guess, that there must be some quirk in the initialization sequence, I imported some functionality from lpc17xx_ssp.c, while stripping it down to necessary features. I added frequency calculation, init function, and readwrite from this file and made them switchable.
BUT... Unfortunately, loading of firmware.bin is now much slower. But this is independent of enabling the new functions. Even with the old implementation (including a lot of hopefully disabled test harness) compiled with gcc 4.9.3 is still very slow. I obviously left something in the code I am not aware of. So, next step will be to cherrypick essential changes to a clean branch to find out what happened --> to be continued |
Frequency is off? hmm, now that I look at it I think you're right.. Put
|
I first thought 25Mhz could be wrong. I think this depends on init. What I mean is, if I want 4Mhz, I get around 4.2 etc. That's 5% too high. Thanks, I know how to use version control, it's my daily business. But a lot if changes are a lot of changes. In all those trst lines must be some that are still active. It's kind of "living" test code and at some point the brain stops keeping track of all that locations. Another problem is mixed tab+spaces and tab size of 4...the usual open aource policy is to eliminate tabs. |
here some data from the current calculation (CRf is the real factor, which is (CR0>>8)&0xFF+1 so that real_f = sspclk/CPSR/CRf):
and this is how it is calculated by the library function:
Now you might say 5% is ok (better tahn using ca. 3MHz instead of 4MHz) but then you cold use a 5% bigger value for the maximum value. With the current algorithm I am not sure if the error could eventually be much higher... Unfortunately I had not enough time today to go further. At least I found, that every method is slow now, SOFTSPI, the current code and the new code in different configurations. |
Ok...just had a look...that was easy. I had added a short delay to setleds(), which isn't good if each sector is setting the leds (even if they don't change). I also added a printf to show all configured registers:
so, CR0=0x300 is the problem, the lower byte should be 0x07. Now, this works
but this doesn't:
despite the fact, the expression on the right is 0x7 (I added CPHA and CPOL, but they are zero), the assignment results in CR0 being zero afterwards. So, it seems to be some optimization for assignments, that doesn't hit assignments combined with or. The code also works with 12.5MHz, but it doesn't result in faster flashing, may be my card is too slow: Now while everything is working, I'll probably reorder things into function groups and/or files instead of many #if clauses to make everything more clear.
I will first create a minimal PR that fixes the problem |
you may look into my repo, on branch hg42 for a lot of other code changes... |
given that the other function also uses while debugging yesterday, I thought they might have introduced that |
Today, I had the same effect in the new functions. Not sure what's going on. While testing this, I noticed when requesting a frequency of 4200000 (experimentally adding 5% for the new algorithm), I got 6250000 instead with the old algorithm: |
Just compiled the official develop branch from triffid with gcc 7.3.1. |
Guess I should merge that PR, now that it's affecting more than one person
with more than one version of gcc
…On Mon, 18 Nov 2019 at 05:48, Martin Patzel ***@***.***> wrote:
Just compiled the official develop branch from triffid with gcc 7.3.1.
Still the same problem.
Fix #7 <#7> helped
- SD card is working now.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#6?email_source=notifications&email_token=AABICGVPO6JFBJMEY6SZ4L3QUG32FA5CNFSM4EJRNGX2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEEIXBKI#issuecomment-554791081>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AABICGWFACRHUQE4CVXSF2DQUG32FANCNFSM4EJRNGXQ>
.
|
I have an early Smoothieboard v1.0 (the one with A498x drivers) so I am not totally sure if it has a different pinout.
This code always fails on my board:
SDCard_disk_initialize() finally goes here:
and fails with "Could not put SD card in to SPI idle state".
But this works with the bootloader packaged with Smoothieware (it worked before and it works now).
Which version is this?
The Smoothieware documentation simply links to this github repo without any tag or branch, so I assume it should actually still work.
I also guessed it could be some older version, so I tried several versions like
I also tried to change some values that might have an influence on this code:
Googling for the error message indicates the pins could be wrong, but it works with the version packed with Smoothieware and I think the pins never changed...
Any guess what else could be going on?
The text was updated successfully, but these errors were encountered: