1#include <libopencm3/cm3/cortex.h>
2#include <libopencm3/cm3/nvic.h>
3#include <libopencm3/stm32/gpio.h>
4#include <libopencm3/stm32/rcc.h>
5#include <libopencm3/stm32/usart.h>
13#define ASC_USART USART2
15char dataBuffer[MAXDATALEN];
20#define extraInputBuffer_size 64
21uint8_t extraInputBuffer_raw[extraInputBuffer_size];
25char ascVersion, appVersion, command;
36 ascii_serial_com_set_ignore_CRC_mismatch(&asc);
41 extraInputBuffer_raw);
45 rcc_periph_clock_enable(RCC_GPIOA);
46 rcc_periph_clock_enable(RCC_USART2);
47 setup_usart(ASC_USART, 9600, GPIOA, GPIO2, GPIO_AF1, GPIOA, GPIO3,
49 nvic_enable_irq(NVIC_USART2_IRQ);
50 usart_enable_rx_interrupt(ASC_USART);
51 usart_enable(ASC_USART);
53 Catch(e) {
return e; }
68 &asc, &ascVersion, &appVersion, &command, dataBuffer, &dataLen);
69 if (command !=
'\0') {
71 &asc, ascVersion, appVersion, command, dataBuffer, dataLen);
77 (USART_ISR(ASC_USART) & USART_ISR_TXE)) {
79 usart_send(ASC_USART, tmp_byte);
82 Catch(e) { nExceptions++; }
circular_buffer_uint8 * ascii_serial_com_get_output_buffer(ascii_serial_com *asc)
ASCII Serial Com get output buffer.
void ascii_serial_com_init(ascii_serial_com *asc)
ASCII Serial Com Interface init method.
void ascii_serial_com_put_message_in_output_buffer(ascii_serial_com *asc, char ascVersion, char appVersion, char command, const char *data, size_t dataLen)
ASCII Serial Com Pack and put message in output buffer.
void ascii_serial_com_get_message_from_input_buffer(ascii_serial_com *asc, char *ascVersion, char *appVersion, char *command, char *data, size_t *dataLen)
ASCII Serial Com pop message from input buffer and unpack.
circular_buffer_uint8 * ascii_serial_com_get_input_buffer(ascii_serial_com *asc)
ASCII Serial Com get input buffer.
void circular_buffer_init_uint8(circular_buffer_uint8 *circ_buf, const size_t capacity, uint8_t *buffer)
circular buffer init method
uint8_t circular_buffer_pop_front_uint8(circular_buffer_uint8 *circ_buf)
circular buffer pop front
bool circular_buffer_is_empty_uint8(const circular_buffer_uint8 *circ_buf)
circular buffer get if empty
void circular_buffer_push_back_uint8(circular_buffer_uint8 *circ_buf, const uint8_t element)
circular buffer push back
To be used with the USART peripherals on STM32 microcontrollers.
#define setup_usart(usart, baud, tx_port, tx_pin, tx_af, rx_port, rx_pin, rx_af)
Setup a USART.
#define def_usart_isr_push_rx_to_circ_buf(isr_name, usart, circular_buffer)
Define the ISR for a USART to push rx bytes to a circular buffer.
ASCII Serial Com Interface State struct.