stm32 arduino 如何解放JTAG IO PB3,PB4

stm32 arduino 解放JTAG IO PB3,PB4

原生相关资料
https://blog.csdn.net/euxnijuoh/article/details/74939446
STM32F103的PC13、PB3和PB4定义为普通IO口使用
引用

GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE);

GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE);  //关闭JTAG,SWD可以调`试的

arduino 编程如何设置呢?搜索JTAG
gpio.h相关配置代码


```cpp
/**
 * @brief Debug port configuration
 *
 * Used to configure the behavior of JTAG and Serial Wire (SW) debug
 * ports and their associated GPIO pins.
 *
 * @see afio_cfg_debug_ports()
 */
typedef enum afio_debug_cfg {
    /** Full Serial Wire and JTAG debug */
    AFIO_DEBUG_FULL_SWJ          = AFIO_MAPR_SWJ_CFG_FULL_SWJ,
    /** Full Serial Wire and JTAG, but no NJTRST. */
    AFIO_DEBUG_FULL_SWJ_NO_NJRST = AFIO_MAPR_SWJ_CFG_FULL_SWJ_NO_NJRST,
    /** Serial Wire debug only (JTAG-DP disabled, SW-DP enabled) */
    AFIO_DEBUG_SW_ONLY           = AFIO_MAPR_SWJ_CFG_NO_JTAG_SW,
    /** No debug; all JTAG and SW pins are free for use as GPIOs. */
    AFIO_DEBUG_NONE              = AFIO_MAPR_SWJ_CFG_NO_JTAG_NO_SW,
} afio_debug_cfg;

/**
 * @brief Enable or disable the JTAG and SW debug ports.
 * @param config Desired debug port configuration
 * @see afio_debug_cfg
 */
static inline void afio_cfg_debug_ports(afio_debug_cfg config) {
    __IO uint32 *mapr = &AFIO_BASE->MAPR;
    *mapr = (*mapr & ~AFIO_MAPR_SWJ_CFG) | config;
}

afio_cfg_debug_ports,何处调用呢?

wirish_debug.cpp中

/**
 * @file wirish/stm32f1/wirish_debug.cpp
 * @brief High level debug port configuration
 */

#include <wirish_debug.h>
#include <libmaple/gpio.h>

void disableDebugPorts(void) {
    afio_cfg_debug_ports(AFIO_DEBUG_NONE);
}

void enableDebugPorts(void) {
    afio_cfg_debug_ports(AFIO_DEBUG_SW_ONLY);
}

有示例board.cpp中可以设置



// boardInit(): nothing special to do for Maple.
//
// When defining your own board.cpp, you can put extra code in this
// function if you have anything you want done on reset, before main()
// or setup() are called.
//
// If there's nothing special you need done, feel free to leave this
// function out, as we do here.
/*
void boardInit(void) {
}
*/

// Pin map: this lets the basic I/O functions (digitalWrite(),
// analogRead(), pwmWrite()) translate from pin numbers to STM32
// peripherals.
//
// PMAP_ROW() lets us specify a row (really a struct stm32_pin_info)
// in the pin map. Its arguments are:
//
// - GPIO device for the pin (&gpioa, etc.)
// - GPIO bit for the pin (0 through 15)
// - Timer device, or NULL if none
// - Timer channel (1 to 4, for PWM), or 0 if none
// - ADC device, or NULL if none
// - ADC channel, or ADCx if none


// boardInit(): NUCLEO rely on some remapping
void boardInit(void) {
     afio_cfg_debug_ports(AFIO_DEBUG_SW_ONLY); // relase PC3 and PC5 on nucleo
     afio_remap(AFIO_REMAP_USART3_PARTIAL); // remap Serial2(USART3)PB10/PB11
    // to PC10/PC11 -> don't forget to insert into gpio.h:
    //     AFIO_REMAP_USART3_PARTIAL = AFIO_MAPR_USART3_REMAP_PARTIAL
   afio_remap(AFIO_REMAP_TIM2_FULL); // better PWM compatibility
   afio_remap(AFIO_REMAP_TIM3_PARTIAL);// better PWM compatibility
}

我觉得更改库不是好的选择,简单粗暴一点,还是写在setup里面吧

#include <wirish_debug.h>
void setup(){

   //禁用JTAG调试,这两句都可以
   //afio_cfg_debug_ports(AFIO_DEBUG_SW_ONLY);
   afio_cfg_debug_ports(AFIO_DEBUG_NONE);


}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值