2024-07-11 12:42 AM
Hello,
I have a custom made board, currently running with just an STM32F030K6T and a simple regulator on it.
Trying to implement power saving modes I face some weird behavior on the DBG module of the MCU.
The problem is that even after writing the DBG_MCU->CR Register via the HAL_DBGMCU_DisableDBGStopMode();
I am not able to see the module stops during the Stop Mode.
Initially that was really interesting.
So I tried to Disable the DBG in Stop mode from Debugger configuration window ("Debug in low power modes:Disabled").
The debugger then during connection is initializing on itself the DBG_MCU Registers and everything seems to work fine after the Debugger is been killed after __WFE(); execution.
Although if I debug the system with the "Debug in low power modes:Disabled" and I stop the debug session before the system goes into stop mode the MCU is not able to change and keep the DBG Module unclocked in order to prevent further power consumption.
So I tried again to stop firmwarely the DBG Module form in-code side but this time did 2 things:
1) CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STOP);
2)__HAL_RCC_DBGMCU_CLK_DISABLE();
Again nothing happened.
So By Now the only way to achieve disabling the DBG Module is not form in-code side.
Have anyone face such problem before an may came with a solution?
Best Regards
Pelekis
2024-07-22 03:25 AM
Hello @Pelekis ,
First, is your device going to stop mode without debugger connection, that is starting from power on ?
In case STOP mode is working fine in that case, when using debug in stop mode you need to disable the systick using HAL_SuspendTick();
This would make a sequence like this:
HAL_SuspendTick();
HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFE);
SystemClock_Config();
HAL_ResumeTick();
I hope this will help
Best regards
Jocelyn
2024-07-22 04:15 AM
@Pelekis wrote:Have anyone face such problem before
Yes: https://community.st.com/t5/stm32cubeide-mcus/dbgmcu-cr-dbg-stop-setting-ignored/td-p/616278
2024-07-24 03:48 AM
Hello @Jocelyn RICARD ,
The system enters and exit Low Power STOP Mode perfectly!!
I have implement the HAL_SuspendTick() and STOP on main loop.
I Exiting the STOP Mode after RTC Event happens where I call SystemClock_Config(); again and HAL_ResumeTick();
So as far as I can understand I have done everything accordingly correct.
void HAL_RTC_AlarmAEventCallback(RTC_HandleTypeDef *hrtc){
SystemClock_Config();
HAL_ResumeTick();
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
__HAL_RCC_GPIOC_CLK_ENABLE();
__HAL_RCC_GPIOD_CLK_ENABLE();
__HAL_RCC_GPIOF_CLK_ENABLE();
}
while (1){
LD_STAT(1);
DS18B20_Init_DQ_Pin();
rfm23_IRQ_Pin_Init();
MX_TIM1_Init();
MX_ADC_Init();
HAL_Delay(50);
DS18B20_GetTemperature();
DS18B20_GetTemperature();
if(Sensors[0]!=Sensor_temp){
MX_SPI1_Init();
init_RFM22(); // Initialize all RFM22 registers
rfm23_prepare_packet();
rfm23_send_new_data_packet();
HAL_Delay(100);
rfm23_send_new_data_packet();
HAL_Delay(100);
rfm23_send_new_data_packet();
RFM_SDN(1);
Sensor_temp=Sensors[0];
}
RTC_ALARM_Reset();
MX_TIM1_DeInit();
MX_SPI1_DeInit();
DS18B20_DeInit_DQ_Pin();
rfm23_IRQ_Pin_Init();
ADC_DeInit_ADC1_Pin();
LD_STAT(0);
__HAL_RCC_GPIOA_CLK_DISABLE();
__HAL_RCC_GPIOB_CLK_DISABLE();
__HAL_RCC_GPIOC_CLK_DISABLE();
__HAL_RCC_GPIOD_CLK_DISABLE();
__HAL_RCC_GPIOF_CLK_DISABLE();
HAL_SuspendTick();
HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON,PWR_STOPENTRY_WFE);
}
But the problem is not on STOP Mode.
The problem is that after POR the firmware is not able to edit the DBG Registers.
So even if the code execution(after POR) ask the MCU to disable the DBG in low Power stop mode,
the MCU keeps the DBG Module on causing draining of power form the battery.
int main(void){
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* Configure the system clock */
SystemClock_Config();
HAL_Delay(500);
HAL_DBGMCU_DisableDBGStopMode();
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_RTC_Init();
/* USER CODE BEGIN 2 */
LD_STAT(1);
HAL_Delay(1000);
LD_STAT(0);
DBG Module is only able to get deactivated when "Debug in low power modes have been Disabled from debug menu (and not always working)
The problem is when I am flashing the MCU in production,
the code execution is not disabling the DBG Module so the System drains Power from the battery.
Best Regards,
Pelekis Marios
2024-07-24 04:58 AM
Hello @Pelekis,
I don't think you are doing a real POR as you are battery powered.
After POR, the DBGMCU register is reset to 0. After a system reset, value is maintained.
Now, can you try enabling the DBGMCU clock before accessing the register using following macro ?
__HAL_RCC_DBGMCU_CLK_ENABLE();
This should normally solve your issue
Best regards
Jocelyn
2024-07-24 06:07 AM
Hello @Jocelyn RICARD ,
I tried your solution where seams that works in case the debugger is not edits the "Debug in low power modes"
But in order to test that really worked I implemented the following steps:
The result is that the DBG module still working since the Debugger is still connected to the MCU after the STOP Execution.
Best Regards,
Pelekis Marios
2024-07-24 07:06 AM
Hello @Pelekis ,
I could reproduce your issue.
After different trials I could see that writing DBGMCU->CR to 0, disabling also the STANDBY debug solves the issue
I hope this will solve your issue this time !
Best regards
Jocelyn
2024-07-24 10:51 PM
Hello @Jocelyn RICARD ,
Yes, this Solve the problem and this was the only way as I have also found, But we are not able to flash the MCUs in production with the debugger.
So we need to find a way that by just writing DBGMCU->CR to 0 from code side, it will disable the DBG Module without the need of flag editing with the debugger.
Best Regards,
Pelekis Marios
2024-07-25 12:13 AM
Hi @Pelekis ,
not sure to understand your issue now.
You mean you cannot add DBGMCU->CR=0; in your code?
Also how do you flash in production?
Best regards
Jocelyn
2024-07-29 02:45 AM
Hello @Jocelyn RICARD ,
I can add the DBGMCU->CR=0; in my code BUT seems that does not work!
the only way to make it work is only if proper flag (debug in low power modes) is disabled form the debug window.
We use STM32 ST-Link Utility for flashing in the production.
In any case if DBGMCU->CR=0; was working good, it should disconnect my debugger while STOP was executed.
But this never happens.
It will only happen if debug in low power modes is disabled form the debug window.
Best Regards,
Pelekis Marios