Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
130 commits
Select commit Hold shift + click to select a range
046fcf2
Handle multiple SPI buses per controller
LinoBarreca Nov 21, 2019
cbe5d2e
Make SD search order customizable by user
LinoBarreca Nov 25, 2019
7b648f1
Cleanup
LinoBarreca Nov 25, 2019
a8f4c5b
Added SPI debug functions
LinoBarreca Nov 26, 2019
5b89256
Debug master clock too.
LinoBarreca Nov 26, 2019
2daeccd
Frequency change on SPI bus after first SD init
LinoBarreca Nov 26, 2019
52b2fda
Probe the bus matching the detect switch and
LinoBarreca Nov 26, 2019
1cd45f4
Force the prescaler.
LinoBarreca Nov 26, 2019
9da399b
Check bus initialization before usage
LinoBarreca Nov 26, 2019
06f99a3
Fix for no-sleep commit. Sorry.
LinoBarreca Nov 27, 2019
3f21d46
More logging.
LinoBarreca Nov 27, 2019
36f0804
some more logging
LinoBarreca Nov 27, 2019
f83b8a1
Don't try to change the bus during initialization
LinoBarreca Nov 27, 2019
8c630f8
Don't mangle CS line while switching card mode.
LinoBarreca Nov 27, 2019
d347ed6
Use MSB according to documentation
LinoBarreca Nov 27, 2019
9d51071
Cleanup and optimization
LinoBarreca Nov 27, 2019
7f498ad
Add customizable SD card order to configuration.h
LinoBarreca Nov 27, 2019
1244f00
Rollback some optimizations to track what's wrong
LinoBarreca Nov 27, 2019
0b3cc42
Fix for SD_DETECT_INVERTED
LinoBarreca Nov 27, 2019
e27a695
Restore SPI_MODE_0 on BUS0
LinoBarreca Nov 27, 2019
68d0d24
Increase SPI speed
LinoBarreca Nov 28, 2019
14c9812
Allow more than one card per bus
LinoBarreca Nov 28, 2019
5229057
First support for SPI drivers
LinoBarreca Nov 28, 2019
8122b08
Better messages on card probing/detection
LinoBarreca Nov 28, 2019
909cd0c
Try to initialize cards at least three times
LinoBarreca Nov 28, 2019
3e0331f
Re-activate SPI data logging
LinoBarreca Nov 28, 2019
c229ec4
Write buffer to SPI all at once
LinoBarreca Nov 28, 2019
a99b47a
Removed some output
LinoBarreca Nov 28, 2019
e991286
Reenable spaces for debug output
LinoBarreca Nov 28, 2019
866d494
Easy activation/deactivation of bus traffic dump
LinoBarreca Nov 29, 2019
4a8bb7a
Initial support for Hardware CRC on SPI<->SD comm
LinoBarreca Nov 29, 2019
cbe0675
More compliant to SD specifications
LinoBarreca Nov 29, 2019
42b8f65
Set correct data size for HW-CRC algo
LinoBarreca Nov 29, 2019
4bab1ae
Don't wait for CRC byte on cardCommand
LinoBarreca Nov 29, 2019
63483d5
HW-CRC on 5 bytes command is stupid.
LinoBarreca Nov 29, 2019
0c5195a
Fix SPI drivers access
LinoBarreca Dec 2, 2019
9d1aa34
Pass correct CS pin for hardware SPI-DRIVER ctor
LinoBarreca Dec 2, 2019
48e8684
Always define SPI drivers if the driver is SPI
LinoBarreca Dec 2, 2019
fd3cfc4
SD card: read the number of bytes expected by CMD
LinoBarreca Dec 2, 2019
86eb954
restore old card response reading logic
LinoBarreca Dec 2, 2019
afb2ad6
....let's try again.
LinoBarreca Dec 2, 2019
3b03259
Fix build error, reenable skipping proper number of bytes
LinoBarreca Dec 3, 2019
7e1c11d
better messages
LinoBarreca Dec 3, 2019
92e8045
Fix CMD8 external response parsing.
LinoBarreca Dec 3, 2019
ef09468
Don't read the extra byte for correct parsing
LinoBarreca Dec 3, 2019
93ea08e
Auto resend message if CRC error is reported
LinoBarreca Dec 3, 2019
040c48f
Correct CRC bit check
LinoBarreca Dec 3, 2019
091de17
Fix for "incorrect speed" error.
LinoBarreca Dec 3, 2019
e034b57
Set correct CRC polynomial for CCITT
LinoBarreca Dec 3, 2019
6c25cda
Some more CRC modifications
LinoBarreca Dec 3, 2019
ce88045
sendBlock can't take CRC into account
LinoBarreca Dec 3, 2019
677f7d2
Build and call HW-CRC only if supported by HAL
LinoBarreca Dec 3, 2019
6192558
Fix build error when SD_CHECK_AND_RETRY is undefined
LinoBarreca Dec 3, 2019
ca22301
Changes to help HW-CRC debugging:
LinoBarreca Dec 4, 2019
3033f9d
Change polynomial parameter for CRC
LinoBarreca Dec 4, 2019
cec7d54
Don't loop forever if CRC error to CMD
LinoBarreca Dec 5, 2019
d616a78
Enable HW-CRC7-CCITT for commands in 8 bit mode
LinoBarreca Dec 5, 2019
fc3e8f0
Dump SPI registers after configuration has supposedly been done
LinoBarreca Dec 5, 2019
8f4342d
LOW level SPI send and trace
LinoBarreca Dec 5, 2019
38f8a19
Deactivate HW-CRC on CMD and activate it on data-block (again)
LinoBarreca Dec 5, 2019
d083341
Fix cast for build error
LinoBarreca Dec 6, 2019
cdd55cd
Log only significant parts of SPI communication for HW-CRC debugging
LinoBarreca Dec 6, 2019
4449159
Send FF on MOSI when reading from SD
LinoBarreca Dec 6, 2019
adee9dc
Modified data reception with CRC
LinoBarreca Dec 6, 2019
78b1707
Fix logic for second readData
LinoBarreca Dec 6, 2019
6e03d52
Send zero on MOSI to read from MISO
LinoBarreca Dec 6, 2019
dfb0f9c
Altered send to see where it hangs
LinoBarreca Dec 6, 2019
38aaf47
Trace and flush to see where it hangs
LinoBarreca Dec 6, 2019
790fb7b
Don't peek DR or it clears RXNE
LinoBarreca Dec 6, 2019
f1d452a
Clear OVR only if set in SR and dump DR at the end
LinoBarreca Dec 6, 2019
812a57b
Write message when/if clearing OVR at end
LinoBarreca Dec 7, 2019
cbeb84a
Dump both buffers for the same logical read operation
LinoBarreca Dec 9, 2019
f1ac3fd
Different logic for data read and CRC verification
LinoBarreca Dec 9, 2019
39019a8
Use driver functions for second CMD17
LinoBarreca Dec 9, 2019
e94293d
Swap readData calls to check their output.
LinoBarreca Dec 9, 2019
9dd651f
don't enable HW-CRC in readData2
LinoBarreca Dec 9, 2019
a0233a8
Disable and reenable spi to see if we can corrupt data
LinoBarreca Dec 9, 2019
5e5dbf0
Temporary fix for fake clock when activating HW-CRC
LinoBarreca Dec 9, 2019
160fc72
fix build error from previous commit
LinoBarreca Dec 9, 2019
68b061c
Added some SERIAL_FLUSH
LinoBarreca Dec 9, 2019
7ed282d
Don't do too many things with variables
LinoBarreca Dec 10, 2019
fdcf6c7
Add messages to debug freeze
LinoBarreca Dec 10, 2019
12c335c
Proper CRC calls by device and not by bus
LinoBarreca Dec 10, 2019
b6d671b
Initial support for transactions
LinoBarreca Dec 10, 2019
93a0d86
Remove debug messages and keep MOSI high in receive
LinoBarreca Dec 10, 2019
417c61d
Properly set polarity and phase on CLK
LinoBarreca Dec 10, 2019
cb75535
Fix spiReadCRC16 endianness
LinoBarreca Dec 10, 2019
f6fabe3
HW-CRC: Clean-up receive and implement send
LinoBarreca Dec 11, 2019
cf04175
Some more cleanup
LinoBarreca Dec 11, 2019
49958f4
Switch endianness on write
LinoBarreca Dec 11, 2019
30fddac
Dump CRC values before send
LinoBarreca Dec 12, 2019
cb4294f
We need TX, not RX
LinoBarreca Dec 12, 2019
3603c7c
Added some debug output to sent CRC
LinoBarreca Dec 13, 2019
f04070d
Send the correct number of halfwords
LinoBarreca Dec 13, 2019
e6d9724
Let the hardware send the CRC at the end of transfer
LinoBarreca Dec 13, 2019
edba8f1
Manually send HW-CRC after data send
LinoBarreca Dec 13, 2019
e383053
Give card time to calculate CRC on sent data
LinoBarreca Dec 16, 2019
3806278
Fix for subsequent CMDs HW-CRCs after first spiReadCRC16
LinoBarreca Dec 17, 2019
5627a37
Wait for HW-CRC calculation to be ready
LinoBarreca Dec 17, 2019
efb4a89
SKR-PRO: properly set SPI0 bus for R5 presence
LinoBarreca Dec 17, 2019
58521e6
Don't transfer CRCs when messing with the bus settings
LinoBarreca Dec 17, 2019
9bd7aa4
Formatting
LinoBarreca Dec 17, 2019
2c3f42f
Add support for device speed in pins config
LinoBarreca Dec 20, 2019
9a53dfa
Avoid useless bus reconfiguration
LinoBarreca Dec 20, 2019
9b5d06e
Low Level bus setting must always be done
LinoBarreca Dec 20, 2019
9798456
Provide method to write block to SPI device
LinoBarreca Dec 23, 2019
38d2814
SD-Card access by device
LinoBarreca Dec 23, 2019
eec4dcc
Merge branch 'bugfix-2.0.x' into MultiSPI
LinoBarreca Dec 30, 2019
9968cfb
Fix for devices which don't support HW-CRC
LinoBarreca Dec 30, 2019
f7f8278
Normalize and differentiate SPI functions' names
LinoBarreca Dec 30, 2019
70dcf8b
Merge remote-tracking branch 'upstream/bugfix-2.0.x' into MultiSPI
LinoBarreca Jan 7, 2020
2b18ab9
Merge remote-tracking branch 'upstream/bugfix-2.0.x' into MultiSPI
LinoBarreca Jan 13, 2020
a4d9bb2
Remove unneded extra checks
LinoBarreca Jan 14, 2020
865d756
Merge remote-tracking branch 'upstream/bugfix-2.0.x' into bf2_multi_s…
thinkyhead Feb 4, 2020
c9b2a0f
Add more axes, clean up
thinkyhead Feb 5, 2020
bdca67d
Fix up some inits
thinkyhead Feb 5, 2020
6c36747
Merge remote-tracking branch 'upstream/bugfix-2.0.x' into bf2_multi_s…
thinkyhead Feb 5, 2020
d119130
Handle multiple SPI buses per controller
LinoBarreca Nov 21, 2019
ea7ac66
Fix some tests compilation, but not all
thinkyhead Feb 6, 2020
507fad5
Merge branch 'bugfix-2.0.x' into MultiSPI
LinoBarreca Feb 20, 2020
df1f16c
Merge remote-tracking branch 'upstream/bugfix-2.0.x' into bf2_multi_s…
thinkyhead Feb 25, 2020
917ff08
Merge remote-tracking branch 'LinoBarreca/MultiSPI' into bf2_multi_sp…
thinkyhead Feb 25, 2020
d1779fc
Syntax error
Keltere Mar 2, 2020
631268d
Merge pull request #8 from Keltere:MultiSPI
LinoBarreca May 5, 2020
a0b7537
Merge remote-tracking branch 'upstream/bugfix-2.0.x' into pr/16260
thinkyhead Aug 11, 2020
0ae5e86
Add sanity check for AVR spiBegin
thinkyhead Aug 11, 2020
0d0129f
ap
thinkyhead Aug 11, 2020
3773075
Indent before merge
thinkyhead Nov 30, 2020
3df6fa6
Merge remote-tracking branch 'upstream/bugfix-2.0.x' into pr/16260
thinkyhead Nov 30, 2020
f78a7e3
Restore indentation
thinkyhead Nov 30, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Marlin/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -1770,6 +1770,15 @@
*/
//#define SDSUPPORT

/**
* SD CARD: SEARCH ORDER
* Order in which SD-Cards should be searched on the device, if there are more than one.
* (see SD-Cards definitions in your pins.h file)
* This setting makes marlin prioritize the cards if more than one is inserted.
* Change only if you prefer one SD-Card over the other (maybe because it's more accessible)
*/
//#define SD_SEARCH_ORDER { 0, 1, 2, 3 }

/**
* SD CARD: SPI SPEED
*
Expand Down
16 changes: 5 additions & 11 deletions Marlin/src/HAL/AVR/HAL_SPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,16 @@
#include "../../inc/MarlinConfig.h"

void spiBegin() {
#if !PIN_EXISTS(SS)
#error "SS_PIN not defined!"
#endif
OUT_WRITE(SS_PIN, HIGH);
SET_OUTPUT(SCK_PIN);
SET_INPUT(MISO_PIN);
SET_OUTPUT(MOSI_PIN);

#if DISABLED(SOFTWARE_SPI)
// SS must be in output mode even it is not chip select
//SET_OUTPUT(SS_PIN);
// set SS high - may be chip select for another SPI device
//#if SET_SPI_SS_HIGH
//WRITE(SS_PIN, HIGH);
//#endif
// set a default rate
spiInit(1);
#endif
// set a default rate
spiInit(1);
}

#if NONE(SOFTWARE_SPI, FORCE_SOFT_SPI)
Expand Down Expand Up @@ -249,5 +244,4 @@ void spiBegin() {
}

#endif // SOFTWARE_SPI || FORCE_SOFT_SPI

#endif // __AVR__
25 changes: 20 additions & 5 deletions Marlin/src/HAL/STM32/HAL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,20 +63,35 @@ uint16_t HAL_adc_result;
void HAL_init() {
FastIO_init();

#if ENABLED(SDSUPPORT) && DISABLED(SDIO_SUPPORT) && (defined(SDSS) && SDSS != -1)
OUT_WRITE(SDSS, HIGH); // Try to set SDSS inactive before any other SPI users start up
#if ENABLED(SDSUPPORT) && DISABLED(SDIO_SUPPORT)
// Temporary measure to prevent devices on the bus trying to become master.
// This will be done again when the SPI device is initialized.
for (uint8_t dev = 0; dev < NUM_SPI_DEVICES; dev++) {
extDigitalWrite(CS_OF_DEV(dev), HIGH); // Set CS HIGH (inactive) before other SPI users start.
pinMode(CS_OF_DEV(dev), OUTPUT);
if (IS_DEV_SD(dev) && SW_OF_SD(dev) != NC) // For an SD card with a real switch, set the pin as input
_SET_MODE(SW_OF_SD(dev), DLV_OF_SD(dev) == LOW ? INPUT_PULLUP : INPUT_PULLDOWN); // with the appropriate pull.
}
#endif

#if PIN_EXISTS(LED)
OUT_WRITE(LED_PIN, LOW);
#endif

#if ENABLED(SRAM_EEPROM_EMULATION)
// Enable access to backup SRAM
__HAL_RCC_PWR_CLK_ENABLE();
HAL_PWR_EnableBkUpAccess(); // Enable access to backup SRAM
HAL_PWR_EnableBkUpAccess();
__HAL_RCC_BKPSRAM_CLK_ENABLE();
LL_PWR_EnableBkUpRegulator(); // Enable backup regulator
while (!LL_PWR_IsActiveFlag_BRR()); // Wait until backup regulator is initialized

// Enable backup regulator
LL_PWR_EnableBkUpRegulator();
// Wait until backup regulator is initialized
while (!LL_PWR_IsActiveFlag_BRR());
#endif

#if HAS_TMC_SW_SERIAL
SoftwareSerial::setInterruptPriority(SWSERIAL_TIMER_IRQ_PRIO, 0);
#endif

SetTimerInterruptPriorities();
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/HAL/STM32/HAL.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ extern uint16_t HAL_adc_result;
// Memory related
#define __bss_end __bss_end__

// Enable hooks into setup for HAL
// Enable hooks into setup for HAL
void HAL_init();

// Clear reset reason
Expand Down
Loading