我正在使用Launchpad的 gcc-arm-none-eabi 4.9-2015q2来编译STM32F0,现在我想使用该集合中的arm-none-eabi-gdb进行调试.我的ST-Link v2是Nucleo F411RE板的一部分,附带外部硬件(STM32F0目标).闪烁F0工作正常,所以我得出结论,我的SWD连接是好的.
现在我想启动OpenOCD,但它失败了:
$ openocd -f interface/stlink-v2.cfg -f target/stm32f0x.cfg
Open On-Chip Debugger 0.9.0 (2015-07-26-16:02)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
Info : auto-selecting first available session transport "hla_swd". To override use 'transport select <transport>'.
Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
adapter speed: 1000 kHz
adapter_nsrst_delay: 100
none separate
Info : Unable to match requested speed 1000 kHz, using …
Run Code Online (Sandbox Code Playgroud) 我已经购买了STM32F411核板,现在我正在尝试了解HAL的各种零碎.从外部中断开始似乎是一个好主意,因为电路板有一个连接到PC13的按钮.所以我设置了一个简单的切换频率闪烁.下面的代码有点简化:
#define LED_PIN GPIO_PIN_5
#define BTN_PIN GPIO_PIN_13
static uint32_t blink_period = 250;
int main(void)
{
HAL_Init();
SystemClock_Config();
__GPIOA_CLK_ENABLE();
GPIO_InitTypeDef pinConfig;
pinConfig.Pin = (LED_PIN);
pinConfig.Pull = GPIO_NOPULL;
pinConfig.Mode = GPIO_MODE_OUTPUT_PP;
pinConfig.Speed = GPIO_SPEED_FAST;
HAL_GPIO_Init(GPIOA, &pinConfig);
__GPIOC_CLK_ENABLE();
pinConfig.Pin = (BTN_PIN);
pinConfig.Pull = GPIO_NOPULL;
pinConfig.Mode = GPIO_MODE_IT_FALLING;
pinConfig.Speed = GPIO_SPEED_LOW;
HAL_GPIO_Init(GPIOC, &pinConfig);
HAL_NVIC_SetPriority(EXTI15_10_IRQn, 0x0F, 0x00);
HAL_NVIC_EnableIRQ(EXTI15_10_IRQn);
while (1)
{
HAL_GPIO_TogglePin(GPIOA, LED_PIN);
HAL_Delay(blink_period);
}
}
void EXTI15_10_IRQHandler(void)
{
HAL_GPIO_EXTI_IRQHandler(BTN_PIN);
}
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
if(GPIO_Pin == BTN_PIN)
{
if (blink_period == 500)
{
blink_period …
Run Code Online (Sandbox Code Playgroud) 我想每隔几秒钟处理一次 youtube 直播的输出。在其他人的帮助下,我想出了一个解决方案来捕获图像以供以后处理,但它往往会损坏并且速度太慢:
youtube-dl --prefer-ffmpeg -f worst "https://www.youtube.com/watch?v=Gy5PC5Auoak" -o - | dd count=32 bs=4096 | ffmpeg -i - -f image2 -frames:v 1 img22.jpeg
Run Code Online (Sandbox Code Playgroud)
(获取 128 KB 的流数据并将其中的一帧提取到 jpg 中)。最快的运行需要大约 30 秒。其他尝试涉及将 youtube-dl 导入 mplayer,但上面显示的方法似乎更有意义,因为它明确限制了接收的数据量。
我希望结果在树莓派上运行。
我正在尝试为嵌入式系统实现一组互斥锁和锁类.我之前从未使用过标签调度,而且我不确定我是否做得对.boost文档中包含的描述只是这样:
struct input_iterator_tag { };
Run Code Online (Sandbox Code Playgroud)
并使用它来选择专门的模板功能.我没有模板,我只想根据标签的存在选择一个特定的构造函数:
// in mutex.h:
struct TryLock { };
// defined nowhere, i.e. there's no cpp file for this:
extern TryLock try_lock;
template<typename MutexType>
class ScopedLock
{
public:
ScopedLock(MutexType& mtx) : m_mtx(mtx), m_acquired(true)
{
m_mtx.lock();
}
ScopedLock(MutexType& mtx, TryLock) : m_mtx(mtx)
{
m_acquired = m_mtx.tryLock();
}
...
}
Run Code Online (Sandbox Code Playgroud)
在我的代码中的某个地方,我有一个我要锁定的互斥锁:
Mutex mtx;
ScopedLock<Mutex> lock(mtx, try_lock);
Run Code Online (Sandbox Code Playgroud)
这编译好并且有效.我只是好奇我是否可以摆脱它extern TryLock try_lock;
,因为我的印象是它有点多余.
编辑:根据Jonathan的回答,我在我的问题下面添加了一些解决方案
我想在给定目录中有一个具有特定名称模式的常规文件列表.我从boost.filesystem(boost 1.53)中获取了一个示例并对其进行了修改.这是我基本上想要的工作版本:
#include <iostream>
#include <boost/filesystem.hpp>
#include <boost/foreach.hpp>
using namespace std;
using namespace boost::filesystem;
int main(int argc, char* argv[])
{
path p ("."); // search directory
try
{
if (exists(p))
{
if (is_directory(p))
{
cout << "logfiles in " << absolute(p) << '\n';
// I want to replace this part:
std::list<directory_entry> datFiles;
for(directory_iterator it(p); it != directory_iterator(); ++it)
{
if (is_regular_file(*it) && (extension(*it) == ".dat"))
{
datFiles.push_back(*it);
}
}
// part to be replaced ends …
Run Code Online (Sandbox Code Playgroud) 我有一个带有相当小点标记的QGraphicsScene.我想扩大这些标记的面积,使拖动更容易.标记是距离原点+/- 2像素的十字形.我重新实现了
QGraphicsItem::contains(const QPointF & point ) const
{
return QRectF(-10,-10,20,20);
}
Run Code Online (Sandbox Code Playgroud)
和
void hoverEnterEvent(QGraphicsSceneHoverEvent* event)
{
setPen(QPen(Qt::red));
update();
}
Run Code Online (Sandbox Code Playgroud)
但是当光标直接被光标击中时,标记只会变成红色(甚至有点挑剔).如何扩大"悬停区域"?
这是这个问题的后续内容,我鼓励在可变参数模板operator()(...)实现中使用完美转发.这是我的观察者模式,我想用它来调用具有可变参数的自由函数和成员函数:
#ifndef _SIGNALS_H_
#define _SIGNALS_H_
#include <utility>
/** Interface for delegates with a specific set of arguments **/
template<typename... args>
class AbstractDelegate
{
public:
virtual void operator()(args&&...) const = 0;
virtual ~AbstractDelegate() {}
};
/** Concrete function delegate that discards the function's return value **/
template<typename ReturnType, typename... args>
class FnDelegate : public AbstractDelegate<args...>
{
public:
/** member function typedef **/
using Fn = ReturnType(*)(args...);
/** constructor **/
FnDelegate(Fn fn)
: fn_{fn}
{
}
/** call operator that …
Run Code Online (Sandbox Code Playgroud) 可能重复:
如何在C++中重载一元减号运算符?
我有一个C类,它重载了许多运算符:
class C
{
...
C& operator-=(const C& other) {...}
const C operator-(const C& other) {...}
}
inline const C operator*(const double& lhs, const C& rhs)
Run Code Online (Sandbox Code Playgroud)
现在我想要反转一个C类型的对象
c = -c;
Run Code Online (Sandbox Code Playgroud)
并且gcc给了我以下错误:
no match for >>operator-<< in >>-d<<
candidate is: const C C::operator-(const C&)
Run Code Online (Sandbox Code Playgroud)
使用c = -1*c有效,但我希望能够缩短它.我班上缺少什么?
解决:添加了一元运算符 - :
C operator-() const {...}
Run Code Online (Sandbox Code Playgroud)
作为C的成员
我有一个不完整的子类的CRTP缺少一个在基类中"没有真正"实现的方法:
#include <iostream>
using namespace std;
template<class T>
class BaseA
{
public:
T& asChild(){return static_cast<T&>(*this);}
void AMethod(void) {asChild().AMethod();}
};
class IncompleteChild : public BaseA<IncompleteChild>
{
public:
// uncomment the following to avoid segfault:
// void AMethod(void) {cout << "IncompleteChild Method" << endl;}
};
class Child : public BaseA<Child>
{
public:
void AMethod(void) {cout << "Child AMethod" << endl;}
};
template<class T>
void printBaseA(BaseA<T>& a)
{
a.AMethod();
}
int main()
{
IncompleteChild cI;
cI.AMethod();
printBaseA(cI);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
这编译得很好,但在运行时会导致分段错误.我怎么能避免这种情况?我更喜欢这里的编译器错误(使用gcc 4.6.3).