Hi,
I am writing a sketch - for the Arduino Giga - which needs to be fast but I need often to execute the pinMode function. Due to this need, my sketch executes slowly. I know there’s the chance to manipulate Arduino’s registers instead of using the pinMode function but there is no documentation on how to do that. Please, help me. It’s very important! Thank you.
You do not say which board you are using
If you are using an AVR processor on a board such as a Uno or classic Nano then take a look at https://docs.arduino.cc/hacking/software/PortManipulation
NOTE the OP updated his initial post after I had replied here
Sorry… You’re right. I have just updated my topic.
That is not a polite thing to have done because it makes a nonsense of my reply but at least we know now know which board you are using
Search: arduino port manipulation
About 1,950,000 results
Search: manipulate Arduino register
About 2,030,000
You did not try. I need to read better.
You need to look at ST's document RM0399 - Reference Manual for STM32H747XI
See chapter 12, page 568 / 3556.
And how many of those links that you found refer to the Arduino Giga?
Sorry but I also changed the title of the thread so it is even more clear. So that people who know little about this processor don't waste their time.
None. (walking it backwards, looking for stm32 info)
Thank you John. I find really difficult reading a datasheet. Can you please help me to understand?
Why do you need to call pinMode() so often? As long as you're using a pin for only input or output and not both, you only need to call pinMode().
The device datasheet is the authoritative source for this information. So, if you're going to continue with this activity / hobby, you might as well get used to reading them. It helps to also look at the source code for the pinMode(), digitialRead(), and digital Write() functions. There you can see how the information from the datasheet is put into practice.
It is a very strange... Usually the pinMode() uses once at start of the code.
I agree, but to be fair, a bad place to start is on page 568 of 3556.
I'm amazed my little tablet didn't choke on it.
This. Given the amazing even bewildering flexibility of the GPIO pins on this microprocessor, raiding examining the source code would probably be faster.
Not something one can learn and then just know like the UNO's PORT, PIN and DDR in seven minutes from an instructable.
@thestarboyguy please share anything you cobble together if indeed it is you who does. Figure it out.
a7
A valid reason can be reading and writing the same pin on an external device. What that device is is another question (a data bus can be an example).
Alas, @thestarboyguy has shared neither the application nor the code.
Another thing I've done is use the standard pinMode() function to set the pin's mode (again there are very few applications where this needs to be done more than once). That makes things simpler as setting the mode is typically the most complicated task. Then, I implement the pin read or write function my self. I bypass the normal "safety checks" that digitalRead() & digitalWrite() provide and just access the pin using the appropriate register / bit mask. Bypassing the checks makes it much faster.
I'm fully aware of that
I also always find it strange when people state something like "it needs to be fast"; that is so relative.
setting pins for deep sleep.
a7
Do you? On AVRs, one switches from input to output mode to simulate open-drain configurations, but the ST processor on the Giga has a native open-drain mode. (it doesn't seem to be supported by Arduino, though.)
Hi!
Is there a mapping document between the addresses in STM32H745 and the physical pins on the Arduino Giga?
Hi!
To be able to do direct port manipulation on the Arduino Giga, you need the mapping between the address+bit and the physical pins. I went to the source code in Github and found the mapping in “ArduinoCore-mbed-main\ArduinoCore-mbed-main\variants\GIGA\variant.cpp”, but it can probably be found in more places. For the digital pins 0-76, I have defined the following constants:
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Define the Arduino Giga direct port addresses
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#define D0_PHYS_PIN 0 // pin 0
#define D0_REG GPIOB // pin 0
#define D0_PIN (1UL<<7) // pin 0
#define D1_PHYS_PIN 1 // pin 1
#define D1_REG GPIOA // pin 1
#define D1_PIN (1UL<<9) // pin 1
#define D2_PHYS_PIN 2 // pin 2
#define D2_REG GPIOA // pin 2
#define D2_PIN (1UL<<3) // pin 2
#define D3_PHYS_PIN 3 // pin 3
#define D3_REG GPIOA // pin 3
#define D3_PIN (1UL<<2) // pin 3
#define D4_PHYS_PIN 4 // pin 4
#define D4_REG GPIOJ // pin 4
#define D4_PIN (1UL<<8) // pin 4
#define D5_PHYS_PIN 5 // pin 5
#define D5_REG GPIOA // pin 5
#define D5_PIN (1UL<<7) // pin 5
#define D6_PHYS_PIN 6 // pin 6
#define D6_REG GPIOD // pin 6
#define D6_PIN (1UL<<13) // pin 6
#define D7_PHYS_PIN 7 // pin 7
#define D7_REG GPIOB // pin 7
#define D7_PIN (1UL<<4) // pin 7
#define D8_PHYS_PIN 8 // pin 8
#define D8_REG GPIOB // pin 8
#define D8_PIN (1UL<<8) // pin 8
#define D9_PHYS_PIN 9 // pin 9
#define D9_REG GPIOB // pin 9
#define D9_PIN (1UL<<9) // pin 9
#define D10_PHYS_PIN 10 // pin 10
#define D10_REG GPIOK // pin 10
#define D10_PIN (1UL<<1) // pin 10
#define D11_PHYS_PIN 11 // pin 11
#define D11_REG GPIOJ // pin 11
#define D11_PIN (1UL<<10) // pin 11
#define D12_PHYS_PIN 12 // pin 12
#define D12_REG GPIOJ // pin 12
#define D12_PIN (1UL<<11) // pin 12
#define D13_PHYS_PIN 13 // pin 13
#define D13_REG GPIOH // pin 13
#define D13_PIN (1UL<<6) // pin 13
#define D14_PHYS_PIN 14 // pin 14
#define D14_REG GPIOG // pin 14
#define D14_PIN (1UL<<14) // pin 14
#define D15_PHYS_PIN 15 // pin 15
#define D15_REG GPIOC // pin 15
#define D15_PIN (1UL<<7) // pin 15
#define D16_PHYS_PIN 16 // pin 16
#define D16_REG GPIOH // pin 16
#define D16_PIN (1UL<<13) // pin 16
#define D17_PHYS_PIN 17 // pin 17
#define D17_REG GPIOI // pin 17
#define D17_PIN (1UL<<9) // pin 17
#define D18_PHYS_PIN 18 // pin 18
#define D18_REG GPIOD // pin 18
#define D18_PIN (1UL<<5) // pin 18
#define D19_PHYS_PIN 19 // pin 19
#define D19_REG GPIOD // pin 19
#define D19_PIN (1UL<<6) // pin 19
#define D20_PHYS_PIN 20 // pin 20
#define D20_REG GPIOB // pin 20
#define D20_PIN (1UL<<11) // pin 20
#define D21_PHYS_PIN 21 // pin 21
#define D21_REG GPIOH // pin 21
#define D21_PIN (1UL<<4) // pin 21
#define D22_PHYS_PIN 22 // pin 22
#define D22_REG GPIOJ // pin 22
#define D22_PIN (1UL<<12) // pin 22
#define D23_PHYS_PIN 23 // pin 23
#define D23_REG GPIOG // pin 23
#define D23_PIN (1UL<<13) // pin 23
#define D24_PHYS_PIN 24 // pin 24
#define D24_REG GPIOG // pin 24
#define D24_PIN (1UL<<12) // pin 24
#define D25_PHYS_PIN 25 // pin 25
#define D25_REG GPIOJ // pin 25
#define D25_PIN (1UL<<0) // pin 25
#define D26_PHYS_PIN 26 // pin 26
#define D26_REG GPIOJ // pin 26
#define D26_PIN (1UL<<14) // pin 26
#define D27_PHYS_PIN 27 // pin 27
#define D27_REG GPIOJ // pin 27
#define D27_PIN (1UL<<1) // pin 27
#define D28_PHYS_PIN 28 // pin 28
#define D28_REG GPIOJ // pin 28
#define D28_PIN (1UL<<15) // pin 28
#define D29_PHYS_PIN 29 // pin 29
#define D29_REG GPIOJ // pin 29
#define D29_PIN (1UL<<2) // pin 29
#define D30_PHYS_PIN 30 // pin 30
#define D30_REG GPIOK // pin 30
#define D30_PIN (1UL<<3) // pin 30
#define D31_PHYS_PIN 31 // pin 31
#define D31_REG GPIOJ // pin 31
#define D31_PIN (1UL<<3) // pin 31
#define D32_PHYS_PIN 32 // pin 32
#define D32_REG GPIOK // pin 32
#define D32_PIN (1UL<<4) // pin 32
#define D33_PHYS_PIN 33 // pin 33
#define D33_REG GPIOJ // pin 33
#define D33_PIN (1UL<<4) // pin 33
#define D34_PHYS_PIN 34 // pin 34
#define D34_REG GPIOK // pin 34
#define D34_PIN (1UL<<5) // pin 34
#define D35_PHYS_PIN 35 // pin 35
#define D35_REG GPIOJ // pin 35
#define D35_PIN (1UL<<5) // pin 35
#define D36_PHYS_PIN 36 // pin 36
#define D36_REG GPIOK // pin 36
#define D36_PIN (1UL<<6) // pin 36
#define D37_PHYS_PIN 37 // pin 37
#define D37_REG GPIOJ // pin 37
#define D37_PIN (1UL<<6) // pin 37
#define D38_PHYS_PIN 38 // pin 38
#define D38_REG GPIOJ // pin 38
#define D38_PIN (1UL<<7) // pin 38
#define D39_PHYS_PIN 39 // pin 39
#define D39_REG GPIOI // pin 39
#define D39_PIN (1UL<<14) // pin 39
#define D40_PHYS_PIN 40 // pin 40
#define D40_REG GPIOE // pin 40
#define D40_PIN (1UL<<6) // pin 40
#define D41_PHYS_PIN 41 // pin 41
#define D41_REG GPIOK // pin 41
#define D41_PIN (1UL<<7) // pin 41
#define D42_PHYS_PIN 42 // pin 42
#define D42_REG GPIOI // pin 42
#define D42_PIN (1UL<<15) // pin 42
#define D43_PHYS_PIN 43 // pin 43
#define D43_REG GPIOI // pin 43
#define D43_PIN (1UL<<10) // pin 43
#define D44_PHYS_PIN 44 // pin 44
#define D44_REG GPIOG // pin 44
#define D44_PIN (1UL<<10) // pin 44
#define D45_PHYS_PIN 45 // pin 45
#define D45_REG GPIOI // pin 45
#define D45_PIN (1UL<<13) // pin 45
#define D46_PHYS_PIN 46 // pin 46
#define D46_REG GPIOH // pin 46
#define D46_PIN (1UL<<15) // pin 46
#define D47_PHYS_PIN 47 // pin 47
#define D47_REG GPIOB // pin 47
#define D47_PIN (1UL<<2) // pin 47
#define D48_PHYS_PIN 48 // pin 48
#define D48_REG GPIOK // pin 48
#define D48_PIN (1UL<<0) // pin 48
#define D49_PHYS_PIN 49 // pin 49
#define D49_REG GPIOE // pin 49
#define D49_PIN (1UL<<4) // pin 49
#define D50_PHYS_PIN 50 // pin 50
#define D50_REG GPIOI // pin 50
#define D50_PIN (1UL<<11) // pin 50
#define D51_PHYS_PIN 51 // pin 51
#define D51_REG GPIOE // pin 51
#define D51_PIN (1UL<<5) // pin 51
#define D52_PHYS_PIN 52 // pin 52
#define D52_REG GPIOK // pin 52
#define D52_PIN (1UL<<2) // pin 52
#define D53_PHYS_PIN 53 // pin 53
#define D53_REG GPIOG // pin 53
#define D53_PIN (1UL<<7) // pin 53
#define D54_PHYS_PIN 54 // pin 54
#define D54_REG GPIOI // pin 54
#define D54_PIN (1UL<<5) // pin 54
#define D55_PHYS_PIN 55 // pin 55
#define D55_REG GPIOH // pin 55
#define D55_PIN (1UL<<8) // pin 55
#define D56_PHYS_PIN 56 // pin 56
#define D56_REG GPIOA // pin 56
#define D56_PIN (1UL<<6) // pin 56
#define D57_PHYS_PIN 57 // pin 57
#define D57_REG GPIOJ // pin 57
#define D57_PIN (1UL<<9) // pin 57
#define D58_PHYS_PIN 58 // pin 58
#define D58_REG GPIOI // pin 58
#define D58_PIN (1UL<<7) // pin 58
#define D59_PHYS_PIN 59 // pin 59
#define D59_REG GPIOI // pin 59
#define D59_PIN (1UL<<6) // pin 59
#define D60_PHYS_PIN 60 // pin 60
#define D60_REG GPIOI // pin 60
#define D60_PIN (1UL<<4) // pin 60
#define D61_PHYS_PIN 61 // pin 61
#define D61_REG GPIOH // pin 61
#define D61_PIN (1UL<<14) // pin 61
#define D62_PHYS_PIN 62 // pin 62
#define D62_REG GPIOG // pin 62
#define D62_PIN (1UL<<11) // pin 62
#define D63_PHYS_PIN 63 // pin 63
#define D63_REG GPIOH // pin 63
#define D63_PIN (1UL<<11) // pin 63
#define D64_PHYS_PIN 64 // pin 64
#define D64_REG GPIOH // pin 64
#define D64_PIN (1UL<<10) // pin 64
#define D65_PHYS_PIN 65 // pin 65
#define D65_REG GPIOH // pin 65
#define D65_PIN (1UL<<9) // pin 65
#define D66_PHYS_PIN 66 // pin 66
#define D66_REG GPIOA // pin 66
#define D66_PIN (1UL<<1) // pin 66
#define D67_PHYS_PIN 67 // pin 67
#define D67_REG GPIOD // pin 67
#define D67_PIN (1UL<<4) // pin 67
#define D68_PHYS_PIN 68 // pin 68
#define D68_REG GPIOC // pin 68
#define D68_PIN (1UL<<6) // pin 68
#define D69_PHYS_PIN 69 // pin 69
#define D69_REG GPIOI // pin 69
#define D69_PIN (1UL<<0) // pin 69
#define D70_PHYS_PIN 70 // pin 70
#define D70_REG GPIOI // pin 70
#define D70_PIN (1UL<<1) // pin 70
#define D71_PHYS_PIN 71 // pin 71
#define D71_REG GPIOI // pin 71
#define D71_PIN (1UL<<2) // pin 71
#define D72_PHYS_PIN 72 // pin 72
#define D72_REG GPIOI // pin 72
#define D72_PIN (1UL<<3) // pin 72
#define D73_PHYS_PIN 73 // pin 73
#define D73_REG GPIOC // pin 73
#define D73_PIN (1UL<<1) // pin 73
#define D74_PHYS_PIN 74 // pin 74
#define D74_REG GPIOB // pin 74
#define D74_PIN (1UL<<12) // pin 74
#define D75_PHYS_PIN 75 // pin 75
#define D75_REG GPIOD // pin 75
#define D75_PIN (1UL<<3) // pin 75
I have not tested all of them, but quite many. If you find an error, please correct me. To use the constants for a pin, in this example the pin D2, use the following syntax:
void loop() {
// Enter the pins you want to test
// Switch on, wait 1 s, switch off and wait one second more...
// Switch on...
D2_REG->ODR |= D2_PIN;
delay(1000);
// Switch off...
D2_REG->ODR &= ~D2_PIN;
delay(1000);
}