C++ std::function的用法

我想实现std::function定义的函数类型可以传递参数。
参数类型设置为void的时候,语法是没有错的:

 typedef std::function<void(void)> TestFunc;

class Test{
public:
    void setFunc(TestFunc f){ fn = f; }
private:
    TestFunc fn;
};

void test(){
    Test t;
    t.setFunc(func);
}

void func(){
    /*………………*/
}


有参数的时候会报语法错误:

 typedef std::function<void(int,int)> TestFunc;

class Test{
public:
    void setFunc(TestFunc f){ fn = f; }
private:
    TestFunc fn;
};

void test(){
    Test t;
    t.setFunc(func);
}

void func(int i,int j){
    /*………………*/
}

显示错误信息
不存在从 "void (int i, int j)" 转换到 "std::function<void (int i, int j)>" 的适当构造函数

请问这是为什么啊~

3个回答

把模板返回类型改成bool或者其他类型,不要使用void就可以了,跟参数的类型没有关系,我改成了<bool(int, char, String)>你看看

typedef std::function<bool(int, char, String)> TestFunc;

class Test{
public:
    void setFunc(TestFunc f){ fn = f; }
private:
    TestFunc fn;
};

void test(){
    Test t;
    t.setFunc(func);
}

bool func(int i, char c,String str){
    /*………………*/
}
lgj123xj
猿长大人 解决了!谢谢!
2 年多之前 回复

把func函数的定义:
void func(int i, int j){
/*………………*/
}
调整到void test(){之前,就可以编译成功了。
也就是写成这样:
typedef std::function TestFunc;
class Test{
public:
void setFunc(TestFunc f){ fn = f; }
private:
TestFunc fn;
};
void func(int i, int j){
/*………………*/
}
void test(){
Test t;
t.setFunc(func);
}

lgj123xj
猿长大人 还是不可以啊,我是不是编译错误,是IDE提示的语法错误
2 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
C++ std::function的用法

我想实现std::function定义的函数类型可以传递参数。 参数类型设置为void的时候,语法是没有错的: ``` typedef std::function<void(void)> TestFunc; class Test{ public: void setFunc(TestFunc f){ fn = f; } private: TestFunc fn; }; void test(){ Test t; t.setFunc(func); } void func(){ /*………………*/ } ``` *** 有参数的时候会报语法错误: ```c typedef std::function<void(int,int)> TestFunc; class Test{ public: void setFunc(TestFunc f){ fn = f; } private: TestFunc fn; }; void test(){ Test t; t.setFunc(func); } void func(int i,int j){ /*………………*/ } ``` **显示错误信息**: `不存在从 "void (int i, int j)" 转换到 "std::function<void (int i, int j)>" 的适当构造函数` 请问这是为什么啊~

std::thread 绑定函数出错

``` #include <thread> #include <iostream> #include <functional> using namespace std; void show(const char *str, const int id) { cout << "线程 " << id + 1 << " :" << str << endl; } int main() { thread t1(show, "hello cplusplus!", 0); thread t2(show, "你好,C++!", 1); thread t3(show, "hello!", 2); return 0; } ``` ![图片说明](https://img-ask.csdn.net/upload/201907/08/1562587805_770531.png) 应该是正确的绑定方法,为什么一直报错呢?

使用标准 c + + / c + + 11 / c 检查文件是否存在的最快方法?

<div class="post-text" itemprop="text"> <p>I would like to find the fastest way to check if a file exist in standard C++11, C++, or C. I have thousands of files and before doing something on them I need to check if all of them exist. What can I write instead of <code>/* SOMETHING */</code> in the following function? </p> <pre><code>inline bool exist(const std::string&amp; name) { /* SOMETHING */ } </code></pre> </div> <p>转载于:https://stackoverflow.com/questions/12774207/fastest-way-to-check-if-a-file-exist-using-standard-c-c11-c</p>

c++函数模板实例化问题

怎样实现数组的特化?这样写有错啊![![图片说明](https://img-ask.csdn.net/upload/201604/08/1460101474_979027.png)图片说明](https://img-ask.csdn.net/upload/201604/08/1460101446_26189.png)

dll工程添加json.lib出错

dll工程中添加了a.h以及a.cpp,实现一些导出类以及导出函数的相关功能,我要使用json协议,代码如下: a.cpp如下:#include "StdAfx.h" #include "Date.h" #include <json/json.h> #include <string> using namespace std; #ifdef _DEBUG #undef THIS_FILE static char THIS_FILE[]=__FILE__; #define new DEBUG_NEW #endif Date::Date(void) { day=0; month=0; year=0; } Date::~Date(void) { } void Date::SetDay(int num) { day=num; } void Date::SetMonth(int num) { month=num; } void Date::SetYear(int num) { year=num; } int Date::GetDay() { return day; } int Date::GetMonth() { return month; } int Date::GetYear() { return year; } CString Date::GetDate() { CString date; date.Format(_T("%d年%d月%d日"),year,month,day); return date; } int Max(int a,int b) { return a>b?a:b; } int GetPCTOOLUseCount(const char* pctoolIdentity)//pctoolIdentity客户端传递过来的参数,函数返回值为客户端使用次数 { return 1;此处省略。。。} 工程属性配置有:配置属性-》常规-》配置类型:动态库(.dll) MFC的使用:在共享DLL中使用MFC;VC ++目录:包含目录$(MSBuildProjectDirectory)\include;$(IncludePath),这里include文件夹里面存放的是json文件夹,有用的.h文件;VC++-》库目录$(MSBuildProjectDirectory)\lib\debug;$(LibraryPath)工程目录下的lib文件夹下的debug文件夹里面存放的是json.lib; C/C++C->运行库4种方式都试过,都不行。 链接器-》输入-》附加依赖项:json.lib 生成的错误: 1> 正在删除文件“Debug\TestDll.lastbuildstate”。 1>InitializeBuildStatus: 1> 正在对“Debug\TestDll.unsuccessfulbuild”执行 Touch 任务。 1>ClCompile: 1> stdafx.cpp 1>d:\program files\microsoft visual studio 10.0\vc\atlmfc\include\afxver_.h(81): fatal error C1189: #error : Please use the /MD switch for _AFXDLL builds 1> 1>生成失败。 1> 1>已用时间 00:00:00.46 ========== 全部重新生成: 成功 0 个,失败 1 个,跳过 0 个 ========== 而我在非dll工程中用同样的方法是没有任何问题的,

string转换为Cstring时,format显示没有此成员,这是为什么?

``` string content = data["content"].asString(); CString strText(content.c_str()); strText = content.c_str; strText.format("%s", content.c_str()); ``` 我想把content转换为Cstring的形式,请问有什么方法吗?

Mac 使用make编译gtest出现很多错误,如何解决?

## 系统环境 * Mac OS X Catalina 10.15.3 * 终端: zsh ## 编译过程 1. git clone googletest 2. mkdir mybuild && cd mybuild 3. cmake ../ ![成功](https://img-ask.csdn.net/upload/202002/15/1581750491_801128.png) 4. make ![失败](https://img-ask.csdn.net/upload/202002/15/1581750095_487520.png) ![失败](https://img-ask.csdn.net/upload/202002/15/1581750136_768008.png) ## 尝试 1. 按照网上搜到的方法,在.zshrc配置文件中加入 ```alias clang++="clang++ -std=c++11 -stdlib=libc++ -Weverything" ``` 之类的别名,再source .zshrc均无效。 2. 针对很多如下问题,[-Wer error: deleted function definitions are a C++11 extension [-Werror,-Wc++11-extensions] 我自己写了包含C++11的例子,如delete new,然后用clang++或者g++编译,均成功。

请问,调用cef库,用注册回调js的方法,实现c++调用js,为什么只能在继承了v8中Execute的方法里调用,保存,context 和 call_back后在别的函数里还是不能调用?

参考了https://blog.csdn.net/CAir2/article/details/91576805这篇博客 ``` 继承v8的Execute函数, ```bool ClientV8ExtensionHandler::Execute(const CefString& func_name, CefRefPtr<CefV8Value> object, const CefV8ValueList& arguments, CefRefPtr<CefV8Value>& retval, CefString& exception) { if (func_name == L"register") { if (arguments.size() == 1 && arguments[0]->IsFunction()) { CefRefPtr<CefV8Context> context = CefV8Context::GetCurrentContext(); CefRefPtr<CefV8Value> call_back = arguments[0]; //由于这里只是一个demo,所以把funcid固定为1,如果存在多个注册回调函数,请维护funcid和callback的关系 //if (m_render_app) // m_render_app->AddCallBack(1, context, call_back); //调用回调,进入上下文 context->Enter(); CefV8ValueList call_arguments; call_arguments.push_back(CefV8Value::CreateString(_T("hellow word"))); //调用回调函数,回调参数 call_back->ExecuteFunction(NULL, call_arguments); //退出上下文 context->Exit(); return true; } } else if (func_name == L"ReadID") { if (arguments.size() == 1 && arguments[0]->IsFunction()) { CPublic::ReadID_context = CefV8Context::GetCurrentContext();//保存context CPublic::browser = CPublic::ReadID_context->GetBrowser();//保存call_back CPublic::ReadID_call_back = arguments[0]; HWND hwnd = AfxGetApp()->GetMainWnd()->GetSafeHwnd(); ::PostMessage(hwnd, WM_MYMSGReadID, 0, 0);//发送消息到主窗口执行消息函数 return true; } else { return false; } } ``` 调用的消息函数 ``` LRESULT CMFCApplication1Dlg::OnMyMsgReadID(WPARAM H, LPARAM J) { //CPublic::ReadID_context->GetBrowser() = CPublic::browser; //CefRefPtr<CefBrowser> browser = CPublic::ReadID_context->GetBrowser(); if (CPublic::ReadID_context&&CPublic::ReadID_call_back) { CPublic::ReadID_context->Enter();//一定要先Enter if (CPublic::ReadID_context->GetBrowser()) //判断上下文中的Browser是否存在 { ////处理任务,并且执行回调 CefV8ValueList call_arguments; call_arguments.push_back(CefV8Value::CreateString(_T("123456"))); CPublic::ReadID_call_back->ExecuteFunctionWithContext(NULL,NULL, call_arguments); } CPublic::ReadID_context->Exit();//退出Context //m_CallBackMap.erase(callbackId); ``` ``` } return 0; } ``` 注册的回调方法 void CCefBrowserApp::OnWebKitInitialized() { std::string extensionCode = "var g_value=\"global value here\";" "var MyMath;" "if (!MyMath)" " MyMath = {};" "(function() {" " MyMath.register = function(call_back) {" " native function register(call_back);" " return register(call_back);" " MyMath.hellow = 'Hello JS!';"//定义一个MyMath的成员变量" " };" " MyMath.ReadID = function(call_back) {" " native function ReadID(call_back);" " return ReadID(call_back);" " };" "})();"; CefRefPtr<CefV8Handler> handler = new ClientV8ExtensionHandler(); // Register the extension. CefRegisterExtension("v8/test", extensionCode, handler); }

运行C应用程序时出现运行时应用程序错误,该应用程序从使用c-shared创建的DLL中导入方法

<div class="post-text" itemprop="text"> <p>Created a simple console application which imports functions exposed in the DLL and the DLL was created using c-shared option in golang. The go DLL depends on other DLL which was created using C++. The dependent DLL are placed in the correct path so console application is able to locate them while loading. "The application was unable to to start correctly(0x0000142)" error is seen while launching console application.</p> <p>I tried it on Windows10 machine and tried to create executable program in go using cgo to add dependency on other DLL. The executable works fine but when the same is turned into DLL and then issue is while importing the DLL in C application.</p> <p>Check DLL were created using following code</p> <p>check.h</p> <pre><code>#ifdef __cplusplus extern "C" { #endif __declspec(dllexport) char* testing1(char* input); __declspec(dllexport) char* testing2(char* input); #ifdef __cplusplus } #endif check.cpp #include &lt;cstdio&gt; #include &lt;cstdlib&gt; #include &lt;iostream&gt; #define DllExport __declspec(dllexport) extern "C" __declspec(dllexport) char* testing1(char* input){ return input; } extern "C" __declspec(dllexport) char* testing2(char* input){ return input; } int main(int argc, char* argv[]) { char* result = testing1("testing "); std::cout&lt;&lt;"Result : "&lt;&lt; result&lt;&lt;std::endl; }``` Go code for creating DLL which dependency on above created Check.DLL package main /* #cgo LDFLAGS: -lCheck #include &lt;check.h&gt; #include &lt;stdlib.h&gt; #include &lt;string.h&gt; */ import "C" import "fmt" //export AddTwoNums func AddTwoNums(numone int, numtwo int) int { return numone + numtwo } //export Validate func Validate(args *C.char) *C.char { str := C.GoString(args) str = str + "-" + str return C.CString(str) } func importFromClib1() { str1 := "Testing1" cstr := C.CString(str1) result := C.testing1(cstr) fmt.Println("Testing1 result : ", C.GoString(result)) } func importFromClib2() { str1 := "Testing2" cstr := C.CString(str1) result := C.testing2(cstr) fmt.Println("Testing2 result : ", C.GoString(result)) } func main() { } </code></pre> <p>Expected the importing of function AddTwoNums and Validate should not cause any issue while running the console application. But the error mentioned in the problem is seen.</p> </div>

C++程序,关于strcpy_s使用报错(新手初学,虚心请教)

strcpy_s或是strcpy都尝试过, 前者报错 error C2065: 'strcpy_s' : undeclared identifier 后者报错 error C2660: 'strcpy' : function does not take 3 parameters 全程序 ``` #include<iostream> #include<cstring> using namespace std; class Name { public: Name(char *pn); Name(const Name &Obj); ~Name(); void setName(char*); void showName(); protected: char *pName; int size; }; Name::Name(char *pn) { cout<<"Constructibng"<<pn<<endl; pName=new char[strlen(pn)+1]; if(pName!=0) strcpy_s(pName,strlen(pn)+1,pn); size=strlen(pn); } Name::Name(const Name& Obj) { cout<<"Copying"<<Obj.pName<<"into its own block\n"; pName=new char[strlen(Obj.pName)+1]; if(pName!=0) strcpy_s(pName,strlen(Obj.pName)+1,Obj.pName); size=Obj.size; } Name::~Name() { cout<<"Destructing"<<pName<<endl; pName[0]='\0'; delete []pName; pName=NULL; size=0; } void Name::setName(char *pn) { delete []pName; pName=new char[strlen(pn)+1]; if(pName!=0) strcpy_s(pName,strlen(pn)+1,pn); size=strlen(pn); } void Name::showName() { cout<<pName<<endl; } int main() { Name Obj1("NoName"); Name Obj2=Obj1; Obj1.showName(); Obj2.showName(); Obj1.setName("sudongpo"); Obj2.setName("dufu"); Obj1.showName(); Obj2.showName(); } ``` 使用软件为 Visual C++ 6.0

如何调用dll中类的方法

才学C++,正在研究dll动态调用,调用函数算是明白了,不知道怎么调用dll中类的方法,网上也没找到具体的实现。自己瞎想了一个办法,就是在包含类定义的dll中加一个返回该类实例指针的函数,再通过调用这个函数得到该类的实例指针。可是在调用类的方法时出错,信息如下: 2>ExeProj.obj : error LNK2019: unresolved external symbol "public: void __thiscall ClassA::M(void)" (?M@ClassA@@QAEXXZ) referenced in function _main 2>c:\users\administrator\documents\visual studio 2015\Projects\TestSln\Debug\ExeProj.exe : fatal error LNK1120: 1 unresolved externals dll中类的h文件如下: ``` #pragma once class ClassA { public: void M(); }; ``` dll中cpp文件如下: ``` #include <iostream> #include "ClassA.h" using namespace std; void ClassA::M() { cout << "I am invoked."; } extern "C" _declspec(dllexport) ClassA* CreatClassA() { return new ClassA; } ``` 调用程序cpp文件如下: ``` #include <Windows.h> #include <iostream> #include "../TestSln/ClassA.h" using namespace std; int main() { auto hmod = LoadLibrary("DllProj.dll"); if (hmod == NULL) { cout << "Load dll failed."; FreeLibrary(hmod); return 0; } auto hf = GetProcAddress(hmod, "CreatClassA"); if (hf == NULL) { cout << "Get funtion failed."; FreeLibrary(hmod); return 0; } typedef ClassA* (*pf)(); auto pClass = reinterpret_cast<pf>(hf)(); pClass->M(); FreeLibrary(hmod); delete pClass; return 0; } ``` 请专家指点: 1、调用dll中类的方法 的正确方法如何实现?烦请演示一下代码。 2、我的办法为什么出错?如何修正? 谢谢!

native client demo 无法加载本地native模块

你好,我刚学习native client,使用sdk里面的例子跑发现无法加载本地native 模块对象。自己按照你说的方法也写了一个demo,但是运行也是发现加载native module对象失败,该值为空。无法加载本地native模块对象。这是怎么回事呀?具体代码如下: 前端: <!DOCTYPE html> <html> <head> <title>hello_tutorial</title> <script type="text/javascript"> hello_tutorialModule = null; // 模块的全局对象 statusText = 'NO-STATUS'; // 更新状态 function moduleDidLoad() { hello_tutorialModule = document.getElementById('hello_tutorial'); updateStatus('SUCCESS'); // 向模块发送消息 hello_tutorialModule.postMessage('hello'); } // 消息句柄函数。句柄在NaCl模块发送相应消息时自动唤起。 // 在C中是PPB_Messaging.PostMessage(),C++中则是pp::Instance.PostMessage() // 在这个demo当中,我们收到消息之后弹窗示意 function handleMessage(message_event) { alert(message_event.data); } // 页面载入时很可能NaCl模块还没有载入,因此我们将状态写为正在读取; // 而如果模块已经载入,则什么都不做。 function pageDidLoad() { if (hello_tutorialModule == null) { updateStatus('LOADING...'); } else { // 事实上,NaCl模块的载入成功事件是不可能在页面载入成功事件之前就发生的, // 因此我们这里简单的认为页面载入之后所更新显示的消息仍旧是当前消息,而不是'SUCCESS'。 updateStatus(); } } // 设置状态。如果存在id为'statusField'的元素,那么将其设置为参数携带的状态 function updateStatus(opt_message) { if (opt_message) statusText = opt_message; var statusField = document.getElementById('status_field'); if (statusField) { statusField.innerHTML = statusText; } } </script> </head> <body onload="pageDidLoad()"> <h1>Native Client Module hello_tutorial</h1> <p> <!-- 读取.nexe文件。通过.nmf,浏览器将结合目前所处的CPU架构来读取不同的模块文件。 于此同时,<embed>元素之外的<div>还绑定着两个事件监听('load'以及'message'), 之所以绑定在div上,而不是embed之上,是为了确保模块在载入之前就可以将监听的绑定彻底完成, 同时也确保了开发者可以在模块内部的初始化阶段调用API发送消息。 --> <div id="listener"> <script type="text/javascript"> var listener = document.getElementById('listener'); listener.addEventListener('load', moduleDidLoad, true); listener.addEventListener('message', handleMessage, true); </script> <embed name="nacl_module" id="hello_tutorial" width=0 height=0 src="hello_tutorial.nmf" type="application/x-nacl" /> </div> </p> <h2>Status</h2> <div id="status_field">NO-STATUS</div> </body> </html> native端: /// @file hello_tutorial.cc /// 载入NaCl模块时,浏览器首先将搜索CreateModule()方法,CreateModule()会返回一个对象实例, /// 之后浏览器会调用该实例的CreateInstance()方法,这时浏览器每遇到一次相应的<embed>就会调用一次。 /// /// 浏览器通过Javascript的postMessage()函数与NaCl通信。 /// 当调用postMessage()时,浏览器会转而调用pp::Instance的HandleMessage()方法。 /// 而如果模块需要与外界主动通信,则是使用pp::Instance的postMessage()方法。 /// 注意,这两个postMessage()都是异步的,因此两者在调用之后迅速返回。 #include <cstdio> #include <string> #include "ppapi/cpp/instance.h" #include "ppapi/cpp/module.h" #include "ppapi/cpp/var.h" namespace { // 这个字符串用来判断消息是否是我们期望的内容 const char* const kHelloString = "hello"; // 这个字符串用来向浏览器返回内容 const char* const kReplyString = "hello from NaCl"; } // namespace /// 每一个NaCl模块都将有一个相应的pp::Instance子类实例对应, /// 为了与浏览器进行通信,你必须重载 HandleMessage()方法以及PostMessage()方法 class hello_tutorialInstance : public pp::Instance { public: explicit hello_tutorialInstance(PP_Instance instance) : pp::Instance(instance) {} virtual ~hello_tutorialInstance() {} /// HandleMessage() 负责接收浏览器中postMessage()发送的消息内容 /// 其中的参数几乎可以表示任何东西,但通常都是JSON字符串,比如这样: /// var json_message = JSON.stringify({ "myMethod" : "3.14159" }); /// nacl_module.postMessage(json_message); virtual void HandleMessage(const pp::Var& var_message) { // 这里是处理消息的代码了 if (!var_message.is_string()) return; std::string message = var_message.AsString(); pp::Var var_reply; if (message == kHelloString) { var_reply = pp::Var(kReplyString); PostMessage(var_reply); } } }; class hello_tutorialModule : public pp::Module { public: hello_tutorialModule() : pp::Module() {} virtual ~hello_tutorialModule() {} virtual pp::Instance* CreateInstance(PP_Instance instance) { return new hello_tutorialInstance(instance); } }; namespace pp { Module* CreateModule() { return new hello_tutorialModule(); } } // namespace pp

linux使用clion进行c++和python的交叉编译,无法导入python的第三方库

在ubuntu14.04下使用clion进行c++调用python编写的模块,当python中import第三方库(如numpy时),出现错误。具体如下: 这是我的代码: cmakelist: ``` cmake_minimum_required(VERSION 3.5) project(image_pretreat) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -util -ldl -pthread") # 添加Python.h头文件路径 include_directories(/home/neil/.pyenv/versions/3.6.4/include/python3.6m) # 添加python动态链接库文件目录 link_directories(/home/neil/.pyenv/versions/3.6.4/lib/python3.6/config-3.6m-x86_64-linux-gnu) set(SOURCE_FILES main.cpp) add_executable(image_pretreat ${SOURCE_FILES}) # 依赖库文件 target_link_libraries(image_pretreat libpython3.6m.a) target_link_libraries(image_pretreat ${CMAKE_DL_LIBS}) target_link_libraries(image_pretreat util) ``` main函数 ``` #include <Python.h> #include <iostream> using namespace std; int main() { Py_Initialize(); //声明python对象(模型、函数、参数、返回值) PyObject *pModule, *pFunction, *pArgs, *pRetValue; PyRun_SimpleString("import sys"); PyRun_SimpleString("sys.path.append('/home/neil/ClionProjects/image_pretreat')"); //调用python模块 pModule = PyImport_ImportModule("test123"); if (!pModule) { printf("import python failed!!\n"); return -1; } //调用python模块中的函数 pFunction = PyObject_GetAttrString(pModule, "add"); if (!pFunction) { printf("get python function failed!!!\n"); return -1; } //新建python元组对象 pArgs = PyTuple_New(2); PyTuple_SetItem(pArgs, 0, Py_BuildValue("i", 1)); PyTuple_SetItem(pArgs, 1, Py_BuildValue("i", 2)); int r1,r2; r1=r2=0; pRetValue=PyObject_CallObject(pFunction, pArgs); PyArg_ParseTuple(pRetValue, "i|i", &r1, &r2); printf("%d,%d",r1,r2); //关闭 Python 脚本解释器 Py_Finalize(); return 0; } ``` Python模块 ``` import numpy as np def add(a,b): return a+b,a-b ``` 报错: import python failed!! Process finished with exit code 255 已采取方法: 1、将python3.6各个路径都包含进了PYTHONPATH和PYTHONHOME环境变量 2、主函数中手动设置py_SetPythonhome函数

有大佬有灰度梯度法亚像素位移计算的matlab程序吗?

或者我手头有一些function,帮我写个主程序也行,可提升c币报酬 ``` function xyinput=cpcorr_graient(varargin) [xyinput_in,xybase_in,input,base]=ParseInputs(varargin{:}); %相关系数,据实验为10时较合理 CORRSIZE=10; %直角坐标输入 rects_input=calc_rects(xyinput_in,CORRSIZE,input); rects_base=calc_rects(xybase_in,CORRSIZE,base); ncp=size(xyinput_in,1); xyinput=xyinput_in;%初始化调整后 for icp=1:ncp if isequal(rects_input(icp,3:4),[0 0])||isequal(rects_base(icp,3:4),[0 0]) %靠近边缘无法调整 continue end sub_input=imcrop(input,rects_input(icp,:)); sub_base=imcrop(base,rects_base(icp,:)); % sub_input = imresize( sub_input ,scale,' bicubic '); % sub_base = imresize ( sub_base ,scale,' bicubicf'); inputsize=size(sub_input); % 确定有限 if any(~isfinite(sub_input(:)))||any(~isfinite( sub_base(:))) % NaN or Inf , unable to adjust continue end % 确定sub_input标准差非零 if std( sub_input(:))==0 % 标准差为0无法调整 continue end norm_cross_corr=normxcorr2(sub_input,sub_base); % 将其设置为false,使得峰值寻找程序只返回像素精确的峰值数据 %因此可以使用梯度方法来获取亚像素数据 subpixel=false; [xpeak,ypeak,amplitude]=findpeak(norm_cross_corr,subpixel); % eliminate any poor correlations THRESHOLD=0.5; if(amplitude<THRESHOLD) continue end % 通过互相关修正得到的偏移量,以反映图像的缩放 corr_offset=[(( xpeak-inputsize(2))-CORRSIZE)... (( ypeak-inputsize(l))-CORRSIZE)]; % 限制像素位移到10所以梯度法的空间,即子图像总是完全重叠基图像 if abs(corr_offset (1))>= CORRSIZE corr_offset(1)=0; end if abs(corr_offset(2))>C0RRSIZE corr_offset(2)=0; end filtx =[1/12-8/12 0 8/12 -1/12]; %y方向的转置 filty =filtxf; %用掩模卷积子图像得到偏导数近似 for i=l: size( sub_input,2) Gx(i,:)= conv(filtx,sub_input (i,:)); end % 同一段求导四次 Gx=Gx(3:size(Gx,1)-2,5:size(Gx,2)-4); % 同样方法计算 for i=l: size( sub_input,1) Gy(:,i)= conv(filty,sub_input(:,i)); end Gy=Gy(5:size(Gy,l)-4,3: size (Gy ,2),2); % 计算截断泰勒展开式最小二乘解的和 Gx2=sum(sum(Gx.*Gx)); Gy2=sum(sum(Gy.*Gy)); Gxy=sum(sum(Gx.*Gy)); xshift = CORRSIZE+corr_offset(l,1); yshift = CORRSIZE+corr_offset(l,2); % 子图像下的基图像部分,包括像素位移 sub_base_shift=sub_base(yshift+3:yshift+inputsize(1,1)-2,xshift +3: xshift ... + inputsize (1,2)-2); sub_input_shift=sub_input(3:size(sub_input,1)-2,3:size(sub_input,2),2); Gxt=sum(sum (( sub_base_shift- sub_input_shift ).*Gx)); Gyt=sum(sum (( sub_base_shift- sub_input_shift ).*Gy)); mat=[Gx2 Gxy;Gxy Gy2]; % 亚像素位移 disp=pinv(mat)*[Gxt;Gyt]; corr_offset=corr_offset +disp'; clear Gx Gy Gx Gxt Gxy Gyt xshift yshift % 消除控制点的突变 ind=find(abs(corr_offset)>(CORRSIZE-1), 1); if~isempty(ind) continue end input_fractional_offset=xyinput(icp,:)-round(xyinput(icp,:)); base_fractional_offset=xybase_in(icp,:)- round (xybase_in(icp,:)); %调整控制点 xyinput(icp,:)=xyinput(icp,:)-input_fractional_offset-corr_offset+base_fractional_offset; end % function rect=calc_rects(xy,halfwidth,img) % 计算矩形,这样imcrop将返回中心像素内xy坐标的图像 default_width=2* halfwidth ; default_height=default_width ; % xy指定矩形的中心,需要左上角坐标 upperleft=round(xy)-halfwidth; %需要修改图像边缘附近的像素 upper=upperleft(:,2); left=upperleft(:,1); lower=upper+default_height; right=left + default_width; width=default_width*ones(size(upper)); height = default_height*ones( size ( upper )); %检查图像外的坐标边缘 [upper,height]=adjust_lo_edge(upper,height); [dum,height]=adjust_hi_edge(lower,size(img ,1),height ); [left,width]= adjust_lo_edge(left,1,width); [dum ,width ]=adjust_hi_edge (right,size(img,2),width); %当小于默认大小时,将宽度和高度设置为零 iw=find(width<default_width); ih=find(height<default_height); idx=unique([iw;ih]); width(idx)=0; height(idx)=0; rect=[left upper width height ]; %-------------------------------- function [coordinates,breadth]=adjust_lo_edge(coordinates,edge,breadth) indx = find(coordinates<edge); if~isempty ( indx ) breadth(indx)=breadth(indx)-abs(coordinates(indx)-edge); coordinates(indx)=edge; end %-------------------------- function[coordinates,breadth]=adjust_hi_edge ( coordinates,edge,breadth ) indx = find ( coordinates > edge ); if~isempty ( indx ) breadth ( indx ) = breadth ( indx ) - abs ( coordinates ( indx )-edge); coordinates ( indx ) = edge ; end %------------------------------- function [ xyinput_in,xybase_in,input, base]= ParseInputs(varargin) iptchecknargin(4,4,nargin,mfilename); xyinput_in=varargin{1}; xybase_in= varargin{2}; if size ( xyinput_in,2)~=2||size(xybase_in,2)~=2 msg = sprintf('In fimction %s control point matrices must be M-by -2.',mfilename); eid = sprintf ('Images:%s: cpMatrixMustBeMby2', mfilename ); error(eid,msg); end if size ( xyinput_in,1)~=size(xybase_in,1) msg = sprintf('%s,INPUT and BASE images need same number of control points.',mfilename); eid = sprintf('Images:%s: needSameNumOfControlPoints',mfilename); error(eid,msg); end input = varargin{3}; base = varargin {4}; if ndims( input )~=2 ||ndims(base)~=2 msg = sprintf ... ('In function %s,Images must be intensity images',mfilename ); eid=sprintf('Images :%s: intensityImagesReq',mfilename); error(eid,msg); end input=double(input); base=double(base); if any(xyinput_in (:) <0.5)||any(xyinput_in (:,1) >size (input,2)+0.5)||any(xyinput_in(:,2) >size (input ,1) +0.5)||any( xybase_in (:) <0.5)||any( xybase_in (:,1) >... size(base,2)+0,5)||any( xybase_in (:,2) >size (base,1) +0.5) msg = sprintf('In function %s,Control Points must be in pixel coordinates',mfilename ); eid = sprintf('Images:%s: cpPointsMustBelnPixCoord',mfilename); error(eid,msg); end ```

小白使用keil编程debug进入了harddefault,搞了半天没解决。求大佬帮下忙。

/* USER CODE BEGIN Header */ /** ****************************************************************************** * @file : main.c * @brief : Main program body ****************************************************************************** * @attention * * <h2><center>&copy; Copyright (c) 2019 STMicroelectronics. * All rights reserved.</center></h2> * * This software component is licensed by ST under BSD 3-Clause license, * the "License"; You may not use this file except in compliance with the * License. You may obtain a copy of the License at: * opensource.org/licenses/BSD-3-Clause * ****************************************************************************** */ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ #include "main.h" #include "can.h" #include "usart.h" #include "gpio.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ void CAN_SetTxMsg(void) { hcan.pTxMsg->ExtId=0x1314; //使用的扩展ID hcan.pTxMsg->IDE=CAN_ID_EXT; //扩展模式 hcan.pTxMsg->RTR=CAN_RTR_DATA; //发送的是数据 hcan.pTxMsg->DLC=8; //数据长度为2字节 hcan.pTxMsg->data[0]=0x01; hcan.pTxMsg->data[1]=0x02; hcan.pTxMsg->data[2]=0x03; hcan.pTxMsg->data[3]=0x04; hcan.pTxMsg->data[4]=0x05; hcan.pTxMsg->data[5]=0x06; hcan.pTxMsg->data[6]=0x07; hcan.pTxMsg->data[7]=0x08; } /* USER CODE END Includes */ /* Private typedef -----------------------------------------------------------*/ /* USER CODE BEGIN PTD */ /* USER CODE END PTD */ /* Private define ------------------------------------------------------------*/ /* USER CODE BEGIN PD */ /* USER CODE END PD */ /* Private macro -------------------------------------------------------------*/ /* USER CODE BEGIN PM */ /* USER CODE END PM */ /* Private variables ---------------------------------------------------------*/ /* USER CODE BEGIN PV */ /* USER CODE END PV */ /* Private function prototypes -----------------------------------------------*/ void SystemClock_Config(void); /* USER CODE BEGIN PFP */ /* USER CODE END PFP */ /* Private user code ---------------------------------------------------------*/ /* USER CODE BEGIN 0 */ /* USER CODE END 0 */ /** * @brief The application entry point. * @retval int */ int main(void) { /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ /* MCU Configuration--------------------------------------------------------*/ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); /* USER CODE BEGIN Init */ /* USER CODE END Init */ /* Configure the system clock */ SystemClock_Config(); /* USER CODE BEGIN SysInit */ /* USER CODE END SysInit */ /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_CAN_Init(); MX_USART1_UART_Init(); /* USER CODE BEGIN 2 */ CAN_SetTxMsg(); HAL_CAN_AddTxMessage(&hcan,hcan.pTxMsg,hcan.pTxMsg->data,(uint32_t*)CAN_TX_MAILBOX0); HAL_CAN_ActivateNotification(&hcan,CAN_IT_RX_FIFO0_MSG_PENDING); /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ while (1) { /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ } /* USER CODE END 3 */ } /** * @brief System Clock Configuration * @retval None */ void SystemClock_Config(void) { RCC_OscInitTypeDef RCC_OscInitStruct = {0}; RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; /** Initializes the CPU, AHB and APB busses clocks */ RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; RCC_OscInitStruct.HSEState = RCC_HSE_ON; RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1; RCC_OscInitStruct.HSIState = RCC_HSI_ON; RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9; if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) { Error_Handler(); } /** Initializes the CPU, AHB and APB busses clocks */ RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2; RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2; RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK) { Error_Handler(); } /** Enables the Clock Security System */ HAL_RCC_EnableCSS(); } /* USER CODE BEGIN 4 */ void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef *hcan) { HAL_CAN_AddTxMessage(hcan,hcan->pTxMsg,hcan->pTxMsg->data,(uint32_t*)CAN_TX_MAILBOX0); HAL_CAN_ActivateNotification(hcan,CAN_IT_RX_FIFO0_MSG_PENDING); } /* USER CODE END 4 */ /** * @brief This function is executed in case of error occurrence. * @retval None */ void Error_Handler(void) { /* USER CODE BEGIN Error_Handler_Debug */ /* User can add his own implementation to report the HAL error return state */ /* USER CODE END Error_Handler_Debug */ } #ifdef USE_FULL_ASSERT /** * @brief Reports the name of the source file and the source line number * where the assert_param error has occurred. * @param file: pointer to the source file name * @param line: assert_param error line source number * @retval None */ void assert_failed(uint8_t *file, uint32_t line) { /* USER CODE BEGIN 6 */ /* User can add his own implementation to report the file name and line number, tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ /* USER CODE END 6 */ } #endif /* USE_FULL_ASSERT */ /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 这是我的主程序,debug总是在CAN_SetMsg()那里进入了hardfault.下面是定义的一些初始化结构体。 /** ****************************************************************************** * @file stm32f1xx_hal_can.h * @author MCD Application Team * @brief Header file of CAN HAL module. ****************************************************************************** * @attention * * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2> * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * 3. Neither the name of STMicroelectronics nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ****************************************************************************** */ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef STM32F1xx_HAL_CAN_H #define STM32F1xx_HAL_CAN_H #ifdef __cplusplus extern "C" { #endif /* Includes ------------------------------------------------------------------*/ #include "stm32f1xx_hal_def.h" /** @addtogroup STM32F1xx_HAL_Driver * @{ */ #if defined (CAN1) /** @addtogroup CAN * @{ */ /* Exported types ------------------------------------------------------------*/ /** @defgroup CAN_Exported_Types CAN Exported Types * @{ */ /** * @brief HAL State structures definition */ typedef enum { HAL_CAN_STATE_RESET = 0x00U, /*!< CAN not yet initialized or disabled */ HAL_CAN_STATE_READY = 0x01U, /*!< CAN initialized and ready for use */ HAL_CAN_STATE_LISTENING = 0x02U, /*!< CAN receive process is ongoing */ HAL_CAN_STATE_SLEEP_PENDING = 0x03U, /*!< CAN sleep request is pending */ HAL_CAN_STATE_SLEEP_ACTIVE = 0x04U, /*!< CAN sleep mode is active */ HAL_CAN_STATE_ERROR = 0x05U /*!< CAN error state */ } HAL_CAN_StateTypeDef; /** * @brief CAN init structure definition */ typedef struct { uint32_t Prescaler; /*!< Specifies the length of a time quantum. This parameter must be a number between Min_Data = 1 and Max_Data = 1024. */ uint32_t Mode; /*!< Specifies the CAN operating mode. This parameter can be a value of @ref CAN_operating_mode */ uint32_t SyncJumpWidth; /*!< Specifies the maximum number of time quanta the CAN hardware is allowed to lengthen or shorten a bit to perform resynchronization. This parameter can be a value of @ref CAN_synchronisation_jump_width */ uint32_t TimeSeg1; /*!< Specifies the number of time quanta in Bit Segment 1. This parameter can be a value of @ref CAN_time_quantum_in_bit_segment_1 */ uint32_t TimeSeg2; /*!< Specifies the number of time quanta in Bit Segment 2. This parameter can be a value of @ref CAN_time_quantum_in_bit_segment_2 */ FunctionalState TimeTriggeredMode; /*!< Enable or disable the time triggered communication mode. This parameter can be set to ENABLE or DISABLE. */ FunctionalState AutoBusOff; /*!< Enable or disable the automatic bus-off management. This parameter can be set to ENABLE or DISABLE. */ FunctionalState AutoWakeUp; /*!< Enable or disable the automatic wake-up mode. This parameter can be set to ENABLE or DISABLE. */ FunctionalState AutoRetransmission; /*!< Enable or disable the non-automatic retransmission mode. This parameter can be set to ENABLE or DISABLE. */ FunctionalState ReceiveFifoLocked; /*!< Enable or disable the Receive FIFO Locked mode. This parameter can be set to ENABLE or DISABLE. */ FunctionalState TransmitFifoPriority;/*!< Enable or disable the transmit FIFO priority. This parameter can be set to ENABLE or DISABLE. */ } CAN_InitTypeDef; /** * @brief CAN filter configuration structure definition */ typedef struct { uint32_t FilterIdHigh; /*!< Specifies the filter identification number (MSBs for a 32-bit configuration, first one for a 16-bit configuration). This parameter must be a number between Min_Data = 0x0000 and Max_Data = 0xFFFF. */ uint32_t FilterIdLow; /*!< Specifies the filter identification number (LSBs for a 32-bit configuration, second one for a 16-bit configuration). This parameter must be a number between Min_Data = 0x0000 and Max_Data = 0xFFFF. */ uint32_t FilterMaskIdHigh; /*!< Specifies the filter mask number or identification number, according to the mode (MSBs for a 32-bit configuration, first one for a 16-bit configuration). This parameter must be a number between Min_Data = 0x0000 and Max_Data = 0xFFFF. */ uint32_t FilterMaskIdLow; /*!< Specifies the filter mask number or identification number, according to the mode (LSBs for a 32-bit configuration, second one for a 16-bit configuration). This parameter must be a number between Min_Data = 0x0000 and Max_Data = 0xFFFF. */ uint32_t FilterFIFOAssignment; /*!< Specifies the FIFO (0 or 1U) which will be assigned to the filter. This parameter can be a value of @ref CAN_filter_FIFO */ uint32_t FilterBank; /*!< Specifies the filter bank which will be initialized. For single CAN instance(14 dedicated filter banks), this parameter must be a number between Min_Data = 0 and Max_Data = 13. For dual CAN instances(28 filter banks shared), this parameter must be a number between Min_Data = 0 and Max_Data = 27. */ uint32_t FilterMode; /*!< Specifies the filter mode to be initialized. This parameter can be a value of @ref CAN_filter_mode */ uint32_t FilterScale; /*!< Specifies the filter scale. This parameter can be a value of @ref CAN_filter_scale */ uint32_t FilterActivation; /*!< Enable or disable the filter. This parameter can be a value of @ref CAN_filter_activation */ uint32_t SlaveStartFilterBank; /*!< Select the start filter bank for the slave CAN instance. For single CAN instances, this parameter is meaningless. For dual CAN instances, all filter banks with lower index are assigned to master CAN instance, whereas all filter banks with greater index are assigned to slave CAN instance. This parameter must be a number between Min_Data = 0 and Max_Data = 27. */ } CAN_FilterTypeDef; /** * @brief CAN Tx message header structure definition */ typedef struct { uint32_t StdId; /*!< Specifies the standard identifier. This parameter must be a number between Min_Data = 0 and Max_Data = 0x7FF. */ uint32_t ExtId; /*!< Specifies the extended identifier. This parameter must be a number between Min_Data = 0 and Max_Data = 0x1FFFFFFF. */ uint32_t IDE; /*!< Specifies the type of identifier for the message that will be transmitted. This parameter can be a value of @ref CAN_identifier_type */ uint32_t RTR; /*!< Specifies the type of frame for the message that will be transmitted. This parameter can be a value of @ref CAN_remote_transmission_request */ uint32_t DLC; /*!< Specifies the length of the frame that will be transmitted. This parameter must be a number between Min_Data = 0 and Max_Data = 8. */ uint8_t data[8]; FunctionalState TransmitGlobalTime; /*!< Specifies whether the timestamp counter value captured on start of frame transmission, is sent in DATA6 and DATA7 replacing pData[6] and pData[7]. @note: Time Triggered Communication Mode must be enabled. @note: DLC must be programmed as 8 bytes, in order these 2 bytes are sent. This parameter can be set to ENABLE or DISABLE. */ } CAN_TxHeaderTypeDef; /** * @brief CAN Rx message header structure definition */ typedef struct { uint32_t StdId; /*!< Specifies the standard identifier. This parameter must be a number between Min_Data = 0 and Max_Data = 0x7FF. */ uint32_t ExtId; /*!< Specifies the extended identifier. This parameter must be a number between Min_Data = 0 and Max_Data = 0x1FFFFFFF. */ uint32_t IDE; /*!< Specifies the type of identifier for the message that will be transmitted. This parameter can be a value of @ref CAN_identifier_type */ uint32_t RTR; /*!< Specifies the type of frame for the message that will be transmitted. This parameter can be a value of @ref CAN_remote_transmission_request */ uint32_t DLC; /*!< Specifies the length of the frame that will be transmitted. This parameter must be a number between Min_Data = 0 and Max_Data = 8. */ uint8_t Data[8]; uint32_t Timestamp; /*!< Specifies the timestamp counter value captured on start of frame reception. @note: Time Triggered Communication Mode must be enabled. This parameter must be a number between Min_Data = 0 and Max_Data = 0xFFFF. */ uint32_t FilterMatchIndex; /*!< Specifies the index of matching acceptance filter element. This parameter must be a number between Min_Data = 0 and Max_Data = 0xFF. */ } CAN_RxHeaderTypeDef; /** * @brief CAN handle Structure definition */ typedef struct __CAN_HandleTypeDef { CAN_TypeDef *Instance; /*!< Register base address */ CAN_InitTypeDef Init; /*!< CAN required parameters */ CAN_TxHeaderTypeDef* pTxMsg; CAN_RxHeaderTypeDef* pRxMsg; HAL_LockTypeDef Lock; __IO HAL_CAN_StateTypeDef State; /*!< CAN communication state */ __IO uint32_t ErrorCode; /*!< CAN Error code. This parameter can be a value of @ref CAN_Error_Code */ } CAN_HandleTypeDef; /** * @} */ /* Exported constants --------------------------------------------------------*/ /** @defgroup CAN_Exported_Constants CAN Exported Constants * @{ */ /** @defgroup CAN_Error_Code CAN Error Code * @{ */ #define HAL_CAN_ERROR_NONE (0x00000000U) /*!< No error */ #define HAL_CAN_ERROR_EWG (0x00000001U) /*!< Protocol Error Warning */ #define HAL_CAN_ERROR_EPV (0x00000002U) /*!< Error Passive */ #define HAL_CAN_ERROR_BOF (0x00000004U) /*!< Bus-off error */ #define HAL_CAN_ERROR_STF (0x00000008U) /*!< Stuff error */ #define HAL_CAN_ERROR_FOR (0x00000010U) /*!< Form error */ #define HAL_CAN_ERROR_ACK (0x00000020U) /*!< Acknowledgment error */ #define HAL_CAN_ERROR_BR (0x00000040U) /*!< Bit recessive error */ #define HAL_CAN_ERROR_BD (0x00000080U) /*!< Bit dominant error */ #define HAL_CAN_ERROR_CRC (0x00000100U) /*!< CRC error */ #define HAL_CAN_ERROR_RX_FOV0 (0x00000200U) /*!< Rx FIFO0 overrun error */ #define HAL_CAN_ERROR_RX_FOV1 (0x00000400U) /*!< Rx FIFO1 overrun error */ #define HAL_CAN_ERROR_TX_ALST0 (0x00000800U) /*!< TxMailbox 0 transmit failure due to arbitration lost */ #define HAL_CAN_ERROR_TX_TERR0 (0x00001000U) /*!< TxMailbox 1 transmit failure due to tranmit error */ #define HAL_CAN_ERROR_TX_ALST1 (0x00002000U) /*!< TxMailbox 0 transmit failure due to arbitration lost */ #define HAL_CAN_ERROR_TX_TERR1 (0x00004000U) /*!< TxMailbox 1 transmit failure due to tranmit error */ #define HAL_CAN_ERROR_TX_ALST2 (0x00008000U) /*!< TxMailbox 0 transmit failure due to arbitration lost */ #define HAL_CAN_ERROR_TX_TERR2 (0x00010000U) /*!< TxMailbox 1 transmit failure due to tranmit error */ #define HAL_CAN_ERROR_TIMEOUT (0x00020000U) /*!< Timeout error */ #define HAL_CAN_ERROR_NOT_INITIALIZED (0x00040000U) /*!< Peripheral not initialized */ #define HAL_CAN_ERROR_NOT_READY (0x00080000U) /*!< Peripheral not ready */ #define HAL_CAN_ERROR_NOT_STARTED (0x00100000U) /*!< Peripheral not started */ #define HAL_CAN_ERROR_PARAM (0x00200000U) /*!< Parameter error */ #define HAL_CAN_ERROR_INTERNAL (0x00800000U) /*!< Internal error */ /** * @} */ /** @defgroup CAN_InitStatus CAN InitStatus * @{ */ #define CAN_INITSTATUS_FAILED (0x00000000U) /*!< CAN initialization failed */ #define CAN_INITSTATUS_SUCCESS (0x00000001U) /*!< CAN initialization OK */ /** * @} */ /** @defgroup CAN_operating_mode CAN Operating Mode * @{ */ #define CAN_MODE_NORMAL (0x00000000U) /*!< Normal mode */ #define CAN_MODE_LOOPBACK ((uint32_t)CAN_BTR_LBKM) /*!< Loopback mode */ #define CAN_MODE_SILENT ((uint32_t)CAN_BTR_SILM) /*!< Silent mode */ #define CAN_MODE_SILENT_LOOPBACK ((uint32_t)(CAN_BTR_LBKM | CAN_BTR_SILM)) /*!< Loopback combined with silent mode */ /** * @} */ /** @defgroup CAN_synchronisation_jump_width CAN Synchronization Jump Width * @{ */ #define CAN_SJW_1TQ (0x00000000U) /*!< 1 time quantum */ #define CAN_SJW_2TQ ((uint32_t)CAN_BTR_SJW_0) /*!< 2 time quantum */ #define CAN_SJW_3TQ ((uint32_t)CAN_BTR_SJW_1) /*!< 3 time quantum */ #define CAN_SJW_4TQ ((uint32_t)CAN_BTR_SJW) /*!< 4 time quantum */ /** * @} */ /** @defgroup CAN_time_quantum_in_bit_segment_1 CAN Time Quantum in Bit Segment 1 * @{ */ #define CAN_BS1_1TQ (0x00000000U) /*!< 1 time quantum */ #define CAN_BS1_2TQ ((uint32_t)CAN_BTR_TS1_0) /*!< 2 time quantum */ #define CAN_BS1_3TQ ((uint32_t)CAN_BTR_TS1_1) /*!< 3 time quantum */ #define CAN_BS1_4TQ ((uint32_t)(CAN_BTR_TS1_1 | CAN_BTR_TS1_0)) /*!< 4 time quantum */ #define CAN_BS1_5TQ ((uint32_t)CAN_BTR_TS1_2) /*!< 5 time quantum */ #define CAN_BS1_6TQ ((uint32_t)(CAN_BTR_TS1_2 | CAN_BTR_TS1_0)) /*!< 6 time quantum */ #define CAN_BS1_7TQ ((uint32_t)(CAN_BTR_TS1_2 | CAN_BTR_TS1_1)) /*!< 7 time quantum */ #define CAN_BS1_8TQ ((uint32_t)(CAN_BTR_TS1_2 | CAN_BTR_TS1_1 | CAN_BTR_TS1_0)) /*!< 8 time quantum */ #define CAN_BS1_9TQ ((uint32_t)CAN_BTR_TS1_3) /*!< 9 time quantum */ #define CAN_BS1_10TQ ((uint32_t)(CAN_BTR_TS1_3 | CAN_BTR_TS1_0)) /*!< 10 time quantum */ #define CAN_BS1_11TQ ((uint32_t)(CAN_BTR_TS1_3 | CAN_BTR_TS1_1)) /*!< 11 time quantum */ #define CAN_BS1_12TQ ((uint32_t)(CAN_BTR_TS1_3 | CAN_BTR_TS1_1 | CAN_BTR_TS1_0)) /*!< 12 time quantum */ #define CAN_BS1_13TQ ((uint32_t)(CAN_BTR_TS1_3 | CAN_BTR_TS1_2)) /*!< 13 time quantum */ #define CAN_BS1_14TQ ((uint32_t)(CAN_BTR_TS1_3 | CAN_BTR_TS1_2 | CAN_BTR_TS1_0)) /*!< 14 time quantum */ #define CAN_BS1_15TQ ((uint32_t)(CAN_BTR_TS1_3 | CAN_BTR_TS1_2 | CAN_BTR_TS1_1)) /*!< 15 time quantum */ #define CAN_BS1_16TQ ((uint32_t)CAN_BTR_TS1) /*!< 16 time quantum */ /** * @} */ /** @defgroup CAN_time_quantum_in_bit_segment_2 CAN Time Quantum in Bit Segment 2 * @{ */ #define CAN_BS2_1TQ (0x00000000U) /*!< 1 time quantum */ #define CAN_BS2_2TQ ((uint32_t)CAN_BTR_TS2_0) /*!< 2 time quantum */ #define CAN_BS2_3TQ ((uint32_t)CAN_BTR_TS2_1) /*!< 3 time quantum */ #define CAN_BS2_4TQ ((uint32_t)(CAN_BTR_TS2_1 | CAN_BTR_TS2_0)) /*!< 4 time quantum */ #define CAN_BS2_5TQ ((uint32_t)CAN_BTR_TS2_2) /*!< 5 time quantum */ #define CAN_BS2_6TQ ((uint32_t)(CAN_BTR_TS2_2 | CAN_BTR_TS2_0)) /*!< 6 time quantum */ #define CAN_BS2_7TQ ((uint32_t)(CAN_BTR_TS2_2 | CAN_BTR_TS2_1)) /*!< 7 time quantum */ #define CAN_BS2_8TQ ((uint32_t)CAN_BTR_TS2) /*!< 8 time quantum */ /** * @} */ /** @defgroup CAN_filter_mode CAN Filter Mode * @{ */ #define CAN_FILTERMODE_IDMASK (0x00000000U) /*!< Identifier mask mode */ #define CAN_FILTERMODE_IDLIST (0x00000001U) /*!< Identifier list mode */ /** * @} */ /** @defgroup CAN_filter_scale CAN Filter Scale * @{ */ #define CAN_FILTERSCALE_16BIT (0x00000000U) /*!< Two 16-bit filters */ #define CAN_FILTERSCALE_32BIT (0x00000001U) /*!< One 32-bit filter */ /** * @} */ /** @defgroup CAN_filter_activation CAN Filter Activation * @{ */ #define CAN_FILTER_DISABLE (0x00000000U) /*!< Disable filter */ #define CAN_FILTER_ENABLE (0x00000001U) /*!< Enable filter */ /** * @} */ /** @defgroup CAN_filter_FIFO CAN Filter FIFO * @{ */ #define CAN_FILTER_FIFO0 (0x00000000U) /*!< Filter FIFO 0 assignment for filter x */ #define CAN_FILTER_FIFO1 (0x00000001U) /*!< Filter FIFO 1 assignment for filter x */ /** * @} */ /** @defgroup CAN_identifier_type CAN Identifier Type * @{ */ #define CAN_ID_STD ((uint32_t)0x00000000) /*!< Standard Id */ #define CAN_ID_EXT ((uint32_t)0x00000004) /*!< Extended Id */ /** * @} */ /** @defgroup CAN_remote_transmission_request CAN Remote Transmission Request * @{ */ #define CAN_RTR_DATA ((uint32_t)0x00000000) /*!< Data frame */ #define CAN_RTR_REMOTE ((uint32_t)0x00000002) /*!< Remote frame */ /** * @} */ /** @defgroup CAN_receive_FIFO_number CAN Receive FIFO Number * @{ */ #define CAN_RX_FIFO0 (0x00000000U) /*!< CAN receive FIFO 0 */ #define CAN_RX_FIFO1 (0x00000001U) /*!< CAN receive FIFO 1 */ /** * @} */ /** @defgroup CAN_Tx_Mailboxes CAN Tx Mailboxes * @{ */ #define CAN_TX_MAILBOX0 (0x00000001U) /*!< Tx Mailbox 0 */ #define CAN_TX_MAILBOX1 (0x00000002U) /*!< Tx Mailbox 1 */ #define CAN_TX_MAILBOX2 (0x00000004U) /*!< Tx Mailbox 2 */ /** * @} */ /** @defgroup CAN_flags CAN Flags * @{ */ /* Transmit Flags */ #define CAN_FLAG_RQCP0 (0x00000500U) /*!< Request complete MailBox 0 flag */ #define CAN_FLAG_TXOK0 (0x00000501U) /*!< Transmission OK MailBox 0 flag */ #define CAN_FLAG_ALST0 (0x00000502U) /*!< Arbitration Lost MailBox 0 flag */ #define CAN_FLAG_TERR0 (0x00000503U) /*!< Transmission error MailBox 0 flag */ #define CAN_FLAG_RQCP1 (0x00000508U) /*!< Request complete MailBox1 flag */ #define CAN_FLAG_TXOK1 (0x00000509U) /*!< Transmission OK MailBox 1 flag */ #define CAN_FLAG_ALST1 (0x0000050AU) /*!< Arbitration Lost MailBox 1 flag */ #define CAN_FLAG_TERR1 (0x0000050BU) /*!< Transmission error MailBox 1 flag */ #define CAN_FLAG_RQCP2 (0x00000510U) /*!< Request complete MailBox2 flag */ #define CAN_FLAG_TXOK2 (0x00000511U) /*!< Transmission OK MailBox 2 flag */ #define CAN_FLAG_ALST2 (0x00000512U) /*!< Arbitration Lost MailBox 2 flag */ #define CAN_FLAG_TERR2 (0x00000513U) /*!< Transmission error MailBox 2 flag */ #define CAN_FLAG_TME0 (0x0000051AU) /*!< Transmit mailbox 0 empty flag */ #define CAN_FLAG_TME1 (0x0000051BU) /*!< Transmit mailbox 1 empty flag */ #define CAN_FLAG_TME2 (0x0000051CU) /*!< Transmit mailbox 2 empty flag */ #define CAN_FLAG_LOW0 (0x0000051DU) /*!< Lowest priority mailbox 0 flag */ #define CAN_FLAG_LOW1 (0x0000051EU) /*!< Lowest priority mailbox 1 flag */ #define CAN_FLAG_LOW2 (0x0000051FU) /*!< Lowest priority mailbox 2 flag */ /* Receive Flags */ #define CAN_FLAG_FF0 (0x00000203U) /*!< RX FIFO 0 Full flag */ #define CAN_FLAG_FOV0 (0x00000204U) /*!< RX FIFO 0 Overrun flag */ #define CAN_FLAG_FF1 (0x00000403U) /*!< RX FIFO 1 Full flag */ #define CAN_FLAG_FOV1 (0x00000404U) /*!< RX FIFO 1 Overrun flag */ /* Operating Mode Flags */ #define CAN_FLAG_INAK (0x00000100U) /*!< Initialization acknowledge flag */ #define CAN_FLAG_SLAK (0x00000101U) /*!< Sleep acknowledge flag */ #define CAN_FLAG_ERRI (0x00000102U) /*!< Error flag */ #define CAN_FLAG_WKU (0x00000103U) /*!< Wake up interrupt flag */ #define CAN_FLAG_SLAKI (0x00000104U) /*!< Sleep acknowledge interrupt flag */ /* Error Flags */ #define CAN_FLAG_EWG (0x00000300U) /*!< Error warning flag */ #define CAN_FLAG_EPV (0x00000301U) /*!< Error passive flag */ #define CAN_FLAG_BOF (0x00000302U) /*!< Bus-Off flag */ /** * @} */ /** @defgroup CAN_Interrupts CAN Interrupts * @{ */ /* Transmit Interrupt */ #define CAN_IT_TX_MAILBOX_EMPTY ((uint32_t)CAN_IER_TMEIE) /*!< Transmit mailbox empty interrupt */ /* Receive Interrupts */ #define CAN_IT_RX_FIFO0_MSG_PENDING ((uint32_t)CAN_IER_FMPIE0) /*!< FIFO 0 message pending interrupt */ #define CAN_IT_RX_FIFO0_FULL ((uint32_t)CAN_IER_FFIE0) /*!< FIFO 0 full interrupt */ #define CAN_IT_RX_FIFO0_OVERRUN ((uint32_t)CAN_IER_FOVIE0) /*!< FIFO 0 overrun interrupt */ #define CAN_IT_RX_FIFO1_MSG_PENDING ((uint32_t)CAN_IER_FMPIE1) /*!< FIFO 1 message pending interrupt */ #define CAN_IT_RX_FIFO1_FULL ((uint32_t)CAN_IER_FFIE1) /*!< FIFO 1 full interrupt */ #define CAN_IT_RX_FIFO1_OVERRUN ((uint32_t)CAN_IER_FOVIE1) /*!< FIFO 1 overrun interrupt */ /* Operating Mode Interrupts */ #define CAN_IT_WAKEUP ((uint32_t)CAN_IER_WKUIE) /*!< Wake-up interrupt */ #define CAN_IT_SLEEP_ACK ((uint32_t)CAN_IER_SLKIE) /*!< Sleep acknowledge interrupt */ /* Error Interrupts */ #define CAN_IT_ERROR_WARNING ((uint32_t)CAN_IER_EWGIE) /*!< Error warning interrupt */ #define CAN_IT_ERROR_PASSIVE ((uint32_t)CAN_IER_EPVIE) /*!< Error passive interrupt */ #define CAN_IT_BUSOFF ((uint32_t)CAN_IER_BOFIE) /*!< Bus-off interrupt */ #define CAN_IT_LAST_ERROR_CODE ((uint32_t)CAN_IER_LECIE) /*!< Last error code interrupt */ #define CAN_IT_ERROR ((uint32_t)CAN_IER_ERRIE) /*!< Error Interrupt */ /** * @} */ /** * @} */ /* Exported macros -----------------------------------------------------------*/ /** @defgroup CAN_Exported_Macros CAN Exported Macros * @{ */ /** @brief Reset CAN handle state * @param __HANDLE__ CAN handle. * @retval None */ #define __HAL_CAN_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_CAN_STATE_RESET) /** * @brief Enable the specified CAN interrupts. * @param __HANDLE__ CAN handle. * @param __INTERRUPT__ CAN Interrupt sources to enable. * This parameter can be any combination of @arg CAN_Interrupts * @retval None */ #define __HAL_CAN_ENABLE_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->IER) |= (__INTERRUPT__)) /** * @brief Disable the specified CAN interrupts. * @param __HANDLE__ CAN handle. * @param __INTERRUPT__ CAN Interrupt sources to disable. * This parameter can be any combination of @arg CAN_Interrupts * @retval None */ #define __HAL_CAN_DISABLE_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->IER) &= ~(__INTERRUPT__)) /** @brief Check if the specified CAN interrupt source is enabled or disabled. * @param __HANDLE__ specifies the CAN Handle. * @param __INTERRUPT__ specifies the CAN interrupt source to check. * This parameter can be a value of @arg CAN_Interrupts * @retval The state of __IT__ (TRUE or FALSE). */ #define __HAL_CAN_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->IER) & (__INTERRUPT__)) /** @brief Check whether the specified CAN flag is set or not. * @param __HANDLE__ specifies the CAN Handle. * @param __FLAG__ specifies the flag to check. * This parameter can be one of @arg CAN_flags * @retval The state of __FLAG__ (TRUE or FALSE). */ #define __HAL_CAN_GET_FLAG(__HANDLE__, __FLAG__) \ ((((__FLAG__) >> 8U) == 5U)? ((((__HANDLE__)->Instance->TSR) & (1U << ((__FLAG__) & CAN_FLAG_MASK))) == (1U << ((__FLAG__) & CAN_FLAG_MASK))): \ (((__FLAG__) >> 8U) == 2U)? ((((__HANDLE__)->Instance->RF0R) & (1U << ((__FLAG__) & CAN_FLAG_MASK))) == (1U << ((__FLAG__) & CAN_FLAG_MASK))): \ (((__FLAG__) >> 8U) == 4U)? ((((__HANDLE__)->Instance->RF1R) & (1U << ((__FLAG__) & CAN_FLAG_MASK))) == (1U << ((__FLAG__) & CAN_FLAG_MASK))): \ (((__FLAG__) >> 8U) == 1U)? ((((__HANDLE__)->Instance->MSR) & (1U << ((__FLAG__) & CAN_FLAG_MASK))) == (1U << ((__FLAG__) & CAN_FLAG_MASK))): \ (((__FLAG__) >> 8U) == 3U)? ((((__HANDLE__)->Instance->ESR) & (1U << ((__FLAG__) & CAN_FLAG_MASK))) == (1U << ((__FLAG__) & CAN_FLAG_MASK))): 0U) /** @brief Clear the specified CAN pending flag. * @param __HANDLE__ specifies the CAN Handle. * @param __FLAG__ specifies the flag to check. * This parameter can be one of the following values: * @arg CAN_FLAG_RQCP0: Request complete MailBox 0 Flag * @arg CAN_FLAG_TXOK0: Transmission OK MailBox 0 Flag * @arg CAN_FLAG_ALST0: Arbitration Lost MailBox 0 Flag * @arg CAN_FLAG_TERR0: Transmission error MailBox 0 Flag * @arg CAN_FLAG_RQCP1: Request complete MailBox 1 Flag * @arg CAN_FLAG_TXOK1: Transmission OK MailBox 1 Flag * @arg CAN_FLAG_ALST1: Arbitration Lost MailBox 1 Flag * @arg CAN_FLAG_TERR1: Transmission error MailBox 1 Flag * @arg CAN_FLAG_RQCP2: Request complete MailBox 2 Flag * @arg CAN_FLAG_TXOK2: Transmission OK MailBox 2 Flag * @arg CAN_FLAG_ALST2: Arbitration Lost MailBox 2 Flag * @arg CAN_FLAG_TERR2: Transmission error MailBox 2 Flag * @arg CAN_FLAG_FF0: RX FIFO 0 Full Flag * @arg CAN_FLAG_FOV0: RX FIFO 0 Overrun Flag * @arg CAN_FLAG_FF1: RX FIFO 1 Full Flag * @arg CAN_FLAG_FOV1: RX FIFO 1 Overrun Flag * @arg CAN_FLAG_WKUI: Wake up Interrupt Flag * @arg CAN_FLAG_SLAKI: Sleep acknowledge Interrupt Flag * @retval None */ #define __HAL_CAN_CLEAR_FLAG(__HANDLE__, __FLAG__) \ ((((__FLAG__) >> 8U) == 5U)? (((__HANDLE__)->Instance->TSR) = (1U << ((__FLAG__) & CAN_FLAG_MASK))): \ (((__FLAG__) >> 8U) == 2U)? (((__HANDLE__)->Instance->RF0R) = (1U << ((__FLAG__) & CAN_FLAG_MASK))): \ (((__FLAG__) >> 8U) == 4U)? (((__HANDLE__)->Instance->RF1R) = (1U << ((__FLAG__) & CAN_FLAG_MASK))): \ (((__FLAG__) >> 8U) == 1U)? (((__HANDLE__)->Instance->MSR) = (1U << ((__FLAG__) & CAN_FLAG_MASK))): 0U) /** * @} */ /* Exported functions --------------------------------------------------------*/ /** @addtogroup CAN_Exported_Functions CAN Exported Functions * @{ */ /** @addtogroup CAN_Exported_Functions_Group1 Initialization and de-initialization functions * @brief Initialization and Configuration functions * @{ */ /* Initialization and de-initialization functions *****************************/ HAL_StatusTypeDef HAL_CAN_Init(CAN_HandleTypeDef *hcan); HAL_StatusTypeDef HAL_CAN_DeInit(CAN_HandleTypeDef *hcan); void HAL_CAN_MspInit(CAN_HandleTypeDef *hcan); void HAL_CAN_MspDeInit(CAN_HandleTypeDef *hcan); /** * @} */ /** @addtogroup CAN_Exported_Functions_Group2 Configuration functions * @brief Configuration functions * @{ */ /* Configuration functions ****************************************************/ HAL_StatusTypeDef HAL_CAN_ConfigFilter(CAN_HandleTypeDef *hcan, CAN_FilterTypeDef *sFilterConfig); /** * @} */ /** @addtogroup CAN_Exported_Functions_Group3 Control functions * @brief Control functions * @{ */ /* Control functions **********************************************************/ HAL_StatusTypeDef HAL_CAN_Start(CAN_HandleTypeDef *hcan); HAL_StatusTypeDef HAL_CAN_Stop(CAN_HandleTypeDef *hcan); HAL_StatusTypeDef HAL_CAN_RequestSleep(CAN_HandleTypeDef *hcan); HAL_StatusTypeDef HAL_CAN_WakeUp(CAN_HandleTypeDef *hcan); uint32_t HAL_CAN_IsSleepActive(CAN_HandleTypeDef *hcan); HAL_StatusTypeDef HAL_CAN_AddTxMessage(CAN_HandleTypeDef *hcan, CAN_TxHeaderTypeDef *pHeader, uint8_t aData[], uint32_t *pTxMailbox); HAL_StatusTypeDef HAL_CAN_AbortTxRequest(CAN_HandleTypeDef *hcan, uint32_t TxMailboxes); uint32_t HAL_CAN_GetTxMailboxesFreeLevel(CAN_HandleTypeDef *hcan); uint32_t HAL_CAN_IsTxMessagePending(CAN_HandleTypeDef *hcan, uint32_t TxMailboxes); uint32_t HAL_CAN_GetTxTimestamp(CAN_HandleTypeDef *hcan, uint32_t TxMailbox); HAL_StatusTypeDef HAL_CAN_GetRxMessage(CAN_HandleTypeDef *hcan, uint32_t RxFifo, CAN_RxHeaderTypeDef *pHeader, uint8_t aData[]); uint32_t HAL_CAN_GetRxFifoFillLevel(CAN_HandleTypeDef *hcan, uint32_t RxFifo); /** * @} */ /** @addtogroup CAN_Exported_Functions_Group4 Interrupts management * @brief Interrupts management * @{ */ /* Interrupts management ******************************************************/ HAL_StatusTypeDef HAL_CAN_ActivateNotification(CAN_HandleTypeDef *hcan, uint32_t ActiveITs); HAL_StatusTypeDef HAL_CAN_DeactivateNotification(CAN_HandleTypeDef *hcan, uint32_t InactiveITs); void HAL_CAN_IRQHandler(CAN_HandleTypeDef *hcan); /** * @} */ /** @addtogroup CAN_Exported_Functions_Group5 Callback functions * @brief Callback functions * @{ */ /* Callbacks functions ********************************************************/ void HAL_CAN_TxMailbox0CompleteCallback(CAN_HandleTypeDef *hcan); void HAL_CAN_TxMailbox1CompleteCallback(CAN_HandleTypeDef *hcan); void HAL_CAN_TxMailbox2CompleteCallback(CAN_HandleTypeDef *hcan); void HAL_CAN_TxMailbox0AbortCallback(CAN_HandleTypeDef *hcan); void HAL_CAN_TxMailbox1AbortCallback(CAN_HandleTypeDef *hcan); void HAL_CAN_TxMailbox2AbortCallback(CAN_HandleTypeDef *hcan); void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef *hcan); void HAL_CAN_RxFifo0FullCallback(CAN_HandleTypeDef *hcan); void HAL_CAN_RxFifo1MsgPendingCallback(CAN_HandleTypeDef *hcan); void HAL_CAN_RxFifo1FullCallback(CAN_HandleTypeDef *hcan); void HAL_CAN_SleepCallback(CAN_HandleTypeDef *hcan); void HAL_CAN_WakeUpFromRxMsgCallback(CAN_HandleTypeDef *hcan); void HAL_CAN_ErrorCallback(CAN_HandleTypeDef *hcan); /** * @} */ /** @addtogroup CAN_Exported_Functions_Group6 Peripheral State and Error functions * @brief CAN Peripheral State functions * @{ */ /* Peripheral State and Error functions ***************************************/ HAL_CAN_StateTypeDef HAL_CAN_GetState(CAN_HandleTypeDef *hcan); uint32_t HAL_CAN_GetError(CAN_HandleTypeDef *hcan); HAL_StatusTypeDef HAL_CAN_ResetError(CAN_HandleTypeDef *hcan); /** * @} */ /** * @} */ /* Private types -------------------------------------------------------------*/ /** @defgroup CAN_Private_Types CAN Private Types * @{ */ /** * @} */ /* Private variables ---------------------------------------------------------*/ /** @defgroup CAN_Private_Variables CAN Private Variables * @{ */ /** * @} */ /* Private constants ---------------------------------------------------------*/ /** @defgroup CAN_Private_Constants CAN Private Constants * @{ */ #define CAN_FLAG_MASK (0x000000FFU) /** * @} */ /* Private Macros -----------------------------------------------------------*/ /** @defgroup CAN_Private_Macros CAN Private Macros * @{ */ #define IS_CAN_MODE(MODE) (((MODE) == CAN_MODE_NORMAL) || \ ((MODE) == CAN_MODE_LOOPBACK)|| \ ((MODE) == CAN_MODE_SILENT) || \ ((MODE) == CAN_MODE_SILENT_LOOPBACK)) #define IS_CAN_SJW(SJW) (((SJW) == CAN_SJW_1TQ) || ((SJW) == CAN_SJW_2TQ) || \ ((SJW) == CAN_SJW_3TQ) || ((SJW) == CAN_SJW_4TQ)) #define IS_CAN_BS1(BS1) (((BS1) == CAN_BS1_1TQ) || ((BS1) == CAN_BS1_2TQ) || \ ((BS1) == CAN_BS1_3TQ) || ((BS1) == CAN_BS1_4TQ) || \ ((BS1) == CAN_BS1_5TQ) || ((BS1) == CAN_BS1_6TQ) || \ ((BS1) == CAN_BS1_7TQ) || ((BS1) == CAN_BS1_8TQ) || \ ((BS1) == CAN_BS1_9TQ) || ((BS1) == CAN_BS1_10TQ)|| \ ((BS1) == CAN_BS1_11TQ)|| ((BS1) == CAN_BS1_12TQ)|| \ ((BS1) == CAN_BS1_13TQ)|| ((BS1) == CAN_BS1_14TQ)|| \ ((BS1) == CAN_BS1_15TQ)|| ((BS1) == CAN_BS1_16TQ)) #define IS_CAN_BS2(BS2) (((BS2) == CAN_BS2_1TQ) || ((BS2) == CAN_BS2_2TQ) || \ ((BS2) == CAN_BS2_3TQ) || ((BS2) == CAN_BS2_4TQ) || \ ((BS2) == CAN_BS2_5TQ) || ((BS2) == CAN_BS2_6TQ) || \ ((BS2) == CAN_BS2_7TQ) || ((BS2) == CAN_BS2_8TQ)) #define IS_CAN_PRESCALER(PRESCALER) (((PRESCALER) >= 1U) && ((PRESCALER) <= 1024U)) #define IS_CAN_FILTER_ID_HALFWORD(HALFWORD) ((HALFWORD) <= 0xFFFFU) #if defined(CAN2) #define IS_CAN_FILTER_BANK_DUAL(BANK) ((BANK) <= 27U) #endif #define IS_CAN_FILTER_BANK_SINGLE(BANK) ((BANK) <= 13U) #define IS_CAN_FILTER_MODE(MODE) (((MODE) == CAN_FILTERMODE_IDMASK) || \ ((MODE) == CAN_FILTERMODE_IDLIST)) #define IS_CAN_FILTER_SCALE(SCALE) (((SCALE) == CAN_FILTERSCALE_16BIT) || \ ((SCALE) == CAN_FILTERSCALE_32BIT)) #define IS_CAN_FILTER_ACTIVATION(ACTIVATION) (((ACTIVATION) == CAN_FILTER_DISABLE) || \ ((ACTIVATION) == CAN_FILTER_ENABLE)) #define IS_CAN_FILTER_FIFO(FIFO) (((FIFO) == CAN_FILTER_FIFO0) || \ ((FIFO) == CAN_FILTER_FIFO1)) #define IS_CAN_TX_MAILBOX(TRANSMITMAILBOX) (((TRANSMITMAILBOX) == CAN_TX_MAILBOX0 ) || \ ((TRANSMITMAILBOX) == CAN_TX_MAILBOX1 ) || \ ((TRANSMITMAILBOX) == CAN_TX_MAILBOX2 )) #define IS_CAN_TX_MAILBOX_LIST(TRANSMITMAILBOX) ((TRANSMITMAILBOX) <= (CAN_TX_MAILBOX0 | CAN_TX_MAILBOX1 | CAN_TX_MAILBOX2)) #define IS_CAN_STDID(STDID) ((STDID) <= 0x7FFU) #define IS_CAN_EXTID(EXTID) ((EXTID) <= 0x1FFFFFFFU) #define IS_CAN_DLC(DLC) ((DLC) <= 8U) #define IS_CAN_IDTYPE(IDTYPE) (((IDTYPE) == CAN_ID_STD) || \ ((IDTYPE) == CAN_ID_EXT)) #define IS_CAN_RTR(RTR) (((RTR) == CAN_RTR_DATA) || ((RTR) == CAN_RTR_REMOTE)) #define IS_CAN_RX_FIFO(FIFO) (((FIFO) == CAN_RX_FIFO0) || ((FIFO) == CAN_RX_FIFO1)) #define IS_CAN_IT(IT) ((IT) <= (CAN_IT_TX_MAILBOX_EMPTY | CAN_IT_RX_FIFO0_MSG_PENDING | \ CAN_IT_RX_FIFO0_FULL | CAN_IT_RX_FIFO0_OVERRUN | \ CAN_IT_RX_FIFO1_MSG_PENDING | CAN_IT_RX_FIFO1_FULL | \ CAN_IT_RX_FIFO1_OVERRUN | CAN_IT_WAKEUP | \ CAN_IT_SLEEP_ACK | CAN_IT_ERROR_WARNING | \ CAN_IT_ERROR_PASSIVE | CAN_IT_BUSOFF | \ CAN_IT_LAST_ERROR_CODE | CAN_IT_ERROR)) /** * @} */ /* End of private macros -----------------------------------------------------*/ /** * @} */ #endif /* CAN1 */ /** * @} */ #ifdef __cplusplus } #endif #endif /* STM32F1xx_HAL_CAN_H */ /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 求大佬指点哪里错了。。

在中国程序员是青春饭吗?

今年,我也32了 ,为了不给大家误导,咨询了猎头、圈内好友,以及年过35岁的几位老程序员……舍了老脸去揭人家伤疤……希望能给大家以帮助,记得帮我点赞哦。 目录: 你以为的人生 一次又一次的伤害 猎头界的真相 如何应对互联网行业的「中年危机」 一、你以为的人生 刚入行时,拿着傲人的工资,想着好好干,以为我们的人生是这样的: 等真到了那一天,你会发现,你的人生很可能是这样的: ...

再不跳槽,应届毕业生拿的都比我多了!

跳槽几乎是每个人职业生涯的一部分,很多HR说“三年两跳”已经是一个跳槽频繁与否的阈值了,可为什么市面上有很多程序员不到一年就跳槽呢?他们不担心影响履历吗? PayScale之前发布的**《员工最短任期公司排行榜》中,两家码农大厂Amazon和Google**,以1年和1.1年的员工任期中位数分列第二、第四名。 PayScale:员工最短任期公司排行榜 意外的是,任期中位数极小的这两家公司,薪资...

我以为我学懂了数据结构,直到看了这个导图才发现,我错了

数据结构与算法思维导图

数据库——玩转SQL语句(以MySQL为例)

一、前言 照着大学的SQL server来学

技术大佬:我去,你写的 switch 语句也太老土了吧

昨天早上通过远程的方式 review 了两名新来同事的代码,大部分代码都写得很漂亮,严谨的同时注释也很到位,这令我非常满意。但当我看到他们当中有一个人写的 switch 语句时,还是忍不住破口大骂:“我擦,小王,你丫写的 switch 语句也太老土了吧!” 来看看小王写的代码吧,看完不要骂我装逼啊。 private static String createPlayer(PlayerTypes p...

华为初面+综合面试(Java技术面)附上面试题

华为面试整体流程大致分为笔试,性格测试,面试,综合面试,回学校等结果。笔试来说,华为的难度较中等,选择题难度和网易腾讯差不多。最后的代码题,相比下来就简单很多,一共3道题目,前2题很容易就AC,题目已经记不太清楚,不过难度确实不大。最后一题最后提交的代码过了75%的样例,一直没有发现剩下的25%可能存在什么坑。 笔试部分太久远,我就不怎么回忆了。直接将面试。 面试 如果说腾讯的面试是挥金如土...

和黑客斗争的 6 天!

互联网公司工作,很难避免不和黑客们打交道,我呆过的两家互联网公司,几乎每月每天每分钟都有黑客在公司网站上扫描。有的是寻找 Sql 注入的缺口,有的是寻找线上服务器可能存在的漏洞,大部分都...

讲一个程序员如何副业月赚三万的真实故事

loonggg读完需要3分钟速读仅需 1 分钟大家好,我是你们的校长。我之前讲过,这年头,只要肯动脑,肯行动,程序员凭借自己的技术,赚钱的方式还是有很多种的。仅仅靠在公司出卖自己的劳动时...

上班一个月,后悔当初着急入职的选择了

最近有个老铁,告诉我说,上班一个月,后悔当初着急入职现在公司了。他之前在美图做手机研发,今年美图那边今年也有一波组织优化调整,他是其中一个,在协商离职后,当时捉急找工作上班,因为有房贷供着,不能没有收入来源。所以匆忙选了一家公司,实际上是一个大型外包公司,主要派遣给其他手机厂商做外包项目。**当时承诺待遇还不错,所以就立马入职去上班了。但是后面入职后,发现薪酬待遇这块并不是HR所说那样,那个HR自...

总结了 150 余个神奇网站,你不来瞅瞅吗?

原博客再更新,可能就没了,之后将持续更新本篇博客。

副业收入是我做程序媛的3倍,工作外的B面人生是怎样的?

提到“程序员”,多数人脑海里首先想到的大约是:为人木讷、薪水超高、工作枯燥…… 然而,当离开工作岗位,撕去层层标签,脱下“程序员”这身外套,有的人生动又有趣,马上展现出了完全不同的A/B面人生! 不论是简单的爱好,还是正经的副业,他们都干得同样出色。偶尔,还能和程序员的特质结合,产生奇妙的“化学反应”。 @Charlotte:平日素颜示人,周末美妆博主 大家都以为程序媛也个个不修边幅,但我们也许...

MySQL数据库面试题(2020最新版)

文章目录数据库基础知识为什么要使用数据库什么是SQL?什么是MySQL?数据库三大范式是什么mysql有关权限的表都有哪几个MySQL的binlog有有几种录入格式?分别有什么区别?数据类型mysql有哪些数据类型引擎MySQL存储引擎MyISAM与InnoDB区别MyISAM索引与InnoDB索引的区别?InnoDB引擎的4大特性存储引擎选择索引什么是索引?索引有哪些优缺点?索引使用场景(重点)...

如果你是老板,你会不会踢了这样的员工?

有个好朋友ZS,是技术总监,昨天问我:“有一个老下属,跟了我很多年,做事勤勤恳恳,主动性也很好。但随着公司的发展,他的进步速度,跟不上团队的步伐了,有点...

我入职阿里后,才知道原来简历这么写

私下里,有不少读者问我:“二哥,如何才能写出一份专业的技术简历呢?我总感觉自己写的简历太烂了,所以投了无数份,都石沉大海了。”说实话,我自己好多年没有写过简历了,但我认识的一个同行,他在阿里,给我说了一些他当年写简历的方法论,我感觉太牛逼了,实在是忍不住,就分享了出来,希望能够帮助到你。 01、简历的本质 作为简历的撰写者,你必须要搞清楚一点,简历的本质是什么,它就是为了来销售你的价值主张的。往深...

程序员写出这样的代码,能不挨骂吗?

当你换槽填坑时,面对一个新的环境。能够快速熟练,上手实现业务需求是关键。但是,哪些因素会影响你快速上手呢?是原有代码写的不够好?还是注释写的不够好?昨夜...

离职半年了,老东家又发 offer,回不回?

有小伙伴问松哥这个问题,他在上海某公司,在离职了几个月后,前公司的领导联系到他,希望他能够返聘回去,他很纠结要不要回去? 俗话说好马不吃回头草,但是这个小伙伴既然感到纠结了,我觉得至少说明了两个问题:1.曾经的公司还不错;2.现在的日子也不是很如意。否则应该就不会纠结了。 老实说,松哥之前也有过类似的经历,今天就来和小伙伴们聊聊回头草到底吃不吃。 首先一个基本观点,就是离职了也没必要和老东家弄的苦...

HTTP与HTTPS的区别

面试官问HTTP与HTTPS的区别,我这样回答让他竖起大拇指!

程序员毕业去大公司好还是小公司好?

虽然大公司并不是人人都能进,但我仍建议还未毕业的同学,尽力地通过校招向大公司挤,但凡挤进去,你这一生会容易很多。 大公司哪里好?没能进大公司怎么办?答案都在这里了,记得帮我点赞哦。 目录: 技术氛围 内部晋升与跳槽 啥也没学会,公司倒闭了? 不同的人脉圈,注定会有不同的结果 没能去大厂怎么办? 一、技术氛围 纵观整个程序员技术领域,哪个在行业有所名气的大牛,不是在大厂? 而且众所...

程序员为什么千万不要瞎努力?

本文作者用对比非常鲜明的两个开发团队的故事,讲解了敏捷开发之道 —— 如果你的团队缺乏统一标准的环境,那么即使勤劳努力,不仅会极其耗时而且成果甚微,使用...

为什么程序员做外包会被瞧不起?

二哥,有个事想询问下您的意见,您觉得应届生值得去外包吗?公司虽然挺大的,中xx,但待遇感觉挺低,马上要报到,挺纠结的。

当HR压你价,说你只值7K,你该怎么回答?

当HR压你价,说你只值7K时,你可以流畅地回答,记住,是流畅,不能犹豫。 礼貌地说:“7K是吗?了解了。嗯~其实我对贵司的面试官印象很好。只不过,现在我的手头上已经有一份11K的offer。来面试,主要也是自己对贵司挺有兴趣的,所以过来看看……”(未完) 这段话主要是陪HR互诈的同时,从公司兴趣,公司职员印象上,都给予对方正面的肯定,既能提升HR的好感度,又能让谈判气氛融洽,为后面的发挥留足空间。...

面试阿里p7,被按在地上摩擦,鬼知道我经历了什么?

面试阿里p7被问到的问题(当时我只知道第一个):@Conditional是做什么的?@Conditional多个条件是什么逻辑关系?条件判断在什么时候执...

终于懂了TCP和UDP协议区别

终于懂了TCP和UDP协议区别

无代码时代来临,程序员如何保住饭碗?

编程语言层出不穷,从最初的机器语言到如今2500种以上的高级语言,程序员们大呼“学到头秃”。程序员一边面临编程语言不断推陈出新,一边面临由于许多代码已存在,程序员编写新应用程序时存在重复“搬砖”的现象。 无代码/低代码编程应运而生。无代码/低代码是一种创建应用的方法,它可以让开发者使用最少的编码知识来快速开发应用程序。开发者通过图形界面中,可视化建模来组装和配置应用程序。这样一来,开发者直...

面试了一个 31 岁程序员,让我有所触动,30岁以上的程序员该何去何从?

最近面试了一个31岁8年经验的程序猿,让我有点感慨,大龄程序猿该何去何从。

大三实习生,字节跳动面经分享,已拿Offer

说实话,自己的算法,我一个不会,太难了吧

程序员垃圾简历长什么样?

已经连续五年参加大厂校招、社招的技术面试工作,简历看的不下于万份 这篇文章会用实例告诉你,什么是差的程序员简历! 疫情快要结束了,各个公司也都开始春招了,作为即将红遍大江南北的新晋UP主,那当然要为小伙伴们做点事(手动狗头)。 就在公众号里公开征简历,义务帮大家看,并一一点评。《启舰:春招在即,义务帮大家看看简历吧》 一石激起千层浪,三天收到两百多封简历。 花光了两个星期的所有空闲时...

《C语言函数速查》main()主函数

每一个C程序都必须有一main()函数, 可以根据自己的爱好把它放在程序的某个地方。有些程序员把它放在最前面, 而另一些程序员把它放在最后面, 无论放在哪个地方, 以下几点说明都是适合的。

Java岗开发3年,公司临时抽查算法,离职后这几题我记一辈子

前几天我们公司做了一件蠢事,非常非常愚蠢的事情。我原以为从学校出来之后,除了找工作有测试外,不会有任何与考试有关的事儿。 但是,天有不测风云,公司技术总监、人事总监两位大佬突然降临到我们事业线,叫上我老大,给我们组织了一场别开生面的“考试”。 那是一个风和日丽的下午,我翘着二郎腿,左手端着一杯卡布奇诺,右手抓着我的罗技鼠标,滚动着轮轴,穿梭在头条热点之间。 “淡黄的长裙~蓬松的头发...

大牛都会用的IDEA调试技巧!!!

导读 前天面试了一个985高校的实习生,问了他平时用什么开发工具,他想也没想的说IDEA,于是我抛砖引玉的问了一下IDEA的调试用过吧,你说说怎么设置断点...

面试官:你连SSO都不懂,就别来面试了

大厂竟然要考我SSO,卧槽。

终于,月薪过5万了!

来看几个问题想不想月薪超过5万?想不想进入公司架构组?想不想成为项目组的负责人?想不想成为spring的高手,超越99%的对手?那么本文内容是你必须要掌握的。本文主要详解bean的生命...

我说我懂多线程,面试官立马给我发了offer

不小心拿了几个offer,有点烦

自从喜欢上了B站这12个UP主,我越来越觉得自己是个废柴了!

不怕告诉你,我自从喜欢上了这12个UP主,哔哩哔哩成为了我手机上最耗电的软件,几乎每天都会看,可是吧,看的越多,我就越觉得自己是个废柴,唉,老天不公啊,不信你看看…… 间接性踌躇满志,持续性混吃等死,都是因为你们……但是,自己的学习力在慢慢变强,这是不容忽视的,推荐给你们! 都说B站是个宝,可是有人不会挖啊,没事,今天咱挖好的送你一箩筐,首先啊,我在B站上最喜欢看这个家伙的视频了,为啥 ,咱撇...

代码注释如此沙雕,会玩还是你们程序员!

某站后端代码被“开源”,同时刷遍全网的,还有代码里的那些神注释。 我们这才知道,原来程序员个个都是段子手;这么多年来,我们也走过了他们的无数套路… 首先,产品经理,是永远永远吐槽不完的!网友的评论也非常扎心,说看这些代码就像在阅读程序员的日记,每一页都写满了对产品经理的恨。 然后,也要发出直击灵魂的质问:你是尊贵的付费大会员吗? 这不禁让人想起之前某音乐app的穷逼Vip,果然,穷逼在哪里都是...

立即提问
相关内容推荐