3
\$\begingroup\$

I've been using STM32 ARM microcontrollers for more than two years, the best way of coding that I've found is using the CMSIS and ST std peripheral libraries, and I think it has no restrictions or any main disadvantages.

But now I want to try HAL drivers to compare with std libraries. It seems that ST has introduced a tool, "STM32CubeMX", that could graphically configure the microcontroller and generate code based on HAL drivers. My problem is that I don't want to use their graphical tool to generate my codes, but after many searches on the Internet I couldn't find any tutorial or example to use HAL drivers directly in my project.

However ST has an user manual that describes anything about HAL drivers, but unfortunately it is about 1300 pages and I think it takes me much time to read.

I really prefer a short instruction or maybe a simple example project for using GPIOs.

\$\endgroup\$

closed as too broad by laptop2d, ThreePhaseEel, pipe, Dmitry Grigoryev, jonk Mar 3 '17 at 11:55

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • \$\begingroup\$ If you want to start out simple and you have already programmed STM32 it should not be any problem to extract the relevant parts (clock config, GPIO config, GPIO control) without working through those 1300 pages... \$\endgroup\$ – JimmyB Feb 14 '17 at 13:59
5
\$\begingroup\$

If you do not want to use the STM32CubeMX code generator tool but still need simple example projects then you should use the STM32Cubexx firmware examples that are available for all STM32 series.

Each link has an application note called "STM32Cube firmware examples for STM32xx Series" (example for F4) which is actually a huge table listing all the available examples for all the development boards.

Also there are the user manual for each series called " Description of STM32xxxx HAL drivers" (example for F4). Yes, this is the 900 - 1300 pages long document but you do not have to read through all of it, just open up the relevant part. There are a short step by step guide at the beginning of every chapter. In case of the GPIO Generic Driver:

27.2.2 How to use this driver

  1. Enable the GPIO AHB clock using the following function: __HAL_RCC_GPIOx_CLK_ENABLE().
  2. Configure the GPIO pin(s) using HAL_GPIO_Init().
    • Configure the IO mode using "Mode" member from GPIO_
    • InitTypeDef structure Activate Pull-up, Pull-down resistor using "Pull" member from GPIO_InitTypeDef structure.
    • In case of Output or alternate function mode selection: the speed is configured through "Speed" member from GPIO_InitTypeDef structure.
    • In alternate mode is selection, the alternate function connected to the IO is configured through "Alternate" member from GPIO_InitTypeDef structure.
    • Analog mode is required when a pin is to be used as ADC channel or DAC output.
    • In case of external interrupt/event selection the "Mode" member from GPIO_InitTypeDef structure select the type (interrupt or event) and the corresponding trigger event (rising or falling or both).
  3. In case of external interrupt/event mode selection, configure NVIC IRQ priority mapped to the EXTI line using HAL_NVIC_SetPriority() and enable it using HAL_NVIC_EnableIRQ().
  4. To get the level of a pin configured in input mode use HAL_GPIO_ReadPin().
  5. To set/reset the level of a pin configured in output mode use HAL_GPIO_WritePin()/HAL_GPIO_TogglePin().
  6. To lock pin configuration until next reset use HAL_GPIO_LockPin().
  7. During and just after reset, the alternate functions are not active and the GPIO pins are configured in input floating mode (except JTAG pins).
  8. The LSE oscillator pins OSC32_IN and OSC32_OUT can be used as general purpose (PC14 and PC15, respectively) when the LSE oscillator is off. The LSE has priority over the GPIO function.
  9. The HSE oscillator pins OSC_IN/OSC_OUT can be used as general purpose PH0 and PH1, respectively, when the HSE oscillator is off. The HSE has priority over the GPIO function.

Based on this you can look up the function descriptions as well in this document and if you really need an example then there are the already mentioned STM32Cubexx example packages and you did not have to use the STM32CubeMX tool at all.

\$\endgroup\$
3
\$\begingroup\$

Visit STM32 discovery .net

The guy who runs this has developed several standard and HAL libraries with examples and tutorials for each library. Also you can discuss your questions in the comment section for each library. Does not use the Cube tool. The libraries can be added in environments like Keil and Coocox.

\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged or ask your own question.