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

Add TRACESWO Manchester support #6

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions firmware/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ pico_generate_pio_header(MioLink ${CMAKE_CURRENT_LIST_DIR}/source/bmp/miolink_re
pico_generate_pio_header(MioLink ${CMAKE_CURRENT_LIST_DIR}/source/bmp/miolink_pico_swd.pio)
pico_generate_pio_header(MioLink ${CMAKE_CURRENT_LIST_DIR}/source/bmp/pico_swd.pio)
pico_generate_pio_header(MioLink ${CMAKE_CURRENT_LIST_DIR}/source/bmp/target_jtag.pio)
pico_generate_pio_header(MioLink ${CMAKE_CURRENT_LIST_DIR}/source/bmp/traceswo_manchester.pio)

# Set linker script and set parameter to print memory usage
if (build_type STREQUAL debug)
Expand Down
5 changes: 1 addition & 4 deletions firmware/include/bmp/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ extern bool debug_bmp;
#define SERIAL_ENDPOINT (0x02)

#ifdef PLATFORM_HAS_TRACESWO
#define SWO_ENCODING (2)
#define SWO_ENCODING (3)
#define SWO_ENDPOINT (0x83)
#endif

Expand Down Expand Up @@ -165,12 +165,9 @@ extern bool debug_bmp;

#define USB_SERIAL_UART_MAIN (uart1)
#define USB_SERIAL_UART_TDI_TDO (uart0)
#define TRACESWO_UART (uart0)

#define USB_SERIAL_UART_MAIN_IRQ (UART_IRQ_NUM(USB_SERIAL_UART_MAIN))
#define USB_SERIAL_UART_TDI_TDO_IRQ (UART_IRQ_NUM(USB_SERIAL_UART_TDI_TDO))
#define TRACESWO_UART_IRQ (UART_IRQ_NUM(TRACESWO_UART))

#define USB_SERIAL_TRACESWO_DMA_IRQ (DMA_IRQ_0)

#define PLATFORM_PRIORITY_LOW (tskIDLE_PRIORITY + 1)
Expand Down
10 changes: 8 additions & 2 deletions firmware/include/bmp/swo.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@
#include <stdlib.h>
#include "FreeRTOS.h"

#define TRACESWO_UART (uart0)
#define TRACESWO_UART_IRQ (UART_IRQ_NUM(TRACESWO_UART))

#define TRACESWO_PIO (pio1)
#define TRACESWO_PIO_IRQ (PIO_IRQ_NUM(TRACESWO_PIO, 0))

#define TRACESWO_BUF_SIZE (1024)

/* Default line rate, used as default for a request without baudrate */
Expand All @@ -41,7 +47,7 @@ extern swo_coding_e swo_current_mode;
/* Initialisation and deinitialisation functions (ties into command.c) */
void swo_init(swo_coding_e swo_mode, uint32_t baudrate, uint32_t itm_stream_bitmask);
void swo_deinit(bool deallocate);
uint32_t swo_uart_get_baudrate(void);
uint32_t swo_get_baudrate(void);

/* Set bitmask of SWO channels to be decoded */
void traceswo_setmask(uint32_t mask);
Expand All @@ -51,7 +57,7 @@ bool traceswo_decode(const void *buf, uint16_t len, bool flush, bool drop_if_no_

void traceswo_task_init(void);

BaseType_t traceswo_uart_dma_handler(void);
BaseType_t traceswo_rx_dma_handler(void);

bool traceswo_uart_is_used(uart_inst_t *uart_instance);

Expand Down
8 changes: 8 additions & 0 deletions firmware/include/bmp/tap_pio_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,19 @@ static inline void tap_pio_common_disable_all_machines(PIO pio)
}
}

static inline uint32_t tap_pio_common_get_irq0_status(PIO pio)
{
check_pio_param(pio);

return pio->ints0;
}

void tap_pio_common_dma_send_uint32(PIO pio, uint32_t sm, const uint32_t *buffer_send, const uint32_t data_amount);
uint32_t tap_pio_common_dma_send_recv_uint32(PIO pio, uint32_t sm, const uint32_t *buffer_send, uint32_t *buffer_recv,
const uint32_t data_amount, const uint32_t data_amount_to_read);
void tap_pio_common_dma_send_uint8(PIO pio, uint32_t sm, const uint8_t *buffer, uint32_t data_amount);
uint32_t tap_pio_common_dma_send_recv_uint8(PIO pio, uint32_t sm, const uint8_t *buffer, uint8_t *buffer_recv,
uint32_t data_amount, uint32_t data_amount_to_read);
uint32_t tap_pio_common_set_sm_freq(PIO pio, uint32_t sm, uint32_t freq, uint32_t max_interface_freq);

#endif //MIOLINK_TAP_PIO_COMMON_H
8 changes: 4 additions & 4 deletions firmware/include/bmp/usb_serial.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ typedef enum usb_serial_interface_e {
#define USB_SERIAL_DATA_RX (0x01)
#define USB_SERIAL_LINE_STATE_UPDATE (0x02)
#define USB_SERIAL_LINE_CODING_UPDATE (0x04)
#define USB_SERIAL_DATA_UART_RX_AVAILABLE (0x08)
#define USB_SERIAL_DATA_UART_RX_FLUSH (0x10)
#define USB_SERIAL_DATA_UART_RX_TIMEOUT (0x20)
#define USB_SERIAL_DATA_UART_TX_COMPLETE (0x40)
#define USB_SERIAL_DATA_RX_AVAILABLE (0x08)
#define USB_SERIAL_DATA_RX_FLUSH (0x10)
#define USB_SERIAL_DATA_RX_TIMEOUT (0x20)
#define USB_SERIAL_DATA_TX_COMPLETE (0x40)

extern bool use_uart_on_tdi_tdo;

Expand Down
25 changes: 25 additions & 0 deletions firmware/source/bmp/tap_pio_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,4 +150,29 @@ uint32_t tap_pio_common_dma_send_recv_uint8(PIO pio, uint32_t sm, const uint8_t
__compiler_memory_barrier();

return recv_data_amount;
}

uint32_t tap_pio_common_set_sm_freq(PIO pio, uint32_t sm, uint32_t freq, uint32_t max_interface_freq)
{
const uint32_t min_freq = (max_interface_freq >> 16); /* Max divider = 65536 */
const uint32_t max_freq = max_interface_freq;

if (freq < min_freq) {
freq = min_freq;
} else if (freq > max_freq) {
freq = max_freq;
}

uint32_t clkdiv_int = (max_interface_freq / freq);
uint32_t clkdiv_fraq = ((((uint64_t)max_interface_freq) << 8) / freq) & 0xFF;

if (clkdiv_int >= (((uint32_t)UINT16_MAX) + 1)) {
clkdiv_int = 0;
clkdiv_fraq = 0;
}

pio_sm_set_clkdiv_int_frac(pio, sm, clkdiv_int, clkdiv_fraq);
pio_sm_clkdiv_restart(pio, sm);

return freq;
}
27 changes: 2 additions & 25 deletions firmware/source/bmp/timing_rp2040.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,36 +126,13 @@ static uint32_t platform_get_max_interface_freq(void)

void platform_max_frequency_set(uint32_t freq)
{
const uint32_t interface_freq = platform_get_max_interface_freq();

const uint32_t min_freq = (interface_freq >> 16); /* Max divider = 65536 */
const uint32_t max_freq = interface_freq;

if (freq < min_freq) {
freq = min_freq;
} else if (freq > max_freq) {
freq = max_freq;
}

uint32_t clkdiv_int = (interface_freq / freq);
uint32_t clkdiv_fraq = ((((uint64_t)interface_freq) << 8) / freq) & 0xFF;

if (clkdiv_int >= (((uint32_t)UINT16_MAX) + 1)) {
clkdiv_int = 0;
clkdiv_fraq = 0;
}

for (uint32_t i = 0; i < NUM_PIO_STATE_MACHINES; i++) {
pio_sm_set_clkdiv_int_frac(TARGET_SWD_PIO, i, clkdiv_int, clkdiv_fraq);
pio_sm_clkdiv_restart(TARGET_SWD_PIO, i);
tap_pio_common_set_sm_freq(TARGET_SWD_PIO, i, freq, platform_get_max_interface_freq());
}

for (uint32_t i = 0; i < NUM_PIO_STATE_MACHINES; i++) {
pio_sm_set_clkdiv_int_frac(TARGET_JTAG_PIO, i, clkdiv_int, clkdiv_fraq);
pio_sm_clkdiv_restart(TARGET_JTAG_PIO, i);
target_interface_frequency = tap_pio_common_set_sm_freq(TARGET_JTAG_PIO, i, freq, platform_get_max_interface_freq());
}

target_interface_frequency = freq;
}

uint32_t platform_max_frequency_get(void)
Expand Down
37 changes: 37 additions & 0 deletions firmware/source/bmp/traceswo_manchester.pio
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
.program traceswo_manchester
.pio_version 0
.origin 0

; bit length == 12 cycles

set x, 0
set y, 1

wait_for_start:
wait 1 pin 0 [7] ; wait for 0->1 transition

jmp pin wait_for_start

start:
mov isr, null [4]

receive_data:
jmp pin receive_1

receive_0:
nop [4]
jmp pin set_0

jmp wait_for_start

set_0:
in x, 1 [3]
jmp receive_data

receive_1:
nop [4]
jmp pin wait_for_start

set_1:
in y, 1 [3]
jmp receive_data
Loading
Loading