Array for GPIO pins
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-03-25 6:59 AM - last edited on ‎2024-04-08 5:19 AM by Amel NASRI
Hello,
I am new to STM world.
I am trying to make an array of GPIO pin in this format {{PIN1_GPIO_PORT, PIN1_PIN}.....
This would then be used in custom function so I can dynamically access this pins.
How should I declare such array and how would i use them with HAL_GPIO_WRITEPIN function.
Main use of this is to select SPI slave to communicate with.
Thanks in advance
Solved! Go to Solution.
- Labels:
-
STM32Cube MCU Packages
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-03-26 3:00 AM - edited ‎2024-03-26 3:07 AM
@Huzo wrote:structured array
To be pedantic, arrayed structures :face_savoring_food:
A complex system designed from scratch never works and cannot be patched up to make it work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-03-26 4:22 AM
Managed to reduce PORT status reading for expander code part by half by using sturctures. If there were 12 or 15 expanders that would be insane code reduction. From around 96 to 120 command to just 8 commands in for loop.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-03-26 4:35 AM
Excellent! :thumbs_up: :beaming_face_with_smiling_eyes:
Time to mark a solution?
A complex system designed from scratch never works and cannot be patched up to make it work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-03-26 4:51 AM
Not sure. As I am using STM32CubeIDE (CubeMX) I dont know where to write declaration of the custom function and where to write it (Code generation and /*USER CODE BEGIN*/, /*USER CODE END*/.
Is it /*USER CODE BEGON PFP*/ to declare them and /*USER CODE BEGIN 4*/ to realise them.
Sorry for dumb questions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-03-26 5:02 AM - edited ‎2024-03-26 5:44 AM
That's really a separate question - so would be better in a new thread.
Are you talking about the "wrapper" function I suggested?
That would be just your user code - exactly the same as any other code that you write yourself.
So, yes, it would go within /* USER CODE xxx */ brackets wherever seems appropriate with the rest of your user code.
Addendum
"PFP" is in the "Private function prototypes" section:
/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
/* USER CODE BEGIN PFP */
/* USER CODE END PFP */
so, yes, that would be a good place to put your function prototypes if you're not going to share them via a header file.
And "User Code 4" is outside the body of main(), and after it - so that would be a reasonable place to put your function definitions:
/* USER CODE BEGIN 4 */
/* USER CODE END 4 */
There is also "User Code 0" outside the body of main(), and before it.
Or you might want to have a separate source file and header.
You might want to make the "wrapper" function inline ...
Again, these are really just general C things - nothing specific to STM32
A complex system designed from scratch never works and cannot be patched up to make it work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-03-26 6:11 AM
Great. For general I know how to make custom functions. Code generated by STM32CubeIde is still a little bit unkown for me (where to put what). I will explore some more and if needed will start a new one. but in general this topic is resolved.
Thank you for the advice.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-03-26 6:50 AM
@Huzo wrote:Code generated by STM32CubeIde is still a little bit unkown for me (where to put what).
For generated code, the tools just put it where they need it - you don't have to worry about that part!
A complex system designed from scratch never works and cannot be patched up to make it work.

- « Previous
-
- 1
- 2
- Next »