Пример #1
0
static int stlink_configure_target_trace_port(void *handle)
{
	int res;
	uint32_t reg;
	struct stlink_usb_handle_s *h = handle;

	assert(handle != NULL);

	/* configure the TPI */

	/* enable the trace subsystem */
	res = stlink_usb_v2_read_debug_reg(handle, DCB_DEMCR, &reg);
	if (res != ERROR_OK)
		goto out;
	res = stlink_usb_write_debug_reg(handle, DCB_DEMCR, TRCENA|reg);
	if (res != ERROR_OK)
		goto out;
	/* set the TPI clock prescaler */
	res = stlink_usb_write_debug_reg(handle, TPI_ACPR, h->trace.prescale);
	if (res != ERROR_OK)
		goto out;
	/* select the pin protocol.  The STLinkv2 only supports asynchronous
	 * UART emulation (NRZ) mode, so that's what we pick. */
	res = stlink_usb_write_debug_reg(handle, TPI_SPPR, 0x02);
	if (res != ERROR_OK)
		goto out;
	/* disable continuous formatting */
	res = stlink_usb_write_debug_reg(handle, TPI_FFCR, (1<<8));
	if (res != ERROR_OK)
		goto out;

	/* configure the ITM */

	/* unlock access to the ITM registers */
	res = stlink_usb_write_debug_reg(handle, ITM_LAR, 0xC5ACCE55);
	if (res != ERROR_OK)
		goto out;
	/* enable trace with ATB ID 1 */
	res = stlink_usb_write_debug_reg(handle, ITM_TCR, (1<<16)|(1<<0)|(1<<2));
	if (res != ERROR_OK)
		goto out;
	/* trace privilege */
	res = stlink_usb_write_debug_reg(handle, ITM_TPR, 1);
	if (res != ERROR_OK)
		goto out;
	/* trace port enable (port 0) */
	res = stlink_usb_write_debug_reg(handle, ITM_TER, (1<<0));
	if (res != ERROR_OK)
		goto out;

	res = ERROR_OK;
out:
	return res;
}
Пример #2
0
static enum target_state stlink_usb_v2_get_status(void *handle)
{
	int result;
	uint32_t status;

	result = stlink_usb_v2_read_debug_reg(handle, DCB_DHCSR, &status);
	if  (result != ERROR_OK)
		return TARGET_UNKNOWN;

	if (status & S_HALT)
		return TARGET_HALTED;
	else if (status & S_RESET_ST)
		return TARGET_RESET;

	return TARGET_RUNNING;
}