Skip to main content
er3481
Associate III
May 10, 2024
Solved

STM32F103VET6 boot problem

Hi,

I want to use PB3 an PB4 pins as SPI1. When i use st-link and debug my code, it works. but when i plug-off st-link it seems that mcu can not boot. I use the codes below for jtag disable , but it does not work. Any advise for my problem?

 

GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO, ENABLE); // GPIOB & AFIO
/* Configure PB.03 (JTDO) and PB.04 (JTRST) as output push-pull */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3 | GPIO_Pin_4;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_PinRemapConfig(GPIO_Remap_SWJ_Disable, ENABLE);
GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE);
GPIO_PinRemapConfig(GPIO_Remap_SWJ_NoJTRST, ENABLE);

 

 

This topic has been closed for replies.
er3481
er3481Best answer
Associate III
May 10, 2024

Hi,

I have found the problem. It is about the SPI1 setups, when i try to read some data from SPI, it was blocked in the read function, so i use the code below for start up and it is solved now.

 

RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD, ENABLE);
 RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO, ENABLE);
 RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO, ENABLE);
 /*!< SPI_FLASH_SPI Periph clock enable */
 RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1, ENABLE);


 /*!< Configure SPI_FLASH_SPI pins: SCK */
 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
 GPIO_Init(GPIOB, &GPIO_InitStructure);

 /*!< Configure SPI_FLASH_SPI pins: MISO */
 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
 GPIO_Init(GPIOB, &GPIO_InitStructure);

 /*!< Configure SPI_FLASH_SPI pins: MOSI */
 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
 GPIO_Init(GPIOB, &GPIO_InitStructure);

 /*!< Configure SPI_FLASH_SPI_CS_PIN pin: SPI_FLASH Card CS pin */
 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
 GPIO_Init(GPIOD, &GPIO_InitStructure);

 GPIO_PinRemapConfig(GPIO_Remap_SPI1, ENABLE);
 GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE);

4 replies

Andrew Neil
Super User
May 10, 2024

An ST-Link will provide a good reset - so check your hardware reset arrangements...

Use LEDs (or similar) to give "life signs"; eg,

  • Does it reach main() ?
  • Does it get stuck in a hardfault or other error handler ?
  • etc ...

 

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
mƎALLEm
ST Technical Moderator
May 10, 2024

What about Boot pin? how did you connect it? GND or VDD or floating?

You need to connect Boot pin to GND.

To give better visibility on the answered topics, please click "Best answer" on the reply which solved your issue or answered your question.
er3481
er3481AuthorBest answer
Associate III
May 10, 2024

Hi,

I have found the problem. It is about the SPI1 setups, when i try to read some data from SPI, it was blocked in the read function, so i use the code below for start up and it is solved now.

 

RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD, ENABLE);
 RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO, ENABLE);
 RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO, ENABLE);
 /*!< SPI_FLASH_SPI Periph clock enable */
 RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1, ENABLE);


 /*!< Configure SPI_FLASH_SPI pins: SCK */
 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
 GPIO_Init(GPIOB, &GPIO_InitStructure);

 /*!< Configure SPI_FLASH_SPI pins: MISO */
 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
 GPIO_Init(GPIOB, &GPIO_InitStructure);

 /*!< Configure SPI_FLASH_SPI pins: MOSI */
 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
 GPIO_Init(GPIOB, &GPIO_InitStructure);

 /*!< Configure SPI_FLASH_SPI_CS_PIN pin: SPI_FLASH Card CS pin */
 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
 GPIO_Init(GPIOD, &GPIO_InitStructure);

 GPIO_PinRemapConfig(GPIO_Remap_SPI1, ENABLE);
 GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE);
Andrew Neil
Super User
May 10, 2024

@er3481 wrote:

it is solved now.


:thumbs_up:

Now please mark the solution.

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.