The problem of delay function being optimized when debugging stm8 microcontroller with IAR

Publisher:平凡梦想Latest update time:2020-02-16 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

When IAR optimization level is set to the highest, the compiler will directly optimize the following delay functions when they are called, and the delay effect cannot be achieved.


void delay_n_ms(u32 time)


{

    u32 m = 0;

    u16 n = 0;

    for(;m < time;m++)

    {

        for(n = 0;n < 2720;n++) // 16Mhz

        {

            ;

        }

    }

}


The problem is solved by adding the volatile keyword before the function's variable.


void delay_n_ms(u32 time)


{

    volatile u32 m = 0;

    volatile u16 n = 0;

    for(;m < time;m++)

    {

        for(n = 0;n < 2720;n++) // 16Mhz

        {

            ;

        }

    }

}

Reference address:The problem of delay function being optimized when debugging stm8 microcontroller with IAR

Previous article:stm8 buzzer BEEP
Next article:STM8S_002_TIM precise delay (blocking)

Recommended ReadingLatest update time:2024-11-16 14:47

Use IAR to create stm8 project records
Open the project 2. Create New Project… 3. Empty project 4. Save the project to the specified folder The newly completed projects are as follows: 5. Configure Options 6. Select stm8 device 7. Output Hex file 8. Linker Configuration 9. Debugger 10. Add files and groups 11. Add STM8S_StdPeriph_Driver
[Microcontroller]
Use IAR to create stm8 project records
Use IAR_STM8 tool chain to develop, compile and debug STM8 projects on vscode
This article describes how to use the IAR_STM8 tool chain on EIDE to complete project creation, compilation, and debugging using STM8-Debug This article takes STM8S105K4T6 as an example 1. Create an 8/16 Bit MCU project using EIDE Note: The STM8 project path should not contain any Chinese characters or spaces, other
[Microcontroller]
Use IAR_STM8 tool chain to develop, compile and debug STM8 projects on vscode
stm8 program occupies flash and ram plug-in
STVD compiler, when compiling, does not show how much RAM and ROM are used? For this problem, there are two ways: one is to look at the .map file and the other is to add a patch. The specific operation is as follows. You can download the corresponding file in My Resources. Link: https://pan.baidu.com/s/1BpPNJ5W08M6l
[Microcontroller]
Why simple software delay does not work when developing STM8 with IAR
Recently, I was fortunate enough to take over the project left by the previous engineer. The MCU I chose was STM8L151XX, and the development tool I used was IAR. After opening the ancestral code, I read it through and burned it into it with ST-Link to run the program. As a result, I found that the effect was not consi
[Microcontroller]
Why simple software delay does not work when developing STM8 with IAR
Taking the STM8 microcontroller as an example, how to implement the Bootloader?
This business trip was to upgrade the program to solve the bug. The user has packaged the product and cannot open the cover. The only way to update the program is to use the CAN bus and use the Bootloader. In fact, the .bin/hex file is sent to the microcontroller by the host computer through CAN communication and stor
[Microcontroller]
Taking the STM8 microcontroller as an example, how to implement the Bootloader?
The problem of occasional jump errors when reading AD values ​​from STM8
When debugging the AD function of STM8S103K3T6, it was found that when the temperature changes rapidly (hair dryer simulation), the read AD value will occasionally jump, and the position of the appearance is relatively fixed; the AD clock is set to 2Mhz, and the data is collected every 100ms, single-channel collection
[Microcontroller]
The problem of occasional jump errors when reading AD values ​​from STM8
STM8 programming
The following problems were encountered when programming STM8 recently 1.Error : Cannot communicate with the tool. Wrong tool selection or check tool power supply or check that a previous session is closed. Error : PROGRAM MEMORY programming failed. There is a problem with the link to stlink, There are two case
[Microcontroller]
STM8|STM32 watchdog usage
Both STM8 and STM32 are equipped with independent watchdogs, and their role is self-evident. The following are examples of using independent watchdogs for STM8 and STM32:       For STM32 MCU: #define SYS_IWDG_OPEN        IWDG- KR=0xCCCC; #define SYS_IWDG_FEED        IWDG- KR=0xAAAA; void SystemIWDG_Config(uint32 Ove
[Microcontroller]
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号