-
-
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
Add Emergency Parser support for STM32 #18095
Add Emergency Parser support for STM32 #18095
Conversation
Some progress on the USB side. STM32Duino offers a hook for DTR toggling (https://github.com/stm32duino/Arduino_Core_STM32/blob/master/cores/arduino/hooks.c). Essentially this allows one to define a function:
Which the user can then implement. It requires the [ststm32-common]
platform = ststm32
build_flags_usb = -DUSBCON -DDTR_TOGGLING_SEQ ... and then for each stm targeting board it is possible to import them: [env:BIGTREE_SKR_PRO]
build_flags = ${common.build_flags} ${ststm32-common.build_flags_usb} it would still be a big change to the file though. |
I have noticed that Update: This seems to be a combination of issues with multiple things on my end. As far as I can tell the BTT TFT 35 I have synchronously sends |
Okay I've just committed a new approach which hooks the The hooked function feeds the buffer into the emergency parser, and then calls the original hook function as follows: static int8_t USBD_CDC_Receive_hook(uint8_t *Buf, uint32_t *Len) {
for(uint32_t i = 0; i < *Len; i++)
emergency_parser.update(emergency_state, Buf[i]);
return USBD_CDC_Receive_original(Buf, Len);
} This is tested and works well over USB. Is anyone able to test this properly with UART (e.g. with a screen that properly supports emergency stop)? |
@rudihorn I' would like to do something similar for AGCM4, are all those functions hooks given by framework or are you doing something different? unluckly Adafruit don't want to add a virtual call to uart and I don't think they want to do something heavier on usb side.... |
@rudihorn, your My first revision of this was tied to upgrading the framework used by HAL/STM32. That review is stalled out at the moment, and isn't likely to go in right away. It won't go in until we either get a 1.9 framework through PlatformIO or some I2C issues get figured out in 1.8. At this point I would want to change the way I modified My latest revision is only for STM32F1 environments, but seems to be a better way of doing things. I'm currently waiting for feedback on that PR. If it goes in, it can that serve as a template for greater re-use in the |
@GMagician sadly and quite annoyingly it is not given by the framework, and especially the USB one is a little bit hacky. These things should be provided by the framework, and if you could get them to add it by submitting a PR that would be best. With that platform you aren't relying on adafruit, you can simply submit a PR to https://github.com/arduino/ArduinoCore-sam I believe, though you can try getting away without changing it like I did. For your platform you would probably want to override the |
@sjasonsmith it luckily turns out that I won't need to add a new flag after all as the DTR thing never worked in any case. I do however support such a change. |
not so sure: and Adafruit will not help on this.
for serial in stm32 I saw the virtual function into uart code. It's called by framework and it return tru or false if char has to be stored in buffer or not. Hence just deriving serial class is enought. Don't know what about usb, but not so easy |
@GMagician could you create a seperate issue for your thing and then we can discuss there? |
How much work is it to get this working on |
@thisiskeithb Is there any need for these two platforms as STM32 generic supports both? |
I assumed it wasn't supported yet for Marlin/Marlin/src/HAL/STM32F1/inc/SanityCheck.h Lines 28 to 30 in 6c99400
Marlin/Marlin/src/HAL/STM32_F4_F7/inc/SanityCheck.h Lines 31 to 33 in 6c99400
|
@thisiskeithb It is a bit confusing, because there are two different platform packages that can be used. I am using a BTT Pro V1.1 which has an STM32F4 chip, but uses https://github.com/stm32duino/Arduino_Core_STM32 as its platform. There are some boards which rely on https://github.com/rogerclarkmelbourne/Arduino_STM32, and this chip introduces the different HAL's for STM32F4_7 and STM32F1. I'm asking why these other HALs exist when the arduino core stm32 platform already targets both (and more!)? |
You'll have to ask @thinkyhead as that's above my paygrade 🙂 |
@rudihorn i think the F1/F4 HALs simply existed first. I don’t know if anything actually uses the F4 HAL. The goal should be to eliminate that one rather than improve it. As for these F1 HAL, many boards use it. Eliminating it—while possible—would likely be more controversial. That doesn’t mean it would be wrong, just that more care would be needed to ensure it wasn’t a feature or performance downgrade. |
The different frameworks/kernels supporting STM32 have different degrees of maturity. The Maple based https://github.com/rogerclarkmelbourne/Arduino_STM32 is the most mature if you have to deal with STM32F103 and similar but was never near to finished for the F4 processors and does not support other processors. This is still maintained, but the speed of development decreased over the last years. The 'official' https://github.com/stm32duino/Arduino_Core_STM32 is the newest, supporting all STM32 processors. We still miss some features like a 'USB-composite device for mas-storage and serial at the same time'. Also Marlins HAL-layer for this is far from perfect - it just works (mostly) (awful ADC handling, ...). But this is the future because it is constantly developed. Not as fast as we want to - because they only have one payed full time developer for that. Please don't use the adjective 'generic' if you try to talk about https://github.com/stm32duino/Arduino_Core_STM32. To make it short. |
I think I've no wayout. I checked your code and you can do what you did because of hooks/callback handled by framework. In my case I don't have any and worst, AGCM4 is samd not sam. Arduino IDE (if I didn't downloaded the wrong package) is using Adafruit framework (more recent than platformio but the same source) so...With no Adafruit help I can't do anything (interrupt handler for serial1 linked by framework and there is no way, that I know, to override it) |
There seems to be one missing line. I get the compile-error I don't know if this was intentional or by mistake, but adding the line |
@sjasonsmith @AnHardt @GMagician you could try submitting PR requests to adafruit https://github.com/adafruit/ArduinoCore-samd. @Haschtl this is a bug, best to submit a PR for this. |
Off topic: Why is the current implementation of ADC handling in the STM32-HAL crap. Arduino ADC-handling is usually done with analogRead(). Even if calling analogRead() should be currently unavoidable, it would better be done in phase tree, avoiding the additional variable. The current implementation completely fails Marlins intention to avoid analogRead() to save time. A good implementation would set up the ADCs/ADC-channels and start DMA to store the results per channel/pin in an array. Phase two would do noting. Phase three would just pick up the value from the array. Since DMA is done in the background the only remaining load for the processor would be picking up a value at any timer. That should be magnitudes faster than what we do with the AVRs not 5 to 10 times slower like that what we do now. |
I apparently need to enable EMERGENCY_PARSER to get ADVANCED_PAUSE_FEATURE working. I downloaded the latest bugfix version today, and am still unable to build because "EMERGENCY_PARSER is not yet implemented for STM32F1." Is the implementation for my hardware still under development? I'm building for an Ender-3 V2 with an SKR Mini E3 V2.0. I've got both the stock V2 display as well as a BTT TFT 3.5 E3 V3.0. Is either of these a "supported LCD controller" so I don't need the EMERGENCY_PARSER? If I enable DWIN_CREALITY_LCD (for the V2's display, which is different from previous enders) the build fails with undefined identifiers such as "'buzzer' was not declared in this scope". |
After I use the emergency stop command (M410), I must restart the machine to send the command again |
I am having the same problem as @fengbaochun When I call M410 I expect to be able to continue to send commands, but it appears marlin either crashes or hangs and I need to reset the board. |
Requirements
Description
This is some initial work that gets the emergency parser function to work on STM32. This requires patching of both the USB and the serial parsers.
Currently I have the serial emergency functionality working. This is done by creating a
MarlinSerial
class, which hooks the interrupt handler to a custom defined handler that feeds the information into the emergency parser.USB emergency parser is now also working. See comment below.
Benefits
Emergency functionality.
Related Issues
#17705