Skip to content
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

stm32: add option to handle tty using DMA #395

Merged
merged 3 commits into from
Sep 25, 2023
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
80 changes: 80 additions & 0 deletions multi/stm32l4-multi/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,86 @@

/* UART_CONSOLE has to be specified in board_config.h */

#ifndef TTY1_DMA
#define TTY1_DMA 0
#endif

#ifndef TTY2_DMA
#define TTY2_DMA 0
#endif

#ifndef TTY3_DMA
#define TTY3_DMA 0
#endif

#ifndef TTY4_DMA
#define TTY4_DMA 0
#endif

#ifndef TTY5_DMA
#define TTY5_DMA 0
#endif

#ifndef TTY1_DMA_RXSZ
#define TTY1_DMA_RXSZ 64
#endif

#ifndef TTY2_DMA_RXSZ
#define TTY2_DMA_RXSZ 64
#endif

#ifndef TTY3_DMA_RXSZ
#define TTY3_DMA_RXSZ 64
#endif

#ifndef TTY4_DMA_RXSZ
#define TTY4_DMA_RXSZ 64
#endif

#ifndef TTY5_DMA_RXSZ
#define TTY5_DMA_RXSZ 64
#endif

#ifndef TTY1_DMA_TXSZ
#define TTY1_DMA_TXSZ 64
#endif

#ifndef TTY2_DMA_TXSZ
#define TTY2_DMA_TXSZ 64
#endif

#ifndef TTY3_DMA_TXSZ
#define TTY3_DMA_TXSZ 64
#endif

#ifndef TTY4_DMA_TXSZ
#define TTY4_DMA_TXSZ 64
#endif

#ifndef TTY5_DMA_TXSZ
#define TTY5_DMA_TXSZ 64
#endif

#ifndef TTY1_LIBTTY_BUFSZ
#define TTY1_LIBTTY_BUFSZ 512
#endif

#ifndef TTY2_LIBTTY_BUFSZ
#define TTY2_LIBTTY_BUFSZ 512
#endif

#ifndef TTY3_LIBTTY_BUFSZ
#define TTY3_LIBTTY_BUFSZ 512
#endif

#ifndef TTY4_LIBTTY_BUFSZ
#define TTY4_LIBTTY_BUFSZ 512
#endif

#ifndef TTY5_LIBTTY_BUFSZ
#define TTY5_LIBTTY_BUFSZ 512
#endif


/* SPI */
#ifndef SPI1
Expand Down
48 changes: 46 additions & 2 deletions multi/stm32l4-multi/libmulti/include/libmulti/libdma.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,59 @@
#define LIBDMA_H_

#include <stddef.h>
#include <stdint.h>
#include <sys/threads.h>


#define DMA_MAX_LEN ((1u << 16) - 1u)


/* clang-format off */
enum { dma_per2mem = 0, dma_mem2per };


int libdma_configureSpi(int num, int dir, int priority, void *paddr, int msize, int psize, int minc, int pinc);
enum { dma_spi = 0, dma_uart };


enum { dma_ht = 0, dma_tc };
/* clang-format on */


struct libdma_per;


/* If cond == NULL only sync function maybe used, otherwise only async functions. */
int libdma_configurePeripheral(const struct libdma_per *per, int dir, int priority, void *paddr, int msize, int psize, int minc, int pinc, handle_t *cond);


/* SYNC FUNCTIONS */


int libdma_transfer(const struct libdma_per *per, void *rx_maddr, const void *tx_maddr, size_t len);


/* ASYNC FUNCTIONS */


/* Only one tx request per channel may be issued at a time. */
int libdma_txAsync(const struct libdma_per *per, const void *tx_maddr, size_t len, volatile int *done_flag);


/* Only one rx request per channel may be issued at a time. */
int libdma_rxAsync(const struct libdma_per *per, void *rx_maddr, size_t len, volatile int *done_flag);


/* Receive infinite rx into circular buffer. Fn is called at each Transfer Complete and Half Transfer interrupt. */
int libdma_infiniteRxAsync(const struct libdma_per *per, void *rx_maddr, size_t len, void fn(void *arg, int type), void *arg);


/* UTILITY FUNCTIONS */


uint16_t libdma_leftToRx(const struct libdma_per *per);


int libdma_transferSpi(int num, void *rx_maddr, const void *tx_maddr, size_t len);
const struct libdma_per *libdma_getPeripheral(int per, unsigned int num);


int libdma_init(void);
Expand Down
11 changes: 7 additions & 4 deletions multi/stm32l4-multi/libmulti/include/libmulti/libspi.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include <stddef.h>
#include <sys/threads.h>
#include "libmulti/libdma.h"


typedef struct {
Expand All @@ -27,21 +28,23 @@ typedef struct {
const unsigned char *obuff;
size_t cnt;

int usedma;
const struct libdma_per *per;
} libspi_ctx_t;


enum { spi1 = 0, spi2, spi3 };
#define SPI_ADDRSHIFT 3
#define SPI_ADDRMASK 0x3


#define SPI_ADDRSHIFT 3
#define SPI_ADDRMASK 0x3
/* clang-format off */
enum { spi1 = 0, spi2, spi3 };


enum { spi_cmd = 0x1, spi_dummy = 0x2, /* 3-bits for SPI_ADDR* ,*/ spi_addrlsb = 0x20 };


enum { spi_dir_read = 0, spi_dir_write, spi_dir_readwrite };
/* clang-format on */


int libspi_transaction(libspi_ctx_t *ctx, int dir, unsigned char cmd, unsigned int addr, unsigned char flags,
Expand Down
Loading
Loading