[feat] add dma_sniff demo
This commit is contained in:
parent
afa684873a
commit
1026053851
@ -631,7 +631,7 @@ static size_t print_exponential_number(out_fct_type out, char* buffer, size_t id
|
||||
|
||||
int exp10;
|
||||
bool abs_exp10_covered_by_powers_table;
|
||||
struct scaling_factor normalization;
|
||||
struct scaling_factor normalization = {0.0, 0};
|
||||
|
||||
|
||||
// Determine the decimal exponent
|
||||
|
||||
9
example/peripherals/dma/dma_sniff/CMakeLists.txt
Normal file
9
example/peripherals/dma/dma_sniff/CMakeLists.txt
Normal file
@ -0,0 +1,9 @@
|
||||
cmake_minimum_required(VERSION 3.10)
|
||||
|
||||
include(proj.conf)
|
||||
|
||||
project(${EXAMPLE_NAME} VERSION 0.1)
|
||||
add_executable(${EXAMPLE_NAME}.elf main.c)
|
||||
|
||||
add_subdirectory(${SDK_BASE_DIR} sdk)
|
||||
target_link_libraries(${EXAMPLE_NAME}.elf sdk)
|
||||
18
example/peripherals/dma/dma_sniff/Makefile
Normal file
18
example/peripherals/dma/dma_sniff/Makefile
Normal file
@ -0,0 +1,18 @@
|
||||
EXAMPLE_BASE_DIR ?= $(shell realpath .)
|
||||
EXAMPLE_NAME := $(notdir $(patsubst %/,%,$(CURDIR)))
|
||||
SDK_BASE_DIR ?= $(shell realpath ./../../../..)
|
||||
|
||||
export SDK_BASE_DIR
|
||||
export EXAMPLE_NAME
|
||||
export EXAMPLE_BASE_DIR
|
||||
|
||||
GCC_PATH := $(shell which arm-none-eabi-gcc)
|
||||
CROSS_COMPILE := $(patsubst %gcc,%,$(GCC_PATH))
|
||||
ifeq ($(GCC_PATH),)
|
||||
$(error arm-none-eabi-gcc not found in PATH. Please install the ARM toolchain.)
|
||||
endif
|
||||
|
||||
# add custom cmake definition
|
||||
#cmake_definition+=-Dxxx=sss
|
||||
|
||||
include $(SDK_BASE_DIR)/project.build
|
||||
85
example/peripherals/dma/dma_sniff/main.c
Normal file
85
example/peripherals/dma/dma_sniff/main.c
Normal file
@ -0,0 +1,85 @@
|
||||
#include "reset.h"
|
||||
#include "dma.h"
|
||||
#include "gpio.h"
|
||||
#include "uart.h"
|
||||
#include "RP2040.h"
|
||||
#include "stdio.h"
|
||||
|
||||
uint8_t dma_buffer_raw[] = { 0x55, 0xD5, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE };
|
||||
uint8_t dma_buffer_calc[20];
|
||||
struct dma_cfg_s dma_cfg = {
|
||||
.read_addr = (uint32_t)dma_buffer_raw,
|
||||
.write_addr = (uint32_t)dma_buffer_calc,
|
||||
.trans_count = sizeof(dma_buffer_raw) / 4,
|
||||
.channel = DMA_CHANNEL_0,
|
||||
.request = DMA_REQ_FOREVER,
|
||||
.data_size = DMA_DATA_SIZE_32BIT,
|
||||
.incr_read = ENABLE,
|
||||
.incr_write = ENABLE,
|
||||
.irq_quiet = DISABLE,
|
||||
.byte_swap = DISABLE,
|
||||
.chain_to = DMA_CHANNEL_0,
|
||||
.high_priority = DISABLE,
|
||||
.ring_sel_write = DISABLE,
|
||||
.ring_size = DMA_RING_SIZE_NONE,
|
||||
.sniff_en = ENABLE,
|
||||
};
|
||||
struct dma_sniff_cfg_s sniff_cfg = {
|
||||
.channel = DMA_CHANNEL_0,
|
||||
.calc = DMA_SNIFF_CALC_CRC32_BITREV,
|
||||
.byte_swap = DISABLE,
|
||||
.out_rev = ENABLE,
|
||||
.out_inv = ENABLE,
|
||||
};
|
||||
|
||||
struct uart_cfg_s uart_cfg = {
|
||||
.baudrate = 6 * 1000 * 1000,
|
||||
.mode = UART_MODE_TX_RX,
|
||||
.data_bits = UART_DATABITS_8,
|
||||
.parity = UART_PARITY_NONE,
|
||||
.stop_bits = UART_STOPBITS_1,
|
||||
.fifo_enable = ENABLE,
|
||||
.tx_fifo_level = UART_FIFO_LEVEL_1_2,
|
||||
.rx_fifo_level = UART_FIFO_LEVEL_1_2,
|
||||
};
|
||||
|
||||
int main(void)
|
||||
{
|
||||
uint32_t sniff_result;
|
||||
|
||||
reset_enable(RESET_DMA);
|
||||
reset_disable(RESET_DMA);
|
||||
gpio_init_simple(0, GPIO_FUNC_UART, DISABLE, ENABLE);
|
||||
uart_init(UART_ID_0, &uart_cfg);
|
||||
|
||||
for (int i = 0; i < sizeof(dma_buffer_calc); i++) {
|
||||
dma_buffer_calc[i] = 0;
|
||||
}
|
||||
|
||||
dma_int_clear_raw_status(1 << DMA_CHANNEL_0);
|
||||
dma_init(&dma_cfg);
|
||||
dma_sniff_init(&sniff_cfg);
|
||||
dma_sniff_write(0xA3123859);
|
||||
dma_sniff_enable();
|
||||
dma_enable_and_trig(dma_cfg.channel);
|
||||
while (!(dma_int_get_raw_status() & (1 << dma_cfg.channel)));
|
||||
for (int i = 0; i < sizeof(dma_buffer_raw); i++) {
|
||||
if (dma_buffer_raw[i] != dma_buffer_calc[i]) {
|
||||
printf("error, [%d] 0x%02X -> 0x%02X\r\n", i, dma_buffer_raw[i], dma_buffer_calc[i]);
|
||||
}
|
||||
}
|
||||
sniff_result = dma_sniff_read();
|
||||
if (sniff_result != 0xB0364FEA) {
|
||||
printf("CRC32 check error, result = 0x%08lX, expert = 0x%08X\r\n", sniff_result, 0xB0364FEA);
|
||||
} else {
|
||||
printf("CRC32 check succeed, result = 0x%08lX\r\n", sniff_result);
|
||||
}
|
||||
|
||||
__enable_irq();
|
||||
|
||||
while (1) {
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
1
example/peripherals/dma/dma_sniff/proj.conf
Normal file
1
example/peripherals/dma/dma_sniff/proj.conf
Normal file
@ -0,0 +1 @@
|
||||
# set(CONFIG_COMPONENT1 1)
|
||||
@ -1,11 +1,10 @@
|
||||
#include "system.h"
|
||||
#include "reset.h"
|
||||
#include "clock.h"
|
||||
#include "sio.h"
|
||||
#include "gpio.h"
|
||||
#include "uart.h"
|
||||
#include "stdio.h"
|
||||
#include "cmsis_gcc.h"
|
||||
#include "RP2040.h"
|
||||
|
||||
struct gpio_cfg_s gpio_led_cfg = {
|
||||
.pin = 25,
|
||||
|
||||
@ -9,6 +9,7 @@ CFLAGS += -O2
|
||||
CFLAGS += -Wall
|
||||
CFLAGS += -ffunction-sections
|
||||
CFLAGS += -fdata-sections
|
||||
CFLAGS += -Wpointer-arith
|
||||
|
||||
LDFLAGS += -mcpu=cortex-m0plus
|
||||
LDFLAGS += -mthumb
|
||||
@ -52,6 +53,7 @@ build:Makefile
|
||||
$(MAKE) -C build -j
|
||||
$(CROSS_COMPILE)objcopy -O binary $(EXAMPLE_BASE_DIR)/build/$(EXAMPLE_NAME).elf $(EXAMPLE_BASE_DIR)/build/$(EXAMPLE_NAME).bin
|
||||
$(CROSS_COMPILE)objdump -d -S $(EXAMPLE_BASE_DIR)/build/$(EXAMPLE_NAME).elf > $(EXAMPLE_BASE_DIR)/build/$(EXAMPLE_NAME).asm
|
||||
size $(EXAMPLE_BASE_DIR)/build/$(EXAMPLE_NAME).elf
|
||||
|
||||
clean::
|
||||
$(RM) build
|
||||
|
||||
Loading…
Reference in New Issue
Block a user