Thanks Lads.
Last Edited: Tue. Apr 7, 2020 - 06:11 PM
Someone must have a uart example I could work from.
Please help a fellow freak.
This is what I have at the moment, but it appears to e poling:
#define USART_ADDR USART0 #define USART_PINS PINS_USART0 char gps_rx; static const struct _pin usart_pins_gps[] = USART_PINS; static struct _usart_desc usart_desc_gps = { .addr = USART_ADDR, .baudrate = 9600, .mode = US_MR_CHMODE_NORMAL | US_MR_PAR_NO | US_MR_CHRL_8_BIT, .transfer_mode = USARTD_MODE_ASYNC, .timeout = 10000, // unit: ms }; #include "../../examples/ARM_Cortex-A5_SAMA5D/cerulean_console/c_printf.h" static int console_handler(void* arg, void* arg2) { //usart_int_handler(gps_rx); c_printf("%c", gps_rx); //console_rx(); return 1; } void console_rx(void) { struct _buffer rx = { .data = (unsigned char*)&gps_rx, .size = 1, .attr = USARTD_BUF_ATTR_READ, }; struct _callback _cb = { .method = console_handler, .arg = 0, }; usartd_transfer(4, &rx, &_cb); } void initialise_gps_hardware (void) { /* configure spi serial flash pins */ pio_configure(usart_pins_gps, ARRAY_SIZE(usart_pins_gps)); usartd_configure(4, &usart_desc_gps); console_rx(); }
You’ve been pointed at the linux source more than once! There’a a fair chance that Atmel poured a bit of effort into the Linux drivers. The uart is the simplest and fairly critical, so there’s a very good chance it works.
At a minimum, you would want to implement buffered rx and tx. Even Arduino does this.
Guys, got it working.
#include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include "board.h" #include "callback.h" #include "chip.h" #include "cpuidle.h" #include "gpio/pio.h" #include "led/led.h" #include "mm/cache.h" #include "mutex.h" #include "peripherals/pmc.h" #include "serial/console.h" #include "serial/usart.h" #include "serial/usartd.h" #include "timer.h" #include "irq/irq.h" #include "gpio/pio.h" #include "peripherals/pit.h" #include "peripherals/tc.h" #include "uart.h" #include "../gps_driver.h" #define USART_ADDR USART0 #define USART_PINS PINS_USART0 char gps_data; static const struct _pin usart_pins_gps[] = USART_PINS; static struct _usart_desc usart_desc_gps = { .addr = USART_ADDR, .baudrate = 9600, .mode = US_MR_CHMODE_NORMAL | US_MR_PAR_NO | US_MR_NBSTOP_1_BIT | US_MR_CHRL_8_BIT, .transfer_mode = USARTD_MODE_ASYNC, .timeout = 1000, // unit: ms }; /** * USART interrupt handler */ static void usart_irq_handler(unsigned int source, void* user_arg) { char test; source = get_usart_id_from_addr(usart_desc_gps.addr); //usartd_configure(0, &usart_desc_gps); Usart* p_us = usart_desc_gps.addr; test = usart_get_char(p_us); p_us->US_CR = US_CR_RSTSTA; } void initialise_gps_hardware (void) { /* configure spi serial flash pins */ pio_configure(usart_pins_gps, ARRAY_SIZE(usart_pins_gps)); usartd_configure(4, &usart_desc_gps); Usart* usart = usart_desc_gps.addr; unsigned int id = get_usart_id_from_addr(usart); /* Driver initialize */ usart_enable_it(usart, US_IER_RXRDY); irq_add_handler(id, usart_irq_handler, NULL); irq_enable(id); // gps_rx(); }