2018年1月10日 星期三

STM32F407 USART PRINTF

Enalbe GPIO clock & UART clock
0x40023830 |= 0x00000004
0x40023840 |= 0x00040000

Connect PXx to USARTx_Tx & Rx
0x40020824 &= ~(0xF << 8)
0x40020824 |= 0x07 << 8
0x40020824 &= ~(0xF << 12)
0x40020824 |= 0x07 << 12

Configure USART Tx as alternate function 
0x40020800 |= 0x02 << (10 * 2)
0x40020808 |= 0x02 << (10 * 2)
0x40020804 |= 0x00 << 10
0x4402080C |= 0x01 << (10 * 2)

Configure USART Rx as alternate function
0x40020800 |= 0x02 << (11 * 2)
0x40020808 |= 0x02 << (11 * 2)
0x40020804 |= 0x00 << 11
0x4402080C |= 0x01 << (11 * 2)


================================================================
0x40023830 = 0x00000004
RCC_AHB1PeriphClockCmd /* Enable GPIO clock */

#define EVAL_COM1_TX_GPIO_CLK            RCC_AHB1Periph_GPIOC
#define EVAL_COM1_RX_GPIO_CLK            RCC_AHB1Periph_GPIOC

#define RCC_AHB1Periph_GPIOC             ((uint32_t)0x00000004)

RCC->AHB1ENR
#define PERIPH_BASE           ((uint32_t)0x40000000)
#define AHB1PERIPH_BASE       (PERIPH_BASE + 0x00020000)
#define RCC_BASE              (AHB1PERIPH_BASE + 0x3800)
__IO uint32_t AHB1ENR;       /*!< RCC AHB1 peripheral clock register, Address offset: 0x30

================================================================
0x40023840 = 0x00040000
RCC_APB1PeriphClockCmd /* Enable UART clock */

#define EVAL_COM1_CLK                    RCC_APB1Periph_USART3
#define RCC_APB1Periph_USART3            ((uint32_t)0x00040000)

RCC->APB1ENR
#define PERIPH_BASE           ((uint32_t)0x40000000)
#define AHB1PERIPH_BASE       (PERIPH_BASE + 0x00020000)
#define RCC_BASE              (AHB1PERIPH_BASE + 0x3800)
__IO uint32_t APB1ENR;       /*!< RCC APB1 peripheral clock enable register, Address offset: 0x40 

=================================================================
0x40020800 = 0x07 << 8
GPIO_PinAFConfig /* Connect PXx to USARTx_Tx*/

GPIOx->AFR
#define PERIPH_BASE           ((uint32_t)0x40000000)
#define AHB1PERIPH_BASE       (PERIPH_BASE + 0x00020000)
#define GPIOC_BASE            (AHB1PERIPH_BASE + 0x0800)
 __IO uint32_t AFR[2];   /*!< GPIO alternate function registers, Address offset: 0x20-0x24 

#define GPIO_PinSource10           ((uint8_t)0x0A)
#define GPIO_AF_USART3        ((uint8_t)0x07)  /* USART3 Alternate Function mapping */

0x07 << ((0x0A & 0x07) * 4)


0x40020800 = 0x07 << 12
#define GPIO_PinSource11           ((uint8_t)0x0B)
#define GPIO_AF_USART3        ((uint8_t)0x07)  /* USART3 Alternate Function mapping */

0x07 << ((0x0B & 0x07) * 4)

=================================================================

#define PERIPH_BASE           ((uint32_t)0x40000000)
#define AHB1PERIPH_BASE       (PERIPH_BASE + 0x00020000)
#define GPIOC_BASE            (AHB1PERIPH_BASE + 0x0800)

0x40020800 |= 0x02 << (10 * 2)
__IO uint32_t MODER;    /*!< GPIO port mode register,               Address offset: 0x00
GPIO_Mode_AF   = 0x02, /*!< GPIO Alternate function Mode */

0x40020808 |= 0x02 << (10 * 2)
__IO uint32_t OSPEEDR;  /*!< GPIO port output speed register,       Address offset: 0x08
GPIO_Speed_50MHz  = 0x02, /*!< Fast speed */

0x40020804 |= 0x00 << 10
__IO uint32_t OTYPER;   /*!< GPIO port output type register,        Address offset: 0x04
GPIO_OType_PP = 0x00,

0x4402080C |= 0x01 << (10 * 2)
__IO uint32_t PUPDR;    /*!< GPIO port pull-up/pull-down register,  Address offset: 0x0C
GPIO_PuPd_UP     = 0x01,

===================================================================

#define PERIPH_BASE           ((uint32_t)0x40000000)
#define APB1PERIPH_BASE       PERIPH_BASE
#define USART3_BASE           (APB1PERIPH_BASE + 0x4800)

0x40004810 |= 0x0000
__IO uint16_t CR2;        /*!< USART Control register 2,                Address offset: 0x10 
#define USART_StopBits_1                     ((uint16_t)0x0000)

0x4000480C |= 0x0 | 0x0 | 0x4 | 0x8
__IO uint16_t CR1;        /*!< USART Control register 1,                Address offset: 0x0C
#define USART_WordLength_8b                  ((uint16_t)0x0000)
#define USART_Parity_No                      ((uint16_t)0x0000)
#define USART_Mode_Rx                        ((uint16_t)0x0004)
#define USART_Mode_Tx                        ((uint16_t)0x0008)

0x40004814 |= 0x0
__IO uint16_t CR3;        /*!< USART Control register 3,                Address offset: 0x14
#define USART_HardwareFlowControl_None       ((uint16_t)0x0000)




__IO uint16_t BRR;        /*!< USART Baud rate register,                Address offset: 0x08

沒有留言:

張貼留言