damiaa 发表于 2024-11-3 11:23

【STM32H7S78-DK】 四 下载失败问题及解决、计数器实现及分析

<div class='showpostmsg'> 本帖最后由 damiaa 于 2024-11-4 08:30 编辑

<div><span style="font-size:20px;"><strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 【STM32H7S78-DK】 四 下载失败问题及解决、计数器实现及分析</strong></span></div>

<div>&nbsp;</div>

<div>&nbsp;</div>

<div><a href="https://bbs.eeworld.com.cn/thread-1294069-1-1.html"><strong>【STM32H7S78-DK】 一 开箱贴</strong></a></div>

<div><a href="https://bbs.eeworld.com.cn/thread-1294071-1-1.html"><strong>【STM32H7S78-DK】 二 touchgxf环境搭建和基本测试</strong></a></div>

<div><a href="https://bbs.eeworld.com.cn/thread-1294464-1-1.html"><strong>【STM32H7S78-DK】 三 touchgxf和stm32cubeide和led按键测试</strong></a> <strong>之后</strong></div>

<div>&nbsp;</div>

<div><strong>一、 在测试和调试一个计数器的程序的时候发现下载不行,查看是连接不上ST-link V3了 如下:</strong></div>

<div><strong></strong></div>

<div><strong></strong></div>

<div><strong>但上次下的还是在显示屏上显示。</strong></div>

<div><strong></strong></div>

<div><strong>&nbsp;使用</strong><strong>STM32CubeProgrammer</strong><strong>连接也是连接不上:</strong></div>

<div><strong></strong></div>

<div>&nbsp;</div>

<div><strong>发现这些问题后想想直接在复位时连接</strong><strong>stlink</strong><strong>接口IO,看行不行,如是还是用</strong><strong>STM32CubeProgrammer</strong><strong>连接 同时按板子复位键。<span style="color:#27ae60;">连上 了还能读和擦除。</span></strong></div>

<div><strong></strong></div>

<div><strong></strong></div>

<div>&nbsp;</div>

<div><strong>用同样的方法(在</strong><strong>touchgfx</strong><strong>下载程序时按复位),</strong><span style="color:#27ae60;"><strong>touchgfx designer </strong><strong>下载</strong><strong>页可以</strong><strong>了,</strong></span></div>

<div><strong></strong></div>

<div>&nbsp;</div>

<div><strong>二、下面看看这个计数器的例子</strong></div>

<div>&nbsp;</div>

<div><strong>从箭头哪里两个点 的地方进去可以编辑源代码</strong></div>

<div></div>

<div></div>

<div><strong>我们</strong><strong>一般关注</strong><strong>下面几个文件</strong></div>

<div></div>

<div><strong>MainViewBase.hpp和MainViewBase.cpp是</strong><strong>touchgfx</strong><strong> designer产生的文件,里面包含了基本的类和实现。</strong></div>

<div><strong>MainViewBase.hpp:</strong></div>

<div>
<pre>
<code class="language-cpp">/*********************************************************************************/
/********** THIS FILE IS GENERATED BY TOUCHGFX DESIGNER, DO NOT MODIFY ***********/
/*********************************************************************************/
#ifndef MAINVIEWBASE_HPP
#define MAINVIEWBASE_HPP

#include &lt;gui/common/FrontendApplication.hpp&gt;
#include &lt;mvp/View.hpp&gt;
#include &lt;gui/main_screen/MainPresenter.hpp&gt;
#include &lt;touchgfx/widgets/Box.hpp&gt;
#include &lt;touchgfx/widgets/Image.hpp&gt;
#include &lt;touchgfx/widgets/TextAreaWithWildcard.hpp&gt;
#include &lt;touchgfx/widgets/Button.hpp&gt;

class MainViewBase : public touchgfx::View&lt;MainPresenter&gt;
{
public:
    MainViewBase();
    virtual ~MainViewBase();
    virtual void setupScreen();

    /*
   * Virtual Action Handlers
   */
    virtual void increaseValue()
    {
      // Override and implement this function in Main
    }
    virtual void decreaseValue()
    {
      // Override and implement this function in Main
    }

protected:
    FrontendApplication&amp; application() {
      return *static_cast&lt;FrontendApplication*&gt;(touchgfx::Application::getInstance());
    }

    /*
   * Member Declarations
   */
    touchgfx::Box __background;
    touchgfx::Image backgroundImage;
    touchgfx::Image counterBackgroundImage;
    touchgfx::TextAreaWithOneWildcard countTxt;
    touchgfx::Button buttonUp;
    touchgfx::Button buttonDown;

    /*
   * Wildcard Buffers
   */
    static const uint16_t COUNTTXT_SIZE = 5;
    touchgfx::Unicode::UnicodeChar countTxtBuffer;

private:

    /*
   * Callback Declarations
   */
    touchgfx::Callback&lt;MainViewBase, const touchgfx::AbstractButton&amp;&gt; buttonCallback;

    /*
   * Callback Handler Declarations
   */
    void buttonCallbackHandler(const touchgfx::AbstractButton&amp; src);

};

#endif // MAINVIEWBASE_HPP</code></pre>

<p>&nbsp;</p>

<p><strong>MainViewBase.cpp</strong></p>

<pre>
<code class="language-cpp">/*********************************************************************************/
/********** THIS FILE IS GENERATED BY TOUCHGFX DESIGNER, DO NOT MODIFY ***********/
/*********************************************************************************/
#include &lt;gui_generated/main_screen/MainViewBase.hpp&gt;
#include &lt;touchgfx/Color.hpp&gt;
#include &lt;images/BitmapDatabase.hpp&gt;
#include &lt;texts/TextKeysAndLanguages.hpp&gt;

MainViewBase::MainViewBase() :
    buttonCallback(this, &amp;MainViewBase::buttonCallbackHandler)
{
    __background.setPosition(0, 0, 800, 480);
    __background.setColor(touchgfx::Color::getColorFromRGB(0, 0, 0));
    add(__background);

    backgroundImage.setXY(150, 120);
    backgroundImage.setBitmap(touchgfx::Bitmap(BITMAP_BG_ID));
    add(backgroundImage);

    counterBackgroundImage.setXY(400, 152);
    counterBackgroundImage.setBitmap(touchgfx::Bitmap(BITMAP_COUNTER_BOX_ID));
    add(counterBackgroundImage);

    countTxt.setPosition(316, 189, 302, 104);
    countTxt.setColor(touchgfx::Color::getColorFromRGB(255, 255, 255));
    countTxt.setLinespacing(4);
    Unicode::snprintf(countTxtBuffer, COUNTTXT_SIZE, "%s", touchgfx::TypedText(T___SINGLEUSE_XERM).getText());
    countTxt.setWildcard(countTxtBuffer);
    countTxt.setTypedText(touchgfx::TypedText(T_TEXTID1));
    add(countTxt);

    buttonUp.setXY(169, 173);
    buttonUp.setBitmaps(touchgfx::Bitmap(BITMAP_UP_BTN_ID), touchgfx::Bitmap(BITMAP_UP_BTN_PRESSED_ID));
    buttonUp.setAction(buttonCallback);
    add(buttonUp);

    buttonDown.setXY(169, 265);
    buttonDown.setBitmaps(touchgfx::Bitmap(BITMAP_DOWN_BTN_ID), touchgfx::Bitmap(BITMAP_DOWN_BTN_PRESSED_ID));
    buttonDown.setAction(buttonCallback);
    add(buttonDown);
}

MainViewBase::~MainViewBase()
{

}

void MainViewBase::setupScreen()
{

}

void MainViewBase::buttonCallbackHandler(const touchgfx::AbstractButton&amp; src)
{
    if (&amp;src == &amp;buttonUp)
    {
      //IncreaseValue
      //When buttonUp clicked call virtual function
      //Call increaseValue
      increaseValue();
    }
    if (&amp;src == &amp;buttonDown)
    {
      //DecreaseValue
      //When buttonDown clicked call virtual function
      //Call decreaseValue
      decreaseValue();
    }
}
</code></pre>

<p>&nbsp;</p>
</div>

<div><strong>MainView.hpp和MainView.cpp是</strong><strong>touchgfx</strong><strong> designer产生的文件,里面包含了用户可以修改的类和实现,是继承了上面两个文件里面实现的基类。</strong></div>

<div><strong>MainView.hpp:</strong></div>

<div>
<pre>
<code class="language-cpp">#ifndef MAIN_VIEW_HPP
#define MAIN_VIEW_HPP

#include &lt;gui_generated/main_screen/MainViewBase.hpp&gt;
#include &lt;gui/main_screen/MainPresenter.hpp&gt;

class MainView : public MainViewBase
{
public:
    MainView();
    ~MainView() {};
    virtual void setupScreen();
    virtual void increaseValue();
    virtual void decreaseValue();

    void updateGFXElements();
protected:

private:
    uint32_t count;
};

#endif // MAIN_VIEW_HPP</code></pre>

<p><strong>MainView.cpp:</strong></p>

<pre>
<code class="language-cpp">#include &lt;gui/main_screen/MainView.hpp&gt;
#include "BitmapDatabase.hpp"

const uint32_t UPPER_LIMIT = 9999;
const uint32_t LOWER_LIMIT = 0;


MainView::MainView() : count(0) {}

void MainView::setupScreen()
{
    updateGFXElements();
}

void MainView::increaseValue()
{
    count = (count++ &gt; UPPER_LIMIT) ? UPPER_LIMIT : count;
    updateGFXElements();
}

void MainView::decreaseValue()
{
    count = (count-- &lt;= LOWER_LIMIT) ? LOWER_LIMIT : count;
    updateGFXElements();
}

void MainView::updateGFXElements()
{
    //Counter text area GFX uptade.
    Unicode::snprintf(countTxtBuffer, 5, "%d", count);
    //Button GFX update and touchable.
    if (count &lt; UPPER_LIMIT)
    {
      buttonUp.setBitmaps(Bitmap(BITMAP_UP_BTN_ID), Bitmap(BITMAP_UP_BTN_PRESSED_ID));
      buttonUp.setTouchable(true);
    }
    else
    {
      buttonUp.setBitmaps(Bitmap(BITMAP_UP_BTN_DISABLED_ID), Bitmap(BITMAP_UP_BTN_DISABLED_ID));
      buttonUp.setTouchable(false);
    }
    if (count &gt; LOWER_LIMIT)
    {
      buttonDown.setBitmaps(Bitmap(BITMAP_DOWN_BTN_ID), Bitmap(BITMAP_DOWN_BTN_PRESSED_ID));
      buttonDown.setTouchable(true);
    }
    else
    {
      buttonDown.setBitmaps(Bitmap(BITMAP_DOWN_BTN_DISABLED_ID), Bitmap(BITMAP_DOWN_BTN_DISABLED_ID));
      buttonDown.setTouchable(false);
    }
    // Invalidate all GFX area, which will result in it being redrawn in next tick.
    countTxt.invalidate();
    buttonUp.invalidate();
    buttonDown.invalidate();
}</code></pre>

<p>&nbsp;</p>
</div>

<div>&nbsp;</div>

<div><strong>为了把显示放的位置放到中间 并且显示数字可以9999以下,修改了几个地方</strong></div>

<div><strong>1,MainviewBase.hpp的基类中修改了这里,目的是把缓冲区变大,能存5个字节 :(这个文件一般用户代码不怎么修改一般由</strong><strong>touchgfx</strong><strong> designer修改,但我这里是借用的例子,就直接修改了)</strong></div>

<div></div>

<div><strong>2,</strong><strong>修改下面MainviewBase.cpp</strong></div>

<div></div>

<div><strong>3,修改Mainview.hpp的uint8_t count</strong><strong> uint32_t count</strong></div>

<div></div>

<div><strong>4,修改Mainview.cpp</strong><strong>的UPPER_LIMIT为9999</strong></div>

<div></div>

<div>&nbsp;</div>

<div><strong>5,代码浅释:</strong></div>

<div><strong>Mainview.hpp中定义了继承于</strong><strong>MainViewBase</strong> <strong>的</strong><strong>MainView</strong> <strong>类</strong></div>

<div><strong>主要定义了虚函数 设置屏幕、值加减、和图片更新函数和变量count</strong></div>

<div><strong>class </strong><strong>MainView</strong><strong> :</strong><strong> public </strong><strong>MainViewBase</strong></div>

<div><strong>{</strong></div>

<div><strong>public:</strong></div>

<div>&nbsp; &nbsp; <strong>MainView</strong><strong>(</strong><strong>);</strong></div>

<div><strong>&nbsp; &nbsp; ~</strong><strong>MainView</strong><strong>(</strong><strong>) {};</strong></div>

<div><strong>&nbsp; &nbsp; virtual void </strong><strong>setupScreen</strong><strong>(</strong><strong>);</strong></div>

<div><strong>&nbsp; &nbsp; virtual void </strong><strong>increaseValue</strong><strong>(</strong><strong>);</strong></div>

<div><strong>&nbsp; &nbsp; virtual void </strong><strong>decreaseValue</strong><strong>(</strong><strong>);</strong></div>

<div><strong>&nbsp; &nbsp; void </strong><strong>updateGFXElements</strong><strong>(</strong><strong>);</strong></div>

<div><strong>protected:</strong></div>

<div><strong>private:</strong></div>

<div><strong>&nbsp; &nbsp; uint32_t count;</strong></div>

<div><strong>};</strong></div>

<div>&nbsp;</div>

<div><strong>Mainview.cpp中定义了这些函数的实现</strong></div>

<div><strong>increaseValue</strong><strong>()</strong><strong>和</strong><strong>decreaseValue</strong><strong>()</strong><strong>分别实现加数和减数,并且调用</strong><strong>updateGFXElements</strong><strong>();</strong><strong>进行界面数据和按键背景更新。</strong></div>

<div>&nbsp;</div>

<div><strong>界面设置中对显示</strong><strong>countTxt</strong><strong>的页面进行了下面的设置</strong></div>

<div></div>

<div><strong>所以在</strong><strong>updateGFXElements</strong><strong>()</strong><strong>函数中使用</strong></div>

<div><strong>Unicode::</strong><strong>snprintf</strong><strong>(</strong><strong>countTxtBuffer</strong><strong>, 5, &quot;%d&quot;, count);</strong></div>

<div><strong>能对</strong><strong>countTxt</strong><strong>的内容进行更新</strong></div>

<div><strong>updateGFXElements</strong><strong>()</strong><strong>函数页对数值</strong><strong>的大小进行了限制,而且重新设置了按键的背景图片。</strong></div>

<div><strong>最后让</strong><strong>countTxt</strong><strong>和</strong><strong>buttonUp</strong><strong>和</strong><strong>buttonDown</strong><strong>失效,这样就能实现重画而更新界面。</strong></div>

<div>&nbsp;</div>

<div><strong>count实现count变量的初始化。</strong></div>

<div> &nbsp;</div>

<div>
<div style="text-align: center;"></div>

<p>&nbsp;</p>
</div>

<div>&nbsp;</div>

<div><strong>好,先分析到这里</strong><strong>。</strong></div>

<div><strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 谢谢</strong></div>

<p><!--importdoc--></p>
</div><script>                                        var loginstr = '<div class="locked">查看本帖全部内容,请<a href="javascript:;"   style="color:#e60000" class="loginf">登录</a>或者<a href="https://bbs.eeworld.com.cn/member.php?mod=register_eeworld.php&action=wechat" style="color:#e60000" target="_blank">注册</a></div>';
                                       
                                        if(parseInt(discuz_uid)==0){
                                                                                                (function($){
                                                        var postHeight = getTextHeight(400);
                                                        $(".showpostmsg").html($(".showpostmsg").html());
                                                        $(".showpostmsg").after(loginstr);
                                                        $(".showpostmsg").css({height:postHeight,overflow:"hidden"});
                                                })(jQuery);
                                        }                </script><script type="text/javascript">(function(d,c){var a=d.createElement("script"),m=d.getElementsByTagName("script"),eewurl="//counter.eeworld.com.cn/pv/count/";a.src=eewurl+c;m.parentNode.insertBefore(a,m)})(document,523)</script>
页: [1]
查看完整版本: 【STM32H7S78-DK】 四 下载失败问题及解决、计数器实现及分析