title: How to send AT commands by UART using stm32 HAL library
body: <p>I'm trying to send AT commands to my bluetooth and wifi modules connected to my board by UART using stm32 HAL library I am using stm32CubeIDE and using C++ for my language because of the GUI library (TouchGFX) and compiling this on Windows.</p>
  
  <p>To provide the proper context I have used CubeMX to set everything up, all my pins are initialised and prior to putting these HAL functions in the program compiles and runs without errors. It's only when I add </p>
  
  <pre><code>HAL_UART(&amp;huartWifi, "AT+CWJAP=SSID,secretPassword", sizeof("AT+CWJAP=SSID,secretPassword"), HAL_MAX_DELAY);
  
  HAL_UART(&amp;huartBluetooth, "AT+NAMEfriendlyName", sizeof("AT+NAMEfriendlyName"), HAL_MAX_DELAY);
  </code></pre>
  
  <p>============= Results ================</p>
  
  <p>There are no errors per say when compiling and I do not see any runtime errors either, but it's not working, when I say it's not working using my limited tool set of remote debugging I can see that my simple experiment of changing the bluetooth module name like so:</p>
  
  <p>uint_8 command[] = "AT+NamefriendlyName";  </p>
  
  <p>is not working also tried using the return \r and \n on the end of the string. Not sure if there is something in the HAL init functions that need to be initialised? </p>
  
  <p>My expected result is the program compiles and I can pass the AT command without any issues and potentially find a callback so I can read if this was set okay or catch any errors both for this particular call but also in the future when I do advanced HTTP requests.</p>
  
  <p><strong>PLEASE SEE CODE BELOW (this code if in the int main section only of my main.cpp file)</strong></p>
  
  <pre><code>int main(void)
  {
    /* USER CODE BEGIN 1 */
  
    /* USER CODE END 1 */
  
  
    /* MCU Configuration--------------------------------------------------------*/
  
    /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
    HAL_Init();
  
    /* USER CODE BEGIN Init */
  
    /* USER CODE END Init */
  
    /* Configure the system clock */
    SystemClock_Config();
  
    /* USER CODE BEGIN SysInit */
  
    /* USER CODE END SysInit */
  
    /* Initialize all configured peripherals */
    MX_GPIO_Init();
    MX_ADC3_Init();
    MX_CRC_Init();
    MX_DCMI_Init();
    MX_ETH_Init();
    MX_I2C1_Init();
    MX_I2C3_Init();
    MX_QUADSPI_Init();
    MX_RTC_Init();
    MX_SAI2_Init();
    MX_SDMMC1_SD_Init();
    MX_SPDIFRX_Init();
    MX_SPI2_Init();
    MX_TIM3_Init();
    MX_TIM5_Init();
    MX_TIM8_Init();
    MX_TIM12_Init();
    MX_USART1_UART_Init();
    MX_USART6_UART_Init();
    /* USER CODE BEGIN 2 */
  
     uint8_t = bluetooth[] = "AT+NAME=AlienAttack\r";
     HAL_UART_Transmit(&amp;huart6, (uint8_t *)bluetooth, 
     sizeof(bluetooth),HAL_MAX_DELAY);
  
     uint8_t = wifi[] = "AT+CWJAP=SSID,secretPassword\r";
     HAL_UART_Transmit(&amp;huart1, (uint8_t *)wifi, 
     sizeof(wifi),HAL_MAX_DELAY);
  
    /* USER CODE END 2 */
  
  /* Initialise the graphical hardware */
    GRAPHICS_HW_Init();
  
    /* Initialise the graphical stack engine */
    GRAPHICS_Init();
  
  
  
    /* USER CODE BEGIN RTOS_MUTEX */
    /* add mutexes, ... */
    /* USER CODE END RTOS_MUTEX */
  
    /* USER CODE BEGIN RTOS_SEMAPHORES */
    /* add semaphores, ... */
    /* USER CODE END RTOS_SEMAPHORES */
  
    /* USER CODE BEGIN RTOS_TIMERS */
    /* start timers, add new ones, ... */
    /* USER CODE END RTOS_TIMERS */
  
    /* USER CODE BEGIN RTOS_QUEUES */
    /* add queues, ... */
    /* USER CODE END RTOS_QUEUES */
  
    /* Create the thread(s) */
    /* definition and creation of defaultTask */
    osThreadDef(defaultTask, StartDefaultTask, osPriorityNormal, 0, 4096);
    defaultTaskHandle = osThreadCreate(osThread(defaultTask), NULL);
  
    /* USER CODE BEGIN RTOS_THREADS */
    /* add threads, ... */
    /* USER CODE END RTOS_THREADS */
  
    /* Start scheduler */
    osKernelStart();
  
    /* We should never get here as control is now taken by the scheduler */
  
  
    while (1)
    {
  
  
  
    }
  
  }
  </code></pre>
  
  <p><strong>================================ UART INIT FUNCTION====================</strong></p>
  
  <pre><code>static void MX_USART6_UART_Init(void)
  {
  
    /* USER CODE BEGIN USART6_Init 0 */
  
    /* USER CODE END USART6_Init 0 */
  
    /* USER CODE BEGIN USART6_Init 1 */
  
    /* USER CODE END USART6_Init 1 */
    huart6.Instance = USART6;
    huart6.Init.BaudRate = 9600;
    huart6.Init.WordLength = UART_WORDLENGTH_8B;
    huart6.Init.StopBits = UART_STOPBITS_1;
    huart6.Init.Parity = UART_PARITY_NONE;
    huart6.Init.Mode = UART_MODE_TX_RX;
    // ORIGINAL huart6.Init.HwFlowCtl = UART_HWCONTROL_NONE;
   huart6.Init.HwFlowCtl = UART_HWCONTROL_RTS;
    huart6.Init.OverSampling = UART_OVERSAMPLING_16;
    huart6.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
    huart6.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
    if (HAL_UART_Init(&amp;huart6) != HAL_OK)
    {
      Error_Handler();
    }
    /* USER CODE BEGIN USART6_Init 2 */
  
    /* USER CODE END USART6_Init 2 */
  
  }
  </code></pre>
  
  <p><strong>==================== HAL UART INIT FUNCTION FOR WIFI ================</strong></p>
  
  <pre><code>static void MX_USART1_UART_Init(void)
  {
  
    /* USER CODE BEGIN USART1_Init 0 */
  
    /* USER CODE END USART1_Init 0 */
  
    /* USER CODE BEGIN USART1_Init 1 */
  
    /* USER CODE END USART1_Init 1 */
    huart1.Instance = USART1;
    huart1.Init.BaudRate = 115200;
    huart1.Init.WordLength = UART_WORDLENGTH_8B;
    huart1.Init.StopBits = UART_STOPBITS_1;
    huart1.Init.Parity = UART_PARITY_NONE;
    huart1.Init.Mode = UART_MODE_TX_RX;
    huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
    huart1.Init.OverSampling = UART_OVERSAMPLING_16;
    huart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
    huart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
    if (HAL_UART_Init(&amp;huart1) != HAL_OK)
    {
      Error_Handler();
    }
    /* USER CODE BEGIN USART1_Init 2 */
  
    /* USER CODE END USART1_Init 2 */
  
  }
  </code></pre>