2024-03-25 06:59 AM - last edited on 2024-04-08 05: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.
2024-03-26 03:00 AM - edited 2024-03-26 03:07 AM
2024-03-26 04: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.
2024-03-26 04:35 AM
Excellent! :thumbs_up: :beaming_face_with_smiling_eyes:
Time to mark a solution?
2024-03-26 04: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.
2024-03-26 05:02 AM - edited 2024-03-26 05: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
2024-03-26 06: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.
2024-03-26 06: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!