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 support of stm32f103c6 devices #20

Open
wants to merge 2 commits into
base: master
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
14 changes: 10 additions & 4 deletions src/DAP42.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ int main(void) {
clock_setup();
tick_setup(1000);
gpio_setup();
led_num(0);
LED_CONNECTED_OUT(0);

if (CDC_AVAILABLE) {
console_setup(DEFAULT_BAUDRATE);
Expand All @@ -97,7 +97,7 @@ int main(void) {
retarget(STDERR_FILENO, CONSOLE_USART);
}

led_num(1);
LED_CONNECTED_OUT(1);

{
char serial[USB_SERIAL_NUM_LENGTH+1];
Expand Down Expand Up @@ -157,9 +157,15 @@ int main(void) {
int x;
for (x=0; x < 3; x++) {
iwdg_reset();
led_num(7);
LED_CONNECTED_OUT(1);
LED_ACTIVITY_OUT(1);
LED_RUNNING_OUT(1);
// led_num(1);
wait_ms(150);
led_num(0);
LED_CONNECTED_OUT(0);
LED_ACTIVITY_OUT(0);
LED_RUNNING_OUT(0);
// led_num(0);
wait_ms(150);
iwdg_reset();
}
Expand Down
18 changes: 18 additions & 0 deletions src/stm32f103/DAP/CMSIS_DAP_hal.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,26 +191,44 @@ static __inline void PIN_nRESET_OUT (uint32_t bit) {

static __inline void LED_CONNECTED_OUT (uint32_t bit) {
if ((bit & 0x1) ^ LED_OPEN_DRAIN) {
#ifndef LED_CON_DISABLE
#ifdef LED_CON_INVERT
gpio_clear(LED_CON_GPIO_PORT, LED_CON_GPIO_PIN);
} else {
gpio_set(LED_CON_GPIO_PORT, LED_CON_GPIO_PIN);
#else
gpio_set(LED_CON_GPIO_PORT, LED_CON_GPIO_PIN);
} else {
gpio_clear(LED_CON_GPIO_PORT, LED_CON_GPIO_PIN);
#endif
}
#else
(void) bit;
#endif
}

static __inline void LED_RUNNING_OUT (uint32_t bit) {
#ifndef LED_RUN_DISABLE
if ((bit & 0x1) ^ LED_OPEN_DRAIN) {
gpio_set(LED_RUN_GPIO_PORT, LED_RUN_GPIO_PIN);
} else {
gpio_clear(LED_RUN_GPIO_PORT, LED_RUN_GPIO_PIN);
}
#else
(void) bit;
#endif
}

static __inline void LED_ACTIVITY_OUT (uint32_t bit) {
#ifndef LED_ACT_DISABLE
if ((bit & 0x1) ^ LED_OPEN_DRAIN) {
gpio_set(LED_ACT_GPIO_PORT, LED_ACT_GPIO_PIN);
} else {
gpio_clear(LED_ACT_GPIO_PORT, LED_ACT_GPIO_PIN);
}
#else
(void) bit;
#endif
}

static __inline void DAP_SETUP (void) {
Expand Down
180 changes: 180 additions & 0 deletions src/stm32f103/daplink_f103c6/DAP/CMSIS_DAP_config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
/*
* Copyright (c) 2013-2017 ARM Limited. All rights reserved.
*
* SPDX-License-Identifier: Apache-2.0
*
* 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
*
* 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.
*
* ----------------------------------------------------------------------
*
* $Date: 1. December 2017
* $Revision: V2.0.0
*
* Project: CMSIS-DAP Configuration
* Title: DAP_config.h CMSIS-DAP Configuration File (Template)
*
*---------------------------------------------------------------------------*/

#ifndef __DAP_CONFIG_H__
#define __DAP_CONFIG_H__


//**************************************************************************************************
/**
\defgroup DAP_Config_Debug_gr CMSIS-DAP Debug Unit Information
\ingroup DAP_ConfigIO_gr
@{
Provides definitions about the hardware and configuration of the Debug Unit.

This information includes:
- Definition of Cortex-M processor parameters used in CMSIS-DAP Debug Unit.
- Debug Unit Identification strings (Vendor, Product, Serial Number).
- Debug Unit communication packet size.
- Debug Access Port supported modes and settings (JTAG/SWD and SWO).
- Optional information about a connected Target Device (for Evaluation Boards).
*/

#include "config.h"

// Board configuration options

/// Processor Clock of the Cortex-M MCU used in the Debug Unit.
/// This value is used to calculate the SWD/JTAG clock speed.
#define CPU_CLOCK 72000000U ///< Specifies the CPU Clock in Hz.

/// Number of processor cycles for I/O Port write operations.
/// This value is used to calculate the SWD/JTAG clock speed that is generated with I/O
/// Port write operations in the Debug Unit by a Cortex-M MCU. Most Cortex-M processors
/// require 2 processor cycles for a I/O Port Write operation. If the Debug Unit uses
/// a Cortex-M0+ processor with high-speed peripheral I/O only 1 processor cycle might be
/// required.
#define IO_PORT_WRITE_CYCLES 2U ///< I/O Cycles: 2=default, 1=Cortex-M0+ fast I/0.

/// Indicate that Serial Wire Debug (SWD) communication mode is available at the Debug Access Port.
/// This information is returned by the command \ref DAP_Info as part of <b>Capabilities</b>.
#define DAP_SWD 1 ///< SWD Mode: 1 = available, 0 = not available.

/// Indicate that JTAG communication mode is available at the Debug Port.
/// This information is returned by the command \ref DAP_Info as part of <b>Capabilities</b>.
#if defined(CONF_JTAG)
#define DAP_JTAG 1 ///< JTAG Mode: 1 = available
#else
#define DAP_JTAG 0 ///< JTAG Mode: 0 = not available
#endif

/// Configure maximum number of JTAG devices on the scan chain connected to the Debug Access Port.
/// This setting impacts the RAM requirements of the Debug Unit. Valid range is 1 .. 255.
#define DAP_JTAG_DEV_CNT 8U ///< Maximum number of JTAG devices on scan chain

/// Default communication mode on the Debug Access Port.
/// Used for the command \ref DAP_Connect when Port Default mode is selected.
#define DAP_DEFAULT_PORT 1U ///< Default JTAG/SWJ Port Mode: 1 = SWD, 2 = JTAG.

/// Default communication speed on the Debug Access Port for SWD and JTAG mode.
/// Used to initialize the default SWD/JTAG clock frequency.
/// The command \ref DAP_SWJ_Clock can be used to overwrite this default setting.
#define DAP_DEFAULT_SWJ_CLOCK 10000000U ///< Default SWD/JTAG clock frequency in Hz.

/// Maximum Package Size for Command and Response data.
/// This configuration settings is used to optimize the communication performance with the
/// debugger and depends on the USB peripheral. Typical vales are 64 for Full-speed USB HID or WinUSB,
/// 1024 for High-speed USB HID and 512 for High-speed USB WinUSB.
#define DAP_PACKET_SIZE 64U ///< Specifies Packet Size in bytes.

/// Maximum Package Buffers for Command and Response data.
/// This configuration settings is used to optimize the communication performance with the
/// debugger and depends on the USB peripheral. For devices with limited RAM or USB buffer the
/// setting can be reduced (valid range is 1 .. 255).
#define DAP_PACKET_COUNT 12U ///< Specifies number of packets buffered.

#define DAP_PACKET_QUEUE_SIZE (DAP_PACKET_COUNT+8)

/// Indicate that UART Serial Wire Output (SWO) trace is available.
/// This information is returned by the command \ref DAP_Info as part of <b>Capabilities</b>.
#define SWO_UART 0 ///< SWO UART: 1 = available, 0 = not available.

/// Maximum SWO UART Baudrate.
#define SWO_UART_MAX_BAUDRATE 10000000U ///< SWO UART Maximum Baudrate in Hz.

/// Indicate that Manchester Serial Wire Output (SWO) trace is available.
/// This information is returned by the command \ref DAP_Info as part of <b>Capabilities</b>.
#define SWO_MANCHESTER 0 ///< SWO Manchester: 1 = available, 0 = not available.

/// SWO Trace Buffer Size.
#define SWO_BUFFER_SIZE 1024U ///< SWO Trace Buffer Size in bytes (must be 2^n).

/// SWO Streaming Trace.
#define SWO_STREAM 0 ///< SWO Streaming Trace: 1 = available, 0 = not available.

/// Clock frequency of the Test Domain Timer. Timer value is returned with \ref TIMESTAMP_GET.
#define TIMESTAMP_CLOCK 1000U ///< Timestamp clock in Hz (0 = timestamps not supported).

/// Debug Unit is connected to fixed Target Device.
/// The Debug Unit may be part of an evaluation board and always connected to a fixed
/// known device. In this case a Device Vendor and Device Name string is stored which
/// may be used by the debugger or IDE to configure device parameters.
#define TARGET_DEVICE_FIXED 0 ///< Target Device: 1 = known, 0 = unknown;

#if TARGET_DEVICE_FIXED
#define TARGET_DEVICE_VENDOR "" ///< String indicating the Silicon Vendor
#define TARGET_DEVICE_NAME "" ///< String indicating the Target Device
#endif

/** Get Vendor ID string.
\param str Pointer to buffer to store the string.
\return String length.
*/
static inline uint8_t DAP_GetVendorString (char *str) {
(void)str;
return (0U);
}

/** Get Product ID string.
\param str Pointer to buffer to store the string.
\return String length.
*/
static inline uint8_t DAP_GetProductString (char *str) {
(void)str;
return (0U);
}

/** Get Serial Number string.
\param str Pointer to buffer to store the string.
\return String length.
*/
static inline uint8_t DAP_GetSerNumString (char *str) {
(void)str;
return (0U);
}

///@}

#define SWCLK_GPIO_PORT GPIOA
#define SWCLK_GPIO_PIN GPIO4
#define SWDIO_GPIO_PORT GPIOA
#define SWDIO_GPIO_PIN GPIO2
#define nRESET_GPIO_PORT GPIOA
#define nRESET_GPIO_PIN GPIO6

#define LED_CON_INVERT
#define LED_CON_GPIO_PORT GPIOB
#define LED_CON_GPIO_PIN GPIO8
#define LED_RUN_DISABLE
#define LED_RUN_GPIO_PORT GPIOB
#define LED_RUN_GPIO_PIN GPIO8
#define LED_ACT_GPIO_PORT GPIOB
#define LED_ACT_GPIO_PIN GPIO12

#define SWDIO_GPIO_PIN_NUM 2

#endif /* __DAP_CONFIG_H__ */
1 change: 1 addition & 0 deletions src/stm32f103/daplink_f103c6/DFU
37 changes: 37 additions & 0 deletions src/stm32f103/daplink_f103c6/USB/usb_setup.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright (c) 2016, Devan Lai
*
* Permission to use, copy, modify, and/or distribute this software
* for any purpose with or without fee is hereby granted, provided
* that the above copyright notice and this permission notice
* appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
* WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
* AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/

#include <libopencm3/stm32/rcc.h>
#include <libopencm3/stm32/gpio.h>
#include <libopencm3/stm32/st_usbfs.h>

#include "USB/usb_setup.h"

const usbd_driver* target_usb_init(void) {
rcc_periph_reset_pulse(RST_USB);

/* Force re-enumeration */
rcc_periph_clock_enable(RCC_GPIOA);
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_10_MHZ,
GPIO_CNF_OUTPUT_PUSHPULL, GPIO12);
gpio_clear(GPIOA, GPIO12);
int i;
for (i = 0; i < 800000; i++)
__asm__("nop");
return &st_usbfs_v1_usb_driver;
}
62 changes: 62 additions & 0 deletions src/stm32f103/daplink_f103c6/config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Copyright (c) 2016, Devan Lai
*
* Permission to use, copy, modify, and/or distribute this software
* for any purpose with or without fee is hereby granted, provided
* that the above copyright notice and this permission notice
* appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
* WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
* AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/

#ifndef CONFIG_H_INCLUDED
#define CONFIG_H_INCLUDED

#define PRODUCT_NAME "DAPLINK-F103C6"

#define CAN_RX_AVAILABLE 0
#define CAN_TX_AVAILABLE 0

#define VCDC_AVAILABLE 0
#define VCDC_TX_BUFFER_SIZE 128
#define VCDC_RX_BUFFER_SIZE 128

#define CDC_AVAILABLE 1
#define DEFAULT_BAUDRATE 115200

#define CONSOLE_USART USART1
#define CONSOLE_TX_BUFFER_SIZE 128
#define CONSOLE_RX_BUFFER_SIZE 1024

#define CONSOLE_USART_GPIO_PORT GPIOA
#define CONSOLE_USART_GPIO_TX GPIO9
#define CONSOLE_USART_GPIO_RX GPIO10

#define CONSOLE_USART_MODE USART_MODE_TX_RX

#define CONSOLE_USART_CLOCK RCC_USART1

#define CONSOLE_USART_IRQ_NAME usart1_isr
#define CONSOLE_USART_NVIC_LINE NVIC_USART1_IRQ
#define CONSOLE_RX_DMA_CONTROLLER DMA1
#define CONSOLE_RX_DMA_CLOCK RCC_DMA1
#define CONSOLE_RX_DMA_CHANNEL DMA_CHANNEL5

#define TARGET_DFU_AVAILABLE 0

/* Word size for usart_recv and usart_send */
typedef uint16_t usart_word_t;

/* Workaround for non-commonalized STM32F0 USART code */
#define USART_RDR(usart_base) USART_DR(usart_base)

#define LED_OPEN_DRAIN 0

#endif
Loading