Skip to content

Update serial_api.c #270

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 22, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ typedef enum {

typedef enum {
UART_1 = (int)USART1_BASE,
UART_2 = (int)USART2_BASE
UART_2 = (int)USART2_BASE,
UART_3 = (int)USART3_BASE
} UARTName;

#define STDIO_UART_TX PA_2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,22 @@
#include <string.h>

static const PinMap PinMap_UART_TX[] = {
{PA_9, UART_1, STM_PIN_DATA(GPIO_Mode_AF_PP, 0)},
{PA_2, UART_2, STM_PIN_DATA(GPIO_Mode_AF_PP, 0)},
{NC, NC, 0}
{PA_9, UART_1, STM_PIN_DATA(GPIO_Mode_AF_PP, 0)},
{PA_2, UART_2, STM_PIN_DATA(GPIO_Mode_AF_PP, 0)},
{PB_10, UART_3, STM_PIN_DATA(GPIO_Mode_AF_PP, 0)},
{NC, NC, 0}
};

static const PinMap PinMap_UART_RX[] = {
{PA_10, UART_1, STM_PIN_DATA(GPIO_Mode_IN_FLOATING, 0)},
{PA_3, UART_2, STM_PIN_DATA(GPIO_Mode_IN_FLOATING, 0)},
{NC, NC, 0}
{PA_10, UART_1, STM_PIN_DATA(GPIO_Mode_IN_FLOATING, 0)},
{PA_3, UART_2, STM_PIN_DATA(GPIO_Mode_IN_FLOATING, 0)},
{PB_11, UART_3, STM_PIN_DATA(GPIO_Mode_IN_FLOATING, 0)},
{NC, NC, 0}
};

#define UART_NUM (2)
#define UART_NUM (3)

static uint32_t serial_irq_ids[UART_NUM] = {0};
static uint32_t serial_irq_ids[UART_NUM] = {0,0,0};

static uart_irq_handler irq_handler;

Expand Down Expand Up @@ -86,9 +88,10 @@ void serial_init(serial_t *obj, PinName tx, PinName rx) {
// Enable USART clock
if (obj->uart == UART_1) {
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
}
if (obj->uart == UART_2) {
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
} else if (obj->uart == UART_2 ) {
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
} else if (obj->uart == UART_3 ) {
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
}

// Configure the UART pins
Expand All @@ -106,6 +109,7 @@ void serial_init(serial_t *obj, PinName tx, PinName rx) {
// The index is used by irq
if (obj->uart == UART_1) obj->index = 0;
if (obj->uart == UART_2) obj->index = 1;
if (obj->uart == UART_3) obj->index = 2;

// For stdio management
if (obj->uart == STDIO_UART) {
Expand Down Expand Up @@ -176,6 +180,7 @@ static void uart_irq(USART_TypeDef* usart, int id) {

static void uart1_irq(void) {uart_irq((USART_TypeDef*)UART_1, 0);}
static void uart2_irq(void) {uart_irq((USART_TypeDef*)UART_2, 1);}
static void uart3_irq(void) {uart_irq((USART_TypeDef*)UART_3, 2);}

void serial_irq_handler(serial_t *obj, uart_irq_handler handler, uint32_t id) {
irq_handler = handler;
Expand All @@ -196,7 +201,12 @@ void serial_irq_set(serial_t *obj, SerialIrq irq, uint32_t enable) {
irq_n = USART2_IRQn;
vector = (uint32_t)&uart2_irq;
}


if (obj->uart == UART_3) {
irq_n = USART3_IRQn;
vector = (uint32_t)&uart3_irq;
}

if (enable) {

if (irq == RxIrq) {
Expand Down