Initial commit

This commit is contained in:
Jochen Friedrich 2021-01-01 14:06:20 +01:00
commit 66c5a26d69
1145 changed files with 938088 additions and 0 deletions

View file

@ -0,0 +1,316 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<meta charset="utf-8" />
<meta name="generator" content="pandoc" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
<title>STM32 USB-C Power Delivery embedded Tracer</title>
<style>
code{white-space: pre-wrap;}
span.smallcaps{font-variant: small-caps;}
span.underline{text-decoration: underline;}
div.column{display: inline-block; vertical-align: top; width: 50%;}
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
ul.task-list{list-style: none;}
.display.math{display: block; text-align: center; margin: 0.5rem auto;}
</style>
<link rel="stylesheet" href="_htmresc/mini-st.css" />
<!--[if lt IE 9]>
<script src="//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv-printshiv.min.js"></script>
<![endif]-->
</head>
<body>
<div class="row">
<div class="col-sm-12 col-lg-4">
<div class="card fluid">
<div class="sectione dark">
<center>
<h1 id="release-notes-for-stm32-usb-c-power-delivery-embedded-tracer"><small>Release Notes for</small> STM32 USB-C Power Delivery embedded Tracer</h1>
<p>Copyright © 2018 STMicroelectronics<br />
</p>
<a href="https://www.st.com" class="logo"><img src="_htmresc/st_logo.png" alt="ST logo" /></a>
</center>
</div>
</div>
<h1 id="license">License</h1>
<p>This software component is licensed by ST under BSD 3-Clause license, the “License”; You may not use this component except in compliance with the License. You may obtain a copy of the License at:</p>
<p><a href="http://www.opensource.org/licenses/BSD-3-Clause">http://www.opensource.org/licenses/BSD-3-Clause</a></p>
<h1 id="purpose">Purpose</h1>
<p>This driver is used for the embedded USB-PD tracer used to debug USB-PD application.</p>
</div>
<section id="update-history" class="col-sm-12 col-lg-8">
<h1>Update History</h1>
<div class="collapse">
<input type="checkbox" id="collapse-section8" checked aria-hidden="true"> <label for="collapse-section8" aria-hidden="true">V1.5.0 / 2-Jul.-2020</label>
<div>
<h2 id="main-changes">Main Changes</h2>
<h3 id="maintenance-release">Maintenance release</h3>
<h2 id="contents">Contents</h2>
<table>
<caption>Fixed bugs list</caption>
<thead>
<tr class="header">
<th>Headline</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>Code aligned to support U5</td>
</tr>
<tr class="even">
<td>update for GPDMA link with LL update</td>
</tr>
<tr class="odd">
<td>Ticket 84212 - Trace non functional with STM32F4</td>
</tr>
<tr class="even">
<td>Remove TRACER_EMB_TX_Process prototype in tracer_emb.h</td>
</tr>
<tr class="odd">
<td>remove the TX processing</td>
</tr>
</tbody>
</table>
<h2 id="known-limitations">Known limitations</h2>
<h2 id="development-toolchains-and-compilers">Development Toolchains and Compilers</h2>
<ul>
<li>IAR Embedded Workbench for ARM (EWARM) toolchain V8.32.3</li>
<li>RealView Microcontroller Development Kit (MDK-ARM) toolchain V5.27</li>
<li>STM32CubeIDE v1.2.0</li>
</ul>
<h2 id="supported-devices-and-boards">Supported Devices and boards</h2>
<h2 id="backward-compatibility">Backward compatibility</h2>
<h2 id="dependencies">Dependencies</h2>
</div>
</div>
<div class="collapse">
<input type="checkbox" id="collapse-section7" aria-hidden="true"> <label for="collapse-section7" aria-hidden="true">V1.4.1 / 16-Apr.-2020</label>
<div>
<h2 id="main-changes-1">Main Changes</h2>
<h3 id="maintenance-release-1">Maintenance release</h3>
<h2 id="contents-1">Contents</h2>
<table>
<caption>Fixed bugs list</caption>
<thead>
<tr class="header">
<th>Headline</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>Remove reference to USBPD</td>
</tr>
</tbody>
</table>
<h2 id="known-limitations-1">Known limitations</h2>
<h2 id="development-toolchains-and-compilers-1">Development Toolchains and Compilers</h2>
<ul>
<li>IAR Embedded Workbench for ARM (EWARM) toolchain V8.32.3</li>
<li>RealView Microcontroller Development Kit (MDK-ARM) toolchain V5.27</li>
<li>STM32CubeIDE v1.2.0</li>
</ul>
<h2 id="supported-devices-and-boards-1">Supported Devices and boards</h2>
<h2 id="backward-compatibility-1">Backward compatibility</h2>
<h2 id="dependencies-1">Dependencies</h2>
</div>
</div>
<div class="collapse">
<input type="checkbox" id="collapse-section6" aria-hidden="true"> <label for="collapse-section6" aria-hidden="true">V1.4.0 / 14-Apr.-2020</label>
<div>
<h2 id="main-changes-2">Main Changes</h2>
<h3 id="maintenance-release-2">Maintenance release</h3>
<h2 id="contents-2">Contents</h2>
<table>
<caption>Fixed bugs list</caption>
<thead>
<tr class="header">
<th>Headline</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>* Ticket 84461 Indicate when trace is lost</td>
</tr>
</tbody>
</table>
<h2 id="known-limitations-2">Known limitations</h2>
<h2 id="development-toolchains-and-compilers-2">Development Toolchains and Compilers</h2>
<ul>
<li>IAR Embedded Workbench for ARM (EWARM) toolchain V8.32.3</li>
<li>RealView Microcontroller Development Kit (MDK-ARM) toolchain V5.27</li>
<li>STM32CubeIDE v1.2.0</li>
</ul>
<h2 id="supported-devices-and-boards-2">Supported Devices and boards</h2>
<h2 id="backward-compatibility-2">Backward compatibility</h2>
<h2 id="dependencies-2">Dependencies</h2>
</div>
</div>
<div class="collapse">
<input type="checkbox" id="collapse-section5" aria-hidden="true"> <label for="collapse-section5" aria-hidden="true">V1.3.0 / 26-March-2020</label>
<div>
<h2 id="main-changes-3">Main Changes</h2>
<h3 id="maintenance-release-3">Maintenance release</h3>
<h2 id="contents-3">Contents</h2>
<table>
<caption>Fixed bugs list</caption>
<thead>
<tr class="header">
<th>Headline</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>Improve Usart IRQ Handler execution time in tracer_emb_hw.c</td>
</tr>
<tr class="even">
<td>Remove commented code sections</td>
</tr>
<tr class="odd">
<td>Update the hardware layer to handle GPDMA</td>
</tr>
<tr class="even">
<td>Ticket 77333 - DMA usage in tracer_emb_hw needs to be under switch</td>
</tr>
<tr class="odd">
<td>Add 2 macros TRACER_EMB_ENABLECHANNEL and TRACER_EMB_DISABLECHANNEL to be compliant with STM32H7</td>
</tr>
</tbody>
</table>
<h2 id="known-limitations-3">Known limitations</h2>
<h2 id="development-toolchains-and-compilers-3">Development Toolchains and Compilers</h2>
<ul>
<li>IAR Embedded Workbench for ARM (EWARM) toolchain V8.32.3</li>
<li>RealView Microcontroller Development Kit (MDK-ARM) toolchain V5.27</li>
<li>STM32CubeIDE v1.2.0</li>
</ul>
<h2 id="supported-devices-and-boards-3">Supported Devices and boards</h2>
<h2 id="backward-compatibility-3">Backward compatibility</h2>
<h2 id="dependencies-3">Dependencies</h2>
</div>
</div>
<div class="collapse">
<input type="checkbox" id="collapse-section3" aria-hidden="true"> <label for="collapse-section3" aria-hidden="true">V1.2.0 / 17-June-2019</label>
<div>
<h2 id="main-changes-4">Main Changes</h2>
<h3 id="maintenance-release-4">Maintenance release</h3>
<h2 id="contents-4">Contents</h2>
<table>
<caption>Fixed bugs list</caption>
<thead>
<tr class="header">
<th>Headline</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>Ticket 66638 - [FOSS-Audit] SLA0044 headers in Utilities files</td>
</tr>
</tbody>
</table>
<h2 id="known-limitations-4">known limitations</h2>
<h2 id="development-toolchains-and-compilers-4">Development Toolchains and Compilers</h2>
<ul>
<li>IAR Embedded Workbench for ARM (EWARM) toolchain V8.20.2</li>
<li>RealView Microcontroller Development Kit (MDK-ARM) toolchain V5.25</li>
<li>System Workbench STM32 (SW4STM32) toolchain V2.7.2</li>
</ul>
<h2 id="supported-devices-and-boards-4">Supported Devices and boards</h2>
<h2 id="backward-compatibility-4">backward compatibility</h2>
<h2 id="dependencies-4">Dependencies</h2>
</div>
</div>
<div class="collapse">
<input type="checkbox" id="collapse-section2" aria-hidden="true"> <label for="collapse-section2" aria-hidden="true">V1.1.0 / 10-April-2019</label>
<div>
<h2 id="main-changes-5">Main Changes</h2>
<h3 id="maintenance-release-5">Maintenance release</h3>
<h2 id="contents-5">Contents</h2>
<table>
<caption>Fixed bugs list</caption>
<thead>
<tr class="header">
<th>Headline</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>Add new defines in tracer_emb_conf_template.h (as done in projects tracer_emb_conf.h files)</td>
</tr>
<tr class="even">
<td>Update tracer file</td>
</tr>
<tr class="odd">
<td>remove dependence with USBPD Application</td>
</tr>
<tr class="even">
<td>Update for low power management</td>
</tr>
<tr class="odd">
<td>call DPM_TraceWakeUp after added message</td>
</tr>
<tr class="even">
<td>Move macro definition about USART/LPUART inside tracer_em_hw.c</td>
</tr>
<tr class="odd">
<td>Change emb_conf to be able to have trace independent of USART or LPUART</td>
</tr>
<tr class="even">
<td>Add LPUART files</td>
</tr>
<tr class="odd">
<td>Add management of LPUART1</td>
</tr>
</tbody>
</table>
<h2 id="known-limitations-5">known limitations</h2>
<h2 id="development-toolchains-and-compilers-5">Development Toolchains and Compilers</h2>
<ul>
<li>IAR Embedded Workbench for ARM (EWARM) toolchain V8.20.2</li>
<li>RealView Microcontroller Development Kit (MDK-ARM) toolchain V5.25</li>
<li>System Workbench STM32 (SW4STM32) toolchain V2.7.2</li>
</ul>
<h2 id="supported-devices-and-boards-5">Supported Devices and boards</h2>
<h2 id="backward-compatibility-5">backward compatibility</h2>
<h2 id="dependencies-5">Dependencies</h2>
</div>
</div>
<div class="collapse">
<input type="checkbox" id="collapse-section1" aria-hidden="true"> <label for="collapse-section1" aria-hidden="true">V1.0.0 / 18-Dec.-2018</label>
<div>
<h2 id="main-changes-6">Main Changes</h2>
<h3 id="maintenance-release-6">Maintenance release</h3>
<p>Maintenance release</p>
<h2 id="contents-6">Contents</h2>
<table>
<caption>Fixed bugs list</caption>
<thead>
<tr class="header">
<th>Headline</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>tracer embedded creation</td>
</tr>
</tbody>
</table>
<h2 id="known-limitations-6">known limitations</h2>
<h2 id="development-toolchains-and-compilers-6">Development Toolchains and Compilers</h2>
<ul>
<li>IAR Embedded Workbench for ARM (EWARM) toolchain V8.20.2</li>
<li>RealView Microcontroller Development Kit (MDK-ARM) toolchain V5.25</li>
<li>System Workbench STM32 (SW4STM32) toolchain V2.7.2</li>
</ul>
<h2 id="supported-devices-and-boards-6">Supported Devices and boards</h2>
<h2 id="backward-compatibility-6">backward compatibility</h2>
<h2 id="dependencies-6">Dependencies</h2>
</div>
</div>
</section>
</div>
<footer class="sticky">
<p>For complete documentation on STM32,visit: [<a href="http://www.st.com">www.st.com/stm32</a>]</p>
This release note uses up to date web standards and, for this reason, should not be opened with Internet Explorer but preferably with popular browsers such as Google Chrome, Mozilla Firefox, Opera or Microsoft Edge.
</footer>
</body>
</html>

File diff suppressed because it is too large Load diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

View file

@ -0,0 +1,393 @@
/**
******************************************************************************
* @file tracer_emb.c
* @author MCD Application Team
* @brief This file contains embeded tracer control functions.
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2018 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under BSD 3-Clause license,
* the "License"; You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "tracer_emb.h"
#include "tracer_emb_hw.h"
#include "string.h"
/** @addtogroup TRACER_EMB
* @{
*/
/** @addtogroup TRACER_EMB
* @{
*/
/** @addtogroup TRACER_EMB
* @{
*/
/* Private enums -------------------------------------------------------------*/
/* Private typedef -----------------------------------------------------------*/
/** @defgroup TRACER_EMB_Private_TypeDef EMB TRACER Private typedef
* @{
*/
typedef enum {
TRACER_OVERFLOW_NONE,
TRACER_OVERFLOW_DETECTED,
TRACER_OVERFLOW_SENT
} TRACER_OverFlowTypedef;
/**
* @}
*/
/** @defgroup TRACER_EMB_Private_TypeDef EMB TRACER Private typedef
* @{
*/
typedef enum {
TRACER_OK,
TRACER_KO
} TRACER_StatusTypedef;
/**
* @}
*/
/** @defgroup TRACER_EMB_Private_TypeDef EMB TRACER Private typedef
* @{
*/
typedef struct {
uint32_t PtrTx_Read;
uint32_t PtrTx_Write;
uint32_t SizeSent;
uint32_t LowPower_Counter;
volatile uint8_t Counter;
const uint8_t *OverFlow_Data;
uint8_t OverFlow_Size;
uint8_t discontinue;
TRACER_OverFlowTypedef OverFlow_Status;
uint8_t PtrDataTx[TRACER_EMB_BUFFER_SIZE];
} TRACER_ContextTypedef;
/**
* @}
*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/** @defgroup TRACER_EMB_Private_Macros TRACE Private Macros
* @{
*/
#define TRACER_WRITE_DATA(_POSITION_,_DATA_) TracerContext.PtrDataTx[(_POSITION_)% TRACER_EMB_BUFFER_SIZE] = (_DATA_); \
(_POSITION_) = ((_POSITION_) + 1u) % TRACER_EMB_BUFFER_SIZE;
#define TRACER_ENTER_CRITICAL_SECTION() uint32_t primask= __get_PRIMASK();\
__disable_irq();
#define TRACER_LEAVE_CRITICAL_SECTION() __set_PRIMASK(primask)
/**
* @}
*/
/* Private function prototypes -----------------------------------------------*/
/** @defgroup TRACER_EMB_Private_Functions TRACE Private Functions
* @{
*/
uint32_t TRACER_CallbackRX(uint8_t character, uint8_t error);
/* Function prototypes -----------------------------------------------*/
uint8_t TRACER_EMB_ReadData(void);
/**
* @}
*/
/* Private variables ---------------------------------------------------------*/
/** @defgroup TRACER_EMB_Private_Variables TRACE Private Variables
* @{
*/
static TRACER_ContextTypedef TracerContext;
/**
* @}
*/
/* Exported functions ---------------------------------------------------------*/
/** @addtogroup TRACER_EMB_Exported_Functions
* @{
*/
void TRACER_EMB_Init(void)
{
/* initialize the Ptr for Read/Write */
memset(&TracerContext, 0, sizeof(TRACER_ContextTypedef));
/* Initialize trace BUS */
HW_TRACER_EMB_Init();
/* Initialize the lowpower aspect */
TRACER_EMB_LowPowerInit();
}
void TRACER_EMB_Add(uint8_t *Ptr, uint32_t Size)
{
int32_t _writepos;
uint8_t *data_to_write = Ptr;
uint32_t index;
/* Data processing */
TRACER_EMB_Lock();
_writepos = TRACER_EMB_AllocateBufer(Size);
/* if allocation is ok, write data into the bufffer */
if (_writepos != -1)
{
/* initialize the Ptr for Read/Write */
for (index = 0u; index < Size; index++)
{
TRACER_WRITE_DATA(_writepos, data_to_write[index]);
}
}
TRACER_EMB_UnLock();
/* Tx processing */
TRACER_EMB_SendData();
}
#if TRACER_EMB_DMA_MODE == 1UL
void TRACER_EMB_IRQHandlerDMA(void)
{
HW_TRACER_EMB_IRQHandlerDMA();
}
#endif
void TRACER_EMB_IRQHandlerUSART(void)
{
HW_TRACER_EMB_IRQHandlerUSART();
}
void TRACER_EMB_WriteData(uint16_t pos, uint8_t data)
{
TracerContext.PtrDataTx[pos % TRACER_EMB_BUFFER_SIZE] = data;
}
void TRACER_EMB_StartRX(void (*callbackRX)(uint8_t, uint8_t))
{
HW_TRACER_EMB_RegisterRxCallback(callbackRX);
HW_TRACER_EMB_StartRX();
}
int32_t TRACER_EMB_EnableOverFlow(const uint8_t *Data, uint8_t Size)
{
if(Size != 0)
{
TracerContext.OverFlow_Data = Data;
TracerContext.OverFlow_Size = Size;
return 0;
}
return -1;
}
uint8_t TRACER_EMB_ReadData()
{
return HW_TRACER_EMB_ReadData();
}
/**
* @}
*/
/** @defgroup TRACER_EMB_Private_Functions TRACE Private Functions
* @{
*/
/**
* @brief callback called to end a transfert.
* @param None.
* @retval None.
*/
void TRACER_EMB_CALLBACK_TX(void)
{
TRACER_ENTER_CRITICAL_SECTION();
TracerContext.PtrTx_Read = (TracerContext.PtrTx_Read + TracerContext.SizeSent) % TRACER_EMB_BUFFER_SIZE;
if((TracerContext.OverFlow_Data != NULL) && (TracerContext.OverFlow_Status == TRACER_OVERFLOW_DETECTED)
&& (TracerContext.discontinue == 0))
{
TracerContext.OverFlow_Status = TRACER_OVERFLOW_SENT;
HW_TRACER_EMB_SendData((uint8_t *)TracerContext.OverFlow_Data, TracerContext.OverFlow_Size);
TRACER_LEAVE_CRITICAL_SECTION();
}
else
{
TracerContext.LowPower_Counter--;
TRACER_LEAVE_CRITICAL_SECTION();
TRACER_EMB_UnLock();
TRACER_EMB_SendData();
}
}
/**
* @brief Lock the trace buffer.
* @param None.
* @retval None.
*/
void TRACER_EMB_Lock(void)
{
TRACER_ENTER_CRITICAL_SECTION();
TracerContext.Counter++;
TRACER_LEAVE_CRITICAL_SECTION();
}
/**
* @brief UnLock the trace buffer.
* @param None.
* @retval None.
*/
void TRACER_EMB_UnLock(void)
{
TRACER_ENTER_CRITICAL_SECTION();
TracerContext.Counter--;
TRACER_LEAVE_CRITICAL_SECTION();
}
/**
* @brief if buffer is not locked return a Begin / end @ to transfert over the media.
* @param address begin of the data
* @param address end of the data
* @retval None.
*/
void TRACER_EMB_SendData(void)
{
uint32_t _begin;
uint32_t _end;
TRACER_ENTER_CRITICAL_SECTION();
if (0u == TracerContext.Counter)
{
_begin = TracerContext.PtrTx_Read;
_end = TracerContext.PtrTx_Write;
if (_begin != _end)
{
TRACER_EMB_Lock();
/* */
if (_end > _begin)
{
TracerContext.SizeSent = _end - _begin;
TracerContext.discontinue = 0;
}
else /* _begin > _end */
{
TracerContext.SizeSent = TRACER_EMB_BUFFER_SIZE - _begin;
TracerContext.discontinue = 1;
}
TRACER_EMB_LowPowerSendData();
TracerContext.LowPower_Counter++;
HW_TRACER_EMB_SendData(&(TracerContext.PtrDataTx[_begin]), TracerContext.SizeSent);
}
}
/* Low power processing */
switch(TracerContext.LowPower_Counter)
{
case 1:
TRACER_EMB_LowPowerSendData();
break;
case 0 :
TRACER_EMB_LowPowerSendDataComplete();
break;
}
TRACER_LEAVE_CRITICAL_SECTION();
}
/**
* @brief allocate space inside the buffer to push data
* @param data size
* @retval write position inside the buffer is -1 no space available.
*/
int32_t TRACER_EMB_AllocateBufer(uint32_t Size)
{
uint32_t _freesize;
int32_t _pos = -1;
TRACER_ENTER_CRITICAL_SECTION();
if (TracerContext.PtrTx_Write == TracerContext.PtrTx_Read)
{
// need to add buffer full managment
_freesize = TRACER_EMB_BUFFER_SIZE;
}
else
{
if (TracerContext.PtrTx_Write > TracerContext.PtrTx_Read)
{
_freesize = TRACER_EMB_BUFFER_SIZE - TracerContext.PtrTx_Write + TracerContext.PtrTx_Read;
}
else
{
_freesize = TracerContext.PtrTx_Read - TracerContext.PtrTx_Write;
}
}
if (_freesize > Size)
{
_pos = (int32_t)TracerContext.PtrTx_Write;
TracerContext.PtrTx_Write = (TracerContext.PtrTx_Write + Size) % TRACER_EMB_BUFFER_SIZE;
if(TRACER_OVERFLOW_SENT == TracerContext.OverFlow_Status)
TracerContext.OverFlow_Status = TRACER_OVERFLOW_NONE;
}
else
{
if(TRACER_OVERFLOW_NONE == TracerContext.OverFlow_Status)
TracerContext.OverFlow_Status = TRACER_OVERFLOW_DETECTED;
}
TRACER_LEAVE_CRITICAL_SECTION();
return _pos;
}
__weak void TRACER_EMB_LowPowerInit(void)
{
}
__weak void TRACER_EMB_LowPowerSendData(void)
{
}
__weak void TRACER_EMB_LowPowerSendDataComplete(void)
{
}
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View file

@ -0,0 +1,147 @@
/**
******************************************************************************
* @file trace_emb.h
* @author MCD Application Team
* @brief This file contains the headers of tracer_emb.h for Cable Attach-Detach
* controls.
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2018 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under BSD 3-Clause license,
* the "License"; You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*
******************************************************************************
*/
#ifndef __TRACER_EMB_H_
#define __TRACER_EMB_H_
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "stdint.h"
#include "tracer_emb_conf.h"
/** @addtogroup TRACER_EMB
* @{
*/
/* Exported types ------------------------------------------------------------*/
/**
* @}
*/
/* Exported define -----------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/
/* Exported macro ------------------------------------------------------------*/
/* Exported variables --------------------------------------------------------*/
/* Exported functions --------------------------------------------------------*/
/** @defgroup TRACER_EMB_Exported_Functions TRACE Exported Functions
* @{
*/
/**
* @brief Initialize the TRACE module
* @retval None
*/
void TRACER_EMB_Init(void);
/**
* @brief Add information in debug trace buffer
* @param Type Trace Type based on @ref TRACER_EMB_EVENT
* @param PortNum Port number value
* @param Sop SOP type
* @param Ptr Pointer on the data to send
* @param Size Size of the data to send
* @retval None.
*/
void TRACER_EMB_Add(uint8_t *Ptr, uint32_t Size);
/**
* @brief Add one data into the trace buffer
* @param pos position
* @param data data value
*/
void TRACER_EMB_WriteData(uint16_t pos, uint8_t data);
/**
* @brief Lock the trace buffer.
* @param None.
* @retval None.
*/
void TRACER_EMB_Lock(void);
/**
* @brief UnLock the trace buffer.
* @param None.
* @retval None.
*/
void TRACER_EMB_UnLock(void);
void TRACER_EMB_SendData(void);
/**
* @brief allocate space inside the buffer to push data
* @param data size
* @retval write position inside the buffer is -1 no space available.
*/
int32_t TRACER_EMB_AllocateBufer(uint32_t Size);
/**
* @brief enable the overflow detection
* @param Data pointer on the overflow string
* @param Size of the overflow string
* @retval 0 if success other value indicate an error.
*/
int32_t TRACER_EMB_EnableOverFlow(const uint8_t *Data, uint8_t Size);
void TRACER_EMB_CALLBACK_TX(void);
#if TRACER_EMB_DMA_MODE == 1UL
void TRACER_EMB_IRQHandlerDMA(void);
#endif
void TRACER_EMB_IRQHandlerUSART(void);
void TRACER_EMB_StartRX(void (*callbackRX)(uint8_t, uint8_t));
/**
* @brief function to initialize LPM for emb tracer.
* @retval Timing
*/
void TRACER_EMB_LowPowerInit(void);
/**
* @brief function to manage LPM when sending data.
* @retval Timing
*/
void TRACER_EMB_LowPowerSendData(void);
/**
* @brief function to manage LPM when data send complete.
* @retval Timing
*/
void TRACER_EMB_LowPowerSendDataComplete(void);
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif /* __TRACER_EMB_H_ */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View file

@ -0,0 +1,109 @@
/**
******************************************************************************
* @file tracer_emb_conf.h
* @author MCD Application Team
* @brief This file contains the Trace HW related defines.
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2018 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under BSD 3-Clause license,
* the "License"; You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*
******************************************************************************
*/
#ifndef TRACER_EMB_CONF_H
#define TRACER_EMB_CONF_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "stm32g0xx_ll_bus.h"
#include "stm32g0xx_ll_dma.h"
#include "stm32g0xx_ll_gpio.h"
#include "stm32g0xx_ll_rcc.h"
#include "stm32g0xx_ll_usart.h"
#if defined(LPUART1)
#include "stm32g0xx_ll_lpuart.h"
#endif /* LPUART1 */
/* Private typedef -----------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* -----------------------------------------------------------------------------
Definitions for TRACE feature
-------------------------------------------------------------------------------*/
#define TRACER_EMB_BAUDRATE 921600UL
#define TRACER_EMB_DMA_MODE 1UL
#define TRACER_EMB_IT_MODE 0UL
#define TRACER_EMB_BUFFER_SIZE 1024UL
/* -----------------------------------------------------------------------------
Definitions for TRACE Hw information
-------------------------------------------------------------------------------*/
/* USART instance is used.*/
#define TRACER_EMB_IS_INSTANCE_LPUART_TYPE 0UL /* set to 1UL if LPUART is used instead of USART */
#define TRACER_EMB_USART_INSTANCE USART3
#define TRACER_EMB_TX_GPIO GPIOC
#define TRACER_EMB_TX_PIN LL_GPIO_PIN_10
#define TRACER_EMB_TX_AF LL_GPIO_AF_0
#define TRACER_EMB_TX_GPIO_ENABLE_CLOCK() LL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOC)
#define TRACER_EMB_TX_GPIO_DISABLE_CLOCK() LL_IOP_GRP1_DisableClock(LL_IOP_GRP1_PERIPH_GPIOC)
#define TRACER_EMB_RX_GPIO GPIOC
#define TRACER_EMB_RX_PIN LL_GPIO_PIN_11
#define TRACER_EMB_RX_AF LL_GPIO_AF_0
#define TRACER_EMB_RX_GPIO_ENABLE_CLOCK() LL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOC)
#define TRACER_EMB_RX_GPIO_DISABLE_CLOCK() LL_IOP_GRP1_DisableClock(LL_IOP_GRP1_PERIPH_GPIOC)
#define TRACER_EMB_ENABLE_CLK_USART() LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_USART3)
#define TRACER_EMB_DISABLE_CLK_USART() LL_APB1_GRP1_DisableClock(LL_APB1_GRP1_PERIPH_USART3)
#define TRACER_EMB_SET_CLK_SOURCE_USART() /* No need for clock source selection in case of USART3 // LL_RCC_SetUSARTClockSource(LL_RCC_USART3_CLKSOURCE_PCLK2) */
#define TRACER_EMB_USART_IRQ USART3_4_LPUART1_IRQn
#define TRACER_EMB_USART_IRQHANDLER USART3_4_LPUART1_IRQHandler
#define TRACER_EMB_TX_AF_FUNCTION LL_GPIO_SetAFPin_8_15
#define TRACER_EMB_RX_AF_FUNCTION LL_GPIO_SetAFPin_8_15
#define TRACER_EMB_TX_IRQ_PRIORITY 3
#if TRACER_EMB_DMA_MODE == 1UL
#define TRACER_EMB_DMA_INSTANCE DMA1
#define TRACER_EMB_ENABLE_CLK_DMA() LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_DMA1)
#if defined (DMAMUX_CxCR_DMAREQ_ID)
#define TRACER_EMB_TX_DMA_REQUEST LL_DMAMUX_REQ_USART3_TX /* This define is needed only in case of DMAMUX management */
#endif /* DMAMUX_CxCR_DMAREQ_ID */
#if defined(DMA_SxCR_CHSEL)
#define TRACER_EMB_TX_DMA_STREAM LL_DMA_STREAM_7 /* This define is needed only in case of use of a DMA IP supporting Streams */
#endif /* DMA_SxCR_CHSEL */
#define TRACER_EMB_TX_DMA_CHANNEL LL_DMA_CHANNEL_7
#if defined(DMA_SxCR_CHSEL)
/* Those defines are needed only in case of use of a DMA IP supporting Streams */
#define TRACER_EMB_ENABLESTREAM LL_DMA_EnableStream
#define TRACER_EMB_DISABLESTREAM LL_DMA_DisableStream
#else
/* Those defines are needed only in case of use of a DMA IP not supporting Streams */
#define TRACER_EMB_ENABLECHANNEL LL_DMA_EnableChannel
#define TRACER_EMB_DISABLECHANNEL LL_DMA_DisableChannel
#endif /* DMA_SxCR_CHSEL */
#define TRACER_EMB_TX_DMA_IRQ DMA1_Ch4_7_DMAMUX1_OVR_IRQn
#define TRACER_EMB_TX_DMA_IRQHANDLER DMA1_Ch4_7_DMAMUX1_OVR_IRQHandler
#define TRACER_EMB_TX_DMA_ACTIVE_FLAG LL_DMA_IsActiveFlag_TC7
#define TRACER_EMB_TX_DMA_CLEAR_FLAG LL_DMA_ClearFlag_GI7
#define TRACER_EMB_TX_DMA_PRIORITY 0
#endif
#ifdef __cplusplus
}
#endif
#endif /* TRACER_EMB_CONF_H */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View file

@ -0,0 +1,623 @@
/**
******************************************************************************
* @file tracer_emb_hw.c
* @author MCD Application Team
* @brief This file contains the low level interface to control trace system.
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2018 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under BSD 3-Clause license,
* the "License"; You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "tracer_emb.h"
#include "tracer_emb_hw.h"
#if TRACER_EMB_DMA_MODE == 1UL && TRACER_EMB_IT_MODE == 1UL
#error "tracer emb hw please select DMA or IT mode"
#endif
/* Private typedef -----------------------------------------------------------*/
/* Private Defines -----------------------------------------------------------*/
#if (TRACER_EMB_IS_INSTANCE_LPUART_TYPE == 1UL)
/* LPUART entry point */
#define TRACER_EMB_ENABLEDIRECTIONRX LL_LPUART_EnableDirectionRx
#define TRACER_EMB_RECEIVE_DATA8 LL_LPUART_ReceiveData8
#define TRACER_EMB_TRANSMIT_DATA8 LL_LPUART_TransmitData8
#define TRACER_EMB_DMA_GETREGADDR LL_LPUART_DMA_GetRegAddr
#define TRACER_EMB_ENABLEDMAREQ_TX LL_LPUART_EnableDMAReq_TX
#define TRACER_EMB_ENABLE_IT_RXNE LL_LPUART_EnableIT_RXNE
#define TRACER_EMB_ENABLE_IT_ERROR LL_LPUART_EnableIT_ERROR
#define TRACER_EMB_ENABLE_IT_TXE LL_LPUART_EnableIT_TXE
#define TRACER_EMB_ENABLE_IT_TC LL_LPUART_EnableIT_TC
#define TRACER_EMB_DISABLEIT_TXE LL_LPUART_DisableIT_TXE
#define TRACER_EMB_DISABLEIT_TC LL_LPUART_DisableIT_TC
#define TRACER_EMB_ISACTIVEFLAG_TXE LL_LPUART_IsActiveFlag_TXE
#define TRACER_EMB_ISACTIVEFLAG_PE LL_LPUART_IsActiveFlag_PE
#define TRACER_EMB_ISACTIVEFLAG_RXNE LL_LPUART_IsActiveFlag_RXNE
#define TRACER_EMB_ISACTIVEFLAG_FE LL_LPUART_IsActiveFlag_FE
#define TRACER_EMB_ISACTIVEFLAG_ORE LL_LPUART_IsActiveFlag_ORE
#define TRACER_EMB_ISACTIVEFLAG_NE LL_LPUART_IsActiveFlag_NE
#define TRACER_EMB_ISACTIVEFLAG_TC LL_LPUART_IsActiveFlag_TC
#define TRACER_EMB_ISENABLEDIT_TXE LL_LPUART_IsEnabledIT_TXE
#define TRACER_EMB_ISENABLEDIT_RXNE LL_LPUART_IsEnabledIT_RXNE
#define TRACER_EMB_ISENABLEDIT_PE LL_LPUART_IsEnabledIT_PE
#define TRACER_EMB_ISENABLEDIT_ERROR LL_LPUART_IsEnabledIT_ERROR
#define TRACER_EMB_ISENABLEDIT_TC LL_LPUART_IsEnabledIT_TC
#define TRACER_EMB_CLEARFLAG_PE LL_LPUART_ClearFlag_PE
#define TRACER_EMB_CLEARFLAG_FE LL_LPUART_ClearFlag_FE
#define TRACER_EMB_CLEARFLAG_ORE LL_LPUART_ClearFlag_ORE
#define TRACER_EMB_CLEARFLAG_NE LL_LPUART_ClearFlag_NE
#define TRACER_EMB_CLEARFLAG_TC LL_LPUART_ClearFlag_TC
#define TRACER_EMB_READREG LL_LPUART_ReadReg
#else
/* UART entry point */
#define TRACER_EMB_ENABLEDIRECTIONRX LL_USART_EnableDirectionRx
#define TRACER_EMB_RECEIVE_DATA8 LL_USART_ReceiveData8
#define TRACER_EMB_TRANSMIT_DATA8 LL_USART_TransmitData8
#define TRACER_EMB_DMA_GETREGADDR LL_USART_DMA_GetRegAddr
#define TRACER_EMB_ENABLEDMAREQ_TX LL_USART_EnableDMAReq_TX
#define TRACER_EMB_ENABLE_IT_RXNE LL_USART_EnableIT_RXNE
#define TRACER_EMB_ENABLE_IT_ERROR LL_USART_EnableIT_ERROR
#define TRACER_EMB_ENABLE_IT_TXE LL_USART_EnableIT_TXE
#define TRACER_EMB_ENABLE_IT_TC LL_USART_EnableIT_TC
#define TRACER_EMB_DISABLEIT_TXE LL_USART_DisableIT_TXE
#define TRACER_EMB_DISABLEIT_TC LL_USART_DisableIT_TC
#define TRACER_EMB_ISACTIVEFLAG_TXE LL_USART_IsActiveFlag_TXE
#define TRACER_EMB_ISACTIVEFLAG_PE LL_USART_IsActiveFlag_PE
#define TRACER_EMB_ISACTIVEFLAG_RXNE LL_USART_IsActiveFlag_RXNE
#define TRACER_EMB_ISACTIVEFLAG_FE LL_USART_IsActiveFlag_FE
#define TRACER_EMB_ISACTIVEFLAG_ORE LL_USART_IsActiveFlag_ORE
#define TRACER_EMB_ISACTIVEFLAG_NE LL_USART_IsActiveFlag_NE
#define TRACER_EMB_ISACTIVEFLAG_TC LL_USART_IsActiveFlag_TC
#define TRACER_EMB_ISACTIVEFLAG_RTO LL_USART_IsActiveFlag_RTO
#define TRACER_EMB_ISENABLEDIT_TXE LL_USART_IsEnabledIT_TXE
#define TRACER_EMB_ISENABLEDIT_RXNE LL_USART_IsEnabledIT_RXNE
#define TRACER_EMB_ISENABLEDIT_PE LL_USART_IsEnabledIT_PE
#define TRACER_EMB_ISENABLEDIT_ERROR LL_USART_IsEnabledIT_ERROR
#define TRACER_EMB_ISENABLEDIT_TC LL_USART_IsEnabledIT_TC
#define TRACER_EMB_ISENABLEDIT_RTO LL_USART_IsEnabledIT_RTO
#define TRACER_EMB_CLEARFLAG_PE LL_USART_ClearFlag_PE
#define TRACER_EMB_CLEARFLAG_FE LL_USART_ClearFlag_FE
#define TRACER_EMB_CLEARFLAG_ORE LL_USART_ClearFlag_ORE
#define TRACER_EMB_CLEARFLAG_NE LL_USART_ClearFlag_NE
#define TRACER_EMB_CLEARFLAG_TC LL_USART_ClearFlag_TC
#define TRACER_EMB_CLEARFLAG_RTO LL_USART_ClearFlag_RTO
#define TRACER_EMB_READREG LL_USART_ReadReg
#endif
#if defined(USART_ISR_RXNE_RXFNE)
#define TRACER_EMB_FLAG_RXNE USART_ISR_RXNE_RXFNE
#elif defined(USART_ISR_RXNE)
#define TRACER_EMB_FLAG_RXNE USART_ISR_RXNE
#else
#define TRACER_EMB_FLAG_RXNE USART_SR_RXNE
#endif /* USART_ISR_RXNE_RXFNE */
#if defined(USART_CR1_TXEIE_TXFNFIE)
#define TRACER_EMB_FLAG_TXE USART_CR1_TXEIE_TXFNFIE
#elif defined(USART_ISR_TXE)
#define TRACER_EMB_FLAG_TXE USART_ISR_TXE
#else
#define TRACER_EMB_FLAG_TXE USART_SR_TXE
#endif /* USART_CR1_TXEIE_TXFNFIE */
#if defined(USART_ISR_PE)
#define TRACER_EMB_FLAG_PE USART_ISR_PE
#define TRACER_EMB_FLAG_FE USART_ISR_FE
#define TRACER_EMB_FLAG_ORE USART_ISR_ORE
#define TRACER_EMB_FLAG_NE USART_ISR_NE
#define TRACER_EMB_FLAG_TC USART_ISR_TC
#else
#define TRACER_EMB_FLAG_PE USART_SR_PE
#define TRACER_EMB_FLAG_FE USART_SR_FE
#define TRACER_EMB_FLAG_ORE USART_SR_ORE
#define TRACER_EMB_FLAG_NE USART_SR_NE
#define TRACER_EMB_FLAG_TC USART_SR_TC
#endif /* USART_ISR_RXNE_RXFNE */
/* Private Variables ---------------------------------------------------------*/
static void (*fptr_rx)(uint8_t, uint8_t) = NULL;
#if TRACER_EMB_IT_MODE == 1UL
uint8_t *txData = NULL;
uint32_t txSize = 0;
#endif
/* Private function prototypes -----------------------------------------------*/
/* Exported functions --------------------------------------------------------*/
/**
* @brief Trace init
* @param callbackTX
* @param callbackRX
* @retval none
*/
void HW_TRACER_EMB_Init(void)
{
/* Enable the peripheral clock of GPIO Port */
TRACER_EMB_TX_GPIO_ENABLE_CLOCK();
TRACER_EMB_RX_GPIO_ENABLE_CLOCK();
/* Configure Tx Pin as : Alternate function, High Speed, Push pull, Pull up */
TRACER_EMB_TX_AF_FUNCTION(TRACER_EMB_TX_GPIO, TRACER_EMB_TX_PIN, TRACER_EMB_TX_AF);
LL_GPIO_SetPinMode(TRACER_EMB_TX_GPIO, TRACER_EMB_TX_PIN, LL_GPIO_MODE_ALTERNATE);
LL_GPIO_SetPinSpeed(TRACER_EMB_TX_GPIO, TRACER_EMB_TX_PIN, LL_GPIO_SPEED_FREQ_HIGH);
LL_GPIO_SetPinOutputType(TRACER_EMB_TX_GPIO, TRACER_EMB_TX_PIN, LL_GPIO_OUTPUT_PUSHPULL);
LL_GPIO_SetPinPull(TRACER_EMB_TX_GPIO, TRACER_EMB_TX_PIN, LL_GPIO_PULL_UP);
/* Configure Rx Pin as : Alternate function, High Speed, Push pull, Pull up */
TRACER_EMB_RX_AF_FUNCTION(TRACER_EMB_RX_GPIO, TRACER_EMB_RX_PIN, TRACER_EMB_RX_AF);
LL_GPIO_SetPinMode(TRACER_EMB_RX_GPIO, TRACER_EMB_RX_PIN, LL_GPIO_MODE_ALTERNATE);
LL_GPIO_SetPinSpeed(TRACER_EMB_RX_GPIO, TRACER_EMB_RX_PIN, LL_GPIO_SPEED_FREQ_HIGH);
LL_GPIO_SetPinOutputType(TRACER_EMB_RX_GPIO, TRACER_EMB_RX_PIN, LL_GPIO_OUTPUT_PUSHPULL);
LL_GPIO_SetPinPull(TRACER_EMB_RX_GPIO, TRACER_EMB_RX_PIN, LL_GPIO_PULL_UP);
/* Enable the peripheral clock for USART */
TRACER_EMB_ENABLE_CLK_USART();
/* Set clock source */
TRACER_EMB_SET_CLK_SOURCE_USART();
if(IS_USART_INSTANCE(TRACER_EMB_USART_INSTANCE))
{
/* Configure USART */
LL_USART_InitTypeDef usart_initstruct;
/* Disable USART prior modifying configuration registers */
LL_USART_Disable(TRACER_EMB_USART_INSTANCE);
/* Set fields of initialization structure */
/* - Prescaler : LL_USART_PRESCALER_DIV1 */
/* - BaudRate : TRACE_BAUDRATE */
/* - DataWidth : LL_USART_DATAWIDTH_8B */
/* - StopBits : LL_USART_STOPBITS_1 */
/* - Parity : LL_USART_PARITY_NONE */
/* - TransferDirection : LL_USART_DIRECTION_TX */
/* - HardwareFlowControl : LL_USART_HWCONTROL_NONE */
/* - OverSampling : LL_USART_OVERSAMPLING_16 */
#if defined(USART_PRESC_PRESCALER)
usart_initstruct.PrescalerValue = LL_USART_PRESCALER_DIV1;
#endif
usart_initstruct.BaudRate = TRACER_EMB_BAUDRATE;
usart_initstruct.DataWidth = LL_USART_DATAWIDTH_8B;
usart_initstruct.StopBits = LL_USART_STOPBITS_1;
usart_initstruct.Parity = LL_USART_PARITY_NONE;
usart_initstruct.TransferDirection = LL_USART_DIRECTION_TX;
usart_initstruct.HardwareFlowControl = LL_USART_HWCONTROL_NONE;
usart_initstruct.OverSampling = LL_USART_OVERSAMPLING_16;
/* Initialize USART instance according to parameters defined in initialization structure */
LL_USART_Init(TRACER_EMB_USART_INSTANCE, &usart_initstruct);
LL_USART_Enable(TRACER_EMB_USART_INSTANCE);
#if defined(USART_ISR_TEACK)
uint32_t _temp1 = LL_USART_IsActiveFlag_TEACK(TRACER_EMB_USART_INSTANCE);
/* Polling USART initialisation */
while(0u == _temp1)
{
_temp1 = LL_USART_IsActiveFlag_TEACK(TRACER_EMB_USART_INSTANCE);
}
#endif /* USART_ISR_TEACK */
}
#if (TRACER_EMB_IS_INSTANCE_LPUART_TYPE == 1UL)
else
{
/* Configure USART */
LL_LPUART_InitTypeDef lpuart_initstruct;
/* Disable USART prior modifying configuration registers */
LL_LPUART_Disable(TRACER_EMB_USART_INSTANCE);
/* Set fields of initialization structure */
/* - Prescaler : LL_USART_PRESCALER_DIV1 */
/* - BaudRate : TRACE_BAUDRATE */
/* - DataWidth : LL_USART_DATAWIDTH_8B */
/* - StopBits : LL_USART_STOPBITS_1 */
/* - Parity : LL_USART_PARITY_NONE */
/* - TransferDirection : LL_USART_DIRECTION_TX */
/* - HardwareFlowControl : LL_USART_HWCONTROL_NONE */
/* - OverSampling : LL_USART_OVERSAMPLING_16 */
#if defined(USART_PRESC_PRESCALER)
lpuart_initstruct.PrescalerValue = LL_USART_PRESCALER_DIV1;
#endif
lpuart_initstruct.BaudRate = TRACER_EMB_BAUDRATE;
lpuart_initstruct.DataWidth = LL_USART_DATAWIDTH_8B;
lpuart_initstruct.StopBits = LL_USART_STOPBITS_1;
lpuart_initstruct.Parity = LL_USART_PARITY_NONE;
lpuart_initstruct.TransferDirection = LL_USART_DIRECTION_TX;
lpuart_initstruct.HardwareFlowControl = LL_USART_HWCONTROL_NONE;
/* Initialize USART instance according to parameters defined in initialization structure */
LL_LPUART_Init(TRACER_EMB_USART_INSTANCE, &lpuart_initstruct);
LL_LPUART_Enable(TRACER_EMB_USART_INSTANCE);
uint32_t _temp1 = LL_LPUART_IsActiveFlag_TEACK(TRACER_EMB_USART_INSTANCE);
/* Polling USART initialisation */
while(0u == _temp1)
{
_temp1 = LL_LPUART_IsActiveFlag_TEACK(TRACER_EMB_USART_INSTANCE);
}
}
#endif
#if TRACER_EMB_DMA_MODE == 1UL
/* Configure TX DMA */
TRACER_EMB_ENABLE_CLK_DMA();
/* (3) Configure the DMA functional parameters for transmission */
#if defined(GPDMA1)
LL_DMA_ConfigDataTransfer(TRACER_EMB_DMA_INSTANCE, TRACER_EMB_TX_DMA_CHANNEL,
LL_DMA_SINC_INCREMENT |
LL_DMA_DINC_NOINCREMENT |
LL_DMA_SRC_DATAWIDTH_BYTE |
LL_DMA_DEST_DATAWIDTH_BYTE);
LL_DMA_SetHardwareRequest(TRACER_EMB_DMA_INSTANCE, TRACER_EMB_TX_DMA_CHANNEL, TRACER_EMB_TX_DMA_REQUEST);
#elif defined(DMA_SxCR_CHSEL)
LL_DMA_SetChannelSelection(TRACER_EMB_DMA_INSTANCE, TRACER_EMB_TX_DMA_STREAM, TRACER_EMB_TX_DMA_CHANNEL);
LL_DMA_ConfigTransfer(TRACER_EMB_DMA_INSTANCE, TRACER_EMB_TX_DMA_STREAM,
LL_DMA_DIRECTION_MEMORY_TO_PERIPH |
LL_DMA_PRIORITY_HIGH |
LL_DMA_MODE_NORMAL |
LL_DMA_PERIPH_NOINCREMENT |
LL_DMA_MEMORY_INCREMENT |
LL_DMA_PDATAALIGN_BYTE |
LL_DMA_MDATAALIGN_BYTE);
#else
LL_DMA_ConfigTransfer(TRACER_EMB_DMA_INSTANCE, TRACER_EMB_TX_DMA_CHANNEL,
LL_DMA_DIRECTION_MEMORY_TO_PERIPH |
LL_DMA_PRIORITY_HIGH |
LL_DMA_MODE_NORMAL |
LL_DMA_PERIPH_NOINCREMENT |
LL_DMA_MEMORY_INCREMENT |
LL_DMA_PDATAALIGN_BYTE |
LL_DMA_MDATAALIGN_BYTE);
#if defined(DMAMUX_CxCR_DMAREQ_ID)
LL_DMA_SetPeriphRequest(TRACER_EMB_DMA_INSTANCE, TRACER_EMB_TX_DMA_CHANNEL, TRACER_EMB_TX_DMA_REQUEST);
#endif
#endif /* GPDMA1 */
#if defined(DMA_SxCR_CHSEL)
LL_DMA_EnableIT_TC(TRACER_EMB_DMA_INSTANCE, TRACER_EMB_TX_DMA_STREAM);
#else
LL_DMA_EnableIT_TC(TRACER_EMB_DMA_INSTANCE, TRACER_EMB_TX_DMA_CHANNEL);
#endif /* DMA_SxCR_CHSEL */
#endif
/* Configure the interrupt for TX */
#if TRACER_EMB_DMA_MODE == 1UL
#ifdef TRACER_EMB_TX_DMA_PRIORITY
NVIC_SetPriority(TRACER_EMB_TX_DMA_IRQ, TRACER_EMB_TX_DMA_PRIORITY);
NVIC_EnableIRQ(TRACER_EMB_TX_DMA_IRQ);
#else
NVIC_SetPriority(TRACER_EMB_TX_DMA_IRQ, 0);
NVIC_EnableIRQ(TRACER_EMB_TX_DMA_IRQ);
#endif
#endif
#ifdef TRACER_EMB_TX_IRQ_PRIORITY
NVIC_SetPriority(TRACER_EMB_USART_IRQ, TRACER_EMB_TX_IRQ_PRIORITY);
NVIC_EnableIRQ(TRACER_EMB_USART_IRQ);
#else
NVIC_SetPriority(TRACER_EMB_USART_IRQ, 3);
NVIC_EnableIRQ(TRACER_EMB_USART_IRQ);
#endif
/* Disable the UART */
if(NULL == fptr_rx)
{
TRACER_EMB_DISABLE_CLK_USART();
}
return;
}
/**
* @brief Trace Deinit
* @retval none
*/
void HW_TRACER_EMB_DeInit(void)
{
TRACER_EMB_DISABLE_CLK_USART();
return;
}
/**
* @brief Allow to update the RX callback
* @param callbackRX
* @retval none
*/
void HW_TRACER_EMB_RegisterRxCallback(void (*callbackRX)(uint8_t, uint8_t))
{
fptr_rx = callbackRX;
TRACER_EMB_ENABLE_CLK_USART();
}
/**
* @brief Start RX reception only when OSKernel have been started
* @retval none
*/
void HW_TRACER_EMB_StartRX(void)
{
/* Enable USART IT for RX */
TRACER_EMB_ENABLE_IT_RXNE(TRACER_EMB_USART_INSTANCE);
TRACER_EMB_ENABLE_IT_ERROR(TRACER_EMB_USART_INSTANCE);
/* Enable RX/TX */
TRACER_EMB_ENABLEDIRECTIONRX(TRACER_EMB_USART_INSTANCE);
/* Configure the interrupt for RX */
NVIC_SetPriority(TRACER_EMB_USART_IRQ, 3);
NVIC_EnableIRQ(TRACER_EMB_USART_IRQ);
}
#if TRACER_EMB_DMA_MODE == 1UL
/**
* @brief Function to handle reception in DMA mode
* @retval none
*/
void HW_TRACER_EMB_IRQHandlerDMA(void)
{
if (1UL == TRACER_EMB_TX_DMA_ACTIVE_FLAG(TRACER_EMB_DMA_INSTANCE))
{
TRACER_EMB_ENABLE_IT_TC(TRACER_EMB_USART_INSTANCE);
TRACER_EMB_TX_DMA_CLEAR_FLAG(TRACER_EMB_DMA_INSTANCE);
}
}
#endif
/**
* @brief USART/LPUART IRQ Handler
* @retval none
*/
void HW_TRACER_EMB_IRQHandlerUSART(void)
{
uint32_t _temp1, _temp2;
uint32_t _isrflags;
uint32_t _errorflags;
uint8_t _error = 0U;
/* Load ISR in local variable */
#if defined(USART_ISR_TC)
_isrflags = TRACER_EMB_READREG(TRACER_EMB_USART_INSTANCE, ISR);
#else
_isrflags = TRACER_EMB_READREG(TRACER_EMB_USART_INSTANCE, SR);
#endif /* USART_ISR_TC */
/* Ready to read received char if any */
_temp1 = TRACER_EMB_ISENABLEDIT_RXNE(TRACER_EMB_USART_INSTANCE);
/* If Reception is ongoing */
if (1UL == _temp1)
{
/* Reception is active : check if new byte is received */
__IO uint32_t received_char;
_errorflags = ((_isrflags) & (TRACER_EMB_FLAG_PE | TRACER_EMB_FLAG_FE | TRACER_EMB_FLAG_NE | TRACER_EMB_FLAG_ORE));
/* Check if RXNE flag is set : new byte is stored in DR */
if ( ((TRACER_EMB_FLAG_RXNE) == ((_isrflags) & (TRACER_EMB_FLAG_RXNE)))
&&(0UL == _errorflags) )
{
/* Read Received character. RXNE flag is cleared by reading of RDR register */
received_char = TRACER_EMB_RECEIVE_DATA8(TRACER_EMB_USART_INSTANCE);
if (fptr_rx != NULL)
{
fptr_rx(received_char, 0U);
}
return;
}
else if (0UL != _errorflags)
{
/* Error has been detected */
/* Check if RXNE flag is set : new byte is stored in DR */
if ((TRACER_EMB_FLAG_RXNE) == ((_isrflags) & (TRACER_EMB_FLAG_RXNE)))
{
/* Read Received character. RXNE flag is cleared by reading of RDR register */
received_char = TRACER_EMB_RECEIVE_DATA8(TRACER_EMB_USART_INSTANCE);
if (fptr_rx != NULL)
{
fptr_rx(received_char, 0U);
}
return;
}
/* Parity error */
_temp2 = TRACER_EMB_ISENABLEDIT_PE(TRACER_EMB_USART_INSTANCE);
if ( (1U == _temp2)
&&(TRACER_EMB_FLAG_PE == ((_errorflags) & (TRACER_EMB_FLAG_PE))) )
{
/* Flags clearing */
TRACER_EMB_CLEARFLAG_PE(TRACER_EMB_USART_INSTANCE);
_error = 1U;
}
/* Generic Errors*/
_temp2 = TRACER_EMB_ISENABLEDIT_ERROR(TRACER_EMB_USART_INSTANCE);
if (1U == _temp2)
{
/* Framing error */
if (TRACER_EMB_FLAG_FE == ((_errorflags) & (TRACER_EMB_FLAG_FE)))
{
/* Flags clearing */
TRACER_EMB_CLEARFLAG_FE(TRACER_EMB_USART_INSTANCE);
_error = 1U;
}
/* Overrun error */
if (TRACER_EMB_FLAG_ORE == ((_errorflags) & (TRACER_EMB_FLAG_ORE)))
{
/* Flags clearing */
TRACER_EMB_CLEARFLAG_ORE(TRACER_EMB_USART_INSTANCE);
_error = 1U;
}
/* Noise detection */
if (TRACER_EMB_FLAG_NE == ((_errorflags) & (TRACER_EMB_FLAG_NE)))
{
/* Flags clearing */
TRACER_EMB_CLEARFLAG_NE(TRACER_EMB_USART_INSTANCE);
_error = 1U;
}
}
if ((1U == _error) && (fptr_rx != NULL))
{
fptr_rx(1U, 1U); /* 1 indicate a reception error */
}
}
else
{
/* no error, no reception */
}
}
#if TRACER_EMB_IT_MODE == 1UL
/* Ready to handle TXE interrupt */
_temp2 = TRACER_EMB_ISENABLEDIT_TXE(TRACER_EMB_USART_INSTANCE);
if (((TRACER_EMB_FLAG_TXE) == ((_isrflags) & (TRACER_EMB_FLAG_TXE))) && (1UL == _temp2))
{
/* Write data inside the data register */
TRACER_EMB_TRANSMIT_DATA8(TRACER_EMB_USART_INSTANCE, *txData);
txData++;
txSize--;
if (txSize == 0)
{
TRACER_EMB_DISABLEIT_TXE(TRACER_EMB_USART_INSTANCE);
if(NULL == fptr_rx)
{
TRACER_EMB_DISABLE_CLK_USART();
}
TRACER_EMB_CALLBACK_TX();
}
}
#endif
#if (TRACER_EMB_DMA_MODE == 1UL)
/* Ready to handle TC interrupt */
_temp2 = TRACER_EMB_ISENABLEDIT_TC(TRACER_EMB_USART_INSTANCE);
if (((TRACER_EMB_FLAG_TC) == ((_isrflags) & (TRACER_EMB_FLAG_TC))) && (1UL == _temp2))
{
TRACER_EMB_DISABLEIT_TC(TRACER_EMB_USART_INSTANCE);
TRACER_EMB_CLEARFLAG_TC(TRACER_EMB_USART_INSTANCE);
#if defined(DMA_SxCR_CHSEL)
TRACER_EMB_DISABLESTREAM(TRACER_EMB_DMA_INSTANCE, TRACER_EMB_TX_DMA_STREAM);
#else
TRACER_EMB_DISABLECHANNEL(TRACER_EMB_DMA_INSTANCE, TRACER_EMB_TX_DMA_CHANNEL);
#endif /* DMA_SxCR_CHSEL */
if(NULL == fptr_rx)
{
TRACER_EMB_DISABLE_CLK_USART();
}
/* call the callback */
TRACER_EMB_CALLBACK_TX();
}
#endif
}
/**
* @brief USART/LPUART send data
* @param data pointer
* @param data size
* @retval none
*/
void HW_TRACER_EMB_SendData(uint8_t *pData, uint32_t Size)
{
/* enable the USART */
TRACER_EMB_ENABLE_CLK_USART();
#if TRACER_EMB_DMA_MODE == 1UL
#if defined(GPDMA1)
LL_DMA_ConfigAddrs(TRACER_EMB_DMA_INSTANCE, TRACER_EMB_TX_DMA_CHANNEL,
(uint32_t)pData,
TRACER_EMB_DMA_GETREGADDR(TRACER_EMB_USART_INSTANCE, LL_USART_DMA_REG_DATA_TRANSMIT));
LL_DMA_SetBlkDataLength(TRACER_EMB_DMA_INSTANCE, TRACER_EMB_TX_DMA_CHANNEL, Size);
/* Enable DMA TX Interrupt */
TRACER_EMB_ENABLEDMAREQ_TX(TRACER_EMB_USART_INSTANCE);
/* Enable DMA Channel Tx */
LL_DMA_EnableChannel(TRACER_EMB_DMA_INSTANCE, TRACER_EMB_TX_DMA_CHANNEL);
TRACER_EMB_ENABLECHANNEL(TRACER_EMB_DMA_INSTANCE, TRACER_EMB_TX_DMA_CHANNEL);
#elif defined(DMA_SxCR_CHSEL)
LL_DMA_ConfigAddresses(TRACER_EMB_DMA_INSTANCE, TRACER_EMB_TX_DMA_STREAM,
(uint32_t)pData,
TRACER_EMB_DMA_GETREGADDR(TRACER_EMB_USART_INSTANCE),
LL_DMA_GetDataTransferDirection(TRACER_EMB_DMA_INSTANCE, TRACER_EMB_TX_DMA_STREAM));
LL_DMA_SetDataLength(TRACER_EMB_DMA_INSTANCE, TRACER_EMB_TX_DMA_STREAM, Size);
/* Enable DMA TX Interrupt */
TRACER_EMB_ENABLEDMAREQ_TX(TRACER_EMB_USART_INSTANCE);
/* Enable DMA Channel Tx */
TRACER_EMB_ENABLESTREAM(TRACER_EMB_DMA_INSTANCE, TRACER_EMB_TX_DMA_STREAM);
#else
LL_DMA_ConfigAddresses(TRACER_EMB_DMA_INSTANCE, TRACER_EMB_TX_DMA_CHANNEL,
(uint32_t)pData,
TRACER_EMB_DMA_GETREGADDR(TRACER_EMB_USART_INSTANCE, LL_USART_DMA_REG_DATA_TRANSMIT),
LL_DMA_GetDataTransferDirection(TRACER_EMB_DMA_INSTANCE, TRACER_EMB_TX_DMA_CHANNEL));
LL_DMA_SetDataLength(TRACER_EMB_DMA_INSTANCE, TRACER_EMB_TX_DMA_CHANNEL, Size);
/* Enable DMA TX Interrupt */
TRACER_EMB_ENABLEDMAREQ_TX(TRACER_EMB_USART_INSTANCE);
/* Enable DMA Channel Tx */
TRACER_EMB_ENABLECHANNEL(TRACER_EMB_DMA_INSTANCE, TRACER_EMB_TX_DMA_CHANNEL);
#endif /* GPDMA1 */
#endif
#if TRACER_EMB_IT_MODE == 1UL
/* keep information about the data to transfert */
txData = pData;
txSize = Size;
/* Enable the TXEIE */
TRACER_EMB_ENABLE_IT_TXE(TRACER_EMB_USART_INSTANCE);
#endif
}
/**
* @brief USART/LPUART read data
* @retval return a data
*/
uint8_t HW_TRACER_EMB_ReadData(void)
{
return TRACER_EMB_RECEIVE_DATA8(TRACER_EMB_USART_INSTANCE);
}
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View file

@ -0,0 +1,47 @@
/**
******************************************************************************
* @file usbpd_bsp_trace.h
* @author MCD Application Team
* @brief This file contains bsp interface control functions.
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2018 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under BSD 3-Clause license,
* the "License"; You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*
******************************************************************************
*/
#ifndef HW_TRACE_H
#define HW_TRACE_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
/* Exported functions ---------------------------------------------------------*/
void HW_TRACER_EMB_Init(void);
void HW_TRACER_EMB_DeInit(void);
void HW_TRACER_EMB_RegisterRxCallback(void (*callbackRX)(uint8_t, uint8_t));
#if TRACER_EMB_DMA_MODE == 1UL
void HW_TRACER_EMB_IRQHandlerDMA(void);
#endif
void HW_TRACER_EMB_IRQHandlerUSART(void);
void HW_TRACER_EMB_StartRX(void);
void HW_TRACER_EMB_SendData(uint8_t *data, uint32_t size);
uint8_t HW_TRACER_EMB_ReadData(void);
#ifdef __cplusplus
}
#endif
#endif /* HW_TRACE_H */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/