130 lines
3.2 KiB
C
130 lines
3.2 KiB
C
#include "main.h"
|
|
//#include "stdio.h"
|
|
|
|
uint32_t ms_passed = 0;
|
|
|
|
PUTCHAR_PROTOTYPE;
|
|
|
|
void puts(const char *s) {
|
|
const char* p = s;
|
|
while (*p != '\0') putchar(*p++);
|
|
}
|
|
|
|
void main(void)
|
|
{
|
|
/*High speed internal clock prescaler: 1*/
|
|
CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1);
|
|
|
|
UART1_DeInit();
|
|
/* UART1 configuration ------------------------------------------------------*/
|
|
/* UART1 configured as follow:
|
|
- BaudRate = 115200 baud
|
|
- Word Length = 8 Bits
|
|
- One Stop Bit
|
|
- No parity
|
|
- Receive and transmit enabled
|
|
- UART1 Clock disabled
|
|
*/
|
|
UART1_Init((uint32_t)115200, UART1_WORDLENGTH_8D, UART1_STOPBITS_1, UART1_PARITY_NO,
|
|
UART1_SYNCMODE_CLOCK_DISABLE, UART1_MODE_TXRX_ENABLE);
|
|
|
|
puts("Demotest\n\r");
|
|
// uint8_t *uniqueid = (uint8_t*)0x4865;
|
|
|
|
// puts("\n\rUnique ID: ");
|
|
// for (int i = 0; i < 12; i++) {
|
|
// if(i > 0) printf(":");
|
|
// printf("%02X", uniqueid[i]);
|
|
// }
|
|
// puts("\n\r");
|
|
|
|
/* Initialize Interrupt*/
|
|
GPIO_Init(GPIOB, GPIO_PIN_4, GPIO_MODE_IN_PU_IT);
|
|
EXTI_SetExtIntSensitivity(EXTI_PORT_GPIOB, EXTI_SENSITIVITY_FALL_ONLY);
|
|
EXTI_SetTLISensitivity(EXTI_TLISENSITIVITY_FALL_ONLY);
|
|
enableInterrupts();
|
|
|
|
/* Initialize I/Os in Output Mode */
|
|
GPIO_Init(LED_GPIO_PORT, (GPIO_Pin_TypeDef)LED_GPIO_PINS, GPIO_MODE_OUT_PP_LOW_FAST);
|
|
/* Show the system is working properly */
|
|
GPIO_WriteHigh(LED_GPIO_PORT, LED_GPIO_PINS);
|
|
delay_ms(200);
|
|
GPIO_WriteLow(LED_GPIO_PORT, LED_GPIO_PINS);
|
|
delay_ms(100);
|
|
GPIO_WriteHigh(LED_GPIO_PORT, LED_GPIO_PINS);
|
|
delay_ms(200);
|
|
GPIO_WriteLow(LED_GPIO_PORT, LED_GPIO_PINS);
|
|
delay_ms(100);
|
|
GPIO_WriteHigh(LED_GPIO_PORT, LED_GPIO_PINS);
|
|
delay_ms(200);
|
|
GPIO_WriteLow(LED_GPIO_PORT, LED_GPIO_PINS);
|
|
|
|
while (1) {
|
|
/* Toggles LEDs */
|
|
delay_ms(10);
|
|
ms_passed += 10;
|
|
if(ms_passed % 1000 == 0) {
|
|
GPIO_WriteReverse(LED_GPIO_PORT, (GPIO_Pin_TypeDef)LED_GPIO_PINS);
|
|
uint32_t ntick = ms_passed / 1000;
|
|
char x = ntick % 58 + 65;
|
|
putchar(8); //backspace
|
|
putchar(x);
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @brief Retargets the C library printf function to the UART.
|
|
* @param c Character to send
|
|
* @retval char Character sent
|
|
*/
|
|
PUTCHAR_PROTOTYPE
|
|
{
|
|
/* Write a character to the UART1 */
|
|
UART1_SendData8(c);
|
|
/* Loop until the end of transmission */
|
|
while (UART1_GetFlagStatus(UART1_FLAG_TXE) == RESET);
|
|
|
|
return (c);
|
|
}
|
|
|
|
/**
|
|
* @brief Retargets the C library scanf function to the USART.
|
|
* @param None
|
|
* @retval char Character to Read
|
|
*/
|
|
GETCHAR_PROTOTYPE
|
|
{
|
|
#ifdef _COSMIC_
|
|
char c = 0;
|
|
#else
|
|
int c = 0;
|
|
#endif
|
|
/* Loop until the Read data register flag is SET */
|
|
while (UART1_GetFlagStatus(UART1_FLAG_RXNE) == RESET);
|
|
c = UART1_ReceiveData8();
|
|
return (c);
|
|
}
|
|
|
|
|
|
#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 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) */
|
|
|
|
/* Infinite loop */
|
|
while (1)
|
|
{
|
|
}
|
|
}
|
|
#endif
|