Comments (9)
there is a (problematic!!!!) dummy in every variant/maplexyz/variant.h
timschuerewegen released a VERY RECOMMENDED patch (not only for SPI but far more compatibility and bugfixes) in the arduino forum thread #1361.
With this patch, the following lines are added to (some!!!) variant.h:
#define digitalPinToPort(P) ( PIN_MAP[P].gpio_device )
#define digitalPinToBitMask(P) ( BIT(PIN_MAP[P].gpio_bit) )
#define portOutputRegister(port) ( &(port->regs->ODR) )
#define portInputRegister(port) ( &(port->regs->IDR) )
In my opinion, I would set these #defines globally (arduino.h or wirish.h?), because they are not device dependent.
from arduino_stm32.
I'm not sure that simply implementing these direct hardware access macros is going to be a one size fits all solution
Alexey (@hiddenpilot) did some to speed up access to hardware with new API commands for digitalWriteFast etc, which I put into a branch of the repo, but this isn't entirely the same as those macros
The problem is that the way the STM32 port registers work isn't consistent with the way the AVR port registers work, so as well as defining these macros, I think each library needs a custom implementation of how to use the macros.
Rather than writing these macros to just work with one library, we need to consider all the libraries that use direct access to the hardware e.g. OneWire
Otherwise we will create a solution which only works for one library
I agree however that the macros need to be in the core. But having broken the core several times, by applying fixes that people have sent me, I have become cautious about changing things that I can't easily test, or changes without details
The best way to manage change is to use git and for anyone to clone the repo, make changes, get a load of people to test them, and then do a pull request back into this repo
from arduino_stm32.
The maple mini variant now has definitions for ..
#define digitalPinToPort(P) ( PIN_MAP[P].gpio_device )
#define digitalPinToBitMask(P) ( BIT(PIN_MAP[P].gpio_bit) )
#define portOutputRegister(port) ( &(port->regs->ODR) )
#define portInputRegister(port) ( &(port->regs->IDR) )
Which were added by Tim as part of his SPI patch, but I think are actually used by the ILI9341 library (LCD display)
Ideally Tim should have added this as part of a different patch, but its done now, and people are using it, so I'll leave it.
I'm not sure why Tim didn't stick them in the core somewhere.
I'll probably move them to somewhere like wirish.h or some other file that is included all the time.
At the moment I don't think I have any way to test these macros, as I don't have that display, so can't use that Library (though I have now ordered a LCD display from eBay).
I think that the OneWire library may use some or all of those macros, so if I get time I'll see if I can test it, as I have some OneWire thermometer DS18B20's
Re: the Other macros not implemented by Tim.
#define portSetRegister(pin)
#define portClearRegister(pin)
#define portToggleRegister(pin)
#define portModeRegister(pin)
#define portConfigRegister(pin)
It shouldn't be too hard to write macros for these, as the SetRegister is a fixed offset from the other register addresses (same for the Clear and Toggle), But I'll need to check for Mode and Config, and with Mode and Config I can't see how any AVR code would work without modification, as its unlikely the the STM mode register operates in the same way as the STM32 mode register etc
from arduino_stm32.
Looking at the list of pins compatibility macros you initially posted, I've just realized that some of these are not available on either the AVR or SAM variants of the Arduino.
e.g. Set and Reset registers are not in either as far as I can see.
This appears to be the list defined for AVR
#define digitalPinToPort(P) ( pgm_read_byte( digital_pin_to_port_PGM + (P) ) )
#define digitalPinToBitMask(P) ( pgm_read_byte( digital_pin_to_bit_mask_PGM + (P) ) )
#define digitalPinToTimer(P) ( pgm_read_byte( digital_pin_to_timer_PGM + (P) ) )
#define analogInPinToBit(P) (P)
#define portOutputRegister(P) ( (volatile uint8_t *)( pgm_read_word( port_to_output_PGM + (P))) )
#define portInputRegister(P) ( (volatile uint8_t *)( pgm_read_word( port_to_input_PGM + (P))) )
#define portModeRegister(P) ( (volatile uint8_t *)( pgm_read_word( port_to_mode_PGM + (P))) )
and SAM its
#define digitalPinToPort(P) ( g_APinDescription[P].pPort )
#define digitalPinToBitMask(P) ( g_APinDescription[P].ulPin )
//#define analogInPinToBit(P) ( )
#define portOutputRegister(port) ( &(port->PIO_ODSR) )
#define portInputRegister(port) ( &(port->PIO_PDSR) )
#define digitalPinHasPWM(P) ( g_APinDescription[P].ulPWMChannel != NOT_ON_PWM || g_APinDescription[P].ulTCChannel != NOT_ON_TIMER )
Without knowing why you want these non-arduino macros for, its not even practical to even test them.
I want to get OneWire working, but I think I'll do it within the confines of just implementing the core Arduino macros, i.e those available on AVR.
from arduino_stm32.
Sorry for such a long time there were no replies. I just got back from the Chinese new year holiday.
It's my mistake about the list of pins compatibility macros I initially posted. I rechecked the official list, it is exactly as same as you posted.
from arduino_stm32.
Hi taoyuan
Belayed Happy New Year ;--)
No worries.
I have put all the normal Pin Compatibility macros into the variant.h for all supported variants. I may be be able to move them into the core some time, but I'm not sure yet.
I have ported the OneWire library, but the way that OneWire used the pin macros could not be completely replicated for STM32 for various reasons
But its OK for some libraries.
Anyway, the project is still moving forwards and I have additions and bug fixes quite often from various contributors, which is good for everyone
Cheers
Roger
from arduino_stm32.
We're also missing the digitalPinHasPWM macro for Marlin 3D Printer firmware on STM32F1.
It seems to be implemented here: https://github.com/redbear/STM32-Arduino/blob/master/arduino/cores/RedBear_Duo/firmware/user/inc/Arduino.h
Could this be copied? Maybe this is a dumb question.
from arduino_stm32.
That example is based on HAL, this is libmaple core.
from arduino_stm32.
Thanks @stevstrong ... but I didn’t know there was a difference. 😂
from arduino_stm32.
Related Issues (20)
- Not Compiling HOT 2
- timer setup interfering with serial communication HOT 1
- DAC HOT 4
- How can I make 'STM32F103C8T6' DIY? help me. HOT 3
- USB Serial echos characters into the input (i.e. keyboard) HOT 15
- Support for Arduino IDE 2.х HOT 7
- PIN_MAP and boardPWMpins tables mismatch HOT 1
- Arduino IDE "Access Denied" on Uploading Sketch HOT 3
- Can't connect to target after flashing generic_boot20_pc13.bin using j-flash HOT 1
- Software reset HOT 1
- How to change default 42/72/128 MHz to 8/16Mhz HOT 2
- Add CH32F103 HOT 2
- Compilation error Problem with sketch that used library Arduino_STM32 HOT 1
- dfu upload failed on macOS + PlatformIO because cannot reset upload port HOT 5
- Writing String to EEPROM HOT 3
- EEPROM donot work on STM32F103C6(32k)
- ‘MCU basic current’ increases after PWM operation. help me. HOT 25
- Wire.h and Wire slave.h using in same program not working HOT 2
- Is 'STM32F103C8' 'digitalWrite' and 'digitalRead' possible in FAST mode? HOT 10
- Is any type a persistent storage available for STM32F4 ?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from arduino_stm32.