ВходНаше всё Теги codebook 无线电组件 Поиск Опросы Закон Среда
10 июля
343598 Топик полностью
SciFi (29.07.2012 21:56, просмотров: 90) ответил _basile на Пля! Столкнулся на встречке с STM32F217... Эта писец! На третий день удалось USART запустить, без прерываний. Сижу, курю, как IRQ запустить. В примерах и мануале - жопа. Пилят! Ну почему у NXP все зашибись, а у ентих...
Да ладно... Не может быть, что всё так плохо. #include "uart.h" #include "stm32f2regs.h" #include "assert_static.h" #define USART_BASE USART3_BASE #define USART_SR REG32(USART_BASE + 0) #define USART_DR REG32(USART_BASE + 4) #define USART_BRR REG32(USART_BASE + 8) #define USART_CR1 REG32(USART_BASE + 0xC) #define USART_CR2 REG32(USART_BASE + 0x10) #define USART_CR3 REG32(USART_BASE + 0x14) #define TXFIFOSIZE 128 #define RXFIFOSIZE 256 #define BAUDREG (30000000 / 100000) /* 100 kbps @ 30 MHz APB1 clock */ static uint8_t volatile txfifo[TXFIFOSIZE]; static uint8_t volatile rxfifo[RXFIFOSIZE]; static unsigned int volatile txtail, rxhead; static unsigned int txhead, rxtail; void uart_init(int prio) { assert_static(IS_PWR_OF_TWO(TXFIFOSIZE)); assert_static(IS_PWR_OF_TWO(RXFIFOSIZE)); /* enable clocking of USART3 */ REGBIT(RCC_APB1ENR, 18) = 1; /* enable clocking of PORT D */ REGBIT(RCC_AHB1ENR, 3) = 1; USART_BRR = BAUDREG; USART_CR1 = (1 << 13) /* USART enable */ | (1 << 5) /* RXNE irq enable */ | (1 << 3) /* transmitter enable */ | (1 << 2);/* receiver enable */ USART_CR3 = 8; /* select half duplex */ NVIC_IP[39 / 4] |= (prio << (8 * (39 % 4))); NVIC_SETENA1 = (1 << (39 - 32)); /* configure PD8 as AF #7 */ GPIOD_AFRH |= 0x00000007; GPIOD_MODER |= 0x00020000; } __root void usart3_handler(void) { uint32_t status; status = USART_SR; if (status & (1 << 5)) /* RXNE */ { int head; head = rxhead; if ((head - rxtail) != RXFIFOSIZE) { rxfifo[head & (RXFIFOSIZE - 1)] = USART_DR; rxhead = head + 1; } else { (void)USART_DR; } } if (status & (1 << 7)) /* TXE */ { int tail; tail = txtail; if (txhead != tail) { USART_DR = txfifo[tail & (TXFIFOSIZE - 1)]; txtail = tail + 1; } else { USART_CR1 &= ~(1 << 7); /* disable TXNE irq */ } } } int uart_txfree(void) { return TXFIFOSIZE - (txhead - txtail); } int uart_txfull(void) { return txhead - txtail; } void uart_putbyte(uint8_t byte) { while (uart_txfree() == 0) { /* wait for free space in Tx FIFO */ } txfifo[txhead & (TXFIFOSIZE - 1)] = byte; txhead++; USART_CR1 |= (1 << 7); /* enable TXNE irq */ } int uart_rxcount(void) { return rxhead - rxtail; } uint8_t uart_getbyte(void) { uint8_t ret; ret = rxfifo[rxtail & (RXFIFOSIZE - 1)]; rxtail++; return ret; }
ส็็็็็็็็็็็็็็็็็็็็็็็็็༼ ຈل͜ຈ༽ส้้้้้้้้้้้้้้้้้้้้้้้