cancel
Showing results for 
Search instead for 
Did you mean: 

STM8 GPIO does not stay high (Solved)

Kmax18
Senior

Hello, I am studying the STM8S208RB MCU and the SPL. I am using STVD and COSMIC, and the Nucleo-8S208RB board for testing.

The below code should configure port GPIOC Pin5 and set it to high and stay high. However, LED2 turns on for only a short moment, not permanently. The STM8 Nucleo-64 board has the User LED2 on GPIO Port C, Pin 5.

What is wrong with the code? Thank you!

/* Configure the LED2 GPIO */
 /* Reset the GPIO Pin in CR2 register */
 LED2_GPIO_PORT->CR2 &= (uint8_t)(~(LED2_GPIO_PIN));
 
 /* Output mode selection */
 LED2_GPIO_PORT->ODR |= (uint8_t)LED2_GPIO_PIN; /* High level output */
 LED2_GPIO_PORT->DDR |= (uint8_t)LED2_GPIO_PIN; /* Output mode */
 LED2_GPIO_PORT->CR1 |= (uint8_t)LED2_GPIO_PIN; /* Push-Pull output mode */
 LED2_GPIO_PORT->CR2 |= (uint8_t)LED2_GPIO_PIN; /* 10 MHz fast output */
 
 /* Turn On LED2 */
 LED2_GPIO_PORT->ODR |= (uint8_t)LED2_GPIO_PIN;

1 ACCEPTED SOLUTION

Accepted Solutions

Not seeing the code.

Attach main.c to the bottom of the post, see Paper Clip Icon below posting window.

How is this all connected? Avoid using Hubs or Docking Stations with ST-LINK / NUCLEO, use quality cables.

Does the STM8 have some kind of debugger? Can you drive that?

How about outputting info via UART at the same time and blinking LED?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

View solution in original post

11 REPLIES 11
Vmere.1
Senior

Can you clarify what is LED2_GPIO_PIN?

 LED2_GPIO_PORT->ODR |= (uint8_t)LED2_GPIO_PIN;

But something is causing the device to a hard fault (Maybe), use a debugger and set breakpoint and see what is happening!

Kmax18
Senior

Thanks for your response! The STM8 Nucleo-64 board has the User LED2 on GPIO Port C, Pin 5.

If it went to a hard fault, then the light will be on for the entire time. So my answer is wrong!

>>What is wrong with the code? 

Perhaps it's not an issue with the code you've shown?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Kmax18
Senior

Update: the example code for ST Application Note AN5178 exhibits the same issue, therefore my source code above may not be the root cause. I am wondering if the ST Visual Programmer is not setup right? The LED2 flashes twice, first during programming, and the second time during code verification. But the following while(1) loop should flash the LED, and that is not happening. Any thoughts?

Thank you. Please see my latest update below.

Not seeing the code.

Attach main.c to the bottom of the post, see Paper Clip Icon below posting window.

How is this all connected? Avoid using Hubs or Docking Stations with ST-LINK / NUCLEO, use quality cables.

Does the STM8 have some kind of debugger? Can you drive that?

How about outputting info via UART at the same time and blinking LED?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Hi Tesla, thanks for your quick response.

Connections:

* ST_Tools on Windows10 desktop -> ST-Link USB driver -> USB data cable -> ST-Link Debugger on Nucleo-8S208RB -> SWIM -> MCU.

Status update (success):

* After loading the .s19 firmware file with STVP the Nucleo's COM LED is green,

LED2 dos not blink.

* Re-open the STVP window 'Configure ST Visual Programmer' (screenshot attached).

* Click OK. The COM LED turns read and the User LED starts blinking!

Question:

* It seems that setting the STVP configuration (again) disconnects the Nucleo-64 board

and starts the program. Is that correct?

* What happens 'behind the scenes' when setting the STVP configuration.

0693W00000SudklQAB.png

S.Ma
Principal

Are you setting level before output? How many codelines from different functions write on the gpio regusters? Anyone under interrupt? Read modify write corruption?