Merge branch 'dev' into ui

This commit is contained in:
Mario Hüttel 2020-02-24 20:03:57 +01:00
commit 49835d9213
14 changed files with 424 additions and 105 deletions

View File

@ -51,6 +51,8 @@ CFILES += stack-check.c
CFILES += ui/lcd.c ui/menu.c
CFILES += onewire-if.c onewire-temp-sensors.c
DEFINES += -DDEBUGBUILD
###################################################################################

View File

@ -27,6 +27,8 @@
#include <stdlib.h>
#include <float.h>
extern struct stm_uart shell_uart;
void calibration_calculate(float low_measured, float low_setpoint, float high_measured, float high_setpoint,
float *sens_deviation, float *sens_corrected_offset)
{
@ -110,7 +112,7 @@ static void wait_for_uart_enter()
int uart_recv_status;
do {
uart_recv_status = uart_receive_data_with_dma(&recv_data, &recv_len);
uart_recv_status = uart_receive_data_with_dma(&shell_uart, &recv_data, &recv_len);
if (uart_recv_status >= 1) {
for (iter = 0; iter < recv_len; iter++) {
if (recv_data[iter] == '\n' || recv_data[iter] == '\r')

View File

@ -0,0 +1,34 @@
/* Reflow Oven Controller
*
* Copyright (C) 2020 Mario Hüttel <mario.huettel@gmx.net>
*
* This file is part of the Reflow Oven Controller Project.
*
* The reflow oven controller is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* The Reflow Oven Control Firmware is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with the reflow oven controller project.
* If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __ONEWIRE_IF_H__
#define __ONEWIRE_IF_H__
#include <stm-periph/uart.h>
int onewire_if_init_uart(struct stm_uart *uart, uint32_t brr_val, USART_TypeDef *onewire_uart, volatile uint32_t *rcc_reg, uint8_t rcc_bit_num);
void onewire_if_disable(struct stm_uart *uart);
int onewire_if_send_byte(struct stm_uart *uart);
int onewire_if_receive_byte(struct stm_uart *uart);
#endif /* __ONEWIRE_IF_H__ */

View File

@ -0,0 +1,47 @@
/* Reflow Oven Controller
*
* Copyright (C) 2020 Mario Hüttel <mario.huettel@gmx.net>
*
* This file is part of the Reflow Oven Controller Project.
*
* The reflow oven controller is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* The Reflow Oven Control Firmware is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with the reflow oven controller project.
* If not, see <http://www.gnu.org/licenses/>.
*/
#include <stddef.h>
#include <stdint.h>
#ifndef __ONEWIRE_TEMP_SENSORS_H__
#define __ONEWIRE_TEMP_SENSORS_H__
#define ONEWIRE_TEMP_PORT GPIOB
#define ONEWIRE_TEMP_RCC_MASK RCC_AHB1ENR_GPIOBEN
#define ONEWIRE_TEMP_TX_PIN 10U
#define ONEWIRE_TEMP_RX_PIN 11U
#define ONEWIRE_TEMP_AF_NUM 7U
#define ONEWIRE_UART_DEV USART3
void onewire_temp_sensors_setup_hw();
/**
* @brief onewire_temp_sensors_discover
* @param id_list
* @param list_len
* @return Negative: error, >= 0: amount of discovered sensors
*/
int onewire_temp_sensors_discover(uint32_t *id_list, size_t list_len);
float onewire_temp_sensor_read_temp(uint32_t id);
#endif /* __ONEWIRE_TEMP_SENSORS_H__ */

View File

@ -0,0 +1,33 @@
#ifndef __SHELL_UART_CONFIG_H__
#define __SHELL_UART_CONFIG_H__
#define SHELL_UART_RECEIVE_DMA_STREAM DMA2_Stream5
#define SHELL_UART_SEND_DMA_STREAM DMA2_Stream7
#define SHELL_UART_PERIPH USART1
#define SHELL_UART_RCC_REG RCC->APB2ENR
#define SHELL_UART_RCC_MASK RCC_APB2ENR_USART1EN
#define SHELL_UART_RX_DMA_TRIGGER 4U
#define SHELL_UART_TX_DMA_TRIGGER 4U
#ifdef DEBUGBUILD
#define SHELL_UART_PORT GPIOA
#define SHELL_UART_PORT_RCC_MASK RCC_AHB1ENR_GPIOAEN
#define SHELL_UART_RX_PIN 10
#define SHELL_UART_TX_PIN 9
#define SHELL_UART_RX_PIN_ALTFUNC 7
#define SHELL_UART_TX_PIN_ALTFUNC 7
#else
#endif
/* UART_DIV is 45.5625 => 115200 @ 84 MHz */
#define SHELL_UART_DIV_FRACTION 9U /* Equals 9/16 = 0.5625 */
#define SHELL_UART_DIV_MANTISSA 45U /* Equals 45 */
#define SHELL_UART_BRR_REG_VALUE ((SHELL_UART_DIV_MANTISSA<<4) | SHELL_UART_DIV_FRACTION);
#endif /* __SHELL_UART_CONFIG_H__ */

View File

@ -24,7 +24,7 @@
#include <stddef.h>
#include <shellmatta.h>
shellmatta_handle_t shell_init(void);
shellmatta_handle_t shell_init(shellmatta_write_t write_func);
void shell_handle_input(shellmatta_handle_t shell, const char *data, size_t len);

View File

@ -29,6 +29,7 @@
#define PINMASK(pin) ((0x3) << (pin * 2))
#define SETAF(PORT,PIN,AF) PORT->AFR[(PIN < 8 ? 0 : 1)] |= AF << ((PIN < 8 ? PIN : (PIN - 8)) * 4)
#define ANALOG(pin) (0x03 << (pin * 2))
#define OTYP_OPENDRAIN(pin) (0x1U << (pin))
#define BITMASK_TO_BITNO(x) (x&0x1?0:x&0x2?1:x&0x4?2:x&0x8?3: \
x&0x10?4:x&0x20?5:x&0x40?6:x&0x80?7: \

View File

@ -18,57 +18,55 @@
* If not, see <http://www.gnu.org/licenses/>.
*/
#include <stm32/stm32f4xx.h>
#include <stm-periph/dma-ring-buffer.h>
#include <stdint.h>
#include <stddef.h>
#ifndef UART_UART_H_
#define UART_UART_H_
#define UART_RECEIVE_DMA_STREAM DMA2_Stream5
struct stm_uart {
USART_TypeDef *uart_dev;
uint32_t brr_val;
uint8_t base_dma_num;
DMA_Stream_TypeDef *dma_tx_stream;
uint8_t dma_tx_trigger_channel;
DMA_Stream_TypeDef *dma_rx_stream;
uint8_t dma_rx_trigger_channel;
char *dma_rx_buff;
char *dma_tx_buff;
size_t rx_buff_count;
size_t tx_buff_count;
volatile uint32_t *rcc_reg;
uint8_t rcc_bit_no;
struct dma_ring_buffer_to_mem rx_ring_buff;
struct dma_ring_buffer_to_periph tx_ring_buff;
uint8_t tx : 1;
uint8_t rx : 1;
};
#define UART_SEND_DMA_STREAM DMA2_Stream7
int uart_init(struct stm_uart *uart);
#define UART_PERIPH USART1
#define UART_RCC_MASK RCC_APB2ENR_USART1EN
void uart_disable(struct stm_uart *uart);
#ifdef DEBUGBUILD
void uart_send_char(struct stm_uart *uart, char c);
#define UART_PORT GPIOA
#define UART_PORT_RCC_MASK RCC_AHB1ENR_GPIOAEN
#define UART_RX_PIN 10
#define UART_TX_PIN 9
#define UART_RX_PIN_ALTFUNC 7
#define UART_TX_PIN_ALTFUNC 7
#else
void uart_send_array(struct stm_uart *uart, const char *data, uint32_t len);
#endif
void uart_send_string(struct stm_uart *uart, const char *string);
/* UART_DIV is 45.5625 => 115200 @ 84 MHz */
#define UART_DIV_FRACTION 9U /* Equals 9/16 = 0.5625 */
#define UART_DIV_MANTISSA 45U /* Equals 45 */
void uart_send_array_with_dma(struct stm_uart *uart, const char *data, uint32_t len);
#define UART_BRR_REG_VALUE ((UART_DIV_MANTISSA<<4) | UART_DIV_FRACTION);
void uart_send_string_with_dma(struct stm_uart *uart, const char *string);
void initUART();
void sendChar(char c);
void sendString(char* s, int count);
int uart_receive_data_with_dma(struct stm_uart *uart, const char **data, size_t *len);
char uart_get_char(struct stm_uart *uart);
void uart_init_with_dma();
int uart_check_rx_avail(struct stm_uart *uart);
void uart_disable();
void uart_send_char(char c);
void uart_send_array(const char *data, uint32_t len);
void uart_send_string(const char *string);
void uart_send_array_with_dma(const char *data, uint32_t len);
void uart_send_string_with_dma(const char *string);
int uart_receive_data_with_dma(const char **data, size_t *len);
void uart_tx_dma_complete_int_callback(struct stm_uart *uart);
#endif /* UART_UART_H_ */

View File

@ -37,6 +37,8 @@
#include <stm-periph/stm32-gpio-macros.h>
#include <stm-periph/clock-enable-manager.h>
#include <stm-periph/uart.h>
#include <reflow-controller/shell-uart-config.h>
#include <helper-macros/helper-macros.h>
static void setup_nvic_priorities()
{
@ -54,6 +56,51 @@ static volatile int pt1000_value_status;
static uint32_t rot;
static inline void uart_gpio_config()
{
#ifdef DEBUGBUILD
rcc_manager_enable_clock(&RCC->AHB1ENR, BITMASK_TO_BITNO(SHELL_UART_PORT_RCC_MASK));
SHELL_UART_PORT->MODER &= MODER_DELETE(SHELL_UART_TX_PIN) & MODER_DELETE(SHELL_UART_RX_PIN);
SHELL_UART_PORT->MODER |= ALTFUNC(SHELL_UART_RX_PIN) | ALTFUNC(SHELL_UART_TX_PIN);
SETAF(SHELL_UART_PORT, SHELL_UART_RX_PIN, SHELL_UART_RX_PIN_ALTFUNC);
SETAF(SHELL_UART_PORT, SHELL_UART_TX_PIN, SHELL_UART_TX_PIN_ALTFUNC);
#endif
}
static char shell_uart_tx_buff[128];
static char shell_uart_rx_buff[32];
struct stm_uart shell_uart;
static shellmatta_retCode_t write_shell_callback(const char *data, uint32_t len)
{
uart_send_array_with_dma(&shell_uart, data, len);
return SHELLMATTA_OK;
}
static inline void setup_sell_uart(struct stm_uart *uart)
{
uart->rx = 1;
uart->tx = 1;
uart->brr_val = SHELL_UART_BRR_REG_VALUE;
uart->rcc_reg = &SHELL_UART_RCC_REG;
uart->rcc_bit_no = BITMASK_TO_BITNO(SHELL_UART_RCC_MASK);
uart->uart_dev = SHELL_UART_PERIPH;
uart->dma_rx_buff = shell_uart_rx_buff;
uart->dma_tx_buff = shell_uart_tx_buff;
uart->rx_buff_count = sizeof(shell_uart_rx_buff);
uart->tx_buff_count = sizeof(shell_uart_tx_buff);
uart->base_dma_num = 2;
uart->dma_rx_stream = SHELL_UART_RECEIVE_DMA_STREAM;
uart->dma_tx_stream = SHELL_UART_SEND_DMA_STREAM;
uart->dma_rx_trigger_channel = SHELL_UART_RX_DMA_TRIGGER;
uart->dma_tx_trigger_channel = SHELL_UART_TX_DMA_TRIGGER;
uart_init(uart);
NVIC_EnableIRQ(DMA2_Stream7_IRQn);
}
int main()
{
const char *uart_input;
@ -71,16 +118,27 @@ int main()
loudspeaker_setup();
rotary_encoder_setup();
uart_init_with_dma();
uart_gpio_config();
setup_sell_uart(&shell_uart);
shell_handle = shell_init();
shell_handle = shell_init(write_shell_callback);
while (1) {
pt1000_value_status = adc_pt1000_get_current_resistance(&pt1000_value);
rot = rotary_encoder_get_abs_val();
uart_receive_status = uart_receive_data_with_dma(&uart_input, &uart_input_len);
uart_receive_status = uart_receive_data_with_dma(&shell_uart, &uart_input, &uart_input_len);
if (uart_receive_status >= 1)
shell_handle_input(shell_handle, uart_input, uart_input_len);
}
}
void DMA2_Stream7_IRQHandler()
{
uint32_t hisr = DMA2->HISR;
DMA2->HIFCR = hisr;
if (hisr & DMA_HISR_TCIF7) {
uart_tx_dma_complete_int_callback(&shell_uart);
}
}

56
stm-firmware/onewire-if.c Normal file
View File

@ -0,0 +1,56 @@
/* Reflow Oven Controller
*
* Copyright (C) 2020 Mario Hüttel <mario.huettel@gmx.net>
*
* This file is part of the Reflow Oven Controller Project.
*
* The reflow oven controller is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* The Reflow Oven Control Firmware is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with the reflow oven controller project.
* If not, see <http://www.gnu.org/licenses/>.
*/
#include <reflow-controller/onewire-if.h>
int onewire_if_init_uart(struct stm_uart *uart, uint32_t brr_val, USART_TypeDef *onewire_uart, volatile uint32_t *rcc_reg, uint8_t rcc_bit_num)
{
if (!uart)
return -1000;
uart->rx = 1;
uart->tx = 1;
uart->brr_val = brr_val;
uart->rcc_reg = rcc_reg;
uart->uart_dev = onewire_uart;
uart->rcc_bit_no = rcc_bit_num;
uart->dma_rx_buff = NULL;
uart->dma_tx_buff = NULL;
return uart_init(uart);
}
void onewire_if_disable(struct stm_uart *uart)
{
if (!uart)
return;
uart_disable(uart);
}
int onewire_if_send_byte(struct stm_uart *uart)
{
}
int onewire_if_receive_byte(struct stm_uart *uart)
{
}

View File

@ -0,0 +1,42 @@
/* Reflow Oven Controller
*
* Copyright (C) 2020 Mario Hüttel <mario.huettel@gmx.net>
*
* This file is part of the Reflow Oven Controller Project.
*
* The reflow oven controller is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* The Reflow Oven Control Firmware is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with the reflow oven controller project.
* If not, see <http://www.gnu.org/licenses/>.
*/
#include <stm32/stm32f4xx.h>
#include <stm-periph/uart.h>
#include <reflow-controller/onewire-if.h>
#include <reflow-controller/onewire-temp-sensors.h>
#include <stm-periph/clock-enable-manager.h>
#include <stm-periph/stm32-gpio-macros.h>
static struct stm_uart if_uart;
void onewire_temp_sensors_setup_hw()
{
rcc_manager_enable_clock(&RCC->AHB1ENR, BITMASK_TO_BITNO(ONEWIRE_TEMP_RCC_MASK));
ONEWIRE_TEMP_PORT->OTYPER |= OTYP_OPENDRAIN(ONEWIRE_TEMP_TX_PIN);
ONEWIRE_TEMP_PORT->MODER &= MODER_DELETE(ONEWIRE_TEMP_RX_PIN) & MODER_DELETE(ONEWIRE_TEMP_TX_PIN);
ONEWIRE_TEMP_PORT->MODER |= ALTFUNC(ONEWIRE_TEMP_RX_PIN) | ALTFUNC(ONEWIRE_TEMP_TX_PIN);
SETAF(ONEWIRE_TEMP_PORT, ONEWIRE_TEMP_RX_PIN, ONEWIRE_TEMP_AF_NUM);
SETAF(ONEWIRE_TEMP_PORT, ONEWIRE_TEMP_TX_PIN, ONEWIRE_TEMP_AF_NUM);
(void)onewire_if_init_uart(&if_uart, 1, ONEWIRE_UART_DEV, &RCC->APB1ENR, BITMASK_TO_BITNO(RCC_APB1ENR_USART3EN));
}

View File

@ -41,12 +41,6 @@ static shellmatta_instance_t shell;
static char shell_buffer[512];
static char history_buffer[1024];
static shellmatta_retCode_t write_shell_callback(const char *data, uint32_t len)
{
uart_send_array_with_dma(data, len);
return SHELLMATTA_OK;
}
static shellmatta_retCode_t shell_cmd_ver(const shellmatta_handle_t handle,
const char *arguments,
uint32_t length)
@ -325,13 +319,13 @@ static shellmatta_cmd_t cmd[9] = {
}
};
shellmatta_handle_t shell_init(void)
shellmatta_handle_t shell_init(shellmatta_write_t write_func)
{
shellmatta_handle_t handle;
shellmatta_retCode_t ret;
ret = shellmatta_doInit(&shell, &handle, shell_buffer, sizeof(shell_buffer), history_buffer, sizeof(history_buffer),
"\e[1;32mEnter command:\e[m\r\n", cmd, write_shell_callback);
"\e[1;32mEnter command:\e[m\r\n", cmd, write_func);
if (ret != SHELLMATTA_OK)
handle = NULL;

View File

@ -25,99 +25,150 @@
#include <stm-periph/dma-ring-buffer.h>
#include <string.h>
static struct dma_ring_buffer_to_mem ring_buff_rx;
static struct dma_ring_buffer_to_periph ring_buff_tx;
static char uart_rx_buffer[64];
static char uart_tx_buffer[256];
#ifdef DEBUGBUILD
static inline void uart_gpio_config()
int uart_init(struct stm_uart *uart)
{
rcc_manager_enable_clock(&RCC->AHB1ENR, BITMASK_TO_BITNO(UART_PORT_RCC_MASK));
UART_PORT->MODER &= MODER_DELETE(UART_TX_PIN) & MODER_DELETE(UART_RX_PIN);
UART_PORT->MODER |= ALTFUNC(UART_RX_PIN) | ALTFUNC(UART_TX_PIN);
SETAF(UART_PORT, UART_RX_PIN, UART_RX_PIN_ALTFUNC);
SETAF(UART_PORT, UART_TX_PIN, UART_TX_PIN_ALTFUNC);
}
#endif
int ret_val = 0;
uint32_t cr3 = 0;
uint32_t cr1 = 0;
void uart_init_with_dma()
{
rcc_manager_enable_clock(&RCC->APB2ENR, BITMASK_TO_BITNO(UART_RCC_MASK));
#ifdef DEBUGBUILD
uart_gpio_config();
#endif
UART_PERIPH->BRR = UART_BRR_REG_VALUE;
UART_PERIPH->CR3 = USART_CR3_DMAR | USART_CR3_DMAT;
UART_PERIPH->CR1 = USART_CR1_TE | USART_CR1_RE | USART_CR1_UE;
if (!uart)
return -1000;
dma_ring_buffer_periph_to_mem_initialize(&ring_buff_rx, 2, UART_RECEIVE_DMA_STREAM, sizeof(uart_rx_buffer), 1U,
uart_rx_buffer, (char *)&UART_PERIPH->DR, 4);
dma_ring_buffer_mem_to_periph_initialize(&ring_buff_tx, 2, UART_SEND_DMA_STREAM, sizeof(uart_tx_buffer), 1U,
uart_tx_buffer, 4U, (void *)&UART_PERIPH->DR);
rcc_manager_enable_clock(uart->rcc_reg, uart->rcc_bit_no);
NVIC_EnableIRQ(DMA2_Stream7_IRQn);
/* Reset all config regs */
uart->uart_dev->CR1 = uart->uart_dev->CR2 = uart->uart_dev->CR3 = 0UL;
/* Set baud rate */
uart->uart_dev->BRR = uart->brr_val;
/* If DMA buffers are present, configure for DMA use */
if (uart->dma_rx_buff && uart->rx) {
cr3 |= USART_CR3_DMAR;
ret_val = dma_ring_buffer_periph_to_mem_initialize(&uart->rx_ring_buff,
uart->base_dma_num,
uart->dma_rx_stream,
uart->rx_buff_count,
1U,
uart->dma_rx_buff,
(char *)&uart->uart_dev->DR,
uart->dma_rx_trigger_channel);
if (ret_val)
return ret_val;
}
if (uart->dma_tx_buff && uart->tx) {
ret_val = dma_ring_buffer_mem_to_periph_initialize(&uart->tx_ring_buff,
uart->base_dma_num,
uart->dma_tx_stream,
uart->tx_buff_count,
1U,
uart->dma_tx_buff,
uart->dma_tx_trigger_channel,
(void *)&uart->uart_dev->DR);
if (ret_val)
return ret_val;
cr3 |= USART_CR3_DMAT;
}
uart->uart_dev->CR3 = cr3;
if (uart->tx)
cr1 |= USART_CR1_TE;
if (uart->rx)
cr1 |= USART_CR1_RE;
/* Enable uart */
cr1 |= USART_CR1_UE;
uart->uart_dev->CR1 = cr1;
return 0;
}
void uart_disable()
void uart_disable(struct stm_uart *uart)
{
UART_PERIPH->CR1 = 0;
UART_PERIPH->CR2 = 0;
UART_PERIPH->CR3 = 0;
dma_ring_buffer_periph_to_mem_stop(&ring_buff_rx);
dma_ring_buffer_mem_to_periph_stop(&ring_buff_tx);
#ifdef DEBUGBUILD
rcc_manager_disable_clock(&RCC->AHB1ENR, BITMASK_TO_BITNO(UART_PORT_RCC_MASK));
#endif
rcc_manager_disable_clock(&RCC->APB2ENR, BITMASK_TO_BITNO(UART_RCC_MASK));
if (!uart)
return;
uart->uart_dev->CR1 = 0;
uart->uart_dev->CR2 = 0;
uart->uart_dev->CR3 = 0;
if (uart->rx && uart->dma_rx_buff)
dma_ring_buffer_periph_to_mem_stop(&uart->rx_ring_buff);
if (uart->dma_tx_buff && uart->tx)
dma_ring_buffer_mem_to_periph_stop(&uart->tx_ring_buff);
rcc_manager_disable_clock(uart->rcc_reg, uart->rcc_bit_no);
}
void uart_send_char(char c)
void uart_send_char(struct stm_uart *uart, char c)
{
while(!(UART_PERIPH->SR & USART_SR_TXE));
UART_PERIPH->DR = c;
if (!uart || !uart->uart_dev)
return;
while(!(uart->uart_dev->SR & USART_SR_TXE));
uart->uart_dev->DR = c;
}
void uart_send_array(const char *data, uint32_t len)
void uart_send_array(struct stm_uart *uart, const char *data, uint32_t len)
{
uint32_t i;
for (i = 0; i < len; i++)
uart_send_char(data[i]);
uart_send_char(uart, data[i]);
}
void uart_send_string(const char *string)
void uart_send_string(struct stm_uart *uart, const char *string)
{
int i;
for (i = 0; string[i] != '\0'; i++)
uart_send_char(string[i]);
uart_send_char(uart, string[i]);
}
void uart_send_array_with_dma(const char *data, uint32_t len)
void uart_send_array_with_dma(struct stm_uart *uart, const char *data, uint32_t len)
{
dma_ring_buffer_mem_to_periph_insert_data(&ring_buff_tx, data, len);
if (!uart || !uart->dma_tx_buff)
return;
dma_ring_buffer_mem_to_periph_insert_data(&uart->tx_ring_buff, data, len);
}
void uart_send_string_with_dma(const char *string)
void uart_send_string_with_dma(struct stm_uart *uart, const char *string)
{
size_t len;
len = strlen(string);
uart_send_array_with_dma(string, (uint32_t)len);
uart_send_array_with_dma(uart, string, (uint32_t)len);
}
int uart_receive_data_with_dma(const char **data, size_t *len)
int uart_receive_data_with_dma(struct stm_uart *uart, const char **data, size_t *len)
{
return dma_ring_buffer_periph_to_mem_get_data(&ring_buff_rx, (const volatile void **)data, len);
if (!uart)
return -1000;
return dma_ring_buffer_periph_to_mem_get_data(&uart->rx_ring_buff, (const volatile void **)data, len);
}
void DMA2_Stream7_IRQHandler()
int uart_check_rx_avail(struct stm_uart *uart)
{
uint32_t hisr = DMA2->HISR;
DMA2->HIFCR = hisr;
if (!uart)
return 0;
if (hisr & DMA_HISR_TCIF7) {
dma_ring_buffer_mem_to_periph_int_callback(&ring_buff_tx);
}
if (uart->uart_dev->SR & USART_SR_RXNE)
return 1;
else
return 0;
}
void uart_tx_dma_complete_int_callback(struct stm_uart *uart)
{
if (!uart)
return;
dma_ring_buffer_mem_to_periph_int_callback(&uart->tx_ring_buff);
}

View File

@ -23,6 +23,7 @@
#include <errno.h>
#include <stddef.h>
extern struct stm_uart shell_uart;
char* _sbrk(int incr)
{
@ -87,6 +88,6 @@ int _read(void)
int _write(int fd, const void *buf, int count)
{
if (fd == 1)
uart_send_array_with_dma((char*)buf, count);
uart_send_array_with_dma(&shell_uart, (char *)buf, count);
return count;
}