Skip to main content
Visitor II
April 26, 2025
Question

Moving code from G030 to C011

  • April 26, 2025
  • 9 replies
  • 1611 views

Hi All

I have a breakout board, I've been testing some ws2812 code , I'm using  TIM1 with DMA + PWM

I developed the code on the G030, it's a 32 pin package.

I'm using internal clock and have it running at 48MHz for Timers.

Works has intended. 

 

Switch to C011 in an 8 Pin package.

Created new project in MX and just copied over the code I added.

I'm using internal clock and have it running at 48MHz for Timers.

Code does not work.  complies fine, but the leds not work.

 

In both porjects I am using TIM1 , configured the same way.

 

I don't have a Scope where I can view the PWM output

Question:  Does anyone of a any differences between how TIM1 works between both MCU? I looked through  AN5969   Migrating between STM32G0 and STM32C0 MCUs  and nothing jumped out.

Can I use CudeMonitor to review the PWM?

 

Any suggestions would be highly appreciated.

 

Regards, Stephen 

 

 

 

    This topic has been closed for replies.

    9 replies

    ST Employee
    April 28, 2025

    Hello @stevecimo

    The STM32C0 series and STM32G0 series are pin-to-pin compatible, using the same package ofc! 

    Are you using this package for STM32C011 and for the STM32G030?

    SarraS_0-1745844925488.png

     

    stevecimoAuthor
    Visitor II
    April 28, 2025

    Hi Sarra

     

    I'm using an 8 pin package for the C011 and a 32 pin package for the G030

     

    Regards, Stephen 

    Super User
    April 28, 2025

    It should work...if compiler shows no warnings...?

    +

    to check, the tim/pwm setting: just stop it in debug and look at sfr -> tim1 , to see, whats it doing:

     

    AScha3_0-1745845339683.png

     

    stevecimoAuthor
    Visitor II
    April 28, 2025

    No warnings, compile is clean in both projects

     

    I'm on my way to work, I'll see if I can run the debug checks in a few days, have to study for an Azure test tonight. ( at 58 years old and 40 years working in IT, work still wants me to do  Azure test..I hate tests....)

     

     

    ST Employee
    April 28, 2025

    Hello,

    can you please share also your projects? 

    stevecimoAuthor
    Visitor II
    April 28, 2025

    happy to , has log has no one laugh's out loud at my coding :)

     

    Bottom line, is I have made some 7 segment led displays 19mm x 12mm  using ws2812 leds

    stevecimoAuthor
    Visitor II
    April 29, 2025

    basically  I first create an array  of  color (rgb) data for 7 leds, in the correct order

    color = ((LED_Data[i][1]<<16) | (LED_Data[i][2]<<8) | (LED_Data[i][3]));

    then from this array , i create an second array to hold the pwm data to be sent via DMA.

    for (int i=23 ; i>=0; i--)

    {

    if (color&(1<<i))

    {

    pwmData[index] = 40; // 2/3 60 using 48MHz clock with AAR of 60 800KHz

    }

    else pwmData[index] = 20; // 1/3 of 60

    index++;

    }

    }

    for (int i=0; i<50; i++)

    {

    pwmData[index] = 0; // add some zeros at the end to flag end of transmission

    index++;

    }

    HAL_TIM_PWM_Start_DMA(&htim1, TIM_CHANNEL_1, (uint32_t *)pwmData, index);

    while (!datasentflag){};

    datasentflag = 0;

    }

    This works fine with the G030, nothing or random leds light up with the C011

    Both MCU are using a 48MHz timer clock. 0 Prescaler and an arr of 60 to give 800KHz timing

    C011:

     

    htim1.Instance = TIM1;

    htim1.Init.Prescaler = 0;

    htim1.Init.CounterMode = TIM_COUNTERMODE_UP;

    htim1.Init.Period = 60-1;

    htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;

    htim1.Init.RepetitionCounter = 0;

    htim1.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;

     

    G030

     

    htim1.Instance = TIM1;

    htim1.Init.Prescaler = 0;

    htim1.Init.CounterMode = TIM_COUNTERMODE_UP;

    htim1.Init.Period = 60-1;

    htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;

    htim1.Init.RepetitionCounter = 0;

    htim1.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;

     On the G030 I us PLL to get a 48MHz clock (C011 runs 48MHz internal clock)  

     

    /** Initializes the RCC Oscillators according to the specified parameters

    * in the RCC_OscInitTypeDef structure.

    */

    RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;

    RCC_OscInitStruct.HSIState = RCC_HSI_ON;

    RCC_OscInitStruct.HSIDiv = RCC_HSI_DIV1;

    RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;

    RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;

    RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;

    RCC_OscInitStruct.PLL.PLLM = RCC_PLLM_DIV1;

    RCC_OscInitStruct.PLL.PLLN = 9;

    RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;

    RCC_OscInitStruct.PLL.PLLR = RCC_PLLR_DIV3;

     

     

    Super User
    April 29, 2025

    There shouldn't be a difference at the HAL level.

    Are the pins properly configured?

    Same LEDs or other ones? Some are said to need a longer (300++ µs) reset pulse.

    A $10 USB logic analyzer could be a great help here.

    hth

    KnarfB

    stevecimoAuthor
    Visitor II
    April 30, 2025

    IMG_0274.jpg

    This is my basic setup, I just swap the 2 break out boards, same leds , using a bench powersupply at 3.3 volts , 

    I preformed all my original testing with the G030, with the C011 , I have only run basic led toggling code. before trying to move my code from G030 to it.

     

    All done with the CubeIDE, just configured a new project for the C011

    stevecimo_0-1746005672417.png

    , Then used the IDE's compare file feature to code over my parts of the code from the G030 main.c, not using any libraries or extra .h .c files.....

     

    Hmmm, maybe I should double check I have  selected the right C011?  apart from Flash sizes, is there any difference in timer operations between submodels to the same main MCU type?

     

    stevecimoAuthor
    Visitor II
    April 30, 2025

    Just checked my order, parts order where STM32C011J6M6  

     

    I might try a different timer.

    stevecimoAuthor
    Visitor II
    April 30, 2025

    I added a simple led  toggle on a gpio pin and it never toggles

    while (1)

    {

    int z = 9;

    while (z >= 0) {

    Set_Display(z, "orange");

    WS2812_send();

    HAL_Delay(1000);

    --z;

    }

    HAL_GPIO_TogglePin(LED_GPIO_Port, LED_Pin);

    z=0;

    while (z <= 9) {

    Set_Di

    splay(z, "green");

    WS2812_send();

    HAL_Delay(1000);

    ++z;

    }

    z=9;

    /* USER CODE END WHILE */

     

    /* USER CODE BEGIN 3 */

    }

     

    I'll keep looking :)

     

    Super User
    May 1, 2025

    What you have shown looks okay.

    Can you set that pin statically to 0 and 1 and measure the output level, i.e. a classic blinky? Could it be a soldering issue?

    hth

    KnarfB

    stevecimoAuthor
    Visitor II
    May 2, 2025

    I'll give it a try, I have received some samples MCU, Including G , F, H series in different packages....

    including a Nuceo-F103RB

    Graduate
    April 30, 2025

    Dear stevecimo,

    I guess there is lack of basically thing.
    You should not think easily migration from STM32G0.
    Build a project as “STM32C0" from scratch.

    Also don't forget to read the datasheet/reference-manual/errata-sheet carefully.

    Best regards,
    Nemui.

    stevecimoAuthor
    Visitor II
    May 2, 2025

    But I did build the project from scratch, started a new project , selected the MCU, configured the timer and clock using cubeMX , then just copied my code across.....

     

    This is what ST recommend when moving between MCU?

    I just used the same process to move the code to a Nucleo F103RB and is working....

     

    I think I'm going to move to 20pin package and have some G and F in 20pins .

     

    :)

     

    Graduate
    May 2, 2025

    Dear stevecimo,

    Here is my simplest STM32C0 project("moving from" G0 project below).
    https://nemuisan.blog.bai.ne.jp/?eid=192848#STM32C0

    STM32G0 is here.
    https://nemuisan.blog.bai.ne.jp/?eid=192848#STM32G0


    Those project includes timer setting(for uSec wait timer).
    And NO-CUBEIDE/NO-CUBEMX to avoid buggy code generation.

    I do not have intend to answer anymore,but may be I told the just answer :)

    Best regards,
    Nemui.

    stevecimoAuthor
    Visitor II
    May 3, 2025

    Thanks, I'll take a look :)

    stevecimoAuthor
    Visitor II
    May 17, 2025

    I have yet to figure this out, I've received some 20 pin G030 and my code works fine on them, so I'll stick with the G030 for now . :)

    I also purchased a F103 Nucleo board and a C011 Discovery board and a Chinese Bluepill (F103 I think it's using a real STm32)  .

    My code moves to the F103 fine (both boards) , still does not work on the C011 Discovery.......

    When I get an Oscilloscope  , I'll take another look :)

     

    Thanks for help :)

     

     

    Graduate II
    May 17, 2025

    You can miss many thinks, but primary read first carefuly about mcus.

    C011

    MM1_0-1747478427917.png

    G030

    MM1_1-1747478459630.png

    no PLL vs PLL usw.