cancel
Showing results for 
Search instead for 
Did you mean: 

STM32f4 HAL library

Cl.1
Associate II

Hi, I am using the STM32F4. Now i learning to use the HAL library so i want to ensure i got the same result with and without using the HAL library but now i face some problem.

I used the HAL library to control the LED by press the button it is work.

void fnvdAss2_V2_Main(void)

{

#ifdef QUESTION_1

GPIO_PinState boButton_state; // Variable to store the state of the button

printf("Hello Cruel World\n");

 while (1)

 {

  boButton_state = HAL_GPIO_ReadPin(B1_GPIO_Port, B1_Pin);

  HAL_GPIO_WritePin(LD6_GPIO_Port, LD6_Pin, boButton_state);

 }

#endif

BUT it is not work without using the HAL library can anyone help me check what is going error in my code?

void fnvdAss2_V2_Main(void)

{

#ifdef QUESTION_1

GPIO_PinState boButton_state; // Variable to store the state of the button

printf("Hello Cruel World\n");

 while (1)

 {

  if((GPIOA->IDR & B1_Pin) != GPIO_PIN_RESET)

   {

  boButton_state = GPIO_PIN_SET;

   }

   else

   {

  boButton_state = GPIO_PIN_RESET;

   }

   return boButton_state;

  if(boButton_state != GPIO_PIN_RESET)

   {

    GPIOD->BSRR = LD6_Pin;

   }

   else

   {

    GPIOD->BSRR = LD6_Pin << 16U;

   }

 }

3 REPLIES 3
berendi
Principal

What does the return statement do in the middle of the function?

I copy from description of STM32F4xx HAL drives. By combine the READ & WRITE function to be my code to control the LED ON/OFF by press the B1 button.

GPIO_PinState HAL_GPIO_ReadPin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)

{

 GPIO_PinState bitstatus;

 /* Check the parameters */

 assert_param(IS_GPIO_PIN(GPIO_Pin));

 if((GPIOx->IDR & GPIO_Pin) != (uint32_t)GPIO_PIN_RESET)

 {

  bitstatus = GPIO_PIN_SET;

 }

 else

 {

  bitstatus = GPIO_PIN_RESET;

 }

 return bitstatus;

void HAL_GPIO_WritePin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, GPIO_PinState PinState)

{

 /* Check the parameters */

 assert_param(IS_GPIO_PIN(GPIO_Pin));

 assert_param(IS_GPIO_PIN_ACTION(PinState));

 if(PinState != GPIO_PIN_RESET)

 {

  GPIOx->BSRR = GPIO_Pin;

 }

 else

 {

  GPIOx->BSRR = (uint32_t)GPIO_Pin << 16U;

 }

berendi
Principal

Rewiev the role of the return keyword in a C textbook.