114 lines
2.9 KiB
C
114 lines
2.9 KiB
C
#include <stdint.h>
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
|
|
#include "stm32h7xx_hal.h"
|
|
|
|
#include "SEGGER_RTT.h"
|
|
#include "SEGGER_SYSVIEW.h"
|
|
#include "SEGGER_SYSVIEW_Conf.h"
|
|
|
|
#include "user_tasks.h"
|
|
|
|
#define SYSVIEW_TX_SIZE 1024
|
|
|
|
extern UART_HandleTypeDef huart1;
|
|
|
|
osThreadId_t g_user_sysview_task_handle;
|
|
osThreadAttr_t g_user_sysview_task_attributes = {
|
|
.name = "SV_TASK",
|
|
.stack_size = 256 * 4,
|
|
.priority = (osPriority_t)osPriorityNormal,
|
|
};
|
|
|
|
osSemaphoreId_t g_user_sysview_uart_rx_semphr;
|
|
osSemaphoreId_t g_user_sysview_uart_tx_semphr;
|
|
|
|
uint8_t g_sysview_tx_buf[SYSVIEW_TX_SIZE] __attribute__((section(".dma_ram")));
|
|
|
|
static const U8 sysview_hello_message[] = {
|
|
'S',
|
|
'E',
|
|
'G',
|
|
'G',
|
|
'E',
|
|
'R',
|
|
' ',
|
|
'S',
|
|
'y',
|
|
's',
|
|
't',
|
|
'e',
|
|
'm',
|
|
'V',
|
|
'i',
|
|
'e',
|
|
'w',
|
|
' ',
|
|
'V',
|
|
'0' + SEGGER_SYSVIEW_MAJOR,
|
|
'.',
|
|
'0' + (SEGGER_SYSVIEW_MINOR / 10),
|
|
'0' + (SEGGER_SYSVIEW_MINOR % 10),
|
|
'.',
|
|
'0' + (SEGGER_SYSVIEW_REV / 10),
|
|
'0' + (SEGGER_SYSVIEW_REV % 10),
|
|
'\0',
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
};
|
|
|
|
void _user_uart_recv_callback(UART_HandleTypeDef *huart) {
|
|
osSemaphoreRelease(g_user_sysview_uart_rx_semphr);
|
|
}
|
|
|
|
void _user_uart_send_callback(UART_HandleTypeDef *huart) {
|
|
osSemaphoreRelease(g_user_sysview_uart_tx_semphr);
|
|
}
|
|
|
|
void user_sysview_task(void *argument) {
|
|
uint8_t rx_buf[1];
|
|
|
|
int channel_id = SEGGER_SYSVIEW_GetChannelID();
|
|
|
|
g_user_sysview_uart_rx_semphr = osSemaphoreNew(1U, 0U, NULL);
|
|
if(g_user_sysview_uart_rx_semphr == NULL) osThreadExit();
|
|
|
|
g_user_sysview_uart_tx_semphr = osSemaphoreNew(1U, 0U, NULL);
|
|
if(g_user_sysview_uart_tx_semphr == NULL) osThreadExit();
|
|
|
|
HAL_UART_RegisterCallback(&huart1, HAL_UART_RX_COMPLETE_CB_ID,
|
|
_user_uart_recv_callback);
|
|
|
|
HAL_UART_RegisterCallback(&huart1, HAL_UART_TX_COMPLETE_CB_ID,
|
|
_user_uart_send_callback);
|
|
|
|
HAL_UART_Transmit_DMA(&huart1, (uint8_t *)sysview_hello_message,
|
|
sizeof(sysview_hello_message));
|
|
|
|
SEGGER_SYSVIEW_Start();
|
|
|
|
HAL_UART_Receive_IT(&huart1, rx_buf, 1);
|
|
|
|
for(;;) {
|
|
if(osSemaphoreGetCount(g_user_sysview_uart_rx_semphr) > 0) {
|
|
SEGGER_RTT_WriteDownBufferNoLock(channel_id, rx_buf, 1);
|
|
osSemaphoreAcquire(g_user_sysview_uart_rx_semphr, osWaitForever);
|
|
HAL_UART_Receive_IT(&huart1, rx_buf, 1);
|
|
};
|
|
if(osSemaphoreAcquire(g_user_sysview_uart_tx_semphr, 100) == osOK) {
|
|
unsigned int tx_len = SEGGER_RTT_GetBytesInBuffer(channel_id);
|
|
|
|
unsigned int real_len = SEGGER_RTT_ReadUpBufferNoLock(
|
|
channel_id, g_sysview_tx_buf, ((tx_len > SYSVIEW_TX_SIZE) ? SYSVIEW_TX_SIZE : tx_len));
|
|
|
|
SCB_CleanInvalidateDCache_by_Addr((uint32_t *)g_sysview_tx_buf, 1024);
|
|
|
|
if(real_len > 0) HAL_UART_Transmit_DMA(&huart1, g_sysview_tx_buf, real_len);
|
|
}
|
|
osDelay(50);
|
|
}
|
|
} |