cancel
Showing results for 
Search instead for 
Did you mean: 

Programming STM32L w/J-Link Compact

DRkidd22
Associate II

I have created the below circuit and build a PCBA. I'm using the J-Link Base Compact and Tag-Connect TC2030.

Using the Arduino IDE I created a simple sketch to drive the 4 LEDs shown on the schematic below and blink every second.

The code compiles ok and Arduino IDE reports that it has successfully upload to the SMT32 chip, but the LEDs won't blink. I tried enableling outputs to other pins as well, but the problem persists. Any ideas what might be causing this? I'm using the Generic STM32L4 series "board" from Arduino library.

 

LEDTest.png

1 ACCEPTED SOLUTION

Accepted Solutions

So your J-Link should connect to 3V3 - not BATT_IN.

It's for the J-Link to sense what voltage the MCU is actually running at.

 

PS:

Not the latest manual, but:

AndrewNeil_0-1779980700212.png

 

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.

View solution in original post

10 REPLIES 10
TDK
Super User

If BOOT0 is floating it may be booting into the bootloader instead of user code. Either ground BOOT0 or adjust option bytes using STM32CubeProgrammer to boot into the flash regardless of BOOT0 pin state.

If you feel a post has answered your question, please click "Accept as Solution".
DRkidd22
Associate II

Thanks for the tip, but I've connected boot0 to ground and I still have the same issue. The application is not running. I moved over to STM32CubeIDE and instill trying to use Segger J-Link and I'm having the same issue.

The code compiled without issues and I programmed the device with STM32CubeProgrammer and received the output succesfull below.

19:56:49 : Start operation achieved successfully
19:58:40 : Opening and parsing file: BlinkTest.elf
19:58:40 : Memory Programming ...
19:58:40 :   File          : BlinkTest.elf
19:58:40 :   Size          : 4.11 KB 
19:58:40 :   Address       : 0x08000000
19:58:40 : Erasing memory corresponding to segment 0:
19:58:40 : Erasing internal memory sectors [0 2]
19:58:40 : Download in Progress:
19:58:40 : File download complete
19:58:40 : Time elapsed during download operation: 00:00:00.249
19:58:40 : Verifying...
19:58:40 : File size < 32KB legacy verify will be used
19:58:40 : Read progress:
19:58:40 : Time elapsed during verifying operation: 00:00:00.018
19:58:40 : Download verified successfully
19:58:40 : Memory [0x08000000 : 0x08020000] - Checksum : 0x01BD8D08
19:58:40 : RUNNING Program ... 
19:58:40 :   Address:      : 0x08000000
19:58:40 : Application is running, Please Hold on...
19:58:40 : Start operation achieved successfully
20:02:48 : Disconnected from device.

In my main.c I'm running a simple script to toggle some pins to verify board functionality.

#include "main.h"

/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */

/* USER CODE END Includes */

/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */

/* USER CODE END PTD */

/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */

/* USER CODE END PD */

/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */

/* USER CODE END PM */

/* Private variables ---------------------------------------------------------*/

/* USER CODE BEGIN PV */

/* USER CODE END PV */

/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
/* USER CODE BEGIN PFP */

/* USER CODE END PFP */

/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */

/* USER CODE END 0 */

/**
  * @brief  The application entry point.
  * @retval int
  */
int main(void)
{

  /* USER CODE BEGIN 1 */

  /* USER CODE END 1 */

  /* MCU Configuration--------------------------------------------------------*/

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

  /* USER CODE BEGIN Init */

  /* USER CODE END Init */

  /* Configure the system clock */
  SystemClock_Config();

  /* USER CODE BEGIN SysInit */

  /* USER CODE END SysInit */

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  /* USER CODE BEGIN 2 */

  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_4, GPIO_PIN_SET);
HAL_Delay(500);
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_4, GPIO_PIN_RESET);
HAL_Delay(500);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_13, GPIO_PIN_SET);
HAL_Delay(500);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_13, GPIO_PIN_RESET);
HAL_Delay(500);
    /* USER CODE END WHILE */

    /* USER CODE BEGIN 3 */
  }
  /* USER CODE END 3 */
}

The pin configuration was also setup with MX

static void MX_GPIO_Init(void)
{
  GPIO_InitTypeDef GPIO_InitStruct = {0};
  /* USER CODE BEGIN MX_GPIO_Init_1 */

  /* USER CODE END MX_GPIO_Init_1 */

  /* GPIO Ports Clock Enable */
  __HAL_RCC_GPIOC_CLK_ENABLE();
  __HAL_RCC_GPIOA_CLK_ENABLE();
  __HAL_RCC_GPIOB_CLK_ENABLE();

  /*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(GPIOA, GPIO_PIN_7, GPIO_PIN_RESET);

  /*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_4|GPIO_PIN_5
                          |GPIO_PIN_6|GPIO_PIN_7, GPIO_PIN_RESET);

  /*Configure GPIO pins : PA1 PA4 PA5 PA6 */
  GPIO_InitStruct.Pin = GPIO_PIN_1|GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6;
  GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

  /*Configure GPIO pin : PA7 */
  GPIO_InitStruct.Pin = GPIO_PIN_7;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

  /*Configure GPIO pins : PB0 PB1 PB6 PB7 */
  GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_6|GPIO_PIN_7;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

  /*Configure GPIO pins : PB4 PB5 */
  GPIO_InitStruct.Pin = GPIO_PIN_4|GPIO_PIN_5;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_PULLUP;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

  /* USER CODE BEGIN MX_GPIO_Init_2 */

  /* USER CODE END MX_GPIO_Init_2 */
}

 

TDK
Super User

Debug the program. Hit pause, see where execution is at. If BOOT0 is grounded, most likely other things are invalid clock settings in SystemClock_Config, or option bytes are set up not to boot to user flash.

If you feel a post has answered your question, please click "Accept as Solution".
Andrew Neil
Super User

Where is VDDA supplied from ?

What is BATT_IN? Are you using the J-Link to supply power to the board?

 

Have you tested your code on a known-good board; eg, a Nucleo board?

 

PS

See also AN4555Getting started with STM32L4 Series and STM32L4+ Series hardware development

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.
DRkidd22
Associate II

VDDA is tied to 3V3 and BATT_IN is voltage before the regulator, which is about 3.6V.

And yes, the code was tested on the nucleo without issues. This is the rest of the circuit. U3 is not installed and VDDA is tied to 3V3.

LEDTest2.png

So you are using the J-Link to supply power ?

I think you should check with Segger whether this is a valid configuration: I think it's intended to supply power direct to the target MCU - not via a regulator?

https://www.segger.com/support/technical-support/

https://forum.segger.com/board/4-j-link-flasher-related/

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.

No, BATT_IN is connected to an external power supply.

So your J-Link should connect to 3V3 - not BATT_IN.

It's for the J-Link to sense what voltage the MCU is actually running at.

 

PS:

Not the latest manual, but:

AndrewNeil_0-1779980700212.png

 

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.
DRkidd22
Associate II

Tied Vref to 3V3 and I can now toggle a pin. Not sure if that did it since the VTref is only to detect power presence? Isn't it only looking for a voltage?