-
-
Notifications
You must be signed in to change notification settings - Fork 19.3k
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
Multiple, simultaneous, SPI buses handling and Smart SD mounting #16260
Conversation
Every bus has multiple devices which have to be defined with pin/type Each SPI call is now directed to a device SD Cards can now be more than one and can be attached to any SPI bus
and access STM SPI driver directly bypassing framework
provide a method to write to the bus regardless what device you are talking to
@Keltere there were some major changes in Marlin/src/sd/Sd2Card.cpp I started in Marlin/src/sd/cardreader.cpp at void CardReader::mount() function. From there Sd2Card::init is called to initalize the SD-Card. Inside the init procedure the SD-Card shall be set to idle via cardCommand(CMD0, 0), but this does not return R1_IDLE_STATE. I already tried an increased timeout. So I currently don't know if the issue is inside the cardCommand call or if the issue is already 5 lines prior inside the following loop:
|
Thanks, with some debug message, ill try to understand what is going on in that cycle. |
Yeah, goto's should be avoided, they make the code hard to read and to follow. (It also increases the cyclomatic complexity when doing static code analysis. ) The for is not that bad, but if I want an endless loop I typically use a while or a do-while. |
@LehrChristoph you where right, it always go on timeout and if i try to add more time in any way the system will always crash after returning the error. |
@LinoBarreca I'm just considering quick fixes for this problem focusing only on SKR Pro v1.1. Other solution would be to mechanically remove the famous R5, but that might make the closed source bootloader unoperable, thus making the simple firmware update impossible. |
I used multi spi branch about a month ago my experience was the onboard reader worked fine though i only used the 125mb card that was supplied with the board plus one other. The card that came with board has died now and i am running bugfix branch. The problems i had with multi spi branch was with external reader on my lcd display out of about 7 cards at hand only one worked and they are all branded cards. Maybe long ribbon cables may be an issue, they all work on bugfix branch though. I will try the latest multi spi again and let you know if anything has changed. |
39fe6ef
to
7aed32d
Compare
7b92348
to
37176ed
Compare
Syntax error
Sorry this got stale while making (many) other adjustments to the HALs and dealing with the usual blizzard of not really bug reports…. Is this still a viable concept given our ongoing reforms of the HAL? And… What about getting the HALs into a formal shape with a namespace or a HAL class? Is it too soon to make that leap…? |
@thinkyhead times ago I tried to add this to samd51 hal but I found some problem. Samd51 can handle spi only on some specific pins and has spi classes that don't want any pin definition. I was wondering if a different approach was possible, but I think it was not considered. My idea was to use only some spi class to fill see #16260 (comment) |
I was concerned about how this approach affected daisy chained SPI devices. Below is my though process on how I concluded that the needed changes would be fairly easy. If I'm reading the code correctly the top level application view is:
The hard vs. soft SPI implementation is hidden from the application. I have mixed feelings on always having the HAL control the CS. I guess my main concern are the daisy chained SPI devices. Currently the software passes to the lowest application level a command buffer and a stepper number. The lowest level sets CS active, writes to the SPI (adding null commands as needed) and then sets CS inactive. To use this PR's approach, the lowest application level would need to be changed to write to a buffer rather than the SPI and then pass the buffer. As long as the buffer contains one complete transaction then having the HAL control the CS is acceptable. |
I did some serious work on a similar approach a couple of years ago. The Marlin side is a lot of work but certainly manageable. I think there are some major implementation problems:
The multiple PR approach may be applicable to the external library portion. Maybe we create the libraries for the big items (U8G & TMC) first and the others as people complain. EDIT Marlin already has it's own U8G library |
I've been looking through the code and have some questions. What were you planning for the devices that require a soft SPI? What are the various SPI device types intended for and how do they differ from each other? I believe SPI_PHI, SPI_PLO, SPI_LTS, SPI_STL are used to select SPI_MODE_0 ... SPI_MODE_3 when setting up the hardware SPI controllers. If this is the case then I think the pins_YOUR_BOARD.h files should only have SPI_MODE_0 ... SPI_MODE_3 and the SPI_PHI, SPI_PLO, SPI_LTS, SPI_STL detail be hidden from the user in the HAL. |
I have merged the latest code into this PR, so please check to make sure everything is where it's supposed to be. |
4274255
to
a97a1ae
Compare
I have merged the latest code into this PR, so please check to make sure everything is where it's supposed to be. |
Description
This is a work in progress. Do not merge yet.
This PR is meant to allow marlin to have a more modern approach to complex boards with several peripherals.
Work in progress? Why opening it now then?
Basically...It's a hell of work. I'm working on it since one month.
@boelle suggested me to not wait until this is feature complete but make "smaller PRs" so they are easier to review and merge. I am opening the pull request here to discuss it with the Marlin team to see what actually implement and what to delay to "future" and to let the contributors and HAL maintainers make the necessary changes to the other part of the software. Help from everyone is very appreciated.
Why was this even born?
To fix one simple problem and a open million of possibilities.
The problem: On board SD-Card on SKR-PRO 1.1 can't be used.
Why? Several reasons actually, all of them addressed with this huge PR.
How is this supposed to work?
Simple: instead of dealing with "pins" and levels for each device there's a more modern approach: device are accessed by id (somewhat your computer does..but simplified) The developers, when there's a new board, define how many spi buses the controller handles and on which pins (optionally they can give a default bus configuration), then they say which device is attached to which bus along with its type (sdcard, display, driver, eeprom, sensor) and properties and each device has its own identifier. When Marlin needs to access that device it just do a read/write to that device (by ID). the rest is done internally by the hal (setting bus/speed and so on). Another benefit is that looping on an array makes the code simpler and shorted (smaller program) and makes it ready for a variable, (big enough to be considered) infinite, number of axis, estrusors, sensors, and so on. Did someone think about CNC?
So you have a SKR-PRO. What will you gain with this PR:
This is still in an early stage with the other boards but for yours but it's already working and...
What are the benefits for everyone else?
This is a structural change which creates support for simultaneous writes/reads to multiple devices. In the future you'll be able to use more than one card and more than one display working together.
Can you make an example? How does this work?
Sure. I used the SKR-PRO as base (which is the only board I modified, I need others' help to extend this logic to other boards)
SD_DETECTED_INVERTED
, in configuration.h#define SD_SEARCH_ORDER { 1, 0 }
in configuration.hI have a SKR-PRO. So it should be working. What will it happen when I flash it?
It depends on your current situation.
Benefits
This fixes a few bugs on SKR-Pro regarding the not working sdcard and "missing eeprom".
If your display didn't have the sd-card slot you couldn't use the onboard sd neither to print nor for saving the eeprom contents (on SKR-Pro there isn't a real EEPROM).
Things already done since the PR was opened:
Things which are known to be done before this can be merged. In order of priority:
Future development and possibilities that this PR opens:
SPI_Devices
section. While it could work for "default" configuration X,Y,Z,E0,E1,E2 the user might want to use a driver to drive an axis i.e. X2=E2 and we shouldn't ask the user to edit pins file. So we should rather provide a way to map a function (i.e. axis X) to a driver (i.e. ID 5) something like this:As you can easily imagine this would require a biiiig marlin logic rewrite that would allow marlin to run on any kind of machine (from printer to CNCs) and implement in the future a real non planar 3d printing (for example adding another axis which turns clockwise, anti-clockwise the extruder).
At the moment, however, since accessing axis and extruders by index needs a lot of work w need to find a way to make it work with the current logic (besides asking people to edit pins file..which is still possible, and requires no development at all)
SPI_HALF_SPEED
)...but we tested it very well and most modern cards work at full speed (42 Mhz) We might just ignore the compatibility with 10yo cards and merge this to work at the highest speed possible.#define TMC_USE_SW_SPI
. I gotta look at it later.Fixes:
#14684