Table of Contents

Lab05 - Hardware initialization

This exercise deals with NUCLEO I/O initialization of the User LED and User Button. The exercise also deals with the usage of these resources. The definition of the LED and Button connection is described in the board user manual. Go ahead and download the files for this lab session lab5.zip.

Task:

LED

The NUCLEO board contains a green LED controlled by the CPU. The LED is connected to the CPU pin XX of the port GPIOXX. The output needs to be initialized through the MX_GPIO_Init function as depicted below. The initialization should be placed into static void MX_GPIO_Init(void) function of the project.

  GPIO_InitTypeDef GPIO_InitStruct = {0};

  /* GPIO Ports Clock Enable */
  __HAL_RCC_GPIOC_CLK_ENABLE();
  __HAL_RCC_GPIOH_CLK_ENABLE();
  __HAL_RCC_GPIOA_CLK_ENABLE();
  __HAL_RCC_GPIOB_CLK_ENABLE();

  /*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(LD2_GPIO_Port, LD2_Pin, GPIO_PIN_RESET);

  /*Configure GPIO pin : LD2_Pin */
  GPIO_InitStruct.Pin = LD2_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  HAL_GPIO_Init(LD2_GPIO_Port, &GPIO_InitStruct);

Button

The configuration for button B1 (BLUE BUTTTON), is also inside function static void MX_GPIO_Init(void).

  /*Configure GPIO pin : B1_Pin */
  GPIO_InitStruct.Pin = B1_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;
  GPIO_InitStruct.Pull = GPIO_PULLUP;
  HAL_GPIO_Init(B1_GPIO_Port, &GPIO_InitStruct);

The initialization of the input pin is performed in the same way as the output pin with a small difference: GPIO_InitStruct.Mode.

PIN Reading and Writing Functions

The function HAL_GPIO_ReadPin (B1_GPIO_Port, B1_Pin); will read the the status of B1 button. In order to write to a pin, the function HAL_GPIO_WritePin(GPIOA,LD2_Pin,GPIO_PIN_SET); is used

Lab Tasks