/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file : main.c
* @brief : Main program body
******************************************************************************
* @attention
*
* Copyright (c) 2024 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include <string.h>
#include <stdio.h>
#include "stdint.h"
#include "stdbool.h"
#include "init_params.h"
// Function prototypes
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_USART1_UART_Init(void);
static void MX_USART2_UART_Init(void);
void run_pos_authentication(void);
void clear_buffer(void);
void ReceiveATResponse(unsigned char* buffer, size_t buffer_size);
void blinking(uint8_t count);
void get_status(void);
void check_status(void);
void Serial_print(char* command);
uint8_t calculate_crc16(uint8_t *data, size_t length);
uint8_t calculateBCC(uint8_t *data, size_t length);
UART_HandleTypeDef huart1;
UART_HandleTypeDef huart2;
uint16_t crc16_lookup_table[CRC16_TABLE_SIZE] = {
0x0000, 0x1189, 0x2312, 0x329b, 0x4624, 0x57ad, 0x6536, 0x74bf,
0x8c48, 0x9dc1, 0xaf5a, 0xbed3, 0xca6c, 0xdbe5, 0xe97e, 0xf8f7,
0x1081, 0x0108, 0x3393, 0x221a, 0x56a5, 0x472c, 0x75b7, 0x643e,
0x9cc9, 0x8d40, 0xbfdb, 0xae52, 0xdaed, 0xcb64, 0xf9ff, 0xe876,
0x2102, 0x308b, 0x0210, 0x1399, 0x6726, 0x76af, 0x4434, 0x55bd,
0xad4a, 0xbcc3, 0x8e58, 0x9fd1, 0xeb6e, 0xfae7, 0xc87c, 0xd9f5,
0x3183, 0x200a, 0x1291, 0x0318, 0x77a7, 0x662e, 0x54b5, 0x453c,
0xbdcb, 0xac42, 0x9ed9, 0x8f50, 0xfbef, 0xea66, 0xd8fd, 0xc974,
0x4204, 0x538d, 0x6116, 0x709f, 0x0420, 0x15a9, 0x2732, 0x36bb,
0xce4c, 0xdfc5, 0xed5e, 0xfcd7, 0x8868, 0x99e1, 0xab7a, 0xbaf3,
0x5285, 0x430c, 0x7197, 0x601e, 0x14a1, 0x0528, 0x37b3, 0x263a,
0xdecd, 0xcf44, 0xfddf, 0xec56, 0x98e9, 0x8960, 0xbbfb, 0xaa72,
0x6306, 0x728f, 0x4014, 0x519d, 0x2522, 0x34ab, 0x0630, 0x17b9,
0xef4e, 0xfec7, 0xcc5c, 0xddd5, 0xa96a, 0xb8e3, 0x8a78, 0x9bf1,
0x7387, 0x620e, 0x5095, 0x411c, 0x35a3, 0x242a, 0x16b1, 0x0738,
0xffcf, 0xee46, 0xdcdd, 0xcd54, 0xb9eb, 0xa862, 0x9af9, 0x8b70,
0x8408, 0x9581, 0xa71a, 0xb693, 0xc22c, 0xd3a5, 0xe13e, 0xf0b7,
0x0840, 0x19c9, 0x2b52, 0x3adb, 0x4e64, 0x5fed, 0x6d76, 0x7cff,
0x9489, 0x8500, 0xb79b, 0xa612, 0xd2ad, 0xc324, 0xf1bf, 0xe036,
0x18c1, 0x0948, 0x3bd3, 0x2a5a, 0x5ee5, 0x4f6c, 0x7df7, 0x6c7e,
0xa50a, 0xb483, 0x8618, 0x9791, 0xe32e, 0xf2a7, 0xc03c, 0xd1b5,
0x2942, 0x38cb, 0x0a50, 0x1bd9, 0x6f66, 0x7eef, 0x4c74, 0x5dfd,
0xb58b, 0xa402, 0x9699, 0x8710, 0xf3af, 0xe226, 0xd0bd, 0xc134,
0x39c3, 0x284a, 0x1ad1, 0x0b58, 0x7fe7, 0x6e6e, 0x5cf5, 0x4d7c,
0xc60c, 0xd785, 0xe51e, 0xf497, 0x8028, 0x91a1, 0xa33a, 0xb2b3,
0x4a44, 0x5bcd, 0x6956, 0x78df, 0x0c60, 0x1de9, 0x2f72, 0x3efb,
0xd68d, 0xc704, 0xf59f, 0xe416, 0x90a9, 0x8120, 0xb3bb, 0xa232,
0x5ac5, 0x4b4c, 0x79d7, 0x685e, 0x1ce1, 0x0d68, 0x3ff3, 0x2e7a,
0xe70e, 0xf687, 0xc41c, 0xd595, 0xa12a, 0xb0a3, 0x8238, 0x93b1,
0x6b46, 0x7acf, 0x4854, 0x59dd, 0x2d62, 0x3ceb, 0x0e70, 0x1ff9,
0xf78f, 0xe606, 0xd49d, 0xc514, 0xb1ab, 0xa022, 0x92b9, 0x8330,
0x7bc7, 0x6a4e, 0x58d5, 0x495c, 0x3de3, 0x2c6a, 0x1ef1, 0x0f78
};
int main(void)
{
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
MX_USART1_UART_Init();
MX_USART2_UART_Init();
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_SET);
check_status(); //Check Dispenser Status
blinking(2);
while (1)
{
if (Dispenser_control == false){
run_pos_authentication();
}
clear_buffer();
get_status();
HAL_Delay(500);
}
}
void check_status(){
HAL_UART_Transmit(&huart1, (uint8_t*)ENQ_POL, sizeof(ENQ_POL), T_Out);
//HAL_UART_Transmit(&huart2, (uint8_t*)ENQ_POL, sizeof(ENQ_POL), T_Out); //debug
Serial_print((uint8_t*)ENQ_POL);
ReceiveATResponse(response_buffer, 1); // receive First char
HAL_UART_Transmit(&huart2, (uint8_t*)response_buffer, 1, T_Out); //debug
HAL_Delay(200);
HAL_UART_Transmit(&huart1, (uint8_t*)ENQ_SEL, sizeof(ENQ_SEL), T_Out);
HAL_UART_Transmit(&huart2, (uint8_t*)ENQ_SEL, sizeof(ENQ_SEL), T_Out); //debug
while(ack0_received == false){
// Receive ACK_0
ReceiveATResponse(response_buffer, 2); // receive First 5 char to identify if Dispenser POS is already unlocked or not
if (response_buffer[0] == 0x10 && response_buffer[1] == 0x30){
ack0_received = true;
}
else {
ack0_received = false;
HAL_UART_Transmit(&huart1, (uint8_t*)ENQ_SEL, sizeof(ENQ_SEL), T_Out);
}
}
ack0_received = false;
HAL_UART_Transmit(&huart1, (uint8_t*)ENQ_POL, sizeof(ENQ_POL), T_Out);
HAL_UART_Transmit(&huart2, (uint8_t*)ENQ_POL, sizeof(ENQ_POL), T_Out); //debug
ReceiveATResponse(response_buffer, 5); // receive First 5 char to identify if Dispenser POS is already unlocked or not
HAL_UART_Transmit(&huart2, (uint8_t*)response_buffer, 5, T_Out); //debug
//HAL_Delay(100);
if (response_buffer[3] == 0x30 && response_buffer[4] == 0x30){
Dispenser_control = false;
}
else if (response_buffer[3] == 0x36 && response_buffer[4] == 0x30){
Dispenser_control = true;
}
else if (response_buffer[3] == 0x36 && response_buffer[4] == 0x31){
Dispenser_control = true;
}
else if (response_buffer[3] == 0x36 && response_buffer[4] == 0x32){
Dispenser_control = true;
}
else if (response_buffer[3] == 0x36 && response_buffer[4] == 0x35){
Dispenser_control = true;
}
else if (response_buffer[3] == 0x36 && response_buffer[4] == 0x37){
Dispenser_control = true;
}
else {
Dispenser_control = false;
}
if (Dispenser_control == true){
HAL_UART_Transmit(&huart1, (uint8_t*)ACK_1, sizeof(ACK_1), T_Out);
HAL_UART_Transmit(&huart2, (uint8_t*)ACK_1, sizeof(ACK_1), T_Out); // debug
HAL_UART_Transmit(&huart2, (uint8_t*)msg2, sizeof(msg2), T_Out); //debug
}
else {
HAL_UART_Transmit(&huart2, (uint8_t*)msg1, sizeof(msg1), T_Out); //debug
}
}
////// main ends here ////////
void get_status(){
// get_status:
// Start Select sequence
HAL_UART_Transmit(&huart1, (uint8_t*)ENQ_SEL, sizeof(ENQ_SEL), T_Out);
// Receive ACK_0
ReceiveATResponse(response_buffer, sizeof(ACK_0));
while (response_buffer[0] != 0x10 && response_buffer[1] != 0x30){
clear_buffer();
// Start Select sequence
HAL_UART_Transmit(&huart1, (uint8_t*)ENQ_SEL, sizeof(ENQ_SEL), T_Out);
// Receive ACK_0
ReceiveATResponse(response_buffer, sizeof(ACK_0));
}
clear_buffer();
HAL_Delay(500);
// Send request Status Message
HAL_UART_Transmit(&huart1, (uint8_t*)Req_status, sizeof(Req_status), T_Out);
// Receive ACK_1
ReceiveATResponse(response_buffer, sizeof(ACK_1));
while (response_buffer[0] != 0x10 && response_buffer[1] != 0x31){
clear_buffer();
// Start Select sequence
HAL_UART_Transmit(&huart1, (uint8_t*)Req_status, sizeof(Req_status), T_Out);
// Receive ACK_1
ReceiveATResponse(response_buffer, sizeof(ACK_1));
}
clear_buffer();
HAL_Delay(500);
// Send EOT
HAL_UART_Transmit(&huart1, &EOT, sizeof(EOT), T_Out);
HAL_Delay(500);
// Poll the Status Data here
HAL_UART_Transmit(&huart1, (uint8_t*)ENQ_POL, sizeof(ENQ_POL), T_Out);
// Receive Status Data here
ReceiveATResponse(response_buffer, status_len);
if (response_buffer[3] == 0x36 && response_buffer[4] == 0x31){
condition = response_buffer[5];
//f_vol[] array with elements from response_buffer
f_vol[0] = response_buffer[6];
f_vol[1] = response_buffer[7];
f_vol[2] = response_buffer[8];
f_vol[3] = response_buffer[9];
f_vol[4] = '.';
f_vol[5] = response_buffer[10];
f_vol[6] = response_buffer[11];
// price_flag with element from response_buffer
price_flag = response_buffer[12];
// price array with element from response_buffer
price[0] = response_buffer[13];
price[1] = response_buffer[14];
price[2] = response_buffer[15];
price[3] = '.';
price[4] = response_buffer[16];
// amount array with element from response_buffer
amount[0] = response_buffer[17];
amount[1] = response_buffer[18];
amount[2] = response_buffer[19];
amount[3] = response_buffer[20];
amount[4] = response_buffer[21];
amount[5] = '.';
amount[6] = response_buffer[22];
// Nozzle #
Nozzle_Num = response_buffer[23];
/// Sending Price
HAL_UART_Transmit(&huart2, (uint8_t*)m_price, sizeof(m_price), T_Out);
HAL_UART_Transmit(&huart2, (uint8_t*)price, sizeof(price), T_Out);
HAL_UART_Transmit(&huart2, (uint8_t*)tab, sizeof(tab), T_Out);
/// Sending Fuel Volume
HAL_UART_Transmit(&huart2, (uint8_t*)m_vol, sizeof(m_vol), T_Out);
HAL_UART_Transmit(&huart2, (uint8_t*)f_vol, sizeof(f_vol), T_Out);
HAL_UART_Transmit(&huart2, (uint8_t*)tab, sizeof(tab), T_Out);
/// Sending Amount
HAL_UART_Transmit(&huart2, (uint8_t*)m_amount, sizeof(m_amount), T_Out);
HAL_UART_Transmit(&huart2, (uint8_t*)amount, sizeof(amount), T_Out);
HAL_UART_Transmit(&huart2, (uint8_t*)EOL, sizeof(EOL), T_Out);
}
clear_buffer();
}
void blinking(uint8_t count){
for (int i = 0; i<count; i++){
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_RESET);
HAL_Delay(750);
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_SET);
HAL_Delay(750);
}
}
void run_pos_authentication()
{
start_again:
// Send ENQ_POL
HAL_UART_Transmit(&huart1, (uint8_t*)ENQ_POL, sizeof(ENQ_POL), T_Out);
if (debug ==true) {HAL_UART_Transmit(&huart2, (uint8_t*)ENQ_POL, sizeof(ENQ_POL), T_Out);} // debug port monitoring
// Receive Text 1 here
ReceiveATResponse(response_buffer, text_1_length);
HAL_UART_Transmit(&huart2, (uint8_t*)response_buffer, text_1_length, T_Out); //debug
if (debug ==true) {HAL_UART_Transmit(&huart2, (uint8_t*)response_buffer, text_1_length, T_Out);} // debug port monitoring
while (response_buffer[0] != STX)
{
//HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_RESET);
HAL_Delay(200);
//HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_SET);
clear_buffer(); // clear response_buffer for reuse
HAL_UART_Transmit(&huart1, (uint8_t*)ENQ_POL, sizeof(ENQ_POL), T_Out);
if (debug ==true) {HAL_UART_Transmit(&huart2, (uint8_t*)ENQ_POL, sizeof(ENQ_POL), T_Out);}
ReceiveATResponse(response_buffer, text_1_length);
HAL_UART_Transmit(&huart2, (uint8_t*)"0000000000", sizeof("0000000000"), T_Out); //debug
HAL_UART_Transmit(&huart2, (uint8_t*)response_buffer, text_1_length, T_Out); //debug
}
HAL_UART_Transmit(&huart2, (uint8_t*)"Text_1 Received", sizeof("Text_1 Received"), T_Out); //debug
//HAL_UART_Transmit(&huart1, &response_buffer, text_1_length, T_Out);
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_SET);
if (response_buffer[0] == STX)
{
for (int i = 0; i < 6; i++)
{
text1[i] = response_buffer[i + 3];
}
uint8_t crc_code = calculate_crc16(text1, sizeof(text1) / sizeof(text1[0]));
uint8_t byte1 = crc_code & 0x0F; // Extract lower nibble
uint8_t byte2 = (crc_code >> 4) & 0x0F; // Extract upper nibble
byte1 = (byte1 < 10) ? byte1 + '0' : byte1 + ('A' - 10);
byte2 = (byte2 < 10) ? byte2 + '0' : byte2 + ('A' - 10);
uint8_t text2_temp[] = {0x40, 0x51, 0x30, 0x30, byte2, byte1, ETX};
uint8_t text2_bcc = calculateBCC(text2_temp, sizeof(text2_temp));
uint8_t text2[] = {STX, 0x40, 0x51, 0x30, 0x30, byte2, byte1, ETX, text2_bcc};
clear_buffer(); // clear response_buffer for reuse
HAL_UART_Transmit(&huart1, (uint8_t*)ACK_1, sizeof(ACK_1), T_Out);
if (debug ==true) {HAL_UART_Transmit(&huart2, (uint8_t*)ACK_1, sizeof(ACK_1), T_Out);} // debug port monitoring
ReceiveATResponse(response_buffer, sizeof(EOT));
if (debug ==true) {HAL_UART_Transmit(&huart2, (uint8_t*)response_buffer, sizeof(EOT), T_Out);} // debug port monitoring
if (response_buffer[0] == EOT)
{
//HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_RESET);
HAL_Delay(1000);
//HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_SET);
}
clear_buffer(); // clear response_buffer for reuse
/////////////// Send ENQ_SEL ////////////////////
HAL_UART_Transmit(&huart1, (uint8_t*)ENQ_SEL, sizeof(ENQ_SEL), T_Out);
if (debug ==true) {HAL_UART_Transmit(&huart2, (uint8_t*)ENQ_SEL, sizeof(ENQ_SEL), T_Out);} // debug port monitoring
//////////////// Receive ACK_0 /////////////////////////
ReceiveATResponse(response_buffer, sizeof(ACK_0));
if (debug ==true) {HAL_UART_Transmit(&huart2, (uint8_t*)response_buffer, sizeof(ACK_0), T_Out);} // debug port monitoring
if (response_buffer[0] == 0x10 && response_buffer[1] == 0x30)
{
//HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_RESET);
HAL_Delay(500);
//HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_SET);
}
else {
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_RESET);
HAL_Delay(1000);
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_SET);
HAL_Delay(1000);
}
clear_buffer(); // clear response_buffer for reuse
////// Transmit Text 2 ///////////////////////////////////////
HAL_UART_Transmit(&huart1, text2, sizeof(text2), T_Out);
if (debug ==true) {HAL_UART_Transmit(&huart2, text2, sizeof(text2), T_Out);} // debug port monitoring
///////////////////////////////
////// Receive ACK_1/////////
ReceiveATResponse(response_buffer, sizeof(ACK_1));
if (debug ==true) {HAL_UART_Transmit(&huart2, (uint8_t*)response_buffer, sizeof(ACK_1), T_Out);} // debug port monitoring
if (response_buffer[0] == 0x10 && response_buffer[1] == 0x31)
{
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_RESET);
HAL_Delay(1500);
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_SET);
}
else {
while(1){
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_RESET);
HAL_Delay(1000);
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_SET);
HAL_Delay(1000);
HAL_UART_Transmit(&huart2,"LOOP" , sizeof("LOOP"), T_Out); //debug
}
}
HAL_Delay(500);
clear_buffer(); // clear response_buffer for reuse
HAL_UART_Transmit(&huart1, (uint8_t*)ENQ_POL, sizeof(ENQ_POL), T_Out);
if (debug ==true) {HAL_UART_Transmit(&huart2, (uint8_t*)ENQ_POL, sizeof(ENQ_POL), T_Out);} // debug port monitoring
ReceiveATResponse(response_buffer, text_PON);
if (debug ==true) {HAL_UART_Transmit(&huart2, (uint8_t*)response_buffer, text_PON, T_Out);} // debug port monitoring
if (response_buffer[3] == 0x36 && response_buffer[4] == 0x30 && response_buffer[5] == 0x31 && response_buffer[6] == 0x30)
{
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_RESET);
HAL_UART_Transmit(&huart1, (uint8_t*)ACK_1, sizeof(ACK_1), T_Out);
if (debug ==true) {HAL_UART_Transmit(&huart2, (uint8_t*)ACK_1, sizeof(ACK_1), T_Out);} // debug port monitoring
}
ReceiveATResponse(response_buffer, sizeof(EOT));
int frmcount = huart1.RxXferCount;
HAL_UART_Transmit(&huart2, (uint8_t*)frmcount, sizeof(frmcount), T_Out);
if(response_buffer[0]==0x04){
Dispenser_control = true;
for(int i=0; i<3; i++){
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_RESET);
HAL_Delay(1000);
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_SET);
HAL_Delay(500);
}
}
else
{
goto start_again;
}
}
}
void ReceiveATResponse(unsigned char* buffer, size_t buffer_size)
{
memset(buffer, 0, buffer_size);
receive_index = 0;
while (receive_index < buffer_size)
{
if (HAL_UART_Receive(&huart1, &buffer[receive_index], 1, TIMEOUT_MS) == HAL_OK)
{
if (receive_index >= buffer_size || buffer[0] == EOT || buffer[0] == NUL)
{
break;
}
else
{
receive_index++;
}
}
}
}
void clear_buffer(){
for(int i = 0; i<RESPONSE_BUFFER_SIZE;i++){
response_buffer[i]=0;
}
}
uint8_t calculate_crc16(uint8_t *data, size_t length)
{
uint16_t crc = 0;
uint8_t crc_code = 0;
uint8_t crc_code_temp = 0;
for (size_t i = 0; i < length; ++i) {
crc = (crc >> 8) ^ crc16_lookup_table[(crc ^ data[i]) & 0xFF];
}
crc_code = crc;
crc_code_temp = crc>>8;
crc_code = crc_code + crc_code_temp;
return crc_code;
}
uint8_t calculateBCC(uint8_t *data, size_t length)
{
uint8_t bcc = 0;
for (size_t i = 0; i < length; ++i)
{
bcc ^= data[i];
}
return bcc;
}
void Serial_print(char* command) {
HAL_UART_Transmit(&huart1, (uint8_t*)command, sizeof(command), T_Out);
}
void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL4;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
Error_Handler();
}
/** Initializes the CPU, AHB and APB buses clocks
*/
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK)
{
Error_Handler();
}
}
/**
* @brief USART1 Initialization Function
* @param None
* @retval None
*/
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 = 19200;
huart1.Init.WordLength = UART_WORDLENGTH_9B;
huart1.Init.StopBits = UART_STOPBITS_1;
huart1.Init.Parity = UART_PARITY_EVEN;
huart1.Init.Mode = UART_MODE_TX_RX;
huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart1.Init.OverSampling = UART_OVERSAMPLING_16;
if (HAL_UART_Init(&huart1) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN USART1_Init 2 */
/* USER CODE END USART1_Init 2 */
}
/**
* @brief USART2 Initialization Function
* @param None
* @retval None
*/
static void MX_USART2_UART_Init(void)
{
/* USER CODE BEGIN USART2_Init 0 */
/* USER CODE END USART2_Init 0 */
/* USER CODE BEGIN USART2_Init 1 */
/* USER CODE END USART2_Init 1 */
huart2.Instance = USART2;
huart2.Init.BaudRate = 19200;
huart2.Init.WordLength = UART_WORDLENGTH_9B;
huart2.Init.StopBits = UART_STOPBITS_1;
huart2.Init.Parity = UART_PARITY_EVEN;
huart2.Init.Mode = UART_MODE_TX_RX;
huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart2.Init.OverSampling = UART_OVERSAMPLING_16;
if (HAL_UART_Init(&huart2) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN USART2_Init 2 */
/* USER CODE END USART2_Init 2 */
}
/**
* @brief GPIO Initialization Function
* @param None
* @retval None
*/
static void MX_GPIO_Init(void)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
/* USER CODE BEGIN MX_GPIO_Init_1 */
/* USER CODE END MX_GPIO_Init_1 */
/* GPIO Ports Clock Enable */
__HAL_RCC_GPIOC_CLK_ENABLE();
__HAL_RCC_GPIOD_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_RESET);
/*Configure GPIO pin : PC13 */
GPIO_InitStruct.Pin = GPIO_PIN_13;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
/* USER CODE BEGIN MX_GPIO_Init_2 */
/* USER CODE END MX_GPIO_Init_2 */
}
/* USER CODE BEGIN 4 */
/* USER CODE END 4 */
/**
* @brief This function is executed in case of error occurrence.
* @retval None
*/
void Error_Handler(void)
{
/* USER CODE BEGIN Error_Handler_Debug */
/* User can add his own implementation to report the HAL error return state */
__disable_irq();
while (1)
{
}
/* USER CODE END Error_Handler_Debug */
}
#ifdef USE_FULL_ASSERT
/**
* @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @param file: pointer to the source file name
* @param line: assert_param error line source number
* @retval None
*/
void assert_failed(uint8_t *file, uint32_t line)
{
/* USER CODE BEGIN 6 */
/* User can add his own implementation to report the file name and line number,
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
/* USER CODE END 6 */
}
#endif /* USE_FULL_ASSERT */
Loading
stm32-bluepill
stm32-bluepill