-
Notifications
You must be signed in to change notification settings - Fork 33
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
GPIO mode mappings are wrong. Never get remapped to the SPL definitions. Needs rework #119
Comments
For example: In pin_function
for mode from GD_PIN_MODE_GET we get our bit packed gpio info and extract the mode, and then GD_GPIO_MODE turns that into one of the following
Which is a const int. But gpio_init expects this to be one of the following:
For one API, or:
For the other API. But we never map our int to one of these, and instead we are passing the plain int as the mode. Same thing for speed. We should just use the SPL defines here directly to remap these back, similar to how it was done in gpio_clock_enable, no? |
Agreeing very much. This legacy thing that was carried over from the initial core needs to be reworked. I'm a bit skeptical though that it can be done completely without a PeripheralPins.h/.c, after all, the different chips all have different available pins, but using the pure GD32 SPL would expose them all equally, even ones not existing in the package. |
Yes. I could hack something together, but I'm looking for some advice on the best/cleanest/preferred way for it to be done. I'm not sure the answer. While I'm at it, if there is consistency with the chip lines (which is doubtful - but maybe), I may redo the defines to avoid directly ifdef-ing individual chips and do something along the lines of an API V1.0/API V2.0 define instead. It would clean up the code a little, but is a relatively minor change. If it is unwanted I won't though. To be upfront, my main motivation is to ultimately get this to work with Marlin Firmware. Since Creality quietly began shipping motherboards with GD32 mcus, users are left with a less optimized firmware for this chip. (ie. Slower clocks, unsupported mcu features, etc). I would love to be able to use native chip features, since there appears to be an ever-growing list of these chips showing up in 3d printer motherboards. These chips have their upsides and downsides compared to STM32, but so far we haven't been able to tap into any of the upsides. |
Looking through the GPIO mapping and functions, it appears we have tried to abstract the functions away from the hardware registers, but haven't properly mapped back to them. Rather, we are calling the SPL gpio_init function from pin_function, but passing it variables that are still mapped to the abstraction when it is expecting the actual hardware defined bits. It seems that setting/changing GPIO modes won't be working correctly as is.
Since we don't have a HAL library that we are working with here, we really shouldn't abstract away much at all. There are two different GPIO mode APIs used in the SPL (depending on the specific chip) that need to be sorted, but we can either use the SPL header definitions directly here, or alternatively use switch methods in pin_function (and any place else) to remap these bits back to the proper SPL register definitions. This will have to happen anywhere we call SPL functions, so if there are too many cases - we might want to find a better way??
The text was updated successfully, but these errors were encountered: