Skip to main content
mahmoud boroumand
Associate III
July 17, 2017
Solved

SWO pin

  • July 17, 2017
  • 6 replies
  • 2310 views
Posted on July 17, 2017 at 12:37

Hey

I'm using stm32f103c8 and I want to use all of the GPIOB .it work good expect pin 3 and 4.Those pin use for sys_njtrst and sys_jtdo-tracswo but i just use SW and i don't need these pins for programming  and want to use for other purpose but its not work.can i do that?is it possible to use for input or output purpose?

    This topic has been closed for replies.
    Best answer by mahmoud boroumand
    Posted on July 22, 2017 at 08:16

    Thanks

    6 replies

    Vangelis Fortounas
    Associate II
    July 17, 2017
    Posted on July 17, 2017 at 13:01

    Hello!

    You must remap theese pin's function by use AF

    for example

    GPIO_InitTypeDef GPIO_InitStruct;
    //GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
    //GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
    GPIO_InitStruct.Mode = GPIO_MODE_AF_INPUT;
    GPIO_InitStruct.Pull = GPIO_NOPULL;
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_MEDIUM;
    GPIO_InitStruct.Pin = GPIO_PIN_2; 
    HAL_GPIO_Init(GPIO_B, &GPIO_InitStruct);�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?
     �?

    mahmoud boroumand
    Associate III
    July 17, 2017
    Posted on July 17, 2017 at 15:18

    hey thanks for your help.

    can you explain more?Because it's not work

    Vangelis Fortounas
    Associate II
    July 17, 2017
    Posted on July 17, 2017 at 16:12

    Hello again

    what you mean when you say 'is not work'?

    I suppose that you use HAL drivers.

    A very simple example for PB3 as push-pull GPIO Output:

    //initialisation
    __HAL_RCC_GPIOB_CLK_ENABLE();
    GPIO_InitTypeDef GPIO_InitStruct;
    GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
    GPIO_InitStruct.Pin = GPIO_PIN_3;
    HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);�?�?�?�?�?�?
    �?�?�?�?�?�?�?

    After initialize it you can use it as output :

    //Set output level
    HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, GPIO_PIN_SET);// Output is HI�?�?

    or

    HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, GPIO_PIN_RESET);// Output is Low �?

    Read also the STM32F103x8 DataSheet for details about pins and remaps of functions.

    mahmoud boroumand
    Associate III
    July 18, 2017
    Posted on July 18, 2017 at 06:06

    hello

    ♯ define WS2812B_PINS (GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3|GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7|GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11|GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15)

    GPIO_InitStructure.GPIO_Pin = WS2812B_PINS;

    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;

    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

    GPIO_Init(GPIOB, &GPIO_InitStructure);

    DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&WS2812B_PORT->ODR;

    DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)framedata;

    DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;

    DMA_InitStructure.DMA_BufferSize = BUFFER_SIZE;

    DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;

    DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;

    DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word;

    DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;

    DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;

    DMA_InitStructure.DMA_Priority = DMA_Priority_High;

    DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;

    DMA_Init(DMA1_Channel5, &DMA_InitStructure);

    This is my code for config gpio AND I use DMA .all of pin work well expect 

    GPIO_Pin_3|GPIO_Pin_4.

    can you tell me what's wrong in my code?

    thanks

    Vangelis Fortounas
    Associate II
    July 18, 2017
    Posted on July 18, 2017 at 09:48

    Hello!

    After GPIO_Init  function add

    RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);

    GPIO_PinRemapConfig(GPIO_Remap_SWJ_NoJTRST, ENABLE);

    GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE);

    mahmoud boroumand
    mahmoud boroumandAuthorBest answer
    Associate III
    July 22, 2017
    Posted on July 22, 2017 at 08:16

    Thanks