cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to program STM32G031

Stastny.Petr
Associate III

Hello, I am not able to program STM32G031. I have Nucleo kit F401RE and STM32G031 connected to SWD. I have connected SWDIO, SWCLK, 3V3, GND and nRST.

STM32CubeProgrammer can connect only in Hot Plug mode, but writting or errasing gives me: Error: Mass erase operation failed.Please verify flash protection

If I try to connect in Normal mode or Under reset mode, the error is: Error: ST-LINK error (DEV_TARGET_HELD_UNDER_RESET).

Can you help me how to continue? STM32G031 is completely new, never programmed before.

ST-LINK FW : V2J39M27

StastnyPetr_0-1722124632908.png

 

 

7 REPLIES 7
TDK
Guru

> DEV_TARGET_HELD_UNDER_RESET

Suggests NRST is being held low. Can you verify with a multimeter?

Likely to be an issue with the board design or assembly, or the wiring between the programmer and the board. Can you share the schematic?

If you feel a post has answered your question, please click "Accept as Solution".
Stastny.Petr
Associate III

All voltages are OK.

 

This is the schematics:

StastnyPetr_0-1722181085888.png

 

Sure , that your target is powered ?

st-link seems to get no voltage:

AScha3_0-1722181777942.png

+

 try connect with mode : normal + software reset .

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

Yes, it is, I tried different kit for programming. Setup is according your recommendation

 

StastnyPetr_0-1722183573476.png

 

But its connected here:

AScha3_0-1722185504153.png

So look at option bytes, if something set, write protect or so.

Be careful not to do anything with rdp level - read first, what this doing. (you need a new chip then...)

Then try full chip erase and then programming...

If you feel a post has answered your question, please click "Accept as Solution".
Stastny.Petr
Associate III

I think I found the problem but I do not know why...

void CLK_Config(void)
{

    RCC->CR |= RCC_CR_HSION;
    while ((RCC->CR & RCC_CR_HSIRDY) == 0);

    PWR->CR1 |= PWR_CR1_VOS_0;

    RCC->CR &= ~RCC_CR_PLLON;

    while (!(RCC->CR & RCC_CR_HSIRDY)) {

    }
    	
	/*
	
    RCC->PLLCFGR = (RCC_PLLCFGR_PLLSRC_HSI | // Zdroj PLL je HSI
                    (8 << RCC_PLLCFGR_PLLN_Pos) | // PLLN = 8
                    (0 << RCC_PLLCFGR_PLLM_Pos) | // PLLM = 1
                    (1 << RCC_PLLCFGR_PLLR_Pos)); // PLLR = 2

    RCC->CR |= RCC_CR_PLLON;
    while (!(RCC->CR & RCC_CR_PLLRDY));

    RCC->PLLCFGR = (RCC_PLLCFGR_PLLSRC_HSI |
                    RCC_PLLCFGR_PLLM_DIV1 |
                    RCC_PLLCFGR_PLLN_3 |       // PLLN = 8 (8 * 2 MHz = 16 MHz)
                    RCC_PLLCFGR_PLLR_1 |       // PLLR = 2 (16 MHz / 2 = 8 MHz)
                    RCC_PLLCFGR_PLLREN);       // Aktivujte PLLR výstup
	*/

    FLASH->ACR |= FLASH_ACR_LATENCY_2;

    /*
	RCC->CFGR = (0b10 << RCC_CFGR_SW_Pos);
    while ((RCC->CFGR & RCC_CFGR_SWS_Msk) != (0b10 << RCC_CFGR_SWS_Pos));
	*/
	
    SystemCoreClockUpdate();
}

If I comment this it works fine without PLL. But I need PLL and I do not see any problem. If I send this UNCOMENTED code to CPU there is not possible to load program any more.

Do you see some trouble? I do not use HAL.

Thank you

So use Cube/HAL with the setup you want, gen.code, and you can see, how its doing it.

Even if you dont use it , then you know and no reason to keep guessing.

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