Skip to main content
Visitor II
July 27, 2024
Question

Unable to program STM32G031

  • July 27, 2024
  • 3 replies
  • 1530 views

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

 

 

    This topic has been closed for replies.

    3 replies

    Super User
    July 28, 2024

    > 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?

    Visitor II
    July 28, 2024

    All voltages are OK.

     

    This is the schematics:

    StastnyPetr_0-1722181085888.png

     

    Super User
    July 28, 2024

    Sure , that your target is powered ?

    st-link seems to get no voltage:

    AScha3_0-1722181777942.png

    +

     try connect with mode : normal + software reset .

    Visitor II
    July 28, 2024

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

     

    StastnyPetr_0-1722183573476.png

     

    Visitor II
    July 28, 2024

    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

    Super User
    July 28, 2024

    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.