Pins tool: change pin function during runtime

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

Pins tool: change pin function during runtime

跳至解决方案
1,657 次查看
danielholala
Senior Contributor II

Hello everybody,

I'm developing firmware for a custom LPC55xx based board.

Using Pins Tool, I've configured Flexcomm3 to communicate via SPI interface with several slaves (SSEL0 - SSEL2).

Now to reset the SPI slaves, I've to pull all SPI signals to LOW (aka. GND). Otherwise, they are powered from the SPI signals (due to internal diodes that connect SPI signals to VCC) and cannot be reset.

Therefore, I'd need to provide a second configuration set for the device pins that I switch to during runtime. The second configuration set would define all pins used in the first configuration set as GPIOs with default to LOW.

How do I configure this using Pins tool?

Thanks.

Best regards,
Dan

标记 (2)
0 项奖励
1 解答
1,652 次查看
ErichStyger
Senior Contributor V

The tool has the concept of 'functional groups':

ErichStyger_0-1657098490769.png

 

Basically you can group your pins or 'functionalities' into such a group, and configure with the settings (buttons on the right) if the configuration is called during startup from main or not. So you can create to groups, for example 'useAsSPI' and 'useAsGPIO'. 'useAsSPI would be called by default, and 'useAsGPIO' would be something called at runtime.

I'm doing this kind of things for example with the I2C bus, where for a bus reset you have to use the pins in GPIO mode too. One thing you might consider is taking the code generated and use it native in your application, especially if you need to do other 'special' things.

I hope this helps,

Erich

在原帖中查看解决方案

5 回复数
1,653 次查看
ErichStyger
Senior Contributor V

The tool has the concept of 'functional groups':

ErichStyger_0-1657098490769.png

 

Basically you can group your pins or 'functionalities' into such a group, and configure with the settings (buttons on the right) if the configuration is called during startup from main or not. So you can create to groups, for example 'useAsSPI' and 'useAsGPIO'. 'useAsSPI would be called by default, and 'useAsGPIO' would be something called at runtime.

I'm doing this kind of things for example with the I2C bus, where for a bus reset you have to use the pins in GPIO mode too. One thing you might consider is taking the code generated and use it native in your application, especially if you need to do other 'special' things.

I hope this helps,

Erich

1,643 次查看
danielholala
Senior Contributor II

Hi Erich,

Thanks, your note regarding "functional groups" was very helpful. I tried it immediately and it worked. I can now switch the SPI pins to GPIO (and back to SPI) during runtime. Great.

 

What do you mean by "taking the code generated and use it native in your application"?

 

Bye
Dan

0 项奖励
276 次查看
joeatrainamp
Contributor II

Glad you solved the problem.  A sample code snippet would be great.

0 项奖励
218 次查看
danielholala
Senior Contributor II

@joeatrainamp :

When you use the Pins Tool in a project, by default your pin definitions end up in this function in pin_mux.c file 

 

void BOARD_InitPins(void);

 

and it's likely that you call this function early in your main() function (indirectly via BOARD_InitBootPins()  ).

If you use functional groups, you basically define a different pin configuration and for that configuration Pins Tool defines another init function for you which has the same name as the functional group. You can call this init function when you want to activate that pin configuration.

Hope that helps.

Best regards
Dan

0 项奖励
1,639 次查看
ErichStyger
Senior Contributor V

I mean let the tool generate the code, then copy it into my application code so I have full control over it. After that I delete the settings of the config tool.

The reasons are that I can much easier keep things in a version control system, and I had issues in the past with new config tool versions changing the code, or causing side effects. Having it 'native' in the application code let me keep in control for it. Plus I can keep the same code/module for many different MCUs supported.

If you want to see how this looks, see the code in https://github.com/ErichStyger/McuOnEclipseLibrary/blob/master/lib/src/McuShellUart.c which does the UART muxing and configuration, based on the config tools. BTW, this allows to use MCUs from different vendors too, as you see in above example.

I hope this helps.