Example #1
0
int main(void)
{

  /* USER CODE BEGIN 1 */
  trace_printf("Hello\n");
  /* USER CODE END 1 */

  /* MCU Configuration----------------------------------------------------------*/

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

  /* Configure the system clock */
  SystemClock_Config();

  /* Initialize all configured peripherals */
  MX_GPIO_Init();

  /* USER CODE BEGIN 2 */

  /* Initialize VCP */
  BSP_UART_Init(115200);
  uprintf("First LED is blinking in normal mode...\n\r");
  uprintf("Press '1' to enter system in sleep mode.\n\r");
  uprintf("If you want to wake-up the system,\n\r");
  uprintf("press INT/WAKE-UP button (High to Low transition on P2.10).\n\r");
  uprintf("OR Press any key on keyboard (UART Interrupt will be triggered).\n\r");

  /* Initialize On Board LEDs */
  BSP_LED_Init(LED5);
  BSP_LED_Init(LED6);
  BSP_PB_Init(BUTTON_KEY,BUTTON_MODE_EXTI);
  while(ugetche(NONE_BLOCKING) !='1')
  {
    /* Blink LED P0.10 */
    BSP_LED_Toggle(LED5);
    HAL_Delay(500);
  }
  uprintf("\n\n\rSleeping...");
  BSP_Sleepmode_PB();
  /* MCU will be here after waking up */
  uprintf("\n\n\rSystem wake-up! Second LED is blinking...");
  /* Turn off LED */
  BSP_LED_Off(LED5);

  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
  /* USER CODE END WHILE */

  /* USER CODE BEGIN 3 */
    BSP_LED_Toggle(LED6);
    HAL_Delay(500);
  }
  /* USER CODE END 3 */

}
Example #2
0
/**
 * @brief This function receives data from GSM
 * @param dataBuf buffer consist data from GSM
 * @param length total number of elements data to be read from GSM
 */
void BSP_GSM_ReadADV2(uint8_t *dataBuf ,uint16_t length)
{
  uint16_t i=0;
 	while (length--)
  {
		dataBuf[i++] = ugetche(TIME_BLOCKING);
  }
  dataBuf[i]='\0';
}
Example #3
0
void BSP_RFID_Read(uint8_t *RxBuf)
{
    uint8_t i=0;

    for(i=0;i<12;i++)
    {
        RxBuf[i]= ugetche(BLOCKING);					//Read Data from uart2
    }
    RxBuf[12]='\0';
}
Example #4
0
int main(void)
{

  /* USER CODE BEGIN 1 */
  uint8_t Data,Read[10];
  /* USER CODE END 1 */

  /* MCU Configuration----------------------------------------------------------*/

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

  /* Configure the system clock */
  SystemClock_Config();

  /* Initialize all configured peripherals */
  MX_GPIO_Init();

  /* USER CODE BEGIN 2 */
  BSP_UART_Init(115200);

  uprintf("Write single Character:\t");

  /* Receive data on UART 6 */
  Data = ugetche(BLOCKING);
  uprintf("\r\n character in hex %x03 in dec %d03 in char %c in uhex %u and %b\n\r",Data,Data,Data,Data,23);
  uprintf("Write 10 Character:\t");

  /* Receive string on UART 6 */
  uget_line(Read,sizeof(Read));
  uprintf("\n\rPrinted Line: %s",Read);

  trace_printf("Hello\n");

  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
  /* USER CODE END WHILE */

  /* USER CODE BEGIN 3 */

  }
  /* USER CODE END 3 */

}
Example #5
0
/**
 * @brief This function receives data from GSM
 * @return value
 */
char BSP_GSM_ReadADV(void)

{
  int8_t Data,sbuf[2];
	uint8_t i=0,k=0;
	while(i<160)
	{
		i++;
		Data = ugetche(TIME_BLOCKING);
		sbuf[0]=sbuf[1];
		sbuf[1]=Data;
		if((sbuf[0]=='O')&&(sbuf[1]=='K'))
		{
			k=1;
			break;
		}
	}
	return(k);
}
/**
 * @brief It asks user to change Date
 * @return status
 */
uint8_t BSP_RTC_Change_Date (void)
{
  uint8_t DaysPerMonth[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  RTC_DateTypeDef D;
  D.WeekDay = RTC_WEEKDAY_MONDAY;
  D.Month = RTC_MONTH_MAY;
  D.Date = 1;
  D.Year = 00;
  uint8_t Daysthismonth;
  uint8_t DateBuffer[1];
  char cp;                               /* input from keyboard */
  char RTCdata;                          /* buffer */
  uint8_t DateFlag=0;                    /* flag for date data is available */
  uint8_t count = 0;                     /* input character counter */
  uint8_t State = 0;                     /* state for dd=1, mm=2, ccyy=3 */

  uint8_t digit = 0;                     /* indication for 1st, 2nd, 3rd and 4th digit */
                                         /* for dd, mm, yycc */
  uint8_t MaxCount = 8;                  /* maximum no. of digits */
  char AsciiLSB;                         /* temp storage for LSB ascii input */
  char AsciiMSB;                         /* temp storage for MSB ascii input */
  uint8_t DaysThisMonth;                 /* number of days for the given month */

    while(1)
    {
      cp = ugetche(BLOCKING);                    /* get input character */

      if(cp == In_ESC)                   /* if ESCAPE pressed then exit */
      {
        return (cp);
      }
      else if (cp == In_CR)              /* CARRIAGE RETURN ? */
      {
        if(count==0)                     /* any characters at all ? */
        {
          continue;                      /* no, so get another character */
        }

        if(DateFlag==1)
        {   /*  update real time clock  */
          /* Read RTC */
          Year[0] = ((DateBuffer[0] & 0xFF) * 100);
          Year[0] += (DateBuffer[1] & 0xFF);
          D.Year = DateBuffer[1];
          HAL_RTC_SetDate(&hrtc_bsp, &D, FORMAT_BIN);
          return(0);
        }
        else
        {
          break;                       /* check for any character */
        }
      }
      else if (cp == In_DELETE || cp == In_BACKSPACE) /* delete or back space */
      {
        if(count==0)                   /* any characters entered */
        {
          continue;                    /* no, so get another character */
        }

        if(State == 2)                 /* State 2 contains 4 digits */
        {
          if(digit == 0)
          {
            uErase_Backslash();
            digit = 1;                 /* now its point to 2nd digit of month */
            State--;                   /* point to month's state */
            count--;                   /* decrement character count */

            continue;
          }
          else
          {
            uErase_Char_With_UnderScore();
            digit--;                     /* point to 2nd digit */
            count--;                     /* decrement count */

            continue;                    /* go back and get another input */
          }
        }
        else
        {
          if(digit ==0)
          {
            uErase_Backslash();
            State--;                     /* point to month's state */
            digit = 1;                   /* now its point to 2nd digit of month */
            count--;                     /* decrement character count */

            continue;
          }
          else
          {
            uErase_Char_With_UnderScore();
            digit = 0;                   /* point to 1st digit */
            count--;                     /* decrement count */

            continue;                    /* goback and get another input */
          }
        }
      }
      else if (cp>= '0' && cp <='9')     /* is character between 0 to 9? */
      {
        RTCdata = cp;

        /****** check date ****/
        if(count < MaxCount)
        {
          if(State == 0)
          {
            if(digit==0)
            {
              uprintf("%c", RTCdata);    /* echo 1st character */
              AsciiMSB = RTCdata;        /* store 1st byte MSB  */
              count++;                   /* increment character count,will be 1 */
              digit++;                   /* increment digit, will be 1 */

              continue;
            }
            else
            {
              uprintf("%c", RTCdata);             /* echo 2nd character */
              AsciiLSB = RTCdata;                 /* store 2nd byte LSB  */
              RTCdata = ((AsciiMSB & 0x0F) * 10); /* store nibble */
              RTCdata += (AsciiLSB & 0x0F);       /* add to nibble, integer */

              if(RTCdata >= 1 && RTCdata <=31)    /* check date range ( 1-31) */
              {
                D.Date = RTCdata;                 /* store DOM in DateBuffer[0] */

                State++;                 /* increment to mm state */
                count++;                 /* increment character count,will be 2 */
                digit = 0;               /* set digit to zero  */
                uprintf("/");            /* and write '/' on the screen */

                continue;                /* continue for minutes */
              }
              else
              {
                uErase_And_RingTheBell();

                continue;
              }
            }
          }
          /************************* check month *************************/
          if(State == 1)
          {
            if(digit==0)
            {
              uprintf("%c", RTCdata);    /* echo 1st character */
              AsciiMSB = RTCdata;        /* store 1st byte MSB  */
              count++;                   /* increment character count,will be 3 */
              digit++;                   /* increment digit, will be 1  */

              continue;
            }
            else
            {
              uprintf("%c", RTCdata);   /* echo 2nd character */
              AsciiLSB = RTCdata;                 /* store 2nd byte LSB  */
              RTCdata = ((AsciiMSB & 0x0F) * 10); /* store nibble */
              RTCdata += (AsciiLSB & 0x0F);       /* add to nibble, integer */

              if(RTCdata >= 1 && RTCdata <=12)    /* check month range ( 1-12) */
              {
                D.Month = RTCdata;       /* store mm in time buffer */

                State++;                 /* increment to ss state */
                count++;                 /* increment character count,will be 4 */
                digit = 0;               /* set digit to zero  */
                uprintf("/");            /* and write '/' on the screen */

                continue;                /* continue for seconds */
              }
              else
              {
                uErase_And_RingTheBell();

                continue;
              }
            }
          }
          /********** check year and century *********/
          if(State == 2)
          {
            if(digit == 0)
            {
              uprintf("%c", RTCdata);    /* echo 1st character */
              AsciiMSB = RTCdata;        /* store 1st byte MSB  */

              count++;                   /* increment character count,will be 5 */
              digit++;                   /* increment digit no.  */

              continue;
            }
            if(digit == 1)
            {
              uprintf("%c", RTCdata);   /* echo 2nd character */
              AsciiLSB = RTCdata;                 /* store 2nd byte LSB  */
              RTCdata = ((AsciiMSB & 0x0F) * 10); /* store nibble */
              RTCdata += (AsciiLSB & 0x0F);       /* add to nibble, integer */

              if(RTCdata >= 0 && RTCdata <=40)   /* check century range (0-39) */
              {
                DateBuffer[0] = RTCdata;          /* store in century buffer */

                count++;                 /* increment character count,will be 6 */
                digit++;                 /* increment digit number, will be 3  */

                continue;
              }
              else
              {
                uErase_Char_With_UnderScore();
                uprintf("\7");          /* ring the bell */

                continue;
              }
            }
            /**********  check year  ************/
            if(digit == 2)
            {
              uprintf("%c", RTCdata);   /* echo 1st character */
              AsciiMSB = RTCdata;       /* store 1st byte MSB  */

              count++;                  /* increment character count,will be 7 */
              digit++;                  /* increment digit no.  */

              continue;
            }

            if(digit == 3)
            {
              uprintf("%c", RTCdata);              /* echo 2nd character */
              AsciiLSB = RTCdata;                  /* store 2nd byte LSB  */
              RTCdata = ((AsciiMSB & 0x0F) * 10);  /* store nibble */
              RTCdata += (AsciiLSB & 0x0F);        /* add to nibble, integer */

              if(DateBuffer[0] == 40)
              {
                if(RTCdata <=95)              /* check year range (00-95) */
                {
                  DateBuffer[1] = RTCdata;    /* store in year buffer */
                  DateFlag = 1;               /* Time data is ready for RTC */
                    count++;                  /* increment character count,will be 8 */
                    digit++;                  /* increment digit number, will be 4  */
                    continue;
                }
                else
                {
                  uErase_Char_With_UnderScore();
                  uprintf("\7");              /* ring the bell */

                  continue;
                }
              }

              if(RTCdata <=99)                     /* check year range (00-99) */
              {
                DateBuffer[1] = RTCdata;           /* store in year buffer */
                DaysThisMonth = DaysPerMonth[D.Month- 1];
                if(Is_Leap_Year(DateBuffer[1], DateBuffer[0]) && (D.Month == 2))
                {
                  ++DaysThisMonth;
                }
                if(D.Date > DaysThisMonth)
                {
                  D.Date = DaysThisMonth;
                }
                DateFlag = 1;                      /* Time data is ready for RTC */
                count++;                           /* increment character count,will be 8 */
                digit++;                           /* increment digit number, will be 4  */

                continue;
              }
              else
              {
                uErase_Char_With_UnderScore();
                uprintf("\7");           /* ring the bell */

                continue;
              }
            }
          }
          continue;                      /* number of char is more than reqd */
          /* so go back to find the decision */
        }
        else
        {
          uprintf("%c", cp);                   /* echo character */
          uErase_Char();
          uprintf("\7");                       /* ring the bell */

          continue;
        }
      }
    }
    return(0);
}
/**
 * @brief It asks user to set new Time
 * @return status
 */
uint8_t BSP_RTC_Change_Time (void)
{
  RTC_TimeTypeDef T;

  char cp;                          /* input from keyboard */
  char RTCdata;                     /* buffer */
  uint8_t TimeFlag=0;               /* flag for time data is available */
  uint8_t count = 0;                /* input character counter */
  uint8_t State = 0;                /* state for hh=1, mm=2, ss=3 */

  uint8_t digit = 0;                /* indication for 1st and 2nd digit of hh, mm, ss */
  uint8_t MaxCount = 6;             /* maximum no. of digits */
  char AsciiLSB;                    /* temporary storage for lsb ascii input */
  char AsciiMSB;                    /* temporary storage for msb ascii input */

  T.Hours = 0;
  T.Minutes = 0;
  T.Seconds = 0;
  T.SubSeconds = 0;
  T.TimeFormat = RTC_HOURFORMAT12_AM;
  T.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;
  T.StoreOperation = RTC_STOREOPERATION_RESET;

  while(1)
  {
    cp = ugetche(BLOCKING);         /* get input character */

    if (cp == In_ESC)               /* if ESCAPE pressed then exit */
    {
      return (cp);
    }
    else if (cp == In_CR)           /* CARRIAGE RETURN ? */
    {
      if(count==0)                  /* any characters at all ? */
      {
        continue;                   /* no, so get another character */
      }

      if(TimeFlag==1)
      {                             /* update real time clock  */
          /* Write changes to RTC */
        HAL_RTC_SetTime(&hrtc_bsp, &T, FORMAT_BIN);
        return(0);
      }
      else
        break;                      /* check for any character */
    }
    else if (cp == In_DELETE || cp == In_BACKSPACE) /* delete or back space */
    {
      if(count == 0)                /* any characters entered */
      {
        continue;                   /* no, so get another character */
      }

      if(digit == 0)
      {
        uErase_SemiColon();
        digit = 1;                /* now its point to 2nd digit */
        State--;                  /* point to one up state */
        count--;                  /* decrement character count */
        continue;
      }
      else
      {
        if(TimeFlag == 1)
        {
          uErase_Char_With_UnderScore();
          TimeFlag = 0;          /* changed mind so not ready */
          digit = 1;             /* point to 2nd digit */
          count--;               /* decrement count */
          continue;              /* goback and get another input */
        }

        uErase_Char_With_UnderScore();

        digit = 0;               /* now its point to 1st digit */
        count--;                 /* decrement character count */
        continue;
      }
    }
    else if (cp>= '0' && cp <='9')/* is character between 0 to 9? */
    {
      RTCdata = cp;
      /*********** check hours **********/
      if(count < MaxCount)
      {
        if(State == 0)
        {
          if(digit == 0)
          {
            uprintf("%c",RTCdata);     /* echo 1st character */
            AsciiMSB = RTCdata;        /* store 1st byte MSB  */
            count++;                   /* increment character count,will be 1 */
            digit++;                   /* increment digit, will be 1 */
            continue;
          }
          else
          {
            uprintf("%c", RTCdata);               /* echo 2nd character */
            AsciiLSB = RTCdata;                   /* store 2nd byte LSB  */
            RTCdata = ((AsciiMSB & 0x0F) * 10);   /* store nibble */
            RTCdata += (AsciiLSB & 0x0F);         /* add to nibble, integer */

            if(RTCdata <=23)                      /* check hour range ( 0-23) */
            {
              T.Hours = RTCdata;                  /* store hh in time buffer */

              State++;                            /* increment to mm state */
              count++;                            /* increment character count,will be 2 */
              digit = 0;                          /* set digit to zero  */

              uprintf(":");                       /* and write ':' on the screen */
              continue;                           /* continue for minutes */
            }
            else
            {
              uErase_And_RingTheBell();
              continue;
            }
          }
        }

        /********** check minutes ***********/
        if(State == 1)
        {
          if(digit==0)
          {
            uprintf("%c", RTCdata);         /* echo 1st character */
            AsciiMSB = RTCdata;             /* store 1st byte MSB  */
            count++;                        /* increment character count,will be 3 */
            digit++;                        /* increment digit, will be 1  */
            continue;
          }
          else
          {
            uprintf("%c", RTCdata);             /* echo 2nd character */
            AsciiLSB = RTCdata;                 /* store 2nd byte LSB  */
            RTCdata = ((AsciiMSB & 0x0F) * 10); /* store nibble */
            RTCdata += (AsciiLSB & 0x0F);       /* add to nibble, integer */

            if(RTCdata <=59)                    /* check minutes range ( 0-59) */
            {
              T.Minutes = RTCdata;              /* store mm in time buffer */
              State++;                          /* increment to ss state */
              count++;                          /* increment character count,will be 4 */
              digit = 0;                        /* set digit to zero  */
              uprintf(":");                     /* and write ':' on the screen */

              continue;                         /* continue for seconds */
            }
            else
            {
              uErase_And_RingTheBell();
              continue;
            }
          }
        }

        /*********** check seconds ***************/
        if(State == 2)
        {
          if(digit==0)
          {
            uprintf("%c", RTCdata);         /* echo 1st character */
            AsciiMSB = RTCdata;             /* store 1st byte MSB  */
            count++;                        /* increment character count,will be 5 */
            digit++;                        /* increment digit no.  */

            continue;
          }
          else
          {
            uprintf("%c", RTCdata);              /* echo 2nd character */
            AsciiLSB = RTCdata;                  /* store 2nd byte LSB  */
            RTCdata = ((AsciiMSB & 0x0F) * 10);  /* store nibble */
            RTCdata += (AsciiLSB & 0x0F);        /* add to nibble, integer */

            if(RTCdata <=59)                     /* check seconds range ( 0-59) */
            {
              T.Seconds = RTCdata;               /* store ss in time buffer */

              TimeFlag = 1;                      /* Time data is ready for RTC */
              count++;                           /* increment character count,will be 6 */

              continue;                          /* go back and find the decision  */
            }
            else
            {
              uErase_And_RingTheBell();
              continue;
            }
          }
        }

        continue;                                /* number of char is more than read */
        /* so go back to find the decision */
      }
      /*************************************************/
      else
      {
        uprintf("%c", cp);                       /* echo character */
        uErase_Char_With_UnderScore();
        uprintf("\7");                           /* ring the bell */

        continue;
      }
    }
  }
  return(0);
}
Example #8
0
int main(void)
{

  /* USER CODE BEGIN 1 */
  trace_printf("Hello\n");
  /* USER CODE END 1 */

  /* MCU Configuration----------------------------------------------------------*/

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

  /* Configure the system clock */
  SystemClock_Config();

  /* Initialize all configured peripherals */
  MX_GPIO_Init();

  /* USER CODE BEGIN 2 */
  BSP_LED_Init(LED6);
  BSP_LED_Init(LED5);

  /* Checks if reset was because of wakeup from standby */
  if (__HAL_PWR_GET_FLAG(PWR_FLAG_SB) != RESET)
  {
    /* Clear Standby and wakeup flag */
    __HAL_PWR_CLEAR_FLAG(PWR_FLAG_SB | PWR_FLAG_WU);
    BSP_LED_On(LED5);
   /* Reset was from wakeup from standy */
  }
  else
  {
    BSP_LED_Off(LED5);
  }

  BSP_UART_Init(115200);
  uprintf("First LED is blinking in normal mode...\n\r");
  uprintf("Press '1' to enter system in standby mode.\n\r");
  uprintf("Wait 5s, RTC will wake-up system...\n\r");
  // BSP_RTC_Init();

  while(ugetche(NONE_BLOCKING) !='1')
  {
    BSP_LED_Toggle(LED6);
    HAL_Delay(500);
  }
  uprintf("\n\nEnter Deep PowerDown mode...\n\r");
  BSP_StandbyMode_PB();
  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
  /* USER CODE END WHILE */

  /* USER CODE BEGIN 3 */
    BSP_LED_Toggle(LED6);
    HAL_Delay(500);
  }
  /* USER CODE END 3 */


}