STM32L151 NB-IoT and FreeRTOS Project
guowenxue
2018-11-13 8c351e6d738633f62e07710d7e143cdb5a2a263f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/****************************************************************************
*   Copyright: (C)2018 Î人ÁèÔÆÎïÍøÖÇ¿ÆÊµÑéÊÒ www.iot-yun.com
*      Author: GuoWenxue<guowenxue@gmail.com> QQ: 281143292
* Description: STM32L151C8T6 CubeMX ¿ª·¢°å printfºÍ´®¿Ú³õʼ»¯º¯Êý
*   ChangeLog:
*        °æ±¾ºÅ     ÈÕÆÚ       ×÷Õß      ËµÃ÷
*        V1.0.0  2018.11.05  GuoWenxue   ·¢²¼¸Ã°æ±¾
****************************************************************************/
 
#ifndef __STM32_USART_H_
#define __STM32_USART_H_
 
#include "stm32l1xx_usart.h"
 
#define USART_PUTCHR(COM, ch) { USART_SendData(COM, ch);  while (USART_GetFlagStatus(COM, USART_FLAG_TC) == RESET) ; }
 
enum 
{
    USART_PORT1,
    USART_PORT2,
    USART_PORT3,
    USART_MAX,
};
 
typedef struct stm32_usart_pins_s
{
    USART_TypeDef       *USARTx;          /* USART1¡¢USART2¡¢USART3 */
    GPIO_TypeDef        *group;           /* GPIOx: GPIOA¡¢GPIOB */
    uint16_t             txpin;           /* GPIO_Pin:  GPIO_Pin_2 */
    uint16_t             rxpin;           /* GPIO_Pin:  GPIO_Pin_3 */
    uint16_t             txpin_src;       /* GPIO_PinSource:  GPIO_PinSource2 */
    uint16_t             rxpin_src;       /* GPIO_PinSource:  GPIO_PinSource3 */
    uint8_t              gpio_af;         /* GPIO_AF: GPIO_AF_USART1*/
    uint32_t             usart_clk;       /* USART clock:  RCC_APB1Periph_USART1 */
    uint16_t             gpio_clk;        /* USART Tx/Rx Pin Clock: RCC_AHBPeriph_GPIOA */
} stm32_usart_pins_t;
 
 
/* º¯Êý˵Ã÷:  ÅäÖô®¿ÚµÄ²¨ÌØÂÊ¡¢Êý¾Ýλ¡¢ÆæÅ¼Ð£Ñéλ¡¢Í£Ö¹Î»¡¢Á÷¿ØµÈ£»
 * ²ÎÊý˵Ã÷:  whichÖ¸¶¨ÒªÅäÖõĴ®¿Ú,ÆäÖµÓ¦¸ÃΪ USART_PORT1¡¢USART_PORT2¡¢USART_PORT3£¬¶¨ÒåÔÚstm32_usart.hÖУ»
 *            baudrate: ²¨ÌØÂÊ,ÆäֵΪ: 115200,9600,4800,2400,1200....
 *            rxirq: ÊÇ·ñʹÄܽÓÊÕÖжϣ» 1->ʹÄÜ   0->²»Ê¹ÄÜ
 *            txirq: ÊÇ·ñʹÄÜ·¢ËÍÖжϣ» 1->ʹÄÜ   0->²»Ê¹ÄÜ
 * ·µ»ØÖµ:    ÎÞ
 */
#define RXIRQ_ENABLE    1
#define RXIRQ_DISABLE   0
#define TXIRQ_ENABLE    1
#define TXIRQ_DISABLE   0
extern void stm32_init_usart(uint8_t which, uint32_t baudrate, uint8_t txirq, uint8_t rxirq);
 
/* º¯Êý˵Ã÷: ³õʼ»¯µ÷ÊÔ´®¿Ú,²¢Ö¸¶¨ÏàÓ¦µÄ´®¿ÚΪprintfº¯ÊýµÄÊä³ö´®¿Ú
 * ²ÎÊý˵Ã÷: whichÖ¸¶¨ÒªÅäÖõĴ®¿Ú,ÆäÖµÓ¦¸ÃΪ USART_PORT1¡¢USART_PORT2¡¢USART_PORT3£¬¶¨ÒåÔÚstm32_usart.hÖУ»
 *           baudrate: ²¨ÌØÂÊ,ÆäֵΪ: 115200,9600,4800,2400,1200....
 * ·µ»ØÖµ£º  ÎÞ
 */
extern void stm32_init_printf(uint8_t which, uint32_t baudrate);
 
/* º¯Êý˵Ã÷: Íùµ÷ÊÔ´®¿Ú·¢ËÍ×Ö·û´®
 * ²ÎÊý˵Ã÷: str Ö¸ÏòÒª·¢Ë͵Ä×Ö·û´®ÄÚÈÝ
 * ·µ»ØÖµ£º  ÎÞ
 */
extern void usart_puts(const char *str);
 
 
#endif