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

Fix SPI TFT for STM32F1/F4 #26052

Merged
merged 39 commits into from
Jan 8, 2024
Merged
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
aed88a7
Fix SPI TFT for STM32F4
jmz52 Jul 5, 2023
69705bc
Fix SPI TFT for STM32F4
jmz52 Jul 5, 2023
4f9f889
Merge branch 'stm32f4-tft-spi-fix' of https://github.com/jmz52/Marlin…
jmz52 Jul 24, 2023
46b05fd
Merge remote-tracking branch 'upstream/bugfix-2.1.x' into stm32f4-tft…
jmz52 Jul 24, 2023
9d40118
Update tft_spi.cpp
jmz52 Aug 2, 2023
81b216d
Fix lowercase issue introduced in PR#25939
jmz52 Aug 2, 2023
dce700d
Update tft_string.cpp
jmz52 Aug 2, 2023
75af24f
Merge remote-tracking branch 'MarlinFirmware/bugfix-2.1.x' into stm32…
thisiskeithb Aug 2, 2023
e6ee56b
Add debug messages to TFT_SPI::getID()
jmz52 Aug 5, 2023
cac799d
Update tft_spi.cpp
jmz52 Aug 5, 2023
6ae35fe
Update tft_spi.cpp
jmz52 Aug 5, 2023
e619ad9
Merge branch 'bugfix-2.1.x' into pr/26052
thinkyhead Aug 7, 2023
7b05cb6
TFT debug off
thinkyhead Aug 7, 2023
dc79513
Merge remote-tracking branch 'MarlinFirmware/bugfix-2.1.x' into stm32…
thisiskeithb Sep 22, 2023
537c67c
Merge remote-tracking branch 'MarlinFirmware/bugfix-2.1.x' into stm32…
thisiskeithb Oct 4, 2023
d282abd
Merge remote-tracking branch 'MarlinFirmware/bugfix-2.1.x' into stm32…
thisiskeithb Oct 9, 2023
a828692
Merge remote-tracking branch 'MarlinFirmware/bugfix-2.1.x' into stm32…
thisiskeithb Oct 21, 2023
bcc5383
Merge branch 'bugfix-2.1.x' into pr/26052
thinkyhead Oct 26, 2023
55360d0
Use TFT_DEFAULT_DRIVER
thinkyhead Oct 26, 2023
abe0885
or… try it this way
thinkyhead Oct 27, 2023
33cd243
use REMEMBER
thinkyhead Oct 27, 2023
0888bb0
Merge remote-tracking branch 'MarlinFirmware/bugfix-2.1.x' into stm32…
thisiskeithb Nov 21, 2023
ec5a964
Update tft_spi.cpp
jmz52 Nov 22, 2023
64a3258
Fix SPI TFT for STM32F4
jmz52 Jul 5, 2023
234c30a
Update tft_spi.cpp
jmz52 Aug 2, 2023
09f94d6
Update tft_string.cpp
jmz52 Aug 2, 2023
acce304
Add debug messages to TFT_SPI::getID()
jmz52 Aug 5, 2023
1bf6a6b
Update tft_spi.cpp
jmz52 Aug 5, 2023
cc23e90
Update tft_spi.cpp
jmz52 Aug 5, 2023
7afc4c8
TFT debug off
thinkyhead Aug 7, 2023
c4b775d
Use TFT_DEFAULT_DRIVER
thinkyhead Oct 26, 2023
bb54ec9
or… try it this way
thinkyhead Oct 27, 2023
e88d343
use REMEMBER
thinkyhead Oct 27, 2023
3c05cc9
Update tft_spi.cpp
jmz52 Nov 22, 2023
47325d3
Merge branch 'stm32f4-tft-spi-fix' of https://github.com/jmz52/Marlin…
jmz52 Dec 4, 2023
2483e3c
Disable DEBUG_TFT_IO by default
thisiskeithb Dec 16, 2023
20e7229
Merge remote-tracking branch 'MarlinFirmware/bugfix-2.1.x' into stm32…
thisiskeithb Dec 16, 2023
54f10bf
Merge branch 'bugfix-2.1.x' into pr/26052
thinkyhead Jan 8, 2024
2e7a9c4
hint that empty while is intentional
thinkyhead Jan 8, 2024
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
30 changes: 12 additions & 18 deletions Marlin/src/HAL/STM32/tft/tft_spi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ void TFT_SPI::init() {
if ((spiInstance = (SPI_TypeDef *)pinmap_peripheral(digitalPinToPinName(TFT_SCK_PIN), PinMap_SPI_SCLK)) == NP) return;
if (spiInstance != (SPI_TypeDef *)pinmap_peripheral(digitalPinToPinName(TFT_MOSI_PIN), PinMap_SPI_MOSI)) return;

#if PIN_EXISTS(TFT_MISO) && TFT_MISO_PIN != TFT_MOSI_PIN
if (spiInstance != (SPI_TypeDef *)pinmap_peripheral(digitalPinToPinName(TFT_MISO_PIN), PinMap_SPI_MISO)) return;
#if PIN_EXISTS(TFT_MISO)
if ((TFT_MISO_PIN != TFT_MOSI_PIN) && (spiInstance != (SPI_TypeDef *)pinmap_peripheral(digitalPinToPinName(TFT_MISO_PIN), PinMap_SPI_MISO))) return;
thinkyhead marked this conversation as resolved.
Show resolved Hide resolved
#endif

SPIx.Instance = spiInstance;
Expand Down Expand Up @@ -76,8 +76,8 @@ void TFT_SPI::init() {

pinmap_pinout(digitalPinToPinName(TFT_SCK_PIN), PinMap_SPI_SCLK);
pinmap_pinout(digitalPinToPinName(TFT_MOSI_PIN), PinMap_SPI_MOSI);
#if PIN_EXISTS(TFT_MISO) && TFT_MISO_PIN != TFT_MOSI_PIN
pinmap_pinout(digitalPinToPinName(TFT_MISO_PIN), PinMap_SPI_MISO);
#if PIN_EXISTS(TFT_MISO)
if (TFT_MISO_PIN != TFT_MOSI_PIN) pinmap_pinout(digitalPinToPinName(TFT_MISO_PIN), PinMap_SPI_MISO);
#endif

#ifdef SPI1_BASE
Expand Down Expand Up @@ -185,9 +185,7 @@ uint32_t TFT_SPI::readID(const uint16_t inReg) {
__HAL_SPI_ENABLE(&SPIx);
SET_BIT(SPIx.Instance->CR1, SPI_CR1_CSTART);

#if TFT_MISO_PIN != TFT_MOSI_PIN
SPIx.Instance->TXDR = 0;
#endif
if (SPIx.Init.Direction == SPI_DIRECTION_2LINES) SPIx.Instance->TXDR = 0;
while (!__HAL_SPI_GET_FLAG(&SPIx, SPI_FLAG_EOT)) {}
data = (data << 8) | SPIx.Instance->RXDR;
__HAL_SPI_DISABLE(&SPIx);
Expand All @@ -197,10 +195,10 @@ uint32_t TFT_SPI::readID(const uint16_t inReg) {
#else
__HAL_SPI_ENABLE(&SPIx);
for (uint32_t i = 0; i < 4; i++) {
#if TFT_MISO_PIN != TFT_MOSI_PIN
if (SPIx.Init.Direction == SPI_DIRECTION_2LINES) {
while (!__HAL_SPI_GET_FLAG(&SPIx, SPI_FLAG_TXE)) {}
SPIx.Instance->DR = 0;
#endif
}
while (!__HAL_SPI_GET_FLAG(&SPIx, SPI_FLAG_RXNE)) {}
data = (data << 8) | SPIx.Instance->DR;
}
Expand Down Expand Up @@ -263,9 +261,7 @@ void TFT_SPI::abort() {
}

void TFT_SPI::transmit(uint16_t data) {
#if TFT_MISO_PIN == TFT_MOSI_PIN
SPI_1LINE_TX(&SPIx);
#endif
if (SPIx.Init.Direction == SPI_DIRECTION_1LINE) SPI_1LINE_TX(&SPIx);

#ifdef STM32H7xx
MODIFY_REG(SPIx.Instance->CR2, SPI_CR2_TSIZE, 1);
Expand All @@ -278,17 +274,15 @@ void TFT_SPI::transmit(uint16_t data) {

__HAL_SPI_CLEAR_EOTFLAG(&SPIx);
__HAL_SPI_CLEAR_TXTFFLAG(&SPIx);
__HAL_SPI_DISABLE(&SPIx);
#else
__HAL_SPI_ENABLE(&SPIx);
SPIx.Instance->DR = data;
while (__HAL_SPI_GET_FLAG(&SPIx, SPI_FLAG_BSY)) {}
while (!__HAL_SPI_GET_FLAG(&SPIx, SPI_FLAG_TXE)) {} // Wait for data transfer to actually start
while (__HAL_SPI_GET_FLAG(&SPIx, SPI_FLAG_BSY)) {} // Wait until SPI is idle
#endif

__HAL_SPI_DISABLE(&SPIx);

#if TFT_MISO_PIN != TFT_MOSI_PIN
__HAL_SPI_CLEAR_OVRFLAG(&SPIx); // Clear overrun flag in 2 Lines communication mode because received data is not read
#endif
if (SPIx.Init.Direction == SPI_DIRECTION_2LINES) __HAL_SPI_CLEAR_OVRFLAG(&SPIx); // Clear overrun flag in 2 Lines communication mode because received data is not read
}

void TFT_SPI::transmitDMA(uint32_t memoryIncrease, uint16_t *data, uint16_t count) {
Expand Down