GPIO Output Configuration

Hi,

I am trying to make my own custom Luos module to control fans. I tried to see my modules with pyluos and everything works well, except that I can’t get any output from the GPIOs that I want to use.

Is there any GPIO Output configuration to initialise them before using “HAL_GPIO_Write_Pin” ?

I use SD/PB5, CK/PB3, TIM3.3/PB0 pins.

Thanks !

1 Like

Hi Augustin,

Indeed it seems that your GPIO is not configured as output.
I suppose you are using an L0 to prototype your fan module, so you are using an STM32 MCU for your project.
In the ST world there is a tool called CubeMX that allow to setup complete MCU configuration for a project using graphical interface. This tool generate the C code that configure your entire MCU.

If you get one of our project you probably already have a .ioc file. This file is the CubeMX configuration project. Also you probably have some files such as adc.c or gpio.c on your src folder of your project, those are CubeMX generated code files containing MCU configuration.

If you only have to put your GPIO as output you can make it manually into your module init.
Here is an example for your PB5 pin, you can make it the same way for the others :

// For PB5
#define FAN1_PIN GPIO_PIN_5
#define FAN1_PORT GPIOB
#include "gpio.h"

void module_init(void)
{
    // ********************* Gpio configuration ****************************
    GPIO_InitTypeDef GPIO_InitStruct = {0};
    // GPIO Ports Clock Enable
    __HAL_RCC_GPIOB_CLK_ENABLE();
    // Set a safe pin state just in case
    HAL_GPIO_WritePin(FAN1_PORT, FAN1_PIN, GPIO_PIN_SET);
    // configure your pin using the GPIO_InitTypeDef structure
    GPIO_InitStruct.Pin = FAN1_PIN;
    GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
    GPIO_InitStruct.Pull = GPIO_NOPULL;
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
    HAL_GPIO_Init(FAN1_PORT, &GPIO_InitStruct);
    /**
     * Now your GPIO is ready to be used as output
     * You can do your other init things and use it as you want
     */
}

If you want to use your fan using PWM I advise you to use CubeMX configuration.

2 Likes

It works well ! Thanks !

2 Likes