STM32F446ZCT6 GPIO Pin Pull up/down configuration

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 8.

Moderator: Benj

Post Reply
karthickefy
Posts: 74
Joined: Thu Nov 30, 2017 3:21 am
Has thanked: 4 times
Been thanked: 9 times
Contact:

STM32F446ZCT6 GPIO Pin Pull up/down configuration

Post by karthickefy »

Hi BenJ,
I need your help about , how to configure the ARM MCU's GPIO pin Input Pull up or Pull Down configuration through Flowcode. Below is the GPIO configuration details. One of our project, we need to make the GPIO(PC14) Input pin must be in Pull up mode to measure the signal. Can you please advice how to config this pull up mode GPIO input pin?

Below is the details from STM32F446ZCT6 datasheet page no 37.
"3.36 General-purpose input/outputs (GPIOs)
Each of the GPIO pins can be configured by software as output (push-pull or open-drain, with or without pull-up or pull-down), as input (floating, with or without pull-up or pull-down) or as peripheral alternate function. Most of the GPIO pins are shared with digital or analog alternate functions. All GPIOs are high-current-capable and have speed selection to better manage internal noise, power consumption and electromagnetic emission."

https://www.st.com/content/ccc/resource ... 141306.pdf

Also please advice Active High and Active low represent teh Switch Input corect. It is not related to GPIO Pull up and pull down correct? please advice.

Thanks
Karthick.
Attachments
Page 37.PNG
Page 37.PNG (57.83 KiB) Viewed 6561 times
active low.PNG
active low.PNG (30.33 KiB) Viewed 6561 times

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: STM32F446ZCT6 GPIO Pin Pull up/down configuration

Post by LeighM »

Hi,

Unfortunately, the pull-up, pull-down feature of the ST ARM IO is not directly implemented within Flowcode.
However, it can be done with some C code, but there is a complication.
Flowcode access to IO usually also sets up any port/pin direction.
For the ST ARM implementation we use the HAL library functions, but these do not provide the ability to leave the pull up/down status unchanged.
The result of all this is that, if you cannot use external pull up resistors and absolutely must use the internal, then you will need to use C code to initially setup the pull up state, then only use C code (not Flowcode functions) to subsequently read the port pin.
This can be C code within a Flowcode macro that is then always used to read the pin input.
Let me know if you need help with the C code.

Regarding your second question, no, the Active High/Low does not relate to the pull up/down.
The Active polarity determines the input voltage that sets the switch state to true.

And, due to the previous comments about the pull-ups, you would not be able to use the Switch component if you set the internal pull-ups via C code. (Using the component would turn them off again)

Best all round is to just add a resistor, if that is at all possible :D

Leigh

karthickefy
Posts: 74
Joined: Thu Nov 30, 2017 3:21 am
Has thanked: 4 times
Been thanked: 9 times
Contact:

Re: STM32F446ZCT6 GPIO Pin Pull up/down configuration

Post by karthickefy »

Hi Leigh,
Thanks for your explanation. But unfortunately, our boards don't have the external pull up resistor in the PC14 GPIO pin. We use this PC14 port as a digital input. Attached is our flowcode and can you please help to add the C code to activate the internal pull-up resistor in only PC14 Port (SOA_DI)?
I understand that I must use the Input component instead of the switch component correct?
Thanks for your continuous support. :D

Karthick
Attachments
SCCAR ADC Test rev1.2.fcfx
(75.99 KiB) Downloaded 155 times

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: STM32F446ZCT6 GPIO Pin Pull up/down configuration

Post by LeighM »

Hi Karthick,

Attached is the updated version.
I have moved the reading of SOA_DI into a macro/function such that only the C code is executed on the target build.
This is done with the correct selection of a new property SIMULATION, which needs to be set to NO before you do a build to target.
(There is a way to do this automatically, but I've not done that to keep things simple for now)
You will not be able to use an Input or Switch component in the target build, these will remove the pull-up.
The pull-up is set at the start of the program, via some C code.

Leigh
Attachments
SCCAR ADC Test rev1.3.fcfx
(77.29 KiB) Downloaded 166 times

karthickefy
Posts: 74
Joined: Thu Nov 30, 2017 3:21 am
Has thanked: 4 times
Been thanked: 9 times
Contact:

Re: STM32F446ZCT6 GPIO Pin Pull up/down configuration

Post by karthickefy »

HI LeighM,
Thanks for your help. But it looks like it doesn't work. So I have made only for SOA_DI part and read the PC14 pin status through UART to avoid the confusion. As per my understanding, we need to define the variable in C Code and the variable must be connected to UART Send number component. Then only the UART gets the C Code port read data. Can you please guide me on how to define the variable for C Code port response with Pull up ON through UART? I will follow the same for other pin's.

Thanks,
Karthick.
Attachments
SOD_DI test.fcfx
SOA_DI only
(9.88 KiB) Downloaded 158 times

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: STM32F446ZCT6 GPIO Pin Pull up/down configuration

Post by LeighM »

See attached
This reads the pin state into the variable sod_di
Hope it helps.
Are you also saying that you need to turn the pull-up on, read, and then turn off again?
Leigh
Attachments
SOD_DI test.fcfx
(10.19 KiB) Downloaded 154 times

karthickefy
Posts: 74
Joined: Thu Nov 30, 2017 3:21 am
Has thanked: 4 times
Been thanked: 9 times
Contact:

Re: STM32F446ZCT6 GPIO Pin Pull up/down configuration

Post by karthickefy »

Hi Leighm,
Accually not necesary. Just need to pull up during Measurment and after that no need to pull down or high impedence. I have compile this code and the response is always "1". When I connect teh PC14 port to GND still status is "1". and I connect the PC14 to 3V still status is "1" . Status not chnage. Can you please have a look. thanks.

Karthick.

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: STM32F446ZCT6 GPIO Pin Pull up/down configuration

Post by LeighM »

Hi Karthick
Are you using your own PCB, or are you using an ST Nucleo board?

karthickefy
Posts: 74
Joined: Thu Nov 30, 2017 3:21 am
Has thanked: 4 times
Been thanked: 9 times
Contact:

Re: STM32F446ZCT6 GPIO Pin Pull up/down configuration

Post by karthickefy »

Hi LeighM,
I'm using our own board and this step always shows low even PC14 port goes high thorugh other switch circuit in my board.
Even I have ST Nucleo board in my hand. I tested with Nucleo with the attached simple program in the same port configuration and it also measures "0" always. I pull down the PC14 pin to Gnd still the measurment is "0" and I pull up the PC14 pin to 3V and still the port status is "0".

Is there any issues with the PORTC in our flow code? please help to check.

Note: I have updated the Flowcode via Help -> Check for updates

Below are the pictures of our boards and Nucleo board and UART screen shot.

Karthick.
Attachments
Nucleo PC14 fail.PNG
Nucleo PC14 fail.PNG (152.83 KiB) Viewed 6451 times
Cont-Nucleo board.jpg
Cont-Nucleo board.jpg (135.44 KiB) Viewed 6451 times
SOD_DI test.fcfx
(8.68 KiB) Downloaded 144 times

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: STM32F446ZCT6 GPIO Pin Pull up/down configuration

Post by LeighM »

I think the issue is due to PC14 and 15 being related to the LSE.
I recall that on Nucleo boards some jumpers need changing to switch out the oscillator components.
If the input isn’t working on your board either, then it looks like some config is missing, but I’m not sure what yet.
None of this relates to the new C code, I suspect PC14 and 15 won’t work with standard Flowcode Input components or code either.
Unless you want to check that?

karthickefy
Posts: 74
Joined: Thu Nov 30, 2017 3:21 am
Has thanked: 4 times
Been thanked: 9 times
Contact:

Re: STM32F446ZCT6 GPIO Pin Pull up/down configuration

Post by karthickefy »

Hi Leighm,
Yes. I understand that the Nucleo board has the crystal OSC on the PC14 and PC15. But on my board, this port (PC14) is used as DI (Digital Input). Can you please guide me to solve this issues?

Because currently I cannot sense the SOA_DI signal, because my board doesn't have the external pullup resistor on PC14 :(

Karthick.
Attachments
SOA_DI.PNG
SOA_DI.PNG (52.31 KiB) Viewed 6444 times

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: STM32F446ZCT6 GPIO Pin Pull up/down configuration

Post by LeighM »

Yes, what I meant was that the pins PC14 and PC15 are not working properly as inputs because the 446 device uses them for the low speed clock.
It looks like this isn't fully disabled by default.
I'm still looking into how to fully disable the clock and setup the pins as inputs (i.e. all the register configurations required)
but have not yet found the solution.

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: STM32F446ZCT6 GPIO Pin Pull up/down configuration

Post by LeighM »

Hi Karthick,

Add this code into a C icon at the start of your program ...

Code: Select all


    // Enable Power clock
    __PWR_CLK_ENABLE();
 
    // Enable access to Backup domain
    HAL_PWR_EnableBkUpAccess();
 
    // Reset Backup domain
    __HAL_RCC_BACKUPRESET_FORCE();
    __HAL_RCC_BACKUPRESET_RELEASE();
 
    // Disable access to Backup domain
    HAL_PWR_DisableBkUpAccess();
 
    // Disable LSI and LSE clocks
    RCC_OscInitTypeDef RCC_OscInitStruct;
    RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI | RCC_OSCILLATORTYPE_LSE;
    RCC_OscInitStruct.PLL.PLLState   = RCC_PLL_NONE;
    RCC_OscInitStruct.LSIState       = RCC_LSI_OFF;
    RCC_OscInitStruct.LSEState       = RCC_LSE_OFF;
    HAL_RCC_OscConfig(&RCC_OscInitStruct);

ps. You will still also need the C code for the pull-up and pin reading that I gave you previously

karthickefy
Posts: 74
Joined: Thu Nov 30, 2017 3:21 am
Has thanked: 4 times
Been thanked: 9 times
Contact:

Re: STM32F446ZCT6 GPIO Pin Pull up/down configuration

Post by karthickefy »

Hi LeighM,
Thanks for your great support always.
I'm really sorry to say this still PC14 is not working and status always read "0". Now I have try to test the PORTC13 (removed teh RTC OSC disable code) with your pull up C code and it is working fine. I have measured the voltage on PC13 port it measured around 2.77 VDC. It clearly shows that the internal Pull Up resistor is ON and your code "GPIOC->PUPDR |= ((1) << (13 * 2U));" is working fine with PC13.

But it doesn't work for the PC14 even after add your below code.

Karthick.
Attachments
SOD_DI test.fcfx
(10.99 KiB) Downloaded 100 times
PC13.PNG
PC13.PNG (881.84 KiB) Viewed 6417 times

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: STM32F446ZCT6 GPIO Pin Pull up/down configuration

Post by LeighM »

I tested the code on a Nucleo64 F446RE
On the board you have are there any links to change and components to remove to connect the header to PC14/15 instead of the oscillator?

edit: from the Nucleo 144 datasheet ...
LSE not used:
PC14 and PC15 are used as GPIOs instead of low-speed clock.
The configuration must be:
SB144 and SB145 ON
R37 and R38 removed

karthickefy
Posts: 74
Joined: Thu Nov 30, 2017 3:21 am
Has thanked: 4 times
Been thanked: 9 times
Contact:

Re: STM32F446ZCT6 GPIO Pin Pull up/down configuration

Post by karthickefy »

Hi LeighM,
Yes. In my Nucleo-F446ZE board, SB144 is OFF and there is no any connection between the SB144 to CN11 pin 25. After I soldered the Short in SB144 now I can access the PC14 Port from CN11 and it is working fine. Even it works with just "GPIOC->PUPDR |= ((1) << (14 * 2U));" C code. No need to add the RTC OSC disable Code. It was my mistake and I didn't see this SB144 open in my Nucleo Board.
Now I have tested with My project board and it is working fine as I expected. I think no need RTC OSC disable code for my board too.

Thankyou very much for your kind help LeighM. :D :D :D

Karthick.
Attachments
PC14.PNG
PC14.PNG (1.03 MiB) Viewed 6382 times

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: STM32F446ZCT6 GPIO Pin Pull up/down configuration

Post by LeighM »

Great, thanks for the update :D

Post Reply