I'm building a stream for the ITM trace port to stream system formatted print. I took serial.c code as a guide. sdIncomingDataI and sdRequestDataI are called from the serial interrupts. I only need to write to the ITM port but without interrupts. Do I need to regularly poll the out queue? Or is there a better way?
Kr,Jo
ITM stream
Moderator: RoccoMarco
- Giovanni
- Site Admin
- Posts: 14892
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 996 times
Re: ITM stream
Hi,
The serial driver assumes interrupts because it use queues, you should instead create your own object implementing the BaseSequentialStream interface. Your code would not use queues and just do polling.
I did something similar here:
Giovanni
The serial driver assumes interrupts because it use queues, you should instead create your own object implementing the BaseSequentialStream interface. Your code would not use queues and just do polling.
I did something similar here:
Code: Select all
/*
SPC5 HAL - Copyright (C) 2013 STMicroelectronics
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/**
* @file uartstream.c
* @brief UART streams code.
*
* @addtogroup uart_stream
* @{
*/
#include "hal.h"
#include "uartstream.h"
/*===========================================================================*/
/* Driver local definitions. */
/*===========================================================================*/
#define SPC5_LINFLEX2_CLK 100000000
/**
* @name UARTSR register bits definitions
* @{
*/
#define SPC5_UARTSR_NF (1U << 0)
#define SPC5_UARTSR_DTF (1U << 1)
#define SPC5_UARTSR_DRF (1U << 2)
#define SPC5_UARTSR_WUF (1U << 5)
#define SPC5_UARTSR_RPS (1U << 6)
#define SPC5_UARTSR_BOF (1U << 7)
#define SPC5_UARTSR_FEF (1U << 8)
#define SPC5_UARTSR_RMB (1U << 9)
#define SPC5_UARTSR_PE0 (1U << 10)
#define SPC5_UARTSR_PE1 (1U << 11)
#define SPC5_UARTSR_PE2 (1U << 12)
#define SPC5_UARTSR_PE3 (1U << 13)
#define SPC5_UARTSR_OCF (1U << 14)
#define SPC5_UARTSR_SZF (1U << 15)
/** @} */
/**
* @name UARTCR register bits definitions
* @{
*/
#define SPC5_UARTCR_UART (1U << 0)
#define SPC5_UARTCR_WL (1U << 1)
#define SPC5_UARTCR_PCE (1U << 2)
#define SPC5_UARTCR_OP (1U << 3)
#define SPC5_UARTCR_TXEN (1U << 4)
#define SPC5_UARTCR_RXEN (1U << 5)
#define SPC5_UARTCR_TFBM (1U << 8)
/** @} */
/**
* @name Serial driver allowable modes
* @{
*/
#define SD_MODE_8BITS_PARITY_NONE (SPC5_UARTCR_WL)
#define SD_MODE_8BITS_PARITY_EVEN (SPC5_UARTCR_WL | \
SPC5_UARTCR_PCE)
#define SD_MODE_8BITS_PARITY_ODD (SPC5_UARTCR_WL | \
SPC5_UARTCR_PCE | \
SPC5_UARTCR_OP)
/** @} */
/*===========================================================================*/
/* Driver exported variables. */
/*===========================================================================*/
/*===========================================================================*/
/* Driver local variables. */
/*===========================================================================*/
/*===========================================================================*/
/* Driver local functions. */
/*===========================================================================*/
static msg_t put(void *ip, uint8_t b) {
(void)ip;
while (LINFlexD_2.UARTSR.B.DTFTFF)
;
LINFlexD_2.BDRL.B.DATA0 = b;
return MSG_OK;
}
static msg_t get(void *ip) {
(void)ip;
return 4;
}
static size_t writes(void *ip, const uint8_t *bp, size_t n) {
size_t cnt = n;
while (cnt > 0) {
put(ip, *bp);
bp++;
cnt--;
}
return n;
}
static size_t reads(void *ip, uint8_t *bp, size_t n) {
(void)ip;
(void)bp;
(void)n;
return 0;
}
static const struct UartStreamVMT vmt = {writes, reads, put, get};
/*===========================================================================*/
/* Driver exported functions. */
/*===========================================================================*/
/**
* @brief UART stream object initialization.
*
* @param[out] usp pointer to the @p UartStream object to be initialized
*/
void usObjectInit(UartStream *usp) {
uint32_t div;
usp->vmt = &vmt;
/* Enters the configuration mode.*/
LINFlexD_2.LINCR1.R = 1; /* INIT bit. */
/* Configures the LINFlex in UART mode with all the required
parameters.*/
LINFlexD_2.UARTCR.R = SPC5_UARTCR_UART; /* UART mode FIRST. */
LINFlexD_2.UARTCR.R = SPC5_UARTCR_UART | SPC5_UARTCR_TFBM |
SD_MODE_8BITS_PARITY_NONE;
div = SPC5_LINFLEX2_CLK / 38400;
LINFlexD_2.LINFBRR.R = (uint16_t)(div & 15); /* Fractional divider. */
LINFlexD_2.LINIBRR.R = (uint16_t)(div >> 4); /* Integer divider. */
LINFlexD_2.UARTSR.R = 0xFFFF; /* Clearing UARTSR register.*/
LINFlexD_2.LINIER.R = 0; /* No interrupts enabled. */
/* Leaves the configuration mode.*/
LINFlexD_2.LINCR1.R = 0;
LINFlexD_2.UARTCR.B.TxEn = 1;
}
/** @} */
Code: Select all
/*
SPC5 HAL - Copyright (C) 2013 STMicroelectronics
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/**
* @file uartstream.h
* @brief UART stream structures and macros.
* @addtogroup uart_stream
* @{
*/
#ifndef _UARTSTREAM_H_
#define _UARTSTREAM_H_
/*===========================================================================*/
/* Driver constants. */
/*===========================================================================*/
/*===========================================================================*/
/* Driver pre-compile time settings. */
/*===========================================================================*/
/*===========================================================================*/
/* Derived constants and error checks. */
/*===========================================================================*/
/*===========================================================================*/
/* Driver data structures and types. */
/*===========================================================================*/
/**
* @brief @p UartStream specific data.
*/
#define _uart_stream_data \
_base_sequential_stream_data
/**
* @brief @p UartStream virtual methods table.
*/
struct UartStreamVMT {
_base_sequential_stream_methods
};
/**
* @extends BaseSequentialStream
*
* @brief UART stream object.
*/
typedef struct {
/** @brief Virtual Methods Table.*/
const struct UartStreamVMT *vmt;
_uart_stream_data
} UartStream;
/*===========================================================================*/
/* Driver macros. */
/*===========================================================================*/
/*===========================================================================*/
/* External declarations. */
/*===========================================================================*/
#ifdef __cplusplus
extern "C" {
#endif
void usObjectInit(UartStream *usp);
#ifdef __cplusplus
}
#endif
#endif /* _UARTSTREAM_H_ */
/** @} */
Giovanni
Re: ITM stream
Hi Giovanni,
The ITM stream object is finished. Offcourse, no need to use a queue. Straight banging the ITM port in the stream methods.
Tnx!
The ITM stream object is finished. Offcourse, no need to use a queue. Straight banging the ITM port in the stream methods.
Tnx!
Re: ITM stream
FYI zipped ITM trace stream.
Tnx!
Tnx!
- Attachments
-
- RT-STM32F411RE-NUCLEO-ITM.zip
- ITM_stream
- (12.8 KiB) Downloaded 389 times
- Giovanni
- Site Admin
- Posts: 14892
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 996 times
Re: ITM stream
OpenOCD 8.0 on stimulus port 0 works. ST-LINKv2 firmware on the boards should be at least JTAG v17!!
Re: ITM stream
JoVM wrote:FYI zipped ITM trace stream.
Tnx!
Would you expect this to work on stm32f407, or is it different initialization sequence?
I think I've just tried your code on stm32f407 and it did not send anything to ST Link Utility SWV. Would you expect SWV to receive data stream?