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

Miscellaneous TFT improvements #25359

Merged
merged 7 commits into from
Mar 27, 2023

Conversation

jmz52
Copy link
Contributor

@jmz52 jmz52 commented Feb 9, 2023

Description

Hardware IO
STM32F1 and STM32F4 use DMA2 to for data transfers from/to SDIO-connected cards.
Original implementation for FSMC interface also used DMA2 to send data to TFT display.
SDIO data transfer has low priority and can be delayed by on-going FSMC data transfer.

STM32F1 can use both DMA1 and DMA2 to send data to FSMC, so FSMC IO is reconfigured to use DMA1 controller.
STM32F4 can use DMA2 only to send data to FMC, so it will continue to share DMA2 with SDIO cards.
Maple-specific FSMC_DMA_DEV and FSMC_DMA_CHANNEL options removed from various pins.h files.

As a fail-safe measure the TFT_SHARED_SPI option is extended to TFT_SHARED_IO and it now affects both SPI and FSMC interfaces. It is not expected to be needed on STM32F4 MCUs though.

Update:
HAL STM32F1 (maple) uses DMA1_CH1 for ADC1 (temperature reading).
To avoid conflicts with ADC the FSMC in maple HAL is left on DMA2_CH5.
MCUs that could not handle two concurrent data transfers on same DMA controller should use #define TFT_SHARED_IO option to avoid FSMC/SDIO conflict.

TFT Screen Initialization
There are four possible orientations of TFT screen - landscape and portrait, upside down landscape and upside down portrait.
Marlin has 12 possible values for TFT_ROTATION option.
These 12 variants were created to address mirrored image issue on ILI9488 screens. Issue was caused by incomplete initialization sequence where several important parameters were left undefined i.e. were set by bootloader. Different bootloaders used different initialization sequences, so Marlin had to have different settings for different boards.

There are three parameters used by Marlin to configure TFT display orientation - "mirror X", "mirror Y" and "swap XY".
There are other parameters that affect how image is draw on the display, primarily the "Gate Scan Direction" and "Source Scan Direction". Those were undefined in current implementation of initialization sequence, leaving them at the mercy of bootloaders.

Initialization sequences for ILI9341 (320x240), ST7789 (320x240), ILI9488 (480x320) and ST7796 (480x320) were updated to have these parameters set in stone, to simplify screen orientation configuration. Reference sets of parameters for landscape and portrait modes were added/verified to corresponding headers files.

Initialization sequences for SSD1963 (480x272) and old ILI9328 (320x240) and R61505 (320x240) controllers are still in need of rework and update, but it can't be done without access to hardware.

Ultimate goal to to replace TFT_ROTATION with some simpler parameter that will define whether landscape of portrait UI is used.

Requirements

TFT screen

Benefits

Improved FSMC and SDIO performance on STM32F1.
Bootloader-independent behavior of TFT screen (for 4 most common controllers)

@thisiskeithb
Copy link
Member

Ultimate goal to to replace TFT_ROTATION with some simpler parameter that will define whether landscape of portrait UI is used.

TFTs were also installed "upside down" in some machines (intentionally), so having the full list of rotation options will still be wanted/necessary.

@jmz52
Copy link
Contributor Author

jmz52 commented Feb 9, 2023

Full list of four rotations - sure, but 12 is a bit too much.
These four are listed as a refference in header files, named after side FPC cable is coming from - _RIGHT and _LEFT for landscape, _TOP and _BOTTOM for portrait.

@tpruvot
Copy link
Contributor

tpruvot commented Feb 9, 2023

i didn't test the DMA1 yet, but i remember conflicts vs some maple hardcoded values when i decided to use the "free" channel 5

(test on Longer3D F103VE with SDIO + FSMC)

@quiret
Copy link
Contributor

quiret commented Feb 9, 2023

In order for jmz52 to properly test his changes it could be helpful to supply Configuration.h and Configuration_adv.h for anything questionable so he can investigate. But good that Longer3D was mentioned. I hope it does not feel like chasing after a conspiracy theory to him.

@jmz52
Copy link
Contributor Author

jmz52 commented Feb 9, 2023

@tpruvot, do you remember any details about this conflict with DMA2_CH5? Or maybe someone from your local alfawise community dealt with similar problem?
pins_LONGER3D_LK.h has the same DMA2_CH5 settings for FSMC, so it is likely that they were used for a year or two before FSMC support was added to HAL STM32 along with the with Color_UI.

@jmz52
Copy link
Contributor Author

jmz52 commented Feb 9, 2023

@tpruvot, thanks a lot!
I've completely forgot how maple HAL deals with ADC. DMA1_CH1 will ruin temperature measurement.

@jmz52 jmz52 marked this pull request as draft February 9, 2023 20:11
@quiret
Copy link
Contributor

quiret commented Feb 9, 2023

@jmz52 The Marlin Firmware would greatly appreciate if you solve this peripheral resource collision altogether. Like if you could identify a location in the source code where all STM32(F1) Marlin peripherals using DMA can get their fixed DMA channel (stream) assigned distinctively (C++ preprocessor magic). But maybe this is too big of a task for this PR?

@tpruvot
Copy link
Contributor

tpruvot commented Feb 10, 2023

@jmz52 The Marlin Firmware would greatly appreciate if you solve this peripheral resource collision altogether. Like if you could identify a location in the source code where all STM32(F1) Marlin peripherals using DMA can get their fixed DMA channel (stream) assigned distinctively (C++ preprocessor magic). But maybe this is too big of a task for this PR?

image

its in maple framework...

STM32F1/libraries/SPI/src/SPI.cpp:146:    _settings[0].spiDmaDev = DMA1;
STM32F1/libraries/SPI/src/SPI.cpp:147:    _settings[0].spiTxDmaChannel = DMA_CH3;
STM32F1/libraries/SPI/src/SPI.cpp:148:    _settings[0].spiRxDmaChannel = DMA_CH2;
STM32F1/libraries/SPI/src/SPI.cpp:153:    _settings[1].spiDmaDev = DMA1;
STM32F1/libraries/SPI/src/SPI.cpp:154:    _settings[1].spiTxDmaChannel = DMA_CH5;
STM32F1/libraries/SPI/src/SPI.cpp:155:    _settings[1].spiRxDmaChannel = DMA_CH4;
STM32F1/libraries/SPI/src/SPI.cpp:160:    _settings[2].spiDmaDev = DMA2;
STM32F1/libraries/SPI/src/SPI.cpp:161:    _settings[2].spiTxDmaChannel = DMA_CH2;
STM32F1/libraries/SPI/src/SPI.cpp:162:    _settings[2].spiRxDmaChannel = DMA_CH1;
STM32F1/libraries/STM32ADC/src/STM32ADC.cpp:82:        dma_set_num_transfers(DMA1, DMA_CH1, BufLen);
STM32F1/libraries/STM32ADC/src/STM32ADC.cpp:83:        dma_enable(DMA1, DMA_CH1); // Enable the channel
STM32F1/system/libmaple/include/libmaple/sdio.h:41:#define SDIO_DMA_DEV        DMA2
STM32F1/system/libmaple/include/libmaple/sdio.h:42:#define SDIO_DMA_CHANNEL    DMA_CH4

There was no conflict with DMA2 Channel 5... but with the previous channel, 4 if i remember right

on DMA1 CH6 & CH7 may be free
on DMA2 CH3, and CH1 & 2 if SPI3 is not used

the F4 SPI ones are different, they can have 5 SPI pins .. see STM32F4/libraries/SPI/src/SPI.cpp:252

Update FSMC DMA settings for HAL STM32F1 to avoid conflict with ADC
@jmz52
Copy link
Contributor Author

jmz52 commented Feb 10, 2023

So much for code unification.
It does not look like maple has room for improvement at all, so FSMC DMA is reverted to DMA2_CH5.

Maple ADC uses DMA1_CH1 with default priority, so it will be slowed down by FSMC data transter.
SDIO is less likely to cause fire, so it is better to slow down SDIO operations than temperature measurements.
Everyone's favorite GD32 has flawed DMA controller which can't handle two concurrent data transfers, so using DMA1 for FSMC is not an option at all.

For GD32 to avoid FSMC/SDIO DMA conflicts in maple environment the #define TFT_SHARED_IO should be enabled in Configuration.h file

@jmz52 jmz52 marked this pull request as ready for review February 10, 2023 14:11
@jmz52 jmz52 requested a review from tpruvot February 10, 2023 14:12
@thinkyhead thinkyhead force-pushed the bugfix-2.1.x branch 2 times, most recently from e90c213 to 4b9bb85 Compare March 7, 2023 05:17
@thinkyhead thinkyhead force-pushed the bugfix-2.1.x branch 5 times, most recently from 1a6e93f to 724ba4b Compare March 23, 2023 19:46
thinkyhead added a commit to MarlinFirmware/Configurations that referenced this pull request Mar 27, 2023
@thinkyhead
Copy link
Member

This seems pretty safe in its current state. I will go ahead and merge this (soon) if there are no objections.

@thinkyhead thinkyhead merged commit e0132f7 into MarlinFirmware:bugfix-2.1.x Mar 27, 2023
shadow578 added a commit to shadow578/Marlin-H32 that referenced this pull request Apr 7, 2023
* [cron] Bump distribution date (2023-03-05)

* 🐛 Fix apply_power for SPINDLE_SERVO (MarlinFirmware#25465)

* 🐛 Fix Flash EEPROM for STM32G0B1CB (MarlinFirmware#25469)

* 🌐 Update Turkish language (MarlinFirmware#25447)

* [cron] Bump distribution date (2023-03-06)

* 🧑‍💻 Script to make non-accented languages

* 🌐 Update Turkish language

Followup to MarlinFirmware#25447

* [cron] Bump distribution date (2023-03-07)

* 🌐 DGUS Reloaded non-accented French (MarlinFirmware#25443)

Co-authored-by: Scott Lahteine <[email protected]>

* 🔧 Add DGUS_LCD_UI RELOADED conditions

* [cron] Bump distribution date (2023-03-08)

* ✨ Extra Z Servo Probe options (MarlinFirmware#21427)

Co-authored-by: Scott Lahteine <[email protected]>

* 🔧 Update some config.ini options

* 🔨 VSCode + Devcontainer support (MarlinFirmware#22420)

* [cron] Bump distribution date (2023-03-09)

* ✨ Z_SAFE_HOMING_POINT_ABSOLUTE (MarlinFirmware#23069)

* [cron] Bump distribution date (2023-03-10)

* ✨ BTT Octopus Max EZ 1.0, SKR 3.0 / 3.0 EZ (MarlinFirmware#25387)

BTT Octopus Max EZ V1.0 (STM32H723VE/ZE), SKR V3.0 / V3.0 EZ (STM32H723VG)

* [cron] Bump distribution date (2023-03-11)

* 🐛 Fix Anet ET4 SD_SS_PIN (MarlinFirmware#25492)

* [cron] Bump distribution date (2023-03-12)

* BTT Octopus … followup (MarlinFirmware#25495)

Followup to MarlinFirmware#25387

* ⚡️ Exit from ISR on AVR already does sei

Co-Authored-By: tombrazier <[email protected]>

* 🎨 Cosmetic stepper updates

Co-Authored-By: tombrazier <[email protected]>

* ✨ MAX7219_DEBUG_MULTISTEPPING

Co-Authored-By: tombrazier <[email protected]>

* ⚡️ Use hal_timer_t for timing vars

Co-Authored-By: tombrazier <[email protected]>

* ⚡️ Use cached la_active state

Co-Authored-By: tombrazier <[email protected]>

* ⚡️ Use AxisFlags for step_needed

Co-Authored-By: tombrazier <[email protected]>

* [cron] Bump distribution date (2023-03-13)

* ⚡️ Major shaper optimization

Co-Authored-By: tombrazier <[email protected]>

* ⚡️ Set steps_per_isr in calc_multistep_timer_interval

Co-Authored-By: tombrazier <[email protected]>

* 🔧 Expose MULTISTEPPING_LIMIT option

Co-Authored-By: tombrazier <[email protected]>

* ⚡️ Optimize speed lookup for AVR

Co-Authored-By: tombrazier <[email protected]>

* ⚡️ Update ISR cycle counts

Co-Authored-By: tombrazier <[email protected]>

* 📺 DGUS_RELOADED 1.03 (MarlinFirmware#25490)

* [cron] Bump distribution date (2023-03-14)

* 🐛 Fix Polargraph without Z (MarlinFirmware#25514)

* 🐛 Fix long filename read/report (MarlinFirmware#25509)

* 🩹 Fix IA_CREALITY float, startup (MarlinFirmware#25493)

Followup to MarlinFirmware#25440

* [cron] Bump distribution date (2023-03-15)

* 🎨 Misc. formatting

* 🎨 Misc. tramming menu cleanup (MarlinFirmware#25519)

* 🩹 Fan Menu / Status fixes

Followup to MarlinFirmware#21888

* 🩹 Fix DWIN MarlinUI Fan/E/XY (MarlinFirmware#25502)

* [cron] Bump distribution date (2023-03-16)

* 🔧 Safer default for Z_MIN_PROBE_PIN override (MarlinFirmware#25524)

Co-authored-by: Scott Lahteine <[email protected]>

* ♻️ Refactor PROBE_PT_[123]

* ♻️ Refactor UBL 'G29 J'

* [cron] Bump distribution date (2023-03-17)

* 🚸 Refinements for UBL G29 J (tilt mesh) (MarlinFirmware#25486)

* [cron] Bump distribution date (2023-03-18)

* 🔧 Optional MPC_AUTOTUNE to save 5.5 - 5.8KB

* ✨ Sovol v1.3.1 (Sovol SV06) (MarlinFirmware#25267)

* 🧑‍💻 More IntelliSense-friendly declares

* 🎨 Clean up IA_CREALITY includes (MarlinFirmware#25530)

* 🎨 Suppress warning (MarlinFirmware#25529)

* 🔧 SQUARE_WAVE_STEPPING => EDGE_STEPPING (MarlinFirmware#25526)

Co-Authored-By: Scott Lahteine <[email protected]>

* 🚸 Improve Z-Probe raise for deploy (MarlinFirmware#25498)

Co-authored-by: Scott Lahteine <[email protected]>

* 🐛 Fix LVGL / MKS WiFi long filename (MarlinFirmware#25483)

Co-authored-by: Scott Lahteine <[email protected]>

* 🔨 Fix STM32H723Vx_btt for case-sensitive (MarlinFirmware#25535)

* 🐛 Fix FYSETC Cheetah v2.0 Servo/Probe pins (MarlinFirmware#24635)

Co-authored-by: Scott Lahteine <[email protected]>

* 🐛 Prevent MPC E-permm overrun in Load Filament (MarlinFirmware#25531)

Co-authored-by: Scott Lahteine <[email protected]>

* 🚸 Fix / improve LCD_BED_TRAMMING (MarlinFirmware#25425)

Co-authored-by: Scott Lahteine <[email protected]>

* 🔧 Sanity-check PRINTCOUNTER_SAVE_INTERVAL + ESP32 I2S Exp (MarlinFirmware#25527)

Co-authored-by: Scott Lahteine <[email protected]>

* ⚡️ Smart Adaptive Multi-Stepping (MarlinFirmware#25474)

* 🚸 Temperature Variance Monitor tweaks (MarlinFirmware#23571)

Co-authored-by: Scott Lahteine <[email protected]>

* 🩹 Fix Ender 2 stock LCD (MarlinFirmware#25538)

* ⚡️ Misc. optimizations

* [cron] Bump distribution date (2023-03-19)

* ✨ REPORT_ADAPTIVE_FAN_SLOWING (MarlinFirmware#25537)

* 🩹 Fix a serial_ternary

* ✨ Z_SERVO_DEACTIVATE_AFTER_STOW (MarlinFirmware#24215)

* 🐛 Avoid step rate overflow (MarlinFirmware#25541)

* [cron] Bump distribution date (2023-03-20)

* ✨ PROBING_TOOL (MarlinFirmware#24411)

* [cron] Bump distribution date (2023-03-22)

* ✨ FILAMENT_SWITCH_AND_MOTION (MarlinFirmware#25548)

Co-authored-by: Scott Lahteine <[email protected]>

* 🧑‍💻 ExtUI::onSetPowerLoss

* [cron] Bump distribution date (2023-03-23)

* 🎨 calibration_stage => stage

* [cron] Bump distribution date (2023-03-24)

* 🩹 Reset touch screen calibration on failure (MarlinFirmware#25334)

Co-authored-by: Scott Lahteine <[email protected]>

* 🎨 TMC SPI Pins

Co-Authored-By: Martin Turski <[email protected]>

* 🎨 Pins header comments

Co-Authored-By: Martin Turski <[email protected]>

* 🎨 Wrap font includes

Co-Authored-By: Martin Turski <[email protected]>

* 🎨 LPC_SOFTWARE_SPI => SOFTWARE_SPI

Co-Authored-By: Martin Turski <[email protected]>

* 🔨 INI Updates

Co-Authored-By: Martin Turski <[email protected]>

* 🎨 Misc. fixes, cleanup

Co-Authored-By: Martin Turski <[email protected]>

* 🩹 Update TRONXY_V10 SPI_FLASH pins

* [cron] Bump distribution date (2023-03-25)

* 🩹 Fix Chitu3D V6 default probe pin (MarlinFirmware#25552)

* 🔧 Remove TVPM warning (MarlinFirmware#25551)

* 🐛 Fix MKS Gen L 2.1 MOSFET pins (MarlinFirmware#25542)

* 🩹 Refine MKS boards with a dedicated FAN port (MarlinFirmware#25567)

* 🎨 Rename FAN_PIN to FAN0_PIN (MarlinFirmware#25568)

* 📝 Fix spelling (MarlinFirmware#25563)

* [cron] Bump distribution date (2023-03-26)

* 🎨 Timer tweaks

* 🔧 Refactor endstop state config (MarlinFirmware#25574)

* ✨ AnyCubic Vyper / Vyper LCD (MarlinFirmware#25405)

* 🩹 Fix Touch Calibration first point (MarlinFirmware#25298)

* 🧑‍💻 Auto Fan / Cooler Fan updates (MarlinFirmware#25554)

* 🐛 Prevent divide-by-zero in calc_timer_interval (MarlinFirmware#25557)

* 🔧 Sanity-check for endstop inverting

Followup to MarlinFirmware#25574

* 🔧 Clarify axis disable / timeout (MarlinFirmware#25571)

* [cron] Bump distribution date (2023-03-27)

* 🔨 Fix thread-unsafe deque iteration

* 🐛 Fix AnyCubic Vyper ProcessPanelRequest

Followup to MarlinFirmware#25405

* 🎨 Suppress a type warning (MarlinFirmware#25575)

* ⚡️ Improve TFT DMA for STM32 (MarlinFirmware#25359)

* 🐛 Fix M23 long filename support (MarlinFirmware#25540)

* [cron] Bump distribution date (2023-03-28)

* 🎨 Misc. cleanup

* 🔧 Fix up WiFi options (MarlinFirmware#25586)

* 🔨 Update config.ini endstop states

Followup to MarlinFirmware#25574

* [cron] Bump distribution date (2023-03-29)

* 🔧 Impose Hephestos 2 Bed Kit requirements (MarlinFirmware#25585)

* 🎨 Remove unused ProUI : UBLValidMesh (MarlinFirmware#25591)

* 🔨 Improve Docker local tests support (MarlinFirmware#25583)

* 🔨 MarlinSimUI updates (MarlinFirmware#25589)

* [cron] Bump distribution date (2023-03-30)

* 🩹 Update Trigorilla V006 fan pin

Followup to MarlinFirmware#25568

* 🩹 Fix Ender-3 V2 with no fan

* 🐛 Fix _HAS_FAN for fan on Pin 0

* 🎨 Refine probe, more debug

* 🩹 Fix displayed mix percentages

* [cron] Bump distribution date (2023-03-31)

* 🔧  DGUS_LCD_UI selectable options

* 🔧 Fix SENSORLESS hit state error (MarlinFirmware#25604)

* 🧑‍💻 CardReader adjustments (MarlinFirmware#25611)

* [cron] Bump distribution date (2023-04-01)

* 🎨  HAS_SHAPING => HAS_ZV_SHAPING

* ✨ Fixed-Time Motion with Input Shaping by Ulendo (MarlinFirmware#25394)

Co-authored-by: Ulendo Alex <[email protected]>

* 🐛 Fix Long FIlename lookup (MarlinFirmware#25598)

* 🌐 Update Italian language (MarlinFirmware#25587)

* 🔨 Move Docker local test script

Followup to MarlinFirmware#25583

* 🩹 FT_MOTION Followup

* 🐛 Ensure root for 'M503 C'

* 🐛 Clean up DELTA babystep Z

* 🐛 INVERT_*_DIR for FT_MOTION (MarlinFirmware#25637)

* 🔧 Move DOGLCD options

* 🧑‍💻 Update pinsformat.js

* 📝 Update Ender # labels

* [cron] Bump distribution date (2023-04-07)

* 🚸 Support CoreXY without Z (MarlinFirmware#25630)

* 🎨 Apply const (MarlinFirmware#25643)

* update `pins_Aquila_X2.h` to new format

---------

Co-authored-by: thinkyhead <[email protected]>
Co-authored-by: Hans-Christian Ebke <[email protected]>
Co-authored-by: alextrical <[email protected]>
Co-authored-by: Abdullah YILMAZ <[email protected]>
Co-authored-by: albatorsssx <[email protected]>
Co-authored-by: Kurt Haenen <[email protected]>
Co-authored-by: Sion Williams <[email protected]>
Co-authored-by: Evgeniy Zhabotinskiy <[email protected]>
Co-authored-by: Keith Bennett <[email protected]>
Co-authored-by: tombrazier <[email protected]>
Co-authored-by: Neo2003 <[email protected]>
Co-authored-by: jbubik <[email protected]>
Co-authored-by: Eduard Sukharev <[email protected]>
Co-authored-by: Davide Rombolà <[email protected]>
Co-authored-by: dwzg <[email protected]>
Co-authored-by: ellensp <[email protected]>
Co-authored-by: jamespearson04 <[email protected]>
Co-authored-by: Michael Hill <[email protected]>
Co-authored-by: James Gilliland <[email protected]>
Co-authored-by: Liam Powell <[email protected]>
Co-authored-by: George Fu <[email protected]>
Co-authored-by: Piotr Paczyński <[email protected]>
Co-authored-by: Farva42 <[email protected]>
Co-authored-by: John Robertson <[email protected]>
Co-authored-by: John Lagonikas <[email protected]>
Co-authored-by: StevilKnevil <[email protected]>
Co-authored-by: FilippoR <[email protected]>
Co-authored-by: BIGTREETECH <[email protected]>
Co-authored-by: Martin Turski <[email protected]>
Co-authored-by: Giuliano Zaro <[email protected]>
Co-authored-by: Bob Kuhn <[email protected]>
Co-authored-by: Alexander Gavrilenko <[email protected]>
Co-authored-by: Andrew <[email protected]>
Co-authored-by: John Unland <[email protected]>
Co-authored-by: Chris Pepper <[email protected]>
Co-authored-by: Ulendo Alex <[email protected]>
EvilGremlin pushed a commit to EvilGremlin/Marlin that referenced this pull request Apr 8, 2023
thinkyhead pushed a commit that referenced this pull request Apr 10, 2023
thinkyhead pushed a commit to thinkyhead/Marlin that referenced this pull request May 16, 2023
EvilGremlin pushed a commit to EvilGremlin/Marlin that referenced this pull request May 17, 2023
tspiva pushed a commit to tspiva/Marlin that referenced this pull request May 25, 2023
Andy-Big pushed a commit to Andy-Big/Marlin_FB_Reborn that referenced this pull request Jul 11, 2023
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