Skip to main content
Graduate II
September 6, 2022
Solved

STM8 GPIO does not stay high (Solved)

  • September 6, 2022
  • 6 replies
  • 2423 views

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;

    This topic has been closed for replies.
    Best answer by Tesla DeLorean

    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?

    6 replies

    Visitor II
    September 6, 2022

    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!

    Visitor II
    September 6, 2022

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

    Kmax18Author
    Graduate II
    September 6, 2022

    Thank you. Please see my latest update below.

    Kmax18Author
    Graduate II
    September 6, 2022

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

    Graduate II
    September 6, 2022

    >>What is wrong with the code? 

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

    Kmax18Author
    Graduate II
    September 6, 2022

    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?

    Graduate II
    September 6, 2022

    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?

    Kmax18Author
    Graduate II
    September 6, 2022

    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

    Visitor II
    September 7, 2022

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

    Kmax18Author
    Graduate II
    September 7, 2022

    Hi Tesla, thank you for your quick response. The main.c source file is attached. please have a look. This is the code example that comes with the ST Application Note AN5178. ONly SPL function write to the output, I believe.

    I made one change in Line 43 to accommodate the Nucleo-8S208RB:

    #define LEDS_PORT (GPIOC) //for Nucleo-8S208RB

    Thank you for your feedback!

    -km

    Kmax18Author
    Graduate II
    September 9, 2022

    This issue is resolved with a workaround for ST Visual Programmer (STVP). I assume e better solution exists.

    Option 1: Program the Nucleo-8S208RB with the STVP. Close STVP: the Nucleo's COM LED turns red and the application starts running.

    Option 2: Program the Nucleo-8S208RB with the STVP. Open the Configuration window (see below): the COM LED turns ghreen. Click OK: the application start to run.

    0693W00000SudklQAB.png