cancel
Showing results for 
Search instead for 
Did you mean: 

How to use MCO at PG10/NREST Pin with STM32G474RE? Init. code from STM32CubeMX always works at PA8 Pin as MCO function.

庄勇輝.1
Associate II

I am working with a STM32G474RE and I want to use a MCO as an output of HSE(27MHz).

I used STM32CubeMX Ver.5.6.1 for generate simplest init. code, which would work only for MCO function at PG10 Pin.

here's my setup.

0693W000000VyoIQAS.jpg0693W000000VyoXQAS.jpg

I builded the init. code by SW4STM32 without any modification.

27MHz crystal is connected betoween PF0 and PF1.

I measured wave form at PG10 and PA8 Pin by oscilloscope.

PG10 wave form was tied to 3.3V DC, and PA8 wave form was 27MHz clk signal.

I thought that I must write something to set PG10 as standard GPIO in order to avoid confliction with NRST function. Therefore, I can't find how to do it.

Thank you.

1 ACCEPTED SOLUTION

Accepted Solutions

You need to enable PG10 as GPIO pin, see description of PG10_Mode field in option bytes, and the Using PG10 as GPIO chapter in RM.

Note that you will lose the possibility to reset the chip using a signal, i.e. you won't be able to "connect under hardware reset" the debugger (useful e.g. if you change the functionality of SWD pins in software).

jW

View solution in original post

4 REPLIES 4

You need to enable PG10 as GPIO pin, see description of PG10_Mode field in option bytes, and the Using PG10 as GPIO chapter in RM.

Note that you will lose the possibility to reset the chip using a signal, i.e. you won't be able to "connect under hardware reset" the debugger (useful e.g. if you change the functionality of SWD pins in software).

jW

Thank you for your advice.

I read reference manual and HAL API and tried some of programs.

But, My work hasn't been going well.

PG10 seemed to work, but the clk signal amplitude was lower(1Vpp) than expected(3Vpp).

On the other hand, PA8 output was 3Vpp clk signal, which freq. is the same as PG10.​

I decided to use the [HAL_StatusTypeDef HAL_FLASHEx_OBProgram (FLASH_OBProgramInitTypeDef * pOBInit) ] API.

This example program is modified for my application.

->https://community.st.com/s/question/0D50X00009XkfPk/simple-example-program-to-read-and-write-option-bytes-on-stm32f042k6-using-hal-libraries

...........

/* Private user code ---------------------------------------------------------*/

/* USER CODE BEGIN 0 */

FLASH_OBProgramInitTypeDef OBInit; // programming option structure

/* USER CODE END 0 */

/**

 * @brief The application entry point.

 * @retval int

 */

int main(void)

{

 /* USER CODE BEGIN 1 */

 /* USER CODE END 1 */

 /* MCU Configuration--------------------------------------------------------*/

 /* Reset of all peripherals, Initializes the Flash interface and the Systick. */

 HAL_Init();

 /* USER CODE BEGIN Init */

 /* USER CODE END Init */

 /* Configure the system clock */

 SystemClock_Config();

 /* USER CODE BEGIN SysInit */

OBInit.OptionType = OPTIONBYTE_USER;

OBInit.USERType = OB_USER_NRST_MODE;

OBInit.USERConfig = OB_NRST_MODE_GPIO;

// unlock FLASH in general

if(HAL_FLASH_Unlock() == HAL_OK) {

  // unlock option bytes in particular

  if(HAL_FLASH_OB_Unlock() == HAL_OK) {

   // erase option bytes before programming

//    if(HAL_FLASHEx_OBErase() == HAL_OK) {

     // program selected option byte

     HAL_FLASHEx_OBProgram(&OBInit); // result not checked as there is no recourse at this point

     if(HAL_FLASH_OB_Lock() == HAL_OK) {

      HAL_FLASH_Lock(); // again, no recourse

      HAL_FLASH_OB_Launch(); // reset occurs here (sorry, debugger)

     }

//    }

  }

}

 /* USER CODE END SysInit */

 /* Initialize all configured peripherals */

 MX_GPIO_Init();

 /* USER CODE BEGIN 2 */

 /* USER CODE END 2 */

 /* Infinite loop */

 /* USER CODE BEGIN WHILE */

 while (1)

 {

  /* USER CODE END WHILE */

  /* USER CODE BEGIN 3 */

 }

 /* USER CODE END 3 */

}

Do you have any suggestions?

Thank you.

How was GPIO_OSPEEDR set for PG10?

JW

That setting was "LOW" when PG10 output was 1Vpp.

I modify it as ​GPIO_OSPEEDR  = "VERY_HIGH".

Now, PG10 output amplitude become 3.3Vpp!!

And, PA8 still output the same signal as PG10.

I want to use PA8 as OPAMP5 OUT(follower).

I tried to set PA8 = OPAMP5 OUT, and PA8 was stop outputting clk signal.

PG10 and PA8 seemed to work properly from outside of the chip.

Is this setup ​appropriate?

Thank you.