2019-09-05 02:50 AM
Hello,
I am facing some strange behavior when I try to debug a stm32l4s9 MCU using Atollic TrueStudio 9.3.0.
When I try to debug the mcu using a st-link v2 I get following output:
STMicroelectronics ST-LINK GDB server. Version 5.1.0
Copyright (c) 2018, STMicroelectronics. All rights reserved.
Starting server with the following options:
Persistent Mode : Disabled
Logging Level : 1
Listen Port Number : 61234
Status Refresh Delay : 15s
Verbose Mode : Disabled
SWD Debug : Enabled
Waiting for debugger connection...
Debugger connected
-------------------------------------------------------------------
STM32CubeProgrammer v1.3.0
-------------------------------------------------------------------
Log output file: C:\Users\CKRENS~1\AppData\Local\Temp\STM32CubeProgrammer_a04520.log
ST-LINK SN : 56FF71065182525043221987
ST-LINK FW : V2J33S7
Voltage : 3.20V
SWD freq : 4000 KHz
Connect mode: Under Reset
Reset mode : Hardware reset
Device ID : 0x470
Device name : STM32L4Rxxx/STM32L4Sxxx
Device type : MCU
Device CPU : Cortex-M4
Memory Programming ...
Opening and parsing file: C:\Users\CKRENS~1\AppData\Local\Temp\ST-LINK_GDB_server_a04520.srec
File : C:\Users\CKRENS~1\AppData\Local\Temp\ST-LINK_GDB_server_a04520.srec
Size : 93084 Bytes
Address : 0x08000000
Erasing memory corresponding to segment 0:
Erasing external memory sectors [0 13]
Erasing memory corresponding to segment 1:
Erasing external memory sectors [24 33]
File segment @0x08000000 is not 255-bytes aligned. It will be aligned to @0x07FFFFF8
File segment @0x08018000 is not 255-bytes aligned. It will be aligned to @0x08017F77
Download in Progress:
Error: Writing in address 0x07FFFFF8 is not supported with JTAG/SWD debug port
Error: failed to download Segment[0]
Error: failed to download the File
Time elapsed during download operation: 00:00:00.082
Verifying ...
Error: Failed to read memory at address 0x07FFFFF8 during verification
Error: Download verification failed
Encountered Error when opening C:\Program Files (x86)\Atollic\TrueSTUDIO for STM32 9.3.0\Servers\STM32CubeProgrammer\bin\STM32_Programmer_CLI.exe
Error in STM32CubeProgrammer
Debugger connection lost.
Shutting down...
If I try to read the device flash memory using ST-LINK Utility I get this:
I can only read zeros and the read protection is suddenly set to level 1. If I disconnect the device from power und connect it again, I can read the flash memory just fine.
The read protection is set to Level 0 again.
Do you know anything about this topic?
Thank you,
Christian
2019-09-11 05:13 AM
Finally, I found the source / solution of the problem.
Cube programmer does not do anything wrong. But CubeMX does in my opinion.
I obviously changed the clock configuration of the stm32l4s9 to a too low frequency. But cubeMX does not throw any warning and generates code for the clock config just fine.
Here is the clock config source which led to this read protection problem.
void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
/** Configure the main internal regulator output voltage
*/
if (HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1) != HAL_OK)
{
Error_Handler();
}
/** Initializes the CPU, AHB and APB busses clocks
*/
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
RCC_OscInitStruct.PLL.PLLM = 1;
RCC_OscInitStruct.PLL.PLLN = 8;
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
RCC_OscInitStruct.PLL.PLLQ = RCC_PLLQ_DIV2;
RCC_OscInitStruct.PLL.PLLR = RCC_PLLR_DIV4;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
Error_Handler();
}
/** Initializes the CPU, AHB and APB busses clocks
*/
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV16;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
{
Error_Handler();
}
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USART1;
PeriphClkInit.Usart1ClockSelection = RCC_USART1CLKSOURCE_PCLK2;
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
{
Error_Handler();
}
}