Loading...
 

Zephyr project on STM32

   Zephyr Workbench, a VSCode extension to manage Zephyr on STM32.
It enables users to easily create, develop, and debug Zephyr applications.
Main features:
  • Install host dependencies.
  • Import toolchain and SDK.
  • Create, configure, build and manage apps.
  • Debug STM32.
You can directly download it from the VSCode marketplace
For more details, visit the Zephyr Workbench

System Workbench for STM32


Help with UART Receive Interrupt

Hello, I am using the Nucelo-F446RE Dev Kit and am learning how to do a UART Receive Interrupt. I run the code but when I enter a character in the Terminal window I don’t see it getting to the ISR.

Here is my code:
/**
******************************************************************************
* @file main.c
* @author Ac6
* @version V1.0
* @date 01-December-2013
* @brief Default main function.
******************************************************************************

  • /

  1. include
  2. include
  3. include
  4. include “stm32f4xx.h”
  5. include “stm32f4xx_hal_rcc.h”
  6. include “stm32f4xx_nucleo.h”
  7. include “FreeRTOS.h”
  8. include “task.h”
  9. include “queue.h”
  10. include “timers.h”
  11. include “string.h”
  12. include “cmsis_os.h”

  1. ifdef USE_SEMIHOSTING

extern void initialise_monitor_handles(); // used for semihosting

  1. endif


uint8_t rx_buffer100;

UART_HandleTypeDef huart2;

  1. define TRUE 1
  2. define FALSE 0
  3. define AVAILABLE TRUE
  4. define NON_AVAILABLE FALSE
  5. define NOT_PRESSED FALSE
  6. define PRESSED TRUE



// function prototypes
static void prvHardwareSetup(void);
static void GPIO_Init(void);
static void USART2_UART_Init(void);
void Error_Handler(void);
void debugPrintln(UART_HandleTypeDef *huart, char _out[]);

void debugPrintln(UART_HandleTypeDef *huart, char _out[]);
void debugPrint(UART_HandleTypeDef *huart, char _out[]);
void USART2_IRQHandler(void);
uint8_t UART_ACCESS_KEY = AVAILABLE;







char usr_msg 250;

uint8_t button_status_flag = NOT_PRESSED;


int main(void)
{
// Firmware is Hardware Abstraction Layer

prvHardwareSetup();

  1. ifdef USE_SEMIHOSTING

initialise_monitor_handles();
printf(“hello world\n”);

  1. endif



sprintf(usr_msg, “UART Receive Interrupt \r\n”);
debugPrintln(&huart2, usr_msg );

for(;;);
}


static void prvHardwareSetup(void)
{
GPIO_Init();
USART2_UART_Init();
}




static void GPIO_Init(void)
{
GPIO_InitTypeDef gpio_uart_pins = {0}; // zero each member
// PA2 is TX and PA3 is RX

// 1. Enable the UART2 & GPIOA Peripheral Clock
__HAL_RCC_GPIOA_CLK_ENABLE(); // stm32f4xx_hal_rcc.h
__HAL_RCC_GPIOC_CLK_ENABLE();
__HAL_RCC_GPIOH_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();

__HAL_RCC_USART2_CLK_ENABLE();

gpio_uart_pins.Pin = GPIO_PIN_2 | GPIO_PIN_3; // found in stm32f4xx_hal_gpio.h
gpio_uart_pins.Mode = GPIO_MODE_AF_PP; // found in stm32f4xx_hal_gpio.h
gpio_uart_pins.Pull = GPIO_PULLUP;
gpio_uart_pins.Alternate = GPIO_AF7_USART2;
HAL_GPIO_Init(GPIOA, &gpio_uart_pins);

GPIO_InitTypeDef gpio_led = {0};
gpio_led.Pin = GPIO_PIN_5;
gpio_led.Mode = GPIO_MODE_OUTPUT_PP;
gpio_led.Pull = GPIO_NOPULL;
gpio_led.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOA, &gpio_led);

GPIO_InitTypeDef gpio_button = {0};
gpio_button.Pin = GPIO_PIN_13;
gpio_button.Mode = GPIO_MODE_INPUT;
gpio_button.Pull = GPIO_NOPULL;
gpio_button.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOC, &gpio_button);

}



static void USART2_UART_Init(void)
{
memset(&huart2,0, sizeof(huart2));
huart2.Instance = USART2;
huart2.Init.BaudRate = 115200;
huart2.Init.WordLength = UART_WORDLENGTH_8B;
huart2.Init.StopBits = UART_STOPBITS_1;
huart2.Init.Parity = UART_PARITY_NONE;
huart2.Init.Mode = UART_MODE_TX_RX;
huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart2.Init.OverSampling = UART_OVERSAMPLING_16;

//*** setup interrupt on UART2 for Nucleo-F446RE Board ***
HAL_UART_Receive_IT(&huart2, rx_buffer, 100);
HAL_NVIC_SetPriority(USART2_IRQn, 5, 0);
HAL_NVIC_EnableIRQ(USART2_IRQn);
//*********************************************************
if (HAL_UART_Init(&huart2) != HAL_OK)
{
Error_Handler();
}

__HAL_UART_ENABLE(&huart2);

}
//----- USART2 ISR ----
void USART2_IRQHandler(void)
{
// Check if
HAL_UART_IRQHandler(&huart2);
}
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{

HAL_UART_Receive_IT(&huart2, rx_buffer, 100);

}

void debugPrintln(UART_HandleTypeDef *huart, char _out[])
{
HAL_UART_Transmit(huart, (uint8_t *) _out, strlen(_out), 10);
char newline2 = “\r\n”;
HAL_UART_Transmit(huart, (uint8_t *) newline, 2, 10);

HAL_UART_GetState(huart);

}
void debugPrint(UART_HandleTypeDef *huart, char _out[])
{
// wait until transmit reg is empty
while(__HAL_UART_GET_FLAG(huart, UART_FLAG_TC) != SET);


HAL_UART_Transmit(huart, (uint8_t *) _out, strlen(_out), 10);
}

void Error_Handler(void)
{
/* USER CODE BEGIN Error_Handler_Debug */
/* User can add his own implementation to report the HAL error return state */

/* USER CODE END Error_Handler_Debug */
}

I’m not sure I have things set up correctly. Can anyone look over my code and see if I have things set up right. I want to write an application to print a menu and then have the User enter in a selection.

Thank you,
Joe

 

Newest Forum Posts

  1. reservation car service Seattle by Jamesprede, 2025-05-01 10:06
  2. Last day: drone bonus by Danielrug, 2025-04-19 16:55
  3. SPI on Nucleo_STMH533RE by higginsa1, 2025-03-25 07:37
  4. SPI on Nucleo_STMH533RE by royjamil, 2025-03-23 11:31
  5. SPI on Nucleo_STMH533RE by higginsa1, 2025-03-23 09:33
  6. Configuring DMA for ADC in SW? by sam.hodgson, 2025-03-04 12:58
  7. Insightful Perspectives on This Subject by davidsycle, 2025-03-04 05:45
  8. Build a project in "release" mode by info@creosrl.it, 2025-02-20 18:12
  9. Build a project in "release" mode by info@creosrl.it, 2025-02-20 17:05
  10. Build a project in "release" mode by tang, 2025-02-20 10:36

Last-Modified Blogs