add : USB CDC虚拟串口通讯
This commit is contained in:
@@ -2,7 +2,7 @@ require "socket"
|
|||||||
require "log"
|
require "log"
|
||||||
|
|
||||||
-- 目标服务器IP和端口
|
-- 目标服务器IP和端口
|
||||||
local ip, port = "121.43.69.62", "8767"
|
local ip, port = "74538dd1hu30.vicp.fun", "50752"
|
||||||
-- 连接数量
|
-- 连接数量
|
||||||
local clientCount = 1
|
local clientCount = 1
|
||||||
-- 存储所有客户端
|
-- 存储所有客户端
|
||||||
|
|||||||
38
4G/tools/_temp/script/temp_script/clib.lua
Normal file
38
4G/tools/_temp/script/temp_script/clib.lua
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
local uartReceiveCallbacks = {}
|
||||||
|
local uartSentCallbacks = {}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
uart.on = function(id, event, callback)
|
||||||
|
if event == "receive" then
|
||||||
|
uartReceiveCallbacks[id] = callback
|
||||||
|
elseif event == "sent" then
|
||||||
|
uartSentCallbacks[id] = callback
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
rtos.on(rtos.MSG_UART_RXDATA, function(id, length)
|
||||||
|
if uartReceiveCallbacks[id] then
|
||||||
|
uartReceiveCallbacks[id](id, length)
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
rtos.on(rtos.MSG_UART_TX_DONE, function(id)
|
||||||
|
if uartSentCallbacks[id] then
|
||||||
|
uartSentCallbacks[id](id)
|
||||||
|
end
|
||||||
|
end)
|
||||||
14
4G/tools/_temp/script/temp_script/cmd.lua
Normal file
14
4G/tools/_temp/script/temp_script/cmd.lua
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
|
||||||
|
require "linksocket"
|
||||||
|
require "socket"
|
||||||
|
require "sys"
|
||||||
|
|
||||||
|
function handleCmd01(subCmd, payload)
|
||||||
|
|
||||||
|
sendToSocket(subCmd, payload)
|
||||||
|
log.info("CMD 0x01 received, sub:", subCmd, "data len:", #payload)
|
||||||
|
end
|
||||||
|
|
||||||
|
function handleCmd02(subCmd, payload)
|
||||||
|
sys.restart()
|
||||||
|
end
|
||||||
310
4G/tools/_temp/script/temp_script/http.lua
Normal file
310
4G/tools/_temp/script/temp_script/http.lua
Normal file
@@ -0,0 +1,310 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
require"socket"
|
||||||
|
require"utils"
|
||||||
|
module(..., package.seeall)
|
||||||
|
|
||||||
|
local function response(client,cbFnc,result,prompt,head,body)
|
||||||
|
if not result then log.error("http.response",result,prompt) end
|
||||||
|
if cbFnc then cbFnc(result,prompt,head,body) end
|
||||||
|
if client then client:close() end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function receive(client,timeout,cbFnc,result,prompt,head,body)
|
||||||
|
local res,data = client:recv(timeout)
|
||||||
|
if not res then
|
||||||
|
response(client,cbFnc,result,prompt or "receive timeout",head,body)
|
||||||
|
end
|
||||||
|
return res,data
|
||||||
|
end
|
||||||
|
|
||||||
|
local function getFileBase64Len(s)
|
||||||
|
if s then return (io.fileSize(s)+2)/3*4 end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function taskClient(method,protocal,auth,host,port,path,cert,head,body,timeout,cbFnc,rcvFilePath,tCoreExtPara)
|
||||||
|
log.info("http path",path)
|
||||||
|
while not socket.isReady() do
|
||||||
|
if not sys.waitUntil("IP_READY_IND",timeout) then return response(nil,cbFnc,false,"network not ready") end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
local bodyLen = 0
|
||||||
|
if body then
|
||||||
|
if type(body)=="string" then
|
||||||
|
bodyLen = body:len()
|
||||||
|
elseif type(body)=="table" then
|
||||||
|
for i=1,#body do
|
||||||
|
bodyLen = bodyLen + (type(body[i])=="string" and string.len(body[i]) or getFileBase64Len(body[i].file_base64) or io.fileSize(body[i].file))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
local heads = head or {}
|
||||||
|
if not heads.Host then heads["Host"] = (port ~= 80 and port ~= 443) and (host..":"..port) or host end
|
||||||
|
if not heads.Connection then heads["Connection"] = "short" end
|
||||||
|
if bodyLen>0 and bodyLen~=tonumber(heads["Content-Length"] or "0") then heads["Content-Length"] = bodyLen end
|
||||||
|
if auth~="" and not heads.Authorization then heads["Authorization"] = ("Basic "..crypto.base64_encode(auth,#auth)) end
|
||||||
|
local headStr = ""
|
||||||
|
for k,v in pairs(heads) do
|
||||||
|
headStr = headStr..k..": "..v.."\r\n"
|
||||||
|
end
|
||||||
|
headStr = headStr.."\r\n"
|
||||||
|
|
||||||
|
local client = socket.tcp(protocal=="https",cert,tCoreExtPara)
|
||||||
|
if not client then return response(nil,cbFnc,false,"create socket error") end
|
||||||
|
if not client:connect(host,port,timeout/1000) then
|
||||||
|
return response(client,cbFnc,false,"connect fail")
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
if not client:send(method.." "..path.." HTTP/1.1".."\r\n"..headStr..(type(body)=="string" and body or "")) then
|
||||||
|
return response(client,cbFnc,false,"send head fail")
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
if type(body)=="table" then
|
||||||
|
for i=1,#body do
|
||||||
|
if type(body[i])=="string" then
|
||||||
|
if not client:send(body[i]) then
|
||||||
|
return response(client,cbFnc,false,"send body fail")
|
||||||
|
end
|
||||||
|
else
|
||||||
|
local file = io.open(body[i].file or body[i].file_base64,"rb")
|
||||||
|
if file then
|
||||||
|
while true do
|
||||||
|
local dat = file:read(body[i].file and 11200 or 8400)
|
||||||
|
if not dat then
|
||||||
|
io.close(file)
|
||||||
|
break
|
||||||
|
end
|
||||||
|
if body[i].file_base64 then dat=crypto.base64_encode(dat,#dat) end
|
||||||
|
if not client:send(dat) then
|
||||||
|
io.close(file)
|
||||||
|
return response(client,cbFnc,false,"send file fail")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
return response(client,cbFnc,false,"send file open fail")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local rcvCache,rspHead,rspBody,d1,d2,result,data,statusCode,rcvChunked,contentLen = "",{},{}
|
||||||
|
|
||||||
|
while true do
|
||||||
|
result,data = receive(client,timeout,cbFnc,false,nil,rspHead,rcvFilePath or table.concat(rspBody))
|
||||||
|
if not result then return end
|
||||||
|
rcvCache = rcvCache..data
|
||||||
|
d1,d2 = rcvCache:find("\r\n\r\n")
|
||||||
|
if d2 then
|
||||||
|
|
||||||
|
_,d1,statusCode = rcvCache:find("%s(%d+)%s.-\r\n")
|
||||||
|
if not statusCode then
|
||||||
|
return response(client,cbFnc,false,"parse received status error",rspHead,rcvFilePath or table.concat(rspBody))
|
||||||
|
end
|
||||||
|
|
||||||
|
for k,v in string.gmatch(rcvCache:sub(d1+1,d2-2),"(.-):%s*(.-)\r\n") do
|
||||||
|
rspHead[k] = v
|
||||||
|
if (string.upper(k)==string.upper("Transfer-Encoding")) and (string.upper(v)==string.upper("chunked")) then rcvChunked = true end
|
||||||
|
end
|
||||||
|
if not rcvChunked then
|
||||||
|
contentLen = tonumber(rspHead["Content-Length"] or "2147483647")
|
||||||
|
end
|
||||||
|
if method == "HEAD" then
|
||||||
|
contentLen = 0
|
||||||
|
end
|
||||||
|
|
||||||
|
rcvCache = rcvCache:sub(d2+1,-1)
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
if rcvChunked then
|
||||||
|
local chunkSize
|
||||||
|
|
||||||
|
while true do
|
||||||
|
|
||||||
|
if not chunkSize then
|
||||||
|
d1,d2,chunkSize = rcvCache:find("(%x+)\r\n")
|
||||||
|
if chunkSize then
|
||||||
|
chunkSize = tonumber(chunkSize,16)
|
||||||
|
rcvCache = rcvCache:sub(d2+1,-1)
|
||||||
|
else
|
||||||
|
result,data = receive(client,timeout,cbFnc,false,nil,rspHead,rcvFilePath or table.concat(rspBody))
|
||||||
|
if not result then return end
|
||||||
|
rcvCache = rcvCache..data
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if chunkSize then
|
||||||
|
if rcvCache:len()<chunkSize+2 then
|
||||||
|
result,data = receive(client,timeout,cbFnc,false,nil,rspHead,rcvFilePath or table.concat(rspBody))
|
||||||
|
if not result then return end
|
||||||
|
rcvCache = rcvCache..data
|
||||||
|
else
|
||||||
|
if chunkSize>0 then
|
||||||
|
local chunkData = rcvCache:sub(1,chunkSize)
|
||||||
|
|
||||||
|
if type(rcvFilePath)=="string" then
|
||||||
|
local file = io.open(rcvFilePath,"a+")
|
||||||
|
if not file then return response(client,cbFnc,false,"receive: open file error",rspHead,rcvFilePath or table.concat(rspBody)) end
|
||||||
|
if not file:write(chunkData) then response(client,cbFnc,false,"receive: write file error",rspHead,rcvFilePath or table.concat(rspBody)) end
|
||||||
|
file:close()
|
||||||
|
elseif type(rcvFilePath)=="function" then
|
||||||
|
local userResult = rcvFilePath(data,rspHead["Content-Range"] and tonumber((rspHead["Content-Range"]):match("/(%d+)")) or contentLen,statusCode)
|
||||||
|
if userResult~=nil then
|
||||||
|
return response(client,cbFnc,userResult,userResult and statusCode or "receive: user process error",rspHead)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
table.insert(rspBody,chunkData)
|
||||||
|
end
|
||||||
|
rcvCache = rcvCache:sub(chunkSize+3,-1)
|
||||||
|
chunkSize = nil
|
||||||
|
elseif chunkSize==0 then
|
||||||
|
return response(client,cbFnc,true,statusCode,rspHead,rcvFilePath or table.concat(rspBody))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
local rmnLen = contentLen
|
||||||
|
while true do
|
||||||
|
data = rcvCache:len()<=rmnLen and rcvCache or rcvCache:sub(1,rmnLen)
|
||||||
|
if type(rcvFilePath)=="string" then
|
||||||
|
if data:len()>0 then
|
||||||
|
local file = io.open(rcvFilePath,"a+")
|
||||||
|
if not file then return response(client,cbFnc,false,"receive: open file error",rspHead,rcvFilePath or table.concat(rspBody)) end
|
||||||
|
if not file:write(data) then response(client,cbFnc,false,"receive: write file error",rspHead,rcvFilePath or table.concat(rspBody)) end
|
||||||
|
file:close()
|
||||||
|
end
|
||||||
|
elseif type(rcvFilePath)=="function" then
|
||||||
|
local userResult = rcvFilePath(data,rspHead["Content-Range"] and tonumber((rspHead["Content-Range"]):match("/(%d+)")) or contentLen,statusCode)
|
||||||
|
if userResult~=nil then
|
||||||
|
return response(client,cbFnc,userResult,userResult and statusCode or "receive: user process error",rspHead)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
table.insert(rspBody,data)
|
||||||
|
end
|
||||||
|
rmnLen = rmnLen-data:len()
|
||||||
|
if rmnLen==0 then break end
|
||||||
|
result,rcvCache = receive(client,timeout,cbFnc,contentLen==0x7FFFFFFF,contentLen==0x7FFFFFFF and statusCode or nil,rspHead,rcvFilePath or table.concat(rspBody))
|
||||||
|
if not result then return end
|
||||||
|
end
|
||||||
|
return response(client,cbFnc,true,statusCode,rspHead,rcvFilePath or table.concat(rspBody))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function request(method,url,cert,head,body,timeout,cbFnc,rcvFileName,tCoreExtPara)
|
||||||
|
local protocal,auth,hostName,port,path,d1,d2,offset,rcvFilePath
|
||||||
|
d1,d2,protocal = url:find("^(%a+)://")
|
||||||
|
if not protocal then protocal = "http" end
|
||||||
|
offset = d2 or 0
|
||||||
|
|
||||||
|
d1,d2,auth = url:find("(.-:.-)@",offset+1)
|
||||||
|
offset = d2 or offset
|
||||||
|
|
||||||
|
if url:match("^[^/]+:(%d+)",offset+1) then
|
||||||
|
d1,d2,hostName,port = url:find("^([^/]+):(%d+)",offset+1)
|
||||||
|
else
|
||||||
|
d1,d2,hostName = url:find("(.-)/",offset+1)
|
||||||
|
if hostName then
|
||||||
|
d2 = d2-1
|
||||||
|
else
|
||||||
|
hostName = url:sub(offset+1,-1)
|
||||||
|
offset = url:len()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if not hostName then return response(nil,cbFnc,false,"Invalid url, can't get host") end
|
||||||
|
if port=="" or not port then port = (protocal=="https" and 443 or 80) end
|
||||||
|
offset = d2 or offset
|
||||||
|
|
||||||
|
path = url:sub(offset+1,-1)
|
||||||
|
|
||||||
|
sys.taskInit(taskClient,method,protocal,auth or "",hostName,port,path=="" and "/" or path,cert,head,body or "",timeout or 30000,cbFnc,rcvFileName,tCoreExtPara)
|
||||||
|
if type(rcvFileName) == "string" then
|
||||||
|
return rcvFileName
|
||||||
|
end
|
||||||
|
end
|
||||||
461
4G/tools/_temp/script/temp_script/link.lua
Normal file
461
4G/tools/_temp/script/temp_script/link.lua
Normal file
@@ -0,0 +1,461 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
require "net"
|
||||||
|
|
||||||
|
module(..., package.seeall)
|
||||||
|
|
||||||
|
local publish = sys.publish
|
||||||
|
local request = ril.request
|
||||||
|
local ipAddr = ""
|
||||||
|
local gprsAttached
|
||||||
|
local cid_manual = 5
|
||||||
|
local readyTable = {false, false, false}
|
||||||
|
|
||||||
|
|
||||||
|
CELLULAR = 1
|
||||||
|
|
||||||
|
CH395 = 2
|
||||||
|
|
||||||
|
W5500 = 3
|
||||||
|
|
||||||
|
ESP8266 = 4
|
||||||
|
local network = CELLULAR
|
||||||
|
|
||||||
|
function setReady(mode, state)
|
||||||
|
readyTable[mode] = state
|
||||||
|
end
|
||||||
|
function getIp()
|
||||||
|
return ipAddr
|
||||||
|
end
|
||||||
|
function isReady()
|
||||||
|
return readyTable[network]
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
local apnname, username, password
|
||||||
|
local dnsIP
|
||||||
|
local authProt, authApn, authUser, authPassword
|
||||||
|
|
||||||
|
function setAPN(apn, user, pwd)
|
||||||
|
apnname, username, password = apn, user, pwd
|
||||||
|
end
|
||||||
|
|
||||||
|
function setDnsIP(ip1, ip2)
|
||||||
|
dnsIP = "\"" .. (ip1 or "") .. "\",\"" .. (ip2 or "") .. "\""
|
||||||
|
end
|
||||||
|
|
||||||
|
local function setCgdf()
|
||||||
|
request("AT+AUTOAPN=0")
|
||||||
|
request('AT*CGDFLT=1,"IP","' .. authApn .. '",,,,,,,,,,,,,,,,,,1')
|
||||||
|
request('AT*CGDFAUTH=1,' .. authProt .. ',"' .. authUser .. '","' .. authPassword .. '"', nil, function(cmd, result)
|
||||||
|
if result then
|
||||||
|
sys.restart("CGDFAUTH")
|
||||||
|
else
|
||||||
|
sys.timerStart(setCgdf, 5000)
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function setAuthApn(prot, apn, user, pwd)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
request('AT+CPNETAPN=2,"' .. apn .. '","' .. user .. '","' .. pwd .. '",' .. prot)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
local function Pdp_Act()
|
||||||
|
log.info("link.Pdp_Act", readyTable[CELLULAR], net.getNetMode(), gprsAttached)
|
||||||
|
if readyTable[CELLULAR] then
|
||||||
|
request("AT+CGDCONT?", nil, cgdcontRsp)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
if net.getNetMode() == net.NetMode_LTE then
|
||||||
|
if not gprsAttached then
|
||||||
|
gprsAttached = true
|
||||||
|
sys.publish("GPRS_ATTACH", true)
|
||||||
|
end
|
||||||
|
if not apnname then
|
||||||
|
sys.timerStart(pdpCmdCnf, 1000, "SET_PDP_4G_WAITAPN", true)
|
||||||
|
else
|
||||||
|
request("AT+CGDCONT?", nil, cgdcontRsp)
|
||||||
|
|
||||||
|
end
|
||||||
|
else
|
||||||
|
request('AT+CGATT?')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function procshut(curCmd, result, respdata, interdata)
|
||||||
|
if network ~= CELLULAR then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
if IsCidActived(cid_manual, interdata) then
|
||||||
|
ril.request(string.format('AT+CGACT=0,%d', cid_manual), nil, function(cmd, result)
|
||||||
|
if result then
|
||||||
|
readyTable[CELLULAR] = false
|
||||||
|
sys.publish('IP_ERROR_IND')
|
||||||
|
|
||||||
|
if net.getState() ~= 'REGISTERED' then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
sys.timerStart(Pdp_Act, 2000)
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
else
|
||||||
|
readyTable[CELLULAR] = false
|
||||||
|
sys.publish('IP_ERROR_IND')
|
||||||
|
|
||||||
|
if net.getState() ~= 'REGISTERED' then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
sys.timerStart(Pdp_Act, 2000)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function shut()
|
||||||
|
if network ~= CELLULAR then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
readyTable[CELLULAR] = false
|
||||||
|
sys.publish('IP_ERROR_IND')
|
||||||
|
|
||||||
|
if net.getState() ~= 'REGISTERED' then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
sys.timerStart(Pdp_Act, 2000)
|
||||||
|
end
|
||||||
|
|
||||||
|
function analysis_cgdcont(data)
|
||||||
|
local tmp, loc, result
|
||||||
|
while data do
|
||||||
|
_, loc = string.find(data, "\r\n")
|
||||||
|
if loc then
|
||||||
|
tmp = string.sub(data, 1, loc)
|
||||||
|
data = string.sub(data, loc + 1, -1)
|
||||||
|
log.info("analysis_cgdcont ", tmp, loc, data)
|
||||||
|
else
|
||||||
|
tmp = data
|
||||||
|
data = nil
|
||||||
|
log.info("analysis_cgdcont end", tmp, loc, data)
|
||||||
|
end
|
||||||
|
if tmp then
|
||||||
|
local cid, pdptyp, apn, addr = string.match(tmp, "(%d+),(.+),(.+),[\"\'](.+)[\"\']")
|
||||||
|
if not cid or not pdptyp or not apn or not addr then
|
||||||
|
log.info("analysis_cgdcont CGDCONT is empty")
|
||||||
|
ipAddr = ""
|
||||||
|
result = false
|
||||||
|
else
|
||||||
|
log.info("analysis_cgdcont ", cid, pdptyp, apn, addr)
|
||||||
|
if addr:match("%d+%.%d+%.%d+%.%d") then
|
||||||
|
ipAddr = addr
|
||||||
|
return true
|
||||||
|
else
|
||||||
|
log.info("analysis_cgdcont CGDCONT is empty1")
|
||||||
|
ipAddr = ""
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
ipAddr = ""
|
||||||
|
log.info("analysis_cgdcont tmp is empty")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return result
|
||||||
|
end
|
||||||
|
|
||||||
|
function IsCidActived(cid, data)
|
||||||
|
if not data then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
for k, v in string.gfind(data, "(%d+),%s*(%d)") do
|
||||||
|
log.info("iscidactived ", k, v)
|
||||||
|
if cid == tonumber(k) and v == '1' then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
function IsExistActivedCid(data)
|
||||||
|
if not data then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
for k, v in string.gfind(data, "(%d+),%s*(%d)") do
|
||||||
|
if v == '1' then
|
||||||
|
log.info("ExistActivedCid ", k, v)
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local cgdcontResult
|
||||||
|
|
||||||
|
function cgdcontRsp()
|
||||||
|
if cgdcontResult then
|
||||||
|
pdpCmdCnf("CONNECT_DELAY", true)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function pdpCmdCnf(curCmd, result, respdata, interdata)
|
||||||
|
log.info("link.pdpCmdCnf", curCmd, result, respdata, interdata)
|
||||||
|
if string.find(curCmd, "CGDCONT%?") then
|
||||||
|
if result and interdata then
|
||||||
|
result = analysis_cgdcont(interdata)
|
||||||
|
else
|
||||||
|
result = false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if result then
|
||||||
|
cgdcontResult = false
|
||||||
|
if string.find(curCmd, "CGDCONT=") then
|
||||||
|
request(string.format('AT+CGACT=1,%d', cid_manual), nil, pdpCmdCnf)
|
||||||
|
elseif string.find(curCmd, "CGDCONT%?") then
|
||||||
|
|
||||||
|
cgdcontResult = true
|
||||||
|
elseif string.find(curCmd, "CONNECT_DELAY") and network == CELLULAR then
|
||||||
|
log.info("publish IP_READY_IND")
|
||||||
|
readyTable[CELLULAR] = true
|
||||||
|
publish("IP_READY_IND")
|
||||||
|
elseif string.find(curCmd, "CGACT=") then
|
||||||
|
request("AT+CGDCONT?", nil, cgdcontRsp)
|
||||||
|
elseif string.find(curCmd, "CGACT%?") then
|
||||||
|
if IsExistActivedCid(interdata) then
|
||||||
|
sys.timerStart(pdpCmdCnf, 100, "CONNECT_DELAY", true)
|
||||||
|
else
|
||||||
|
request(string.format('AT+CGDCONT=%d,"IP","%s"', cid_manual, authApn or apnname), nil, pdpCmdCnf)
|
||||||
|
end
|
||||||
|
elseif string.find(curCmd, "CGDFLT") then
|
||||||
|
request("AT+CGDCONT?", nil, cgdcontRsp)
|
||||||
|
elseif string.find(curCmd, "SET_PDP_4G_WAITAPN") then
|
||||||
|
if not apnname then
|
||||||
|
sys.timerStart(pdpCmdCnf, 100, "SET_PDP_4G_WAITAPN", true)
|
||||||
|
else
|
||||||
|
request("AT+CGDCONT?", nil, cgdcontRsp, 1000)
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
if net.getState() ~= 'REGISTERED' then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
if net.getNetMode() == net.NetMode_LTE then
|
||||||
|
request("AT+CGDCONT?", nil, cgdcontRsp, 1000)
|
||||||
|
else
|
||||||
|
request("AT+CGATT?", nil, nil, 1000)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
sys.subscribe("IMSI_READY", function()
|
||||||
|
if not apnname then
|
||||||
|
local mcc, mnc = tonumber(sim.getMcc(), 16), tonumber(sim.getMnc(), 16)
|
||||||
|
apnname, username, password = apn and apn.get_default_apn(mcc, mnc)
|
||||||
|
if not apnname or apnname == '' or apnname == "CMNET" then
|
||||||
|
apnname = (mcc == 0x460 and (mnc == 0x01 or mnc == 0x06)) and 'UNINET' or 'CMIOT'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
username = username or ''
|
||||||
|
password = password or ''
|
||||||
|
end)
|
||||||
|
|
||||||
|
ril.regRsp('+CGATT', function(a, b, c, intermediate)
|
||||||
|
local attached = (intermediate == "+CGATT: 1")
|
||||||
|
if gprsAttached ~= attached then
|
||||||
|
gprsAttached = attached
|
||||||
|
sys.publish("GPRS_ATTACH", attached)
|
||||||
|
end
|
||||||
|
|
||||||
|
if readyTable[CELLULAR] then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
if attached then
|
||||||
|
log.info("pdp active", apnname, username, password)
|
||||||
|
request("AT+CGACT?", nil, pdpCmdCnf, 1000)
|
||||||
|
elseif net.getState() == 'REGISTERED' then
|
||||||
|
sys.timerStart(request, 2000, "AT+CGATT=1")
|
||||||
|
sys.timerStart(request, 2000, "AT+CGATT?")
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
rtos.on(rtos.MSG_PDP_DEACT_IND, function()
|
||||||
|
if network ~= CELLULAR then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
readyTable[CELLULAR] = false
|
||||||
|
sys.publish('IP_ERROR_IND')
|
||||||
|
|
||||||
|
if net.getState() ~= 'REGISTERED' then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
sys.timerStart(Pdp_Act, 2000)
|
||||||
|
end)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
sys.subscribe("NET_STATE_REGISTERED", Pdp_Act)
|
||||||
|
|
||||||
|
local function cindCnf(cmd, result)
|
||||||
|
if not result then
|
||||||
|
request("AT+CIND=1", nil, cindCnf, 1000)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function cgevurc(data)
|
||||||
|
if network ~= CELLULAR then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local cid = 0
|
||||||
|
log.info("link.cgevurc", data)
|
||||||
|
|
||||||
|
if string.match(data, "DEACT") then
|
||||||
|
cid = string.match(data, "DEACT,(%d)")
|
||||||
|
cid = tonumber(cid)
|
||||||
|
|
||||||
|
if cid == cid_manual then
|
||||||
|
request("AT+CFUN?")
|
||||||
|
readyTable[CELLULAR] = false
|
||||||
|
sys.publish('IP_ERROR_IND')
|
||||||
|
sys.publish('PDP_DEACT_IND')
|
||||||
|
if net.getState() ~= 'REGISTERED' then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
sys.timerStart(Pdp_Act, 2000)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
request("AT+CIND=1", nil, cindCnf)
|
||||||
|
ril.regUrc("*CGEV", cgevurc)
|
||||||
|
ril.regUrc("+CGDCONT", function(data)
|
||||||
|
pdpCmdCnf("AT+CGDCONT?", true, "OK", data)
|
||||||
|
end)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function openNetwork(mode, para)
|
||||||
|
local tSocketModule = {
|
||||||
|
[CH395] = socketCh395,
|
||||||
|
[W5500] = socketW5500,
|
||||||
|
[ESP8266] = socketESP8266
|
||||||
|
}
|
||||||
|
local md = mode or CELLULAR
|
||||||
|
closeNetWork()
|
||||||
|
network = md
|
||||||
|
if network == CELLULAR then
|
||||||
|
net.switchFly(false)
|
||||||
|
return true
|
||||||
|
else
|
||||||
|
ipAddr = tSocketModule[network].open(para)
|
||||||
|
if ipAddr ~= "" then
|
||||||
|
return true
|
||||||
|
else
|
||||||
|
log.info('link', 'open CH395 err')
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function closeNetWork()
|
||||||
|
local tSocketModule = {
|
||||||
|
[CH395] = socketCh395,
|
||||||
|
[W5500] = socketW5500,
|
||||||
|
[ESP8266] = socketESP8266
|
||||||
|
}
|
||||||
|
|
||||||
|
if network == CELLULAR then
|
||||||
|
|
||||||
|
net.switchFly(true)
|
||||||
|
return true
|
||||||
|
else
|
||||||
|
return tSocketModule[network].close()
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function getNetwork()
|
||||||
|
return network
|
||||||
|
end
|
||||||
83
4G/tools/_temp/script/temp_script/linksocket.lua
Normal file
83
4G/tools/_temp/script/temp_script/linksocket.lua
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
require "socket"
|
||||||
|
require "log"
|
||||||
|
|
||||||
|
|
||||||
|
local ip, port = "121.43.69.62", "8767"
|
||||||
|
|
||||||
|
local clientCount = 1
|
||||||
|
|
||||||
|
local clients = {}
|
||||||
|
|
||||||
|
|
||||||
|
for i = 1, clientCount do
|
||||||
|
local client = {
|
||||||
|
id = i,
|
||||||
|
socket = nil,
|
||||||
|
connected = false
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
sys.taskInit(function()
|
||||||
|
while true do
|
||||||
|
while not socket.isReady() do sys.wait(1000) end
|
||||||
|
client.socket = socket.tcp()
|
||||||
|
log.debug("Client " .. client.id .. ": Connecting to " .. ip .. ":" .. port)
|
||||||
|
while not client.socket:connect(ip, port) do
|
||||||
|
log.warn("Client " .. client.id .. ": Connection failed, retrying...")
|
||||||
|
sys.wait(2000)
|
||||||
|
end
|
||||||
|
client.connected = true
|
||||||
|
log.debug("Client " .. client.id .. ": Connected successfully")
|
||||||
|
|
||||||
|
uart.write(1, "Socket " .. client.id .. " connected\r\n")
|
||||||
|
|
||||||
|
|
||||||
|
while client.socket:asyncSelect(60, "ping") do end
|
||||||
|
|
||||||
|
client.connected = false
|
||||||
|
client.socket:close()
|
||||||
|
log.error("Client " .. client.id .. ": Disconnected")
|
||||||
|
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
|
||||||
|
clients[i] = client
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
local function toHexcode(str)
|
||||||
|
local hexcode = ""
|
||||||
|
for i = 1, #str do
|
||||||
|
hexcode = hexcode .. string.format("%02X", str:byte(i))
|
||||||
|
end
|
||||||
|
return hexcode
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
sys.subscribe("SOCKET_RECV", function(id)
|
||||||
|
|
||||||
|
for i, client in ipairs(clients) do
|
||||||
|
if client.socket and client.socket.id == id then
|
||||||
|
|
||||||
|
local data = client.socket:asyncRecv()
|
||||||
|
log.info("Client " .. client.id .. ": Received data: " .. toHexcode(data))
|
||||||
|
|
||||||
|
local frame = string.char(0x55) .. string.char(0xAA) .. string.char(0x01) .. string.char(i) .. string.char(#data) .. data .. string.char(0xAA) .. string.char(0x55)
|
||||||
|
uart.write(1, frame)
|
||||||
|
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function sendToSocket(id_byte, msg)
|
||||||
|
if clients[id_byte] and clients[id_byte].socket and clients[id_byte].connected then
|
||||||
|
clients[id_byte].socket:asyncSend(msg)
|
||||||
|
else
|
||||||
|
log.error("Socket " .. id_byte .. " not connected or does not exist")
|
||||||
|
end
|
||||||
|
end
|
||||||
123
4G/tools/_temp/script/temp_script/log.lua
Normal file
123
4G/tools/_temp/script/temp_script/log.lua
Normal file
@@ -0,0 +1,123 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
module(..., package.seeall)
|
||||||
|
|
||||||
|
|
||||||
|
LOG_SILENT = 0x00;
|
||||||
|
LOGLEVEL_TRACE = 0x01;
|
||||||
|
LOGLEVEL_DEBUG = 0x02;
|
||||||
|
LOGLEVEL_INFO = 0x03;
|
||||||
|
LOGLEVEL_WARN = 0x04;
|
||||||
|
LOGLEVEL_ERROR = 0x05;
|
||||||
|
LOGLEVEL_FATAL = 0x06;
|
||||||
|
|
||||||
|
|
||||||
|
local LEVEL_TAG = {'T', 'D', 'I', 'W', 'E', 'F'}
|
||||||
|
local PREFIX_FMT = "[%s]-[%s]"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
local function _log(level, tag, ...)
|
||||||
|
|
||||||
|
local OPENLEVEL = LOG_LEVEL and LOG_LEVEL or LOGLEVEL_INFO
|
||||||
|
|
||||||
|
if OPENLEVEL == LOG_SILENT or OPENLEVEL > level then return end
|
||||||
|
|
||||||
|
local prefix = string.format(PREFIX_FMT, LEVEL_TAG[level], type(tag)=="string" and tag or "")
|
||||||
|
print(prefix, ...)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function trace(tag, ...)
|
||||||
|
_log(LOGLEVEL_TRACE, tag, ...)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function debug(tag, ...)
|
||||||
|
_log(LOGLEVEL_DEBUG, tag, ...)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function info(tag, ...)
|
||||||
|
_log(LOGLEVEL_INFO, tag, ...)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function warn(tag, ...)
|
||||||
|
_log(LOGLEVEL_WARN, tag, ...)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function error(tag, ...)
|
||||||
|
_log(LOGLEVEL_ERROR, tag, ...)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function fatal(tag, ...)
|
||||||
|
_log(LOGLEVEL_FATAL, tag, ...)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function openTrace(v, uartid, baudrate)
|
||||||
|
rtos.set_trace(v and 1 or 0, uartid,baudrate)
|
||||||
|
end
|
||||||
65
4G/tools/_temp/script/temp_script/main.lua
Normal file
65
4G/tools/_temp/script/temp_script/main.lua
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
PROJECT = "4G_NETWORK"
|
||||||
|
VERSION = "1.0.0"
|
||||||
|
|
||||||
|
require "sys"
|
||||||
|
require "net"
|
||||||
|
require "log"
|
||||||
|
require "cmd"
|
||||||
|
require "uart"
|
||||||
|
require "linksocket"
|
||||||
|
|
||||||
|
|
||||||
|
uart.setup(1, 115200, 8, uart.PAR_NONE, uart.STOP_1)
|
||||||
|
|
||||||
|
|
||||||
|
require "netLed"
|
||||||
|
pmd.ldoset(2,pmd.LDO_VLCD)
|
||||||
|
netLed.setup(true,pio.P0_1,pio.P0_4)
|
||||||
|
|
||||||
|
local uartID = 1
|
||||||
|
|
||||||
|
|
||||||
|
local function toHexcode(str)
|
||||||
|
local hexcode = ""
|
||||||
|
for i = 1, #str do
|
||||||
|
hexcode = hexcode .. string.format("%02X", str:byte(i))
|
||||||
|
end
|
||||||
|
return hexcode
|
||||||
|
end
|
||||||
|
|
||||||
|
uart.on(uartID, "receive", function()
|
||||||
|
local data = uart.read(uartID, 300)
|
||||||
|
if data and type(data) == "string" and #data > 0 then
|
||||||
|
log.info("UART received:", toHexcode(data))
|
||||||
|
if data:byte(1) == 0x55 and data:byte(2) == 0xAA and data:byte(-2) == 0xAA and data:byte(-1) == 0x55 then
|
||||||
|
local Main_Cmd = data:byte(3)
|
||||||
|
local Sub_Cmd = data:byte(4)
|
||||||
|
local payload = data:sub(5, -3)
|
||||||
|
|
||||||
|
if Main_Cmd ==0x01 then
|
||||||
|
handleCmd01(Sub_Cmd, payload)
|
||||||
|
end
|
||||||
|
if Main_Cmd == 0x02 then
|
||||||
|
handleCmd02(Sub_Cmd, payload)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
log.warn("UART receive callback triggered but no valid data")
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
|
||||||
|
net.startQueryAll(8 * 1000, 60 * 1000)
|
||||||
|
|
||||||
|
ril.request("AT+RNDISCALL=0,1")
|
||||||
|
|
||||||
|
|
||||||
|
sys.init(0, 0)
|
||||||
|
sys.run()
|
||||||
787
4G/tools/_temp/script/temp_script/net.lua
Normal file
787
4G/tools/_temp/script/temp_script/net.lua
Normal file
@@ -0,0 +1,787 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
require "sys"
|
||||||
|
require "ril"
|
||||||
|
require "pio"
|
||||||
|
require "sim"
|
||||||
|
require "log"
|
||||||
|
require "utils"
|
||||||
|
module(..., package.seeall)
|
||||||
|
|
||||||
|
|
||||||
|
local publish = sys.publish
|
||||||
|
|
||||||
|
|
||||||
|
NetMode_noNet= 0
|
||||||
|
NetMode_GSM= 1
|
||||||
|
NetMode_EDGE= 2
|
||||||
|
NetMode_TD= 3
|
||||||
|
NetMode_LTE= 4
|
||||||
|
NetMode_WCDMA= 5
|
||||||
|
local netMode = NetMode_noNet
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
local state = "INIT"
|
||||||
|
|
||||||
|
local simerrsta
|
||||||
|
|
||||||
|
flyMode = false
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
local lac, ci, rssi, rsrp, band = "", "", 0, 0, ""
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
local cellinfo, multicellcb = {}
|
||||||
|
local curCellSeted
|
||||||
|
|
||||||
|
local function cops(data)
|
||||||
|
|
||||||
|
local fmt,oper = data:match('COPS:%s*%d+%s*,(%d+)%s*,"(%d+)"')
|
||||||
|
log.info("cops",fmt,oper,curCellSeted)
|
||||||
|
if fmt=="2" and not curCellSeted then
|
||||||
|
cellinfo[1].mcc = tonumber(oper:sub(1,3),16)
|
||||||
|
cellinfo[1].mnc = tonumber(oper:sub(4,5),16)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
local function creg(data)
|
||||||
|
local p1, s,act
|
||||||
|
local prefix = (netMode == NetMode_LTE) and "+CEREG: " or (netMode == NetMode_noNet and "+CREG: " or "+CGREG: ")
|
||||||
|
log.info("net.creg1",netMode,prefix)
|
||||||
|
if not data:match(prefix) then
|
||||||
|
|
||||||
|
if prefix=="+CREG: " then
|
||||||
|
|
||||||
|
prefix = "+CGREG: "
|
||||||
|
if not data:match("+CGREG: ") then
|
||||||
|
log.warn("net.creg1","no match",data)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
elseif prefix=="+CGREG: " then
|
||||||
|
|
||||||
|
prefix = "+CREG: "
|
||||||
|
if not data:match("+CREG: ") then
|
||||||
|
log.warn("net.creg2","no match",data)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
_, _, p1 = data:find(prefix .. "%d,(%d+)")
|
||||||
|
|
||||||
|
if p1 == nil then
|
||||||
|
_, _, p1 = data:find(prefix .. "(%d+)")
|
||||||
|
|
||||||
|
if p1 == nil then return end
|
||||||
|
act = data:match(prefix .. "%d+,.-,.-,(%d+)")
|
||||||
|
else
|
||||||
|
act = data:match(prefix .. "%d,%d+,.-,.-,(%d+)")
|
||||||
|
end
|
||||||
|
|
||||||
|
log.info("net.creg7",p1,act)
|
||||||
|
|
||||||
|
|
||||||
|
s = (p1=="1" or p1=="5") and "REGISTERED" or "UNREGISTER"
|
||||||
|
|
||||||
|
|
||||||
|
if prefix=="+CGREG: " and s=="UNREGISTER" then
|
||||||
|
log.info("net.creg9 ignore!!!")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
if s ~= state then
|
||||||
|
|
||||||
|
if s == "REGISTERED" then
|
||||||
|
|
||||||
|
publish("NET_STATE_REGISTERED")
|
||||||
|
cengQueryPoll()
|
||||||
|
end
|
||||||
|
state = s
|
||||||
|
end
|
||||||
|
|
||||||
|
if state == "REGISTERED" then
|
||||||
|
p2, p3 = data:match("\"(%x+)\",\"(%x+)\"")
|
||||||
|
if p2 and p3 and (lac ~= p2 or ci ~= p3) then
|
||||||
|
lac = p2
|
||||||
|
ci = p3
|
||||||
|
|
||||||
|
publish("NET_CELL_CHANGED")
|
||||||
|
|
||||||
|
|
||||||
|
cellinfo[1].lac = tonumber(lac,16)
|
||||||
|
cellinfo[1].ci = tonumber(ci,16)
|
||||||
|
cellinfo[1].rssi = 28
|
||||||
|
end
|
||||||
|
|
||||||
|
if act then
|
||||||
|
if act=="0" then
|
||||||
|
UpdNetMode("^MODE: 3,1")
|
||||||
|
elseif act=="1" then
|
||||||
|
UpdNetMode("^MODE: 3,2")
|
||||||
|
elseif act=="3" then
|
||||||
|
UpdNetMode("^MODE: 3,3")
|
||||||
|
elseif act=="7" then
|
||||||
|
UpdNetMode("^MODE: 17,17")
|
||||||
|
else
|
||||||
|
UpdNetMode("^MODE: 5,7")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
local function resetCellInfo()
|
||||||
|
local i
|
||||||
|
cellinfo.cnt = 11
|
||||||
|
for i = 1, cellinfo.cnt do
|
||||||
|
cellinfo[i] = {}
|
||||||
|
cellinfo[i].mcc, cellinfo[i].mnc = nil
|
||||||
|
cellinfo[i].lac = 0
|
||||||
|
cellinfo[i].ci = 0
|
||||||
|
cellinfo[i].rssi = 0
|
||||||
|
cellinfo[i].ta = 0
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
local function eemLteSvc(data)
|
||||||
|
local mcc,mnc,lac,ci,rssi,svcData
|
||||||
|
if data:match("%+EEMLTESVC:%s*%d+,%s*%d+,%s*%d+,%s*.+") then
|
||||||
|
svcData = string.match(data, "%+EEMLTESVC:(.+)")
|
||||||
|
|
||||||
|
if svcData then
|
||||||
|
svcDataT = string.split(svcData, ', ')
|
||||||
|
|
||||||
|
if not(svcDataT[1] and svcDataT[3] and svcDataT[4] and svcDataT[10] and svcDataT[15]) then
|
||||||
|
svcDataT = string.split(svcData, ',')
|
||||||
|
log.info("eemLteSvc2",svcDataT[1],svcDataT[3],svcDataT[4],svcDataT[10],svcDataT[15])
|
||||||
|
end
|
||||||
|
mcc = svcDataT[1]
|
||||||
|
mnc = svcDataT[3]
|
||||||
|
lac = svcDataT[4]
|
||||||
|
ci = svcDataT[10]
|
||||||
|
band = svcDataT[8]
|
||||||
|
rssi = (tonumber(svcDataT[15])-(tonumber(svcDataT[15])%3))/3
|
||||||
|
if rssi>31 then rssi=31 end
|
||||||
|
if rssi<0 then rssi=0 end
|
||||||
|
end
|
||||||
|
log.info("eemLteSvc1",lac,ci,mcc,mnc)
|
||||||
|
if lac and lac~="0" and ci and ci ~= "0" and mcc and mnc then
|
||||||
|
|
||||||
|
resetCellInfo()
|
||||||
|
curCellSeted = true
|
||||||
|
|
||||||
|
cellinfo[1].mcc = mcc
|
||||||
|
cellinfo[1].mnc = mnc
|
||||||
|
cellinfo[1].lac = tonumber(lac)
|
||||||
|
cellinfo[1].ci = tonumber(ci)
|
||||||
|
cellinfo[1].rssi = tonumber(rssi)
|
||||||
|
|
||||||
|
|
||||||
|
if multicellcb then multicellcb(cellinfo) end
|
||||||
|
publish("CELL_INFO_IND", cellinfo)
|
||||||
|
end
|
||||||
|
elseif data:match("%+EEMLTEINTER") or data:match("%+EEMLTEINTRA") or data:match("%+EEMLTEINTERRAT") then
|
||||||
|
|
||||||
|
|
||||||
|
data = data:gsub(" ","")
|
||||||
|
|
||||||
|
if data:match("%+EEMLTEINTERRAT") then
|
||||||
|
mcc,mnc,lac,ci,rssi = data:match("[-]*%d+,[-]*%d+,([-]*%d+),([-]*%d+),([-]*%d+),([-]*%d+),[-]*%d+,[-]*%d+,([-]*%d+)")
|
||||||
|
else
|
||||||
|
rssi,mcc,mnc,lac,ci = data:match("[-]*%d+,[-]*%d+,[-]*%d+,([-]*%d+),[-]*%d+,([-]*%d+),([-]*%d+),([-]*%d+),([-]*%d+)")
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if rssi then
|
||||||
|
rssi = (rssi-(rssi%3))/3
|
||||||
|
if rssi>31 then rssi=31 end
|
||||||
|
if rssi<0 then rssi=0 end
|
||||||
|
end
|
||||||
|
if lac~="0" and lac~="-1" and ci~="0" and ci~="-1" then
|
||||||
|
for i = 1, cellinfo.cnt do
|
||||||
|
|
||||||
|
if cellinfo[i].lac==0 then
|
||||||
|
cellinfo[i] =
|
||||||
|
{
|
||||||
|
mcc = mcc,
|
||||||
|
mnc = mnc,
|
||||||
|
lac = tonumber(lac),
|
||||||
|
ci = tonumber(ci),
|
||||||
|
rssi = tonumber(rssi)
|
||||||
|
}
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
local function eemGsmInfoSvc(data)
|
||||||
|
|
||||||
|
if string.find(data, "%+EEMGINFOSVC:%s*%d+,%s*%d+,%s*%d+,%s*.+") then
|
||||||
|
local mcc,mnc,lac,ci,ta,rssi
|
||||||
|
local svcData = string.match(data, "%+EEMGINFOSVC:(.+)")
|
||||||
|
if svcData then
|
||||||
|
svcDataT = string.split(svcData, ', ')
|
||||||
|
mcc = svcDataT[1]
|
||||||
|
mnc = svcDataT[2]
|
||||||
|
lac = svcDataT[3]
|
||||||
|
ci = svcDataT[4]
|
||||||
|
ta = svcDataT[10]
|
||||||
|
rssi = svcDataT[12]
|
||||||
|
if tonumber(rssi) >31
|
||||||
|
then rssi = 31
|
||||||
|
end
|
||||||
|
if tonumber(rssi) < 0
|
||||||
|
then rssi = 0
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if lac and lac~="0" and ci and ci ~= "0" and mcc and mnc then
|
||||||
|
|
||||||
|
resetCellInfo()
|
||||||
|
curCellSeted = true
|
||||||
|
|
||||||
|
cellinfo[1].mcc = mcc
|
||||||
|
cellinfo[1].mnc = mnc
|
||||||
|
cellinfo[1].lac = tonumber(lac)
|
||||||
|
cellinfo[1].ci = tonumber(ci)
|
||||||
|
cellinfo[1].rssi = (tonumber(rssi) == 99) and 0 or tonumber(rssi)
|
||||||
|
cellinfo[1].ta = tonumber(ta or "0")
|
||||||
|
|
||||||
|
if multicellcb then multicellcb(cellinfo) end
|
||||||
|
publish("CELL_INFO_IND", cellinfo)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
local function eemGsmNCInfoSvc(data)
|
||||||
|
if string.find(data, "%+EEMGINFONC: %d+, %d+, %d+, .+") then
|
||||||
|
local mcc,mnc,lac,ci,ta,rssi,id
|
||||||
|
local svcData = string.match(data, "%+EEMGINFONC:(.+)")
|
||||||
|
if svcData then
|
||||||
|
svcDataT = string.split(svcData, ', ')
|
||||||
|
id = svcDataT[1]
|
||||||
|
mcc = svcDataT[2]
|
||||||
|
mnc = svcDataT[3]
|
||||||
|
lac = svcDataT[4]
|
||||||
|
ci = svcDataT[6]
|
||||||
|
rssi = svcDataT[7]
|
||||||
|
if tonumber(rssi) >31
|
||||||
|
then rssi = 31
|
||||||
|
end
|
||||||
|
if tonumber(rssi) < 0
|
||||||
|
then rssi = 0
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if lac and ci and mcc and mnc then
|
||||||
|
|
||||||
|
cellinfo[id + 2].mcc = mcc
|
||||||
|
cellinfo[id + 2].mnc = mnc
|
||||||
|
cellinfo[id + 2].lac = tonumber(lac)
|
||||||
|
cellinfo[id + 2].ci = tonumber(ci)
|
||||||
|
cellinfo[id + 2].rssi = (tonumber(rssi) == 99) and 0 or tonumber(rssi)
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
local function eemUMTSInfoSvc(data)
|
||||||
|
|
||||||
|
if string.find(data, "%+EEMUMTSSVC: %d+, %d+, %d+, .+") then
|
||||||
|
local mcc,mnc,lac,ci,rssi
|
||||||
|
local svcData = string.match(data, "%+EEMUMTSSVC:(.+)")
|
||||||
|
local cellMeasureFlag, cellParamFlag = string.match(data, "%+EEMUMTSSVC:%d+, (%d+), (%d+), .+")
|
||||||
|
local svcDataT = string.split(svcData, ', ')
|
||||||
|
local offset = 4
|
||||||
|
if svcData and svcDataT then
|
||||||
|
if tonumber(cellMeasureFlag) ~= 0 then
|
||||||
|
offset = offset + 2
|
||||||
|
rssi = svcDataT[offset]
|
||||||
|
offset = offset + 4
|
||||||
|
else
|
||||||
|
offset = offset + 2
|
||||||
|
rssi = svcDataT[offset]
|
||||||
|
offset = offset + 2
|
||||||
|
end
|
||||||
|
|
||||||
|
if tonumber(cellParamFlag) ~= 0 then
|
||||||
|
offset = offset + 3
|
||||||
|
mcc = svcDataT[offset]
|
||||||
|
mnc = svcDataT[offset + 1]
|
||||||
|
lac = svcDataT[offset + 2]
|
||||||
|
ci = svcDataT[offset + 3]
|
||||||
|
offset = offset + 3
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if lac and lac~="0" and ci and ci ~= "0" and mcc and mnc and rssi then
|
||||||
|
|
||||||
|
resetCellInfo()
|
||||||
|
curCellSeted = true
|
||||||
|
|
||||||
|
cellinfo[1].mcc = mcc
|
||||||
|
cellinfo[1].mnc = mnc
|
||||||
|
cellinfo[1].lac = tonumber(lac)
|
||||||
|
cellinfo[1].ci = tonumber(ci)
|
||||||
|
cellinfo[1].rssi = tonumber(rssi)
|
||||||
|
|
||||||
|
if multicellcb then multicellcb(cellinfo) end
|
||||||
|
publish("CELL_INFO_IND", cellinfo)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function UpdNetMode(data)
|
||||||
|
local _, _, SysMainMode,SysMode = string.find(data, "(%d+),(%d+)")
|
||||||
|
local netMode_cur
|
||||||
|
log.info("net.UpdNetMode",netMode_cur,netMode, SysMainMode,SysMode)
|
||||||
|
if SysMainMode and SysMode then
|
||||||
|
if SysMainMode=="3" then
|
||||||
|
netMode_cur = NetMode_GSM
|
||||||
|
elseif SysMainMode=="5" then
|
||||||
|
netMode_cur = NetMode_WCDMA
|
||||||
|
elseif SysMainMode=="15" then
|
||||||
|
netMode_cur = NetMode_TD
|
||||||
|
elseif SysMainMode=="17" then
|
||||||
|
netMode_cur = NetMode_LTE
|
||||||
|
else
|
||||||
|
netMode_cur = NetMode_noNet
|
||||||
|
end
|
||||||
|
|
||||||
|
if SysMode=="3" then
|
||||||
|
netMode_cur = NetMode_EDGE
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if netMode ~= netMode_cur then
|
||||||
|
netMode = netMode_cur
|
||||||
|
publish("NET_UPD_NET_MODE",netMode)
|
||||||
|
log.info("net.NET_UPD_NET_MODE",netMode)
|
||||||
|
ril.request("AT+COPS?")
|
||||||
|
if netMode == NetMode_LTE then
|
||||||
|
ril.request("AT+CEREG?")
|
||||||
|
elseif netMode == NetMode_noNet then
|
||||||
|
ril.request("AT+CREG?")
|
||||||
|
else
|
||||||
|
ril.request("AT+CGREG?")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
local function neturc(data, prefix)
|
||||||
|
if prefix=="+COPS" then
|
||||||
|
cops(data)
|
||||||
|
elseif prefix == "+CREG" or prefix == "+CGREG" or prefix == "+CEREG" then
|
||||||
|
|
||||||
|
csqQueryPoll()
|
||||||
|
|
||||||
|
creg(data)
|
||||||
|
elseif prefix == "+EEMLTESVC" or prefix == "+EEMLTEINTRA" or prefix == "+EEMLTEINTER" or prefix=="+EEMLTEINTERRAT" then
|
||||||
|
eemLteSvc(data)
|
||||||
|
elseif prefix == "+EEMUMTSSVC" then
|
||||||
|
eemUMTSInfoSvc(data)
|
||||||
|
elseif prefix == "+EEMGINFOSVC" then
|
||||||
|
eemGsmInfoSvc(data)
|
||||||
|
elseif prefix == "+EEMGINFONC" then
|
||||||
|
eemGsmNCInfoSvc(data)
|
||||||
|
elseif prefix == "^MODE" then
|
||||||
|
UpdNetMode(data)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function switchFly(mode)
|
||||||
|
if flyMode == mode then return end
|
||||||
|
flyMode = mode
|
||||||
|
|
||||||
|
if mode then
|
||||||
|
ril.request("AT+CFUN=0")
|
||||||
|
|
||||||
|
else
|
||||||
|
ril.request("AT+CFUN=1")
|
||||||
|
|
||||||
|
csqQueryPoll()
|
||||||
|
cengQueryPoll()
|
||||||
|
|
||||||
|
neturc("2", "+CREG")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function getNetMode()
|
||||||
|
return netMode
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function getState()
|
||||||
|
return state
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function getMcc()
|
||||||
|
return cellinfo[1].mcc and string.format("%x",cellinfo[1].mcc) or sim.getMcc()
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function getMnc()
|
||||||
|
return cellinfo[1].mnc and string.format("%x",cellinfo[1].mnc) or sim.getMnc()
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function getLac()
|
||||||
|
return lac
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function getBand()
|
||||||
|
return band
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function getCi()
|
||||||
|
return ci
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function getRssi()
|
||||||
|
return rssi
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function getRsrp()
|
||||||
|
return rsrp
|
||||||
|
end
|
||||||
|
|
||||||
|
function getCell()
|
||||||
|
local i,ret = 1,""
|
||||||
|
for i=1,cellinfo.cnt do
|
||||||
|
if cellinfo[i] and cellinfo[i].lac and cellinfo[i].lac ~= 0 and cellinfo[i].ci and cellinfo[i].ci ~= 0 then
|
||||||
|
ret = ret..cellinfo[i].ci.."."..cellinfo[i].rssi.."."
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return ret
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function getCellInfo()
|
||||||
|
local i, ret = 1, ""
|
||||||
|
for i = 1, cellinfo.cnt do
|
||||||
|
if cellinfo[i] and cellinfo[i].lac and cellinfo[i].lac ~= 0 and cellinfo[i].ci and cellinfo[i].ci ~= 0 then
|
||||||
|
ret = ret .. cellinfo[i].lac .. "." .. cellinfo[i].ci .. "." .. cellinfo[i].rssi .. ";"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return ret
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function getCellInfoExt(rssi)
|
||||||
|
local i, ret = 1, ""
|
||||||
|
for i = 1, cellinfo.cnt do
|
||||||
|
if cellinfo[i] and cellinfo[i].mcc and cellinfo[i].mnc and cellinfo[i].lac and cellinfo[i].lac ~= 0 and cellinfo[i].ci and cellinfo[i].ci ~= 0 then
|
||||||
|
ret = ret .. string.format("%x",cellinfo[i].mcc) .. "." .. string.format("%x",cellinfo[i].mnc) .. "." .. cellinfo[i].lac .. "." .. cellinfo[i].ci .. "." .. (rssi and (cellinfo[i].rssi*2-113) or cellinfo[i].rssi) .. ";"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return ret
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function getTa()
|
||||||
|
return cellinfo[1].ta
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
local function rsp(cmd, success, response, intermediate)
|
||||||
|
local prefix = string.match(cmd, "AT(%+%u+)")
|
||||||
|
|
||||||
|
if intermediate ~= nil then
|
||||||
|
if prefix == "+CSQ" then
|
||||||
|
local s = string.match(intermediate, "+CSQ:%s*(%d+)")
|
||||||
|
if s ~= nil then
|
||||||
|
rssi = tonumber(s)
|
||||||
|
rssi = rssi == 99 and 0 or rssi
|
||||||
|
|
||||||
|
publish("GSM_SIGNAL_REPORT_IND", success, rssi)
|
||||||
|
end
|
||||||
|
elseif prefix == "+CESQ" then
|
||||||
|
local s = string.match(intermediate, "+CESQ: %d+,%d+,%d+,%d+,%d+,(%d+)")
|
||||||
|
if s ~= nil then
|
||||||
|
rsrp = tonumber(s)
|
||||||
|
end
|
||||||
|
elseif prefix == "+CENG" then end
|
||||||
|
end
|
||||||
|
if prefix == "+CFUN" then
|
||||||
|
if success then publish("FLYMODE", flyMode) end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function getMultiCell(cbFnc)
|
||||||
|
multicellcb = cbFnc
|
||||||
|
|
||||||
|
ril.request("AT+EEMGINFO?")
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function cengQueryPoll(period)
|
||||||
|
|
||||||
|
if not flyMode then
|
||||||
|
|
||||||
|
ril.request("AT+EEMGINFO?")
|
||||||
|
else
|
||||||
|
log.warn("net.cengQueryPoll", "flymode:", flyMode)
|
||||||
|
end
|
||||||
|
if nil ~= period then
|
||||||
|
|
||||||
|
sys.timerStopAll(cengQueryPoll)
|
||||||
|
sys.timerStart(cengQueryPoll, period, period)
|
||||||
|
end
|
||||||
|
return not flyMode
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function csqQueryPoll(period)
|
||||||
|
|
||||||
|
if not flyMode then
|
||||||
|
|
||||||
|
ril.request("AT+CSQ")
|
||||||
|
ril.request("AT+CESQ")
|
||||||
|
else
|
||||||
|
log.warn("net.csqQueryPoll", "flymode:", flyMode)
|
||||||
|
end
|
||||||
|
if nil ~= period then
|
||||||
|
|
||||||
|
sys.timerStopAll(csqQueryPoll)
|
||||||
|
sys.timerStart(csqQueryPoll, period, period)
|
||||||
|
end
|
||||||
|
return not flyMode
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function startQueryAll(...)
|
||||||
|
local arg = { ... }
|
||||||
|
csqQueryPoll(arg[1])
|
||||||
|
cengQueryPoll(arg[2])
|
||||||
|
if flyMode then
|
||||||
|
log.info("sim.startQuerAll", "flyMode:", flyMode)
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function stopQueryAll()
|
||||||
|
sys.timerStopAll(csqQueryPoll)
|
||||||
|
sys.timerStopAll(cengQueryPoll)
|
||||||
|
end
|
||||||
|
|
||||||
|
local sEngMode
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function setEngMode(mode)
|
||||||
|
sEngMode = mode or 1
|
||||||
|
ril.request("AT+EEMOPT="..sEngMode,nil,function(cmd,success)
|
||||||
|
function retrySetEngMode()
|
||||||
|
setEngMode(sEngMode)
|
||||||
|
end
|
||||||
|
if success then
|
||||||
|
sys.timerStop(retrySetEngMode)
|
||||||
|
else
|
||||||
|
sys.timerStart(retrySetEngMode,3000)
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
sys.subscribe("SIM_IND", function(para)
|
||||||
|
log.info("SIM.subscribe", simerrsta, para)
|
||||||
|
if simerrsta ~= (para ~= "RDY") then
|
||||||
|
simerrsta = (para ~= "RDY")
|
||||||
|
end
|
||||||
|
|
||||||
|
if para ~= "RDY" then
|
||||||
|
|
||||||
|
state = "UNREGISTER"
|
||||||
|
|
||||||
|
publish("NET_STATE_UNREGISTER")
|
||||||
|
else
|
||||||
|
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
|
||||||
|
ril.regUrc("+COPS", neturc)
|
||||||
|
ril.regUrc("+CREG", neturc)
|
||||||
|
ril.regUrc("+CGREG", neturc)
|
||||||
|
ril.regUrc("+CEREG", neturc)
|
||||||
|
|
||||||
|
ril.regUrc("+EEMLTESVC", neturc)
|
||||||
|
ril.regUrc("+EEMLTEINTER", neturc)
|
||||||
|
ril.regUrc("+EEMLTEINTRA", neturc)
|
||||||
|
ril.regUrc("+EEMLTEINTERRAT", neturc)
|
||||||
|
ril.regUrc("+EEMGINFOSVC", neturc)
|
||||||
|
ril.regUrc("+EEMGINFONC", neturc)
|
||||||
|
ril.regUrc("+EEMUMTSSVC", neturc)
|
||||||
|
ril.regUrc("^MODE", neturc)
|
||||||
|
|
||||||
|
|
||||||
|
ril.regRsp("+CSQ", rsp)
|
||||||
|
ril.regRsp("+CESQ",rsp)
|
||||||
|
|
||||||
|
ril.regRsp("+CFUN", rsp)
|
||||||
|
|
||||||
|
ril.request("AT+COPS?")
|
||||||
|
ril.request("AT+CREG=2")
|
||||||
|
ril.request("AT+CGREG=2")
|
||||||
|
ril.request("AT+CEREG=2")
|
||||||
|
ril.request("AT+CREG?")
|
||||||
|
ril.request("AT+CGREG?")
|
||||||
|
ril.request("AT+CEREG?")
|
||||||
|
ril.request("AT+CALIBINFO?")
|
||||||
|
ril.request("AT*BAND?")
|
||||||
|
setEngMode(1)
|
||||||
|
|
||||||
|
resetCellInfo()
|
||||||
183
4G/tools/_temp/script/temp_script/netLed.lua
Normal file
183
4G/tools/_temp/script/temp_script/netLed.lua
Normal file
@@ -0,0 +1,183 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
module(..., package.seeall)
|
||||||
|
|
||||||
|
require "pins"
|
||||||
|
require "sim"
|
||||||
|
|
||||||
|
|
||||||
|
local simError
|
||||||
|
|
||||||
|
local flyMode
|
||||||
|
|
||||||
|
local gsmRegistered
|
||||||
|
|
||||||
|
local gprsAttached
|
||||||
|
|
||||||
|
local socketConnected
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
local ledState = "NULL"
|
||||||
|
local ON,OFF = 1,2
|
||||||
|
|
||||||
|
local ledBlinkTime =
|
||||||
|
{
|
||||||
|
NULL = {0,0xFFFF},
|
||||||
|
FLYMODE = {0,0xFFFF},
|
||||||
|
SIMERR = {300,5700},
|
||||||
|
IDLE = {300,3700},
|
||||||
|
GSM = {300,1700},
|
||||||
|
GPRS = {300,700},
|
||||||
|
SCK = {100,100},
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
local ledSwitch = false
|
||||||
|
|
||||||
|
local LEDPIN = pio.P2_0
|
||||||
|
|
||||||
|
local lteSwitch = false
|
||||||
|
|
||||||
|
local LTEPIN = pio.P2_1
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
local function updateState()
|
||||||
|
|
||||||
|
if ledSwitch then
|
||||||
|
local newState = "IDLE"
|
||||||
|
if flyMode then
|
||||||
|
newState = "FLYMODE"
|
||||||
|
elseif simError then
|
||||||
|
newState = "SIMERR"
|
||||||
|
elseif socketConnected then
|
||||||
|
newState = "SCK"
|
||||||
|
elseif gprsAttached then
|
||||||
|
newState = "GPRS"
|
||||||
|
elseif gsmRegistered then
|
||||||
|
newState = "GSM"
|
||||||
|
end
|
||||||
|
|
||||||
|
if newState~=ledState then
|
||||||
|
ledState = newState
|
||||||
|
sys.publish("NET_LED_UPDATE")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
local function taskLed(ledPinSetFunc)
|
||||||
|
while true do
|
||||||
|
|
||||||
|
if ledSwitch then
|
||||||
|
local onTime,offTime = ledBlinkTime[ledState][ON],ledBlinkTime[ledState][OFF]
|
||||||
|
if onTime>0 then
|
||||||
|
ledPinSetFunc(1)
|
||||||
|
if not sys.waitUntil("NET_LED_UPDATE", onTime) then
|
||||||
|
if offTime>0 then
|
||||||
|
ledPinSetFunc(0)
|
||||||
|
sys.waitUntil("NET_LED_UPDATE", offTime)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else if offTime>0 then
|
||||||
|
ledPinSetFunc(0)
|
||||||
|
sys.waitUntil("NET_LED_UPDATE", offTime)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
ledPinSetFunc(0)
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
local function taskLte(ledPinSetFunc)
|
||||||
|
while true do
|
||||||
|
local _,arg = sys.waitUntil("LTE_LED_UPDATE")
|
||||||
|
if lteSwitch then
|
||||||
|
ledPinSetFunc(arg and 1 or 0)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function setup(flag,ledPin,ltePin)
|
||||||
|
|
||||||
|
local oldSwitch = ledSwitch
|
||||||
|
if flag~=ledSwitch then
|
||||||
|
ledSwitch = flag
|
||||||
|
sys.publish("NET_LED_UPDATE")
|
||||||
|
end
|
||||||
|
if flag and not oldSwitch then
|
||||||
|
sys.taskInit(taskLed, pins.setup(ledPin or LEDPIN, 0))
|
||||||
|
end
|
||||||
|
if flag~=lteSwitch then
|
||||||
|
lteSwitch = flag
|
||||||
|
end
|
||||||
|
if flag and ltePin and not oldSwitch then
|
||||||
|
sys.taskInit(taskLte, pins.setup(ltePin, 0))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function updateBlinkTime(state,on,off)
|
||||||
|
if not ledBlinkTime[state] then log.error("netLed.updateBlinkTime") return end
|
||||||
|
local updated
|
||||||
|
if on and ledBlinkTime[state][ON]~=on then
|
||||||
|
ledBlinkTime[state][ON] = on
|
||||||
|
updated = true
|
||||||
|
end
|
||||||
|
if off and ledBlinkTime[state][OFF]~=off then
|
||||||
|
ledBlinkTime[state][OFF] = off
|
||||||
|
updated = true
|
||||||
|
end
|
||||||
|
|
||||||
|
if updated then sys.publish("NET_LED_UPDATE") end
|
||||||
|
end
|
||||||
|
|
||||||
|
sys.subscribe("FLYMODE", function(mode) if flyMode~=mode then flyMode=mode updateState() end end)
|
||||||
|
sys.subscribe("SIM_IND", function(para) if simError~=(para~="RDY") then simError=(para~="RDY") updateState() end end)
|
||||||
|
sys.subscribe("NET_STATE_UNREGISTER", function() if gsmRegistered then gsmRegistered=false updateState() end end)
|
||||||
|
sys.subscribe("NET_STATE_REGISTERED", function() if not gsmRegistered then gsmRegistered=true updateState() end end)
|
||||||
|
sys.subscribe("GPRS_ATTACH", function(attach) if gprsAttached~=attach then gprsAttached=attach updateState() end end)
|
||||||
|
sys.subscribe("SOCKET_ACTIVE", function(active) if socketConnected~=active then socketConnected=active updateState() end end)
|
||||||
|
sys.subscribe("NET_UPD_NET_MODE", function() if lteSwitch then sys.publish("LTE_LED_UPDATE",net.getNetMode()==net.NetMode_LTE) end end)
|
||||||
184
4G/tools/_temp/script/temp_script/patch.lua
Normal file
184
4G/tools/_temp/script/temp_script/patch.lua
Normal file
@@ -0,0 +1,184 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
require"pm"
|
||||||
|
module(..., package.seeall)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
local oldostime = os.time
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function safeostime(t)
|
||||||
|
return oldostime(t) or 0
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
os.time = safeostime
|
||||||
|
|
||||||
|
|
||||||
|
local oldosdate = os.date
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function safeosdate(s, t)
|
||||||
|
if s == "*t" then
|
||||||
|
return oldosdate(s, t) or {year = 2012,
|
||||||
|
month = 12,
|
||||||
|
day = 11,
|
||||||
|
hour = 10,
|
||||||
|
min = 9,
|
||||||
|
sec = 0}
|
||||||
|
else
|
||||||
|
return oldosdate(s, t)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
os.date = safeosdate
|
||||||
|
|
||||||
|
|
||||||
|
local rawcoresume = coroutine.resume
|
||||||
|
coroutine.resume = function(...)
|
||||||
|
local arg = { ... }
|
||||||
|
function wrapper(co,...)
|
||||||
|
local arg = { ... }
|
||||||
|
if not arg[1] then
|
||||||
|
local traceBack = debug.traceback(co) or "empty"
|
||||||
|
traceBack = (traceBack and traceBack~="") and ((arg[2] or "").."\r\n"..traceBack) or (arg[2] or "")
|
||||||
|
log.error("coroutine.resume",traceBack)
|
||||||
|
if errDump and type(errDump.appendErr)=="function" then
|
||||||
|
errDump.appendErr(traceBack)
|
||||||
|
end
|
||||||
|
if _G.COROUTINE_ERROR_RESTART then rtos.restart() end
|
||||||
|
end
|
||||||
|
return unpack(arg)
|
||||||
|
end
|
||||||
|
return wrapper(arg[1],rawcoresume(...))
|
||||||
|
end
|
||||||
|
|
||||||
|
os.clockms = function() return rtos.tick()/16 end
|
||||||
|
|
||||||
|
|
||||||
|
if json and json.decode then oldjsondecode = json.decode end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
local function safeJsonDecode(s)
|
||||||
|
local result, info = pcall(oldjsondecode, s)
|
||||||
|
if result then
|
||||||
|
return info, true
|
||||||
|
else
|
||||||
|
return {}, false, info
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
if json and json.decode then json.decode = safeJsonDecode end
|
||||||
|
|
||||||
|
local oldUartWrite = uart.write
|
||||||
|
uart.write = function(...)
|
||||||
|
pm.wake("lib.patch.uart.write")
|
||||||
|
local result = oldUartWrite(...)
|
||||||
|
pm.sleep("lib.patch.uart.write")
|
||||||
|
return result
|
||||||
|
end
|
||||||
|
|
||||||
|
if i2c and i2c.write then
|
||||||
|
local oldI2cWrite = i2c.write
|
||||||
|
i2c.write = function(...)
|
||||||
|
pm.wake("lib.patch.i2c.write")
|
||||||
|
local result = oldI2cWrite(...)
|
||||||
|
pm.sleep("lib.patch.i2c.write")
|
||||||
|
return result
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if i2c and i2c.send then
|
||||||
|
local oldI2cSend = i2c.send
|
||||||
|
i2c.send = function(...)
|
||||||
|
pm.wake("lib.patch.i2c.send")
|
||||||
|
local result = oldI2cSend(...)
|
||||||
|
pm.sleep("lib.patch.i2c.send")
|
||||||
|
return result
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if spi and spi.send then
|
||||||
|
oldSpiSend = spi.send
|
||||||
|
spi.send = function(...)
|
||||||
|
pm.wake("lib.patch.spi.send")
|
||||||
|
local result = oldSpiSend(...)
|
||||||
|
pm.sleep("lib.patch.spi.send")
|
||||||
|
return result
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if spi and spi.send_recv then
|
||||||
|
oldSpiSendRecv = spi.send_recv
|
||||||
|
spi.send_recv = function(...)
|
||||||
|
pm.wake("lib.patch.spi.send_recv")
|
||||||
|
local result = oldSpiSendRecv(...)
|
||||||
|
pm.sleep("lib.patch.spi.send_recv")
|
||||||
|
return result
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if disp and disp.sleep then
|
||||||
|
oldDispSleep = disp.sleep
|
||||||
|
disp.sleep = function(...)
|
||||||
|
pm.wake("lib.patch.disp.sleep")
|
||||||
|
oldDispSleep(...)
|
||||||
|
pm.sleep("lib.patch.disp.sleep")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if io and io.mount then
|
||||||
|
oldIoMount = io.mount
|
||||||
|
io.mount = function (...)
|
||||||
|
pm.wake("lib.patch.io.mount")
|
||||||
|
local result = oldIoMount(...)
|
||||||
|
pm.sleep("lib.patch.io.mount")
|
||||||
|
return result
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
local pmdInited
|
||||||
|
|
||||||
|
if pmd and pmd.init then
|
||||||
|
oldPmdInit = pmd.init
|
||||||
|
pmd.init = function (...)
|
||||||
|
if not pmdInited then pmdInited = true end
|
||||||
|
local result = oldPmdInit(...)
|
||||||
|
return result
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
pmd.libScriptInit = function()
|
||||||
|
if not pmdInited then pmd.init({}) end
|
||||||
|
end
|
||||||
150
4G/tools/_temp/script/temp_script/pins.lua
Normal file
150
4G/tools/_temp/script/temp_script/pins.lua
Normal file
@@ -0,0 +1,150 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
require "sys"
|
||||||
|
module(..., package.seeall)
|
||||||
|
local interruptCallbacks = {}
|
||||||
|
local dirs = {}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function setup(pin, val, pull)
|
||||||
|
|
||||||
|
pio.pin.close(pin)
|
||||||
|
|
||||||
|
if type(val) == "function" then
|
||||||
|
pio.pin.setdir(pio.INT, pin)
|
||||||
|
if pull then pio.pin.setpull(pull or pio.PULLUP, pin) end
|
||||||
|
|
||||||
|
interruptCallbacks[pin] = val
|
||||||
|
dirs[pin] = false
|
||||||
|
return function()
|
||||||
|
return pio.pin.getval(pin)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if val ~= nil then
|
||||||
|
dirs[pin] = true
|
||||||
|
pio.pin.setdir(val == 1 and pio.OUTPUT1 or pio.OUTPUT, pin)
|
||||||
|
else
|
||||||
|
|
||||||
|
dirs[pin] = false
|
||||||
|
pio.pin.setdir(pio.INPUT, pin)
|
||||||
|
if pull then pio.pin.setpull(pull or pio.PULLUP, pin) end
|
||||||
|
end
|
||||||
|
|
||||||
|
return function(val)
|
||||||
|
val = tonumber(val)
|
||||||
|
if (not val and dirs[pin]) or (val and not dirs[pin]) then
|
||||||
|
pio.pin.close(pin)
|
||||||
|
pio.pin.setdir(val and (val == 1 and pio.OUTPUT1 or pio.OUTPUT) or pio.INPUT, pin)
|
||||||
|
if not val and pull then pio.pin.setpull(pull or pio.PULLUP, pin) end
|
||||||
|
dirs[pin] = val and true or false
|
||||||
|
return val or pio.pin.getval(pin)
|
||||||
|
end
|
||||||
|
if val then
|
||||||
|
pio.pin.setval(val, pin)
|
||||||
|
return val
|
||||||
|
else
|
||||||
|
return pio.pin.getval(pin)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function close(pin)
|
||||||
|
pio.pin.close(pin)
|
||||||
|
end
|
||||||
|
|
||||||
|
rtos.on(rtos.MSG_INT, function(msg)
|
||||||
|
if interruptCallbacks[msg.int_resnum] == nil then
|
||||||
|
log.warn('pins.rtos.on', 'warning:rtos.MSG_INT callback nil', msg.int_resnum)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
interruptCallbacks[msg.int_resnum](msg.int_id)
|
||||||
|
end)
|
||||||
|
|
||||||
|
|
||||||
|
IOMUX_GPIO0 = 0
|
||||||
|
IOMUX_GPIO1 = 1
|
||||||
|
IOMUX_GPIO2 = 2
|
||||||
|
IOMUX_GPIO3 = 3
|
||||||
|
IOMUX_GPIO4 = 4
|
||||||
|
IOMUX_GPIO5 = 5
|
||||||
|
|
||||||
|
IOMUX_GPIO8 = 8
|
||||||
|
IOMUX_GPIO9 = 9
|
||||||
|
IOMUX_GPIO10 = 10
|
||||||
|
|
||||||
|
IOMUX_GPIO11 = 11
|
||||||
|
IOMUX_GPIO12 = 12
|
||||||
|
IOMUX_GPIO13 = 13
|
||||||
|
IOMUX_GPIO14 = 14
|
||||||
|
IOMUX_GPIO15 = 15
|
||||||
|
IOMUX_GPIO18 = 18
|
||||||
|
IOMUX_GPIO19 = 19
|
||||||
|
IOMUX_GPIO20 = 20
|
||||||
|
|
||||||
|
IOMUX_GPIO21 = 21
|
||||||
|
IOMUX_GPIO22 = 22
|
||||||
|
IOMUX_GPIO23 = 23
|
||||||
|
IOMUX_GPIO29 = 29
|
||||||
|
IOMUX_GPIO30 = 30
|
||||||
|
|
||||||
|
IOMUX_GPIO31 = 31
|
||||||
|
|
||||||
|
IOMUX_USART_1 = 57
|
||||||
|
IOMUX_USART_2 = 58
|
||||||
|
IOMUX_USART_3 = 59
|
||||||
|
|
||||||
|
IOMUX_I2C_2 = 67
|
||||||
|
IOMUX_I2C_3 = 68
|
||||||
65
4G/tools/_temp/script/temp_script/pm.lua
Normal file
65
4G/tools/_temp/script/temp_script/pm.lua
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
module(..., package.seeall)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
local tags = {}
|
||||||
|
|
||||||
|
local flag = true
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function wake(tag)
|
||||||
|
assert(tag and tag ~= nil, "pm.wake tag invalid")
|
||||||
|
|
||||||
|
tags[tag] = 1
|
||||||
|
|
||||||
|
if flag == true then
|
||||||
|
|
||||||
|
flag = false
|
||||||
|
|
||||||
|
pmd.sleep(0)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function sleep(tag)
|
||||||
|
assert(tag and tag ~= nil, "pm.sleep tag invalid")
|
||||||
|
|
||||||
|
tags[tag] = 0
|
||||||
|
|
||||||
|
for k, v in pairs(tags) do
|
||||||
|
if v > 0 then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
flag = true
|
||||||
|
|
||||||
|
pmd.sleep(1)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function isSleep(tag)
|
||||||
|
return tag and tags[tag] ~= 1 or flag
|
||||||
|
end
|
||||||
554
4G/tools/_temp/script/temp_script/ril.lua
Normal file
554
4G/tools/_temp/script/temp_script/ril.lua
Normal file
@@ -0,0 +1,554 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
require "uart"
|
||||||
|
require "rtos"
|
||||||
|
require "sys"
|
||||||
|
require "log"
|
||||||
|
module(..., package.seeall)
|
||||||
|
|
||||||
|
|
||||||
|
local vwrite = uart.write
|
||||||
|
local vread = uart.read
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
local transparentmode
|
||||||
|
|
||||||
|
local rcvfunc
|
||||||
|
|
||||||
|
|
||||||
|
local TIMEOUT = 60000*3
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
local NORESULT, NUMBERIC, SLINE, MLINE, STRING, SPECIAL = 0, 1, 2, 3, 4, 10
|
||||||
|
|
||||||
|
|
||||||
|
local RILCMD = {
|
||||||
|
["+CSQ"] = 2,
|
||||||
|
["+CESQ"] = 2,
|
||||||
|
["+CGMM"] = 2,
|
||||||
|
["+RFTEMPERATURE"] =2,
|
||||||
|
["+MUID"] = 2,
|
||||||
|
["+CGSN"] = 1,
|
||||||
|
["+WISN"] = 4,
|
||||||
|
["+CIMI"] = 1,
|
||||||
|
["+ICCID"] = 2,
|
||||||
|
["+SIMCROSS"] = 2,
|
||||||
|
["+CGATT"] = 2,
|
||||||
|
["+CCLK"] = 2,
|
||||||
|
['+CNUM'] = 3,
|
||||||
|
|
||||||
|
["+CMGR"] = 3,
|
||||||
|
["+CMGS"] = 2,
|
||||||
|
["+CPBF"] = 3,
|
||||||
|
["+CPBR"] = 3,
|
||||||
|
['+CLCC'] = 3,
|
||||||
|
["+CTFSGETID"] = 2,
|
||||||
|
["+CTFSDECRYPT"] = 2,
|
||||||
|
["+CTFSAUTH"] = 2,
|
||||||
|
["+CGDATA"] = 10,
|
||||||
|
["+CIND"] = 2,
|
||||||
|
|
||||||
|
["+CGACT"] = 3,
|
||||||
|
["+CALIBINFO"] = 4,
|
||||||
|
["*CALINFO"] = 3,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
local radioready, delaying = false
|
||||||
|
|
||||||
|
|
||||||
|
local cmdqueue = {
|
||||||
|
"ATE0",
|
||||||
|
"AT+CMEE=0",
|
||||||
|
}
|
||||||
|
|
||||||
|
local currcmd, currarg, currsp, curdelay, cmdhead, cmdtype, rspformt
|
||||||
|
|
||||||
|
local result, interdata, respdata
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
local function atimeout()
|
||||||
|
|
||||||
|
sys.restart("ril.atimeout_" .. (currcmd or ""))
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
local function defrsp(cmd, success, response, intermediate)
|
||||||
|
log.info("ril.defrsp", cmd, success, response, intermediate)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
local rsptable = {}
|
||||||
|
setmetatable(rsptable, {__index = function() return defrsp end})
|
||||||
|
|
||||||
|
|
||||||
|
local formtab = {}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function regRsp(head, fnc, typ, formt)
|
||||||
|
|
||||||
|
if typ == nil then
|
||||||
|
rsptable[head] = fnc
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
if typ == 0 or typ == 1 or typ == 2 or typ == 3 or typ == 4 or typ == 10 then
|
||||||
|
|
||||||
|
if RILCMD[head] and RILCMD[head] ~= typ then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
RILCMD[head] = typ
|
||||||
|
rsptable[head] = fnc
|
||||||
|
formtab[head] = formt
|
||||||
|
return true
|
||||||
|
else
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
local app_rilcb=nil
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function setrilcb(cb)
|
||||||
|
app_rilcb =cb
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
local function rsp()
|
||||||
|
|
||||||
|
sys.timerStopAll(atimeout)
|
||||||
|
|
||||||
|
if currsp then
|
||||||
|
currsp(currcmd, result, respdata, interdata)
|
||||||
|
|
||||||
|
else
|
||||||
|
rsptable[cmdhead](currcmd, result, respdata, interdata)
|
||||||
|
end
|
||||||
|
|
||||||
|
currcmd, currarg, currsp, curdelay, cmdhead, cmdtype, rspformt = nil
|
||||||
|
result, interdata, respdata = nil
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
local function defurc(data)
|
||||||
|
log.info("ril.defurc", data)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
local urctable = {}
|
||||||
|
setmetatable(urctable, {__index = function() return defurc end})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function regUrc(prefix, handler)
|
||||||
|
urctable[prefix] = handler
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function deRegUrc(prefix)
|
||||||
|
urctable[prefix] = nil
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
local urcfilter
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
local function urc(data)
|
||||||
|
|
||||||
|
if data == "RDY" then
|
||||||
|
radioready = true
|
||||||
|
else
|
||||||
|
local prefix = string.match(data, "([%+%^%*]*[%u%d& ]+)")
|
||||||
|
|
||||||
|
urcfilter = urctable[prefix](data, prefix)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
local function procatc(data)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if interdata and cmdtype == MLINE then
|
||||||
|
|
||||||
|
if data ~= "OK\r\n" then
|
||||||
|
|
||||||
|
if string.find(data, "\r\n", -2) then
|
||||||
|
data = string.sub(data, 1, -3)
|
||||||
|
end
|
||||||
|
|
||||||
|
interdata = interdata .. "\r\n" .. data
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if urcfilter then
|
||||||
|
data, urcfilter = urcfilter(data)
|
||||||
|
end
|
||||||
|
|
||||||
|
if string.find(data, "\r\n", -2) then
|
||||||
|
data = string.sub(data, 1, -3)
|
||||||
|
end
|
||||||
|
|
||||||
|
if data == "" then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
if data:match("^%+EEMLTEINTER") or data:match("^%+EEMLTEINTRA") or data:match("^%+EEMUMTSINTER") or data:match("^%+EEMUMTSINTRA") then
|
||||||
|
|
||||||
|
else
|
||||||
|
log.info("ril.proatc", data)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
if currcmd == nil then
|
||||||
|
urc(data)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local isurc = false
|
||||||
|
|
||||||
|
|
||||||
|
if data:match("^%+CMS ERROR:") or data:match("^%+CME ERROR:") then
|
||||||
|
data = "ERROR"
|
||||||
|
end
|
||||||
|
|
||||||
|
if data == "OK" or data == "SHUT OK" then
|
||||||
|
result = true
|
||||||
|
respdata = data
|
||||||
|
|
||||||
|
elseif data == "ERROR" or data == "NO ANSWER" or data == "NO DIALTONE" then
|
||||||
|
result = false
|
||||||
|
respdata = data
|
||||||
|
|
||||||
|
elseif data == "> " then
|
||||||
|
|
||||||
|
if cmdhead == "+CMGS" then
|
||||||
|
log.info("ril.procatc.send", currarg)
|
||||||
|
vwrite(uart.ATC, currarg, "\026")
|
||||||
|
else
|
||||||
|
log.error("error promot cmd:", currcmd)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
|
||||||
|
if cmdtype == NORESULT then
|
||||||
|
isurc = true
|
||||||
|
|
||||||
|
elseif cmdtype == NUMBERIC then
|
||||||
|
local numstr = data:match("(%x+)")
|
||||||
|
if numstr == data then
|
||||||
|
interdata = data
|
||||||
|
else
|
||||||
|
isurc = true
|
||||||
|
end
|
||||||
|
|
||||||
|
elseif cmdtype == STRING then
|
||||||
|
|
||||||
|
if data:match(rspformt or "^.+$") and not data:match("^%+CPIN:") then
|
||||||
|
interdata = data
|
||||||
|
else
|
||||||
|
isurc = true
|
||||||
|
end
|
||||||
|
elseif cmdtype == SLINE or cmdtype == MLINE then
|
||||||
|
if interdata == nil and string.find(data, cmdhead) == 1 then
|
||||||
|
interdata = data
|
||||||
|
else
|
||||||
|
isurc = true
|
||||||
|
end
|
||||||
|
|
||||||
|
elseif cmdhead == "+CGDATA" then
|
||||||
|
if string.find(data, "CONNECT") == 1 then
|
||||||
|
result = true
|
||||||
|
respdata = data
|
||||||
|
else
|
||||||
|
isurc = true
|
||||||
|
end
|
||||||
|
else
|
||||||
|
isurc = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if isurc then
|
||||||
|
urc(data)
|
||||||
|
|
||||||
|
elseif result ~= nil then
|
||||||
|
rsp()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
local readat = false
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
local function getcmd(item)
|
||||||
|
local cmd, arg, rsp, delay
|
||||||
|
|
||||||
|
if type(item) == "string" then
|
||||||
|
|
||||||
|
cmd = item
|
||||||
|
|
||||||
|
elseif type(item) == "table" then
|
||||||
|
|
||||||
|
cmd = item.cmd
|
||||||
|
|
||||||
|
arg = item.arg
|
||||||
|
|
||||||
|
rsp = item.rsp
|
||||||
|
|
||||||
|
delay = item.delay
|
||||||
|
else
|
||||||
|
log.info("ril.getcmd", "getpack unknown item")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local head = string.match(cmd, "AT([%+%*%^]*%u+)")
|
||||||
|
|
||||||
|
if head == nil then
|
||||||
|
log.error("ril.getcmd", "request error cmd:", cmd)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
if head == "+CMGS" or head == "+CIPSEND" then
|
||||||
|
if arg == nil or arg == "" then
|
||||||
|
log.error("ril.getcmd", "request error no arg", head)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
currcmd = cmd
|
||||||
|
currarg = arg
|
||||||
|
currsp = rsp
|
||||||
|
curdelay = delay
|
||||||
|
cmdhead = head
|
||||||
|
cmdtype = RILCMD[head] or NORESULT
|
||||||
|
rspformt = formtab[head]
|
||||||
|
|
||||||
|
return currcmd
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
local function sendat()
|
||||||
|
|
||||||
|
if not radioready or readat or currcmd ~= nil or delaying then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local item
|
||||||
|
|
||||||
|
while true do
|
||||||
|
|
||||||
|
if #cmdqueue == 0 then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
item = table.remove(cmdqueue, 1)
|
||||||
|
|
||||||
|
getcmd(item)
|
||||||
|
|
||||||
|
if curdelay then
|
||||||
|
|
||||||
|
sys.timerStart(delayfunc, curdelay)
|
||||||
|
|
||||||
|
currcmd, currarg, currsp, curdelay, cmdhead, cmdtype, rspformt = nil
|
||||||
|
item.delay = nil
|
||||||
|
|
||||||
|
delaying = true
|
||||||
|
|
||||||
|
table.insert(cmdqueue, 1, item)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
if currcmd ~= nil then
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
sys.timerStart(atimeout, TIMEOUT)
|
||||||
|
|
||||||
|
log.info("ril.sendat", currcmd)
|
||||||
|
|
||||||
|
if currcmd:match("^AT%+POC=") then
|
||||||
|
vwrite(uart.ATC, currcmd .. "\r\n")
|
||||||
|
else
|
||||||
|
vwrite(uart.ATC, currcmd .. "\r")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function delayfunc()
|
||||||
|
|
||||||
|
delaying = nil
|
||||||
|
|
||||||
|
sendat()
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
local function atcreader()
|
||||||
|
local s
|
||||||
|
|
||||||
|
if not transparentmode then readat = true end
|
||||||
|
|
||||||
|
while true do
|
||||||
|
|
||||||
|
s = vread(uart.ATC, "*l", 0)
|
||||||
|
if string.len(s) ~= 0 then
|
||||||
|
if transparentmode then
|
||||||
|
|
||||||
|
rcvfunc(s)
|
||||||
|
else
|
||||||
|
|
||||||
|
procatc(s)
|
||||||
|
|
||||||
|
if app_rilcb ~=nil then app_rilcb(s) end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if not transparentmode then
|
||||||
|
readat = false
|
||||||
|
|
||||||
|
sendat()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function request(cmd, arg, onrsp, delay)
|
||||||
|
if transparentmode then return end
|
||||||
|
|
||||||
|
if arg or onrsp or delay or formt then
|
||||||
|
table.insert(cmdqueue, {cmd = cmd, arg = arg, rsp = onrsp, delay = delay})
|
||||||
|
else
|
||||||
|
table.insert(cmdqueue, cmd)
|
||||||
|
end
|
||||||
|
|
||||||
|
sendat()
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function setransparentmode(fnc)
|
||||||
|
transparentmode, rcvfunc = true, fnc
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function sendtransparentdata(data)
|
||||||
|
if not transparentmode then return end
|
||||||
|
vwrite(uart.ATC, data)
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
uart.on(uart.ATC, "receive", atcreader)
|
||||||
184
4G/tools/_temp/script/temp_script/sim.lua
Normal file
184
4G/tools/_temp/script/temp_script/sim.lua
Normal file
@@ -0,0 +1,184 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
require "ril"
|
||||||
|
require "sys"
|
||||||
|
module(..., package.seeall)
|
||||||
|
|
||||||
|
local req = ril.request
|
||||||
|
|
||||||
|
local imsi, iccid, status
|
||||||
|
local sNumber,bQueryNumber = ""
|
||||||
|
local simCross,setSimCrossCbFnc
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function getIccid()
|
||||||
|
return iccid
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function getImsi()
|
||||||
|
return imsi
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function getMcc()
|
||||||
|
return (imsi ~= nil and imsi ~= "") and string.sub(imsi, 1, 3) or ""
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function getMnc()
|
||||||
|
return (imsi ~= nil and imsi ~= "") and string.sub(imsi, 4, 5) or ""
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function getStatus()
|
||||||
|
return status
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function setQueryNumber(flag)
|
||||||
|
bQueryNumber = flag
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function getNumber()
|
||||||
|
return sNumber or ""
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
local function rsp(cmd, success, response, intermediate)
|
||||||
|
if cmd == "AT+ICCID" then
|
||||||
|
if intermediate then
|
||||||
|
iccid = string.match(intermediate, "%+ICCID: (.+)")
|
||||||
|
end
|
||||||
|
elseif cmd == "AT+SIMCROSS?" then
|
||||||
|
if success then
|
||||||
|
simCross = tonumber(intermediate:match("%+SIMCROSS:%s*(%d)"))
|
||||||
|
end
|
||||||
|
if setSimCrossCbFnc then setSimCrossCbFnc(success) end
|
||||||
|
elseif cmd:match("AT%+SIMCROSS=") then
|
||||||
|
if success then
|
||||||
|
req("AT+SIMCROSS?")
|
||||||
|
else
|
||||||
|
if setSimCrossCbFnc then setSimCrossCbFnc(false) end
|
||||||
|
end
|
||||||
|
elseif cmd == "AT+CIMI" then
|
||||||
|
imsi = intermediate
|
||||||
|
|
||||||
|
sys.publish("IMSI_READY")
|
||||||
|
elseif cmd == "AT+CNUM" then
|
||||||
|
if success then
|
||||||
|
if intermediate then sNumber = intermediate:match("%+CNUM:%s*\".-\",\"[%+]*(%d+)\",") end
|
||||||
|
else
|
||||||
|
sys.timerStart(ril.request,5000,"AT+CNUM")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
local function urc(data, prefix)
|
||||||
|
|
||||||
|
if prefix == "+CPIN" then
|
||||||
|
status = false
|
||||||
|
|
||||||
|
if data == "+CPIN: READY" then
|
||||||
|
status = true
|
||||||
|
ril.request("AT+ICCID")
|
||||||
|
ril.request("AT+CIMI")
|
||||||
|
if bQueryNumber then ril.request("AT+CNUM") end
|
||||||
|
sys.publish("SIM_IND", "RDY")
|
||||||
|
|
||||||
|
elseif data == "+CPIN: NOT INSERTED" then
|
||||||
|
sys.publish("SIM_IND", "NIST")
|
||||||
|
else
|
||||||
|
|
||||||
|
if data == "+CPIN: SIM PIN" then
|
||||||
|
sys.publish("SIM_IND","SIM_PIN")
|
||||||
|
end
|
||||||
|
sys.publish("SIM_IND", "NORDY")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function set2gSim()
|
||||||
|
ril.request("AT+MEDCR=0,8,1")
|
||||||
|
ril.request("AT+MEDCR=0,17,240")
|
||||||
|
ril.request("AT+MEDCR=0,19,1")
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function setId(id,cbFnc)
|
||||||
|
if id ~= simCross then
|
||||||
|
setSimCrossCbFnc = cbFnc
|
||||||
|
ril.request("AT+SIMCROSS="..id)
|
||||||
|
else
|
||||||
|
if cbFnc then cbFnc(true) end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function getId()
|
||||||
|
return simCross
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
ril.regRsp("+ICCID", rsp)
|
||||||
|
|
||||||
|
ril.regRsp("+CIMI", rsp)
|
||||||
|
ril.regRsp("+CNUM", rsp)
|
||||||
|
ril.regRsp("+SIMCROSS", rsp)
|
||||||
|
|
||||||
|
ril.regUrc("+CPIN", urc)
|
||||||
|
ril.request("AT+SIMCROSS?")
|
||||||
121
4G/tools/_temp/script/temp_script/socket.lua
Normal file
121
4G/tools/_temp/script/temp_script/socket.lua
Normal file
@@ -0,0 +1,121 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
require "socket4G"
|
||||||
|
module(..., package.seeall)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
socket.isReady = link.isReady
|
||||||
|
local tSocketModule = nil
|
||||||
|
local function init()
|
||||||
|
tSocketModule = tSocketModule or {
|
||||||
|
[link.CELLULAR] = socket4G,
|
||||||
|
[link.CH395] = socketCh395,
|
||||||
|
[link.W5500] = socketW5500,
|
||||||
|
[link.ESP8266] = socketESP8266
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function tcp(ssl, cert, tCoreExtPara, ipv6)
|
||||||
|
init()
|
||||||
|
return tSocketModule[link.getNetwork()].tcp(ssl, cert, tCoreExtPara, ipv6)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function udp(ipv6)
|
||||||
|
init()
|
||||||
|
return tSocketModule[link.getNetwork()].udp(ipv6)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function setTcpResendPara(retryCnt, retryMaxTimeout)
|
||||||
|
init()
|
||||||
|
return tSocketModule[link.getNetwork()].setTcpResendPara(retryCnt, retryMaxTimeout)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function setDnsParsePara(retryCnt, retryTimeoutMulti)
|
||||||
|
init()
|
||||||
|
return tSocketModule[link.getNetwork()].setDnsParsePara(retryCnt, retryTimeoutMulti)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function printStatus()
|
||||||
|
init()
|
||||||
|
return tSocketModule[link.getNetwork()].printStatus()
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function setLowPower(tm)
|
||||||
|
init()
|
||||||
|
return tSocketModule[link.getNetwork()].setLowPower(tm)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function setIpStatis(interval)
|
||||||
|
init()
|
||||||
|
return tSocketModule[link.getNetwork()].setIpStatis(interval or 0)
|
||||||
|
end
|
||||||
680
4G/tools/_temp/script/temp_script/socket4G.lua
Normal file
680
4G/tools/_temp/script/temp_script/socket4G.lua
Normal file
@@ -0,0 +1,680 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
require "link"
|
||||||
|
require "utils"
|
||||||
|
module(..., package.seeall)
|
||||||
|
|
||||||
|
local sockets = {}
|
||||||
|
|
||||||
|
local SENDSIZE = 11200
|
||||||
|
|
||||||
|
local INDEX_MAX = 256
|
||||||
|
|
||||||
|
local socketsConnected = 0
|
||||||
|
|
||||||
|
|
||||||
|
local ipStatisInterval, ipDataFlow = 0,0
|
||||||
|
|
||||||
|
local function ipDataFlowAdd(flow)
|
||||||
|
if ipStatisInterval~=0 then
|
||||||
|
ipDataFlow = ipDataFlow+flow
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
local function errorInd(error)
|
||||||
|
local coSuspended = {}
|
||||||
|
|
||||||
|
for _, c in pairs(sockets) do
|
||||||
|
c.error = error
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if c.co and coroutine.status(c.co) == "suspended" then
|
||||||
|
|
||||||
|
table.insert(coSuspended, c.co)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
for k, v in pairs(coSuspended) do
|
||||||
|
if v and coroutine.status(v) == "suspended" then
|
||||||
|
coroutine.resume(v, false, error)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
sys.subscribe("IP_ERROR_IND", function()errorInd('IP_ERROR_IND') end)
|
||||||
|
|
||||||
|
|
||||||
|
local mt = {}
|
||||||
|
mt.__index = mt
|
||||||
|
local function socket(protocol, cert, tCoreExtPara,ipv6)
|
||||||
|
local ssl = protocol:match("SSL")
|
||||||
|
local co = coroutine.running()
|
||||||
|
if not co then
|
||||||
|
log.warn("socket.socket: socket must be called in coroutine")
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
|
local o = {
|
||||||
|
id = nil,
|
||||||
|
protocol = protocol,
|
||||||
|
tCoreExtPara = tCoreExtPara,
|
||||||
|
ssl = ssl,
|
||||||
|
cert = cert,
|
||||||
|
co = co,
|
||||||
|
input = {},
|
||||||
|
output = {},
|
||||||
|
wait = "",
|
||||||
|
connected = false,
|
||||||
|
iSubscribe = false,
|
||||||
|
subMessage = nil,
|
||||||
|
isBlock = false,
|
||||||
|
msg = nil,
|
||||||
|
rcvProcFnc = nil,
|
||||||
|
ipv6 = ipv6,
|
||||||
|
}
|
||||||
|
return setmetatable(o, mt)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function tcp(ssl, cert, tCoreExtPara, ipv6)
|
||||||
|
return socket("TCP" .. (ssl == true and "SSL" or ""), (ssl == true) and cert or nil, tCoreExtPara, ipv6)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function udp(ipv6)
|
||||||
|
return socket("UDP", nil, nil, ipv6)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function mt:connect(address, port, timeout)
|
||||||
|
assert(self.co == coroutine.running(), "socket:connect: coroutine mismatch")
|
||||||
|
|
||||||
|
if not link.isReady() then
|
||||||
|
log.info("socket.connect: ip not ready")
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
if self.protocol=="TCP" then
|
||||||
|
ipDataFlowAdd(120)
|
||||||
|
elseif self.protocol=="TCPSSL" then
|
||||||
|
ipDataFlowAdd(800)
|
||||||
|
end
|
||||||
|
|
||||||
|
self.address = address
|
||||||
|
self.port = port
|
||||||
|
local tCoreExtPara = self.tCoreExtPara or {}
|
||||||
|
|
||||||
|
local rcvBufferSize = tCoreExtPara.rcvBufferSize or 0
|
||||||
|
local socket_connect_fnc = nil
|
||||||
|
if self.ipv6 == true then
|
||||||
|
socket_connect_fnc = socketcore.ipv6_conn
|
||||||
|
else
|
||||||
|
socket_connect_fnc = (type(socketcore.sock_conn_ext)=="function") and socketcore.sock_conn_ext or socketcore.sock_conn
|
||||||
|
end
|
||||||
|
if self.protocol == 'TCP' then
|
||||||
|
self.id = socket_connect_fnc(0, address, port, rcvBufferSize)
|
||||||
|
elseif self.protocol == 'TCPSSL' then
|
||||||
|
local cert = {hostName = address}
|
||||||
|
local insist = 1
|
||||||
|
local hostNameFlag = 0
|
||||||
|
if self.cert then
|
||||||
|
if self.cert.caCert then
|
||||||
|
if self.cert.caCert:sub(1, 1) ~= "/" then self.cert.caCert = "/lua/" .. self.cert.caCert end
|
||||||
|
cert.caCert = io.readFile(self.cert.caCert)
|
||||||
|
end
|
||||||
|
if self.cert.clientCert then
|
||||||
|
if self.cert.clientCert:sub(1, 1) ~= "/" then self.cert.clientCert = "/lua/" .. self.cert.clientCert end
|
||||||
|
cert.clientCert = io.readFile(self.cert.clientCert)
|
||||||
|
end
|
||||||
|
if self.cert.clientKey then
|
||||||
|
if self.cert.clientKey:sub(1, 1) ~= "/" then self.cert.clientKey = "/lua/" .. self.cert.clientKey end
|
||||||
|
cert.clientKey = io.readFile(self.cert.clientKey)
|
||||||
|
end
|
||||||
|
insist = self.cert.insist == 0 and 0 or 1
|
||||||
|
hostNameFlag = self.cert.hostNameFlag == 1 and 1 or 0
|
||||||
|
end
|
||||||
|
self.id = socket_connect_fnc(2, address, port, cert, rcvBufferSize, insist, nil, hostNameFlag)
|
||||||
|
else
|
||||||
|
self.id = socket_connect_fnc(1, address, port, rcvBufferSize)
|
||||||
|
end
|
||||||
|
if self.ipv6 ~= true and type(socketcore.sock_conn_ext)=="function" then
|
||||||
|
if not self.id or self.id<0 then
|
||||||
|
if self.id==-2 then
|
||||||
|
require "http"
|
||||||
|
|
||||||
|
http.request("GET", "119.29.29.29/d?dn=" .. address, nil, nil, nil, 40000,
|
||||||
|
function(result, statusCode, head, body)
|
||||||
|
log.info("socket.httpDnsCb", result, statusCode, head, body)
|
||||||
|
sys.publish("SOCKET_HTTPDNS_RESULT_"..address.."_"..port, result, statusCode, head, body)
|
||||||
|
end)
|
||||||
|
local _, result, statusCode, head, body = sys.waitUntil("SOCKET_HTTPDNS_RESULT_"..address.."_"..port)
|
||||||
|
|
||||||
|
|
||||||
|
if result and statusCode == "200" and body and body:match("^[%d%.]+") then
|
||||||
|
return self:connect(body:match("^([%d%.]+)"),port,timeout)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
self.id = nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if not self.id then
|
||||||
|
log.info("socket:connect: core sock conn error", self.protocol, address, port, self.cert)
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
log.info("socket:connect-coreid,prot,addr,port,cert,timeout", self.id, self.protocol, address, port, self.cert, timeout or 120)
|
||||||
|
sockets[self.id] = self
|
||||||
|
self.wait = "SOCKET_CONNECT"
|
||||||
|
self.timerId = sys.timerStart(coroutine.resume, (timeout or 120) * 1000, self.co, false, "TIMEOUT")
|
||||||
|
local result, reason = coroutine.yield()
|
||||||
|
if self.timerId and reason ~= "TIMEOUT" then sys.timerStop(self.timerId) end
|
||||||
|
if not result then
|
||||||
|
log.info("socket:connect: connect fail", reason)
|
||||||
|
if reason == "RESPONSE" then
|
||||||
|
sockets[self.id] = nil
|
||||||
|
self.id = nil
|
||||||
|
end
|
||||||
|
sys.publish("LIB_SOCKET_CONNECT_FAIL_IND", self.ssl, self.protocol, address, port)
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
log.info("socket:connect: connect ok")
|
||||||
|
|
||||||
|
if not self.connected then
|
||||||
|
self.connected = true
|
||||||
|
socketsConnected = socketsConnected+1
|
||||||
|
sys.publish("SOCKET_ACTIVE", socketsConnected>0)
|
||||||
|
end
|
||||||
|
|
||||||
|
return true, self.id
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function mt:asyncSelect(keepAlive, pingreq)
|
||||||
|
assert(self.co == coroutine.running(), "socket:asyncSelect: coroutine mismatch")
|
||||||
|
if self.error then
|
||||||
|
log.warn('socket.client:asyncSelect', 'error', self.error)
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
self.wait = "SOCKET_SEND"
|
||||||
|
local dataLen = 0
|
||||||
|
|
||||||
|
while #self.output ~= 0 do
|
||||||
|
local data = table.concat(self.output)
|
||||||
|
dataLen = string.len(data)
|
||||||
|
self.output = {}
|
||||||
|
local sendSize = self.protocol == "UDP" and 1472 or SENDSIZE
|
||||||
|
for i = 1, dataLen, sendSize do
|
||||||
|
|
||||||
|
if self.ipv6 == true then
|
||||||
|
socketcore.ipv6_send(self.id, data:sub(i, i + sendSize - 1))
|
||||||
|
else
|
||||||
|
socketcore.sock_send(self.id, data:sub(i, i + sendSize - 1))
|
||||||
|
end
|
||||||
|
ipDataFlowAdd((data:sub(i, i + sendSize - 1)):len()+(self.protocol == "UDP" and 40 or 80))
|
||||||
|
if self.timeout then
|
||||||
|
self.timerId = sys.timerStart(coroutine.resume, self.timeout * 1000, self.co, false, "TIMEOUT")
|
||||||
|
end
|
||||||
|
|
||||||
|
local result, reason = coroutine.yield()
|
||||||
|
if self.timerId and reason ~= "TIMEOUT" then sys.timerStop(self.timerId) end
|
||||||
|
sys.publish("SOCKET_ASYNC_SEND", result)
|
||||||
|
if not result then
|
||||||
|
sys.publish("LIB_SOCKET_SEND_FAIL_IND", self.ssl, self.protocol, self.address, self.port)
|
||||||
|
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
self.wait = "SOCKET_WAIT"
|
||||||
|
|
||||||
|
if dataLen>0 then sys.publish("SOCKET_SEND", self.id, true) end
|
||||||
|
if keepAlive and keepAlive ~= 0 then
|
||||||
|
if type(pingreq) == "function" then
|
||||||
|
sys.timerStart(pingreq, keepAlive * 1000)
|
||||||
|
else
|
||||||
|
sys.timerStart(self.asyncSend, keepAlive * 1000, self, pingreq or "\0")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return coroutine.yield()
|
||||||
|
end
|
||||||
|
|
||||||
|
function mt:getAsyncSend()
|
||||||
|
if self.error then return 0 end
|
||||||
|
return #(self.output)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function mt:asyncSend(data, timeout)
|
||||||
|
if self.error then
|
||||||
|
log.warn('socket.client:asyncSend', 'error', self.error)
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
self.timeout = timeout
|
||||||
|
table.insert(self.output, data or "")
|
||||||
|
|
||||||
|
if self.wait == "SOCKET_WAIT" then coroutine.resume(self.co, true) end
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function mt:asyncRecv()
|
||||||
|
if #self.input == 0 then return "" end
|
||||||
|
if self.protocol == "UDP" then
|
||||||
|
return table.remove(self.input)
|
||||||
|
else
|
||||||
|
local s = table.concat(self.input)
|
||||||
|
self.input = {}
|
||||||
|
if self.ipv6 == true then
|
||||||
|
if self.isBlock then table.insert(self.input, socketcore.ipv6_recv(self.msg.socket_index, self.msg.recv_len)) end
|
||||||
|
else
|
||||||
|
if self.isBlock then table.insert(self.input, socketcore.sock_recv(self.msg.socket_index, self.msg.recv_len)) end
|
||||||
|
end
|
||||||
|
return s
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function mt:send(data, timeout)
|
||||||
|
assert(self.co == coroutine.running(), "socket:send: coroutine mismatch")
|
||||||
|
if self.error then
|
||||||
|
log.warn('socket.client:send', 'error', self.error)
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
log.debug("socket.send", "total " .. string.len(data or "") .. " bytes", "first 30 bytes", (data or ""):sub(1, 30))
|
||||||
|
local sendSize = self.protocol == "UDP" and 1472 or SENDSIZE
|
||||||
|
for i = 1, string.len(data or ""), sendSize do
|
||||||
|
|
||||||
|
self.wait = "SOCKET_SEND"
|
||||||
|
if self.ipv6 == true then
|
||||||
|
socketcore.ipv6_send(self.id, data:sub(i, i + sendSize - 1))
|
||||||
|
else
|
||||||
|
socketcore.sock_send(self.id, data:sub(i, i + sendSize - 1))
|
||||||
|
end
|
||||||
|
ipDataFlowAdd((data:sub(i, i + sendSize - 1)):len()+(self.protocol == "UDP" and 40 or 80))
|
||||||
|
self.timerId = sys.timerStart(coroutine.resume, (timeout or 120) * 1000, self.co, false, "TIMEOUT")
|
||||||
|
local result, reason = coroutine.yield()
|
||||||
|
if self.timerId and reason ~= "TIMEOUT" then sys.timerStop(self.timerId) end
|
||||||
|
if not result then
|
||||||
|
log.info("socket:send", "send fail", reason)
|
||||||
|
sys.publish("LIB_SOCKET_SEND_FAIL_IND", self.ssl, self.protocol, self.address, self.port)
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function mt:recv(timeout, msg, msgNoResume)
|
||||||
|
assert(self.co == coroutine.running(), "socket:recv: coroutine mismatch")
|
||||||
|
if self.error then
|
||||||
|
log.warn('socket.client:recv', 'error', self.error)
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
self.msgNoResume = msgNoResume
|
||||||
|
if msg and not self.iSubscribe then
|
||||||
|
self.iSubscribe = msg
|
||||||
|
self.subMessage = function(data)
|
||||||
|
|
||||||
|
if self.wait == "+RECEIVE" and not self.msgNoResume then
|
||||||
|
if data then table.insert(self.output, data) end
|
||||||
|
coroutine.resume(self.co, 0xAA)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
sys.subscribe(msg, self.subMessage)
|
||||||
|
end
|
||||||
|
if msg and #self.output > 0 then sys.publish(msg, false) end
|
||||||
|
if #self.input == 0 then
|
||||||
|
self.wait = "+RECEIVE"
|
||||||
|
if timeout and timeout > 0 then
|
||||||
|
local r, s = sys.wait(timeout)
|
||||||
|
if r == nil then
|
||||||
|
return false, "timeout"
|
||||||
|
elseif r == 0xAA then
|
||||||
|
local dat = table.concat(self.output)
|
||||||
|
self.output = {}
|
||||||
|
return false, msg, dat
|
||||||
|
else
|
||||||
|
return r, s
|
||||||
|
end
|
||||||
|
else
|
||||||
|
local r, s = coroutine.yield()
|
||||||
|
if r == 0xAA then
|
||||||
|
local dat = table.concat(self.output)
|
||||||
|
self.output = {}
|
||||||
|
return false, msg, dat
|
||||||
|
else
|
||||||
|
return r, s
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if self.protocol == "UDP" then
|
||||||
|
local s = table.remove(self.input)
|
||||||
|
return true, s
|
||||||
|
else
|
||||||
|
log.warn("-------------------使用缓冲区---------------")
|
||||||
|
local s = table.concat(self.input)
|
||||||
|
self.input = {}
|
||||||
|
if self.ipv6 == true then
|
||||||
|
if self.isBlock then table.insert(self.input, socketcore.ipv6_recv(self.msg.socket_index, self.msg.recv_len)) end
|
||||||
|
else
|
||||||
|
if self.isBlock then table.insert(self.input, socketcore.sock_recv(self.msg.socket_index, self.msg.recv_len)) end
|
||||||
|
end
|
||||||
|
return true, s
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function mt:close()
|
||||||
|
assert(self.co == coroutine.running(), "socket:close: coroutine mismatch")
|
||||||
|
if self.iSubscribe then
|
||||||
|
sys.unsubscribe(self.iSubscribe, self.subMessage)
|
||||||
|
self.iSubscribe = false
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
log.info("socket:sock_close", self.id)
|
||||||
|
local result, reason
|
||||||
|
|
||||||
|
if self.id then
|
||||||
|
if self.ipv6 == true then
|
||||||
|
socketcore.ipv6_close(self.id)
|
||||||
|
else
|
||||||
|
socketcore.sock_close(self.id)
|
||||||
|
end
|
||||||
|
if self.protocol~="UDP" then ipDataFlowAdd(120) end
|
||||||
|
self.wait = "SOCKET_CLOSE"
|
||||||
|
while true do
|
||||||
|
result, reason = coroutine.yield()
|
||||||
|
if reason == "RESPONSE" then break end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if self.connected then
|
||||||
|
self.connected = false
|
||||||
|
if socketsConnected>0 then
|
||||||
|
socketsConnected = socketsConnected-1
|
||||||
|
end
|
||||||
|
sys.publish("SOCKET_ACTIVE", socketsConnected>0)
|
||||||
|
end
|
||||||
|
if self.input then
|
||||||
|
self.input = {}
|
||||||
|
end
|
||||||
|
|
||||||
|
if self.id ~= nil then
|
||||||
|
sockets[self.id] = nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function mt:setRcvProc(rcvCbFnc)
|
||||||
|
assert(self.co == coroutine.running(), "socket:setRcvProc: coroutine mismatch")
|
||||||
|
self.rcvProcFnc = rcvCbFnc
|
||||||
|
end
|
||||||
|
|
||||||
|
local function on_response(msg)
|
||||||
|
local t = {
|
||||||
|
[rtos.MSG_SOCK_CLOSE_CNF] = 'SOCKET_CLOSE',
|
||||||
|
[rtos.MSG_SOCK_SEND_CNF] = 'SOCKET_SEND',
|
||||||
|
[rtos.MSG_SOCK_CONN_CNF] = 'SOCKET_CONNECT',
|
||||||
|
}
|
||||||
|
if not sockets[msg.socket_index] then
|
||||||
|
log.warn('response on nil socket', msg.socket_index, t[msg.id], msg.result)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
if sockets[msg.socket_index].wait ~= t[msg.id] then
|
||||||
|
log.warn('response on invalid wait', sockets[msg.socket_index].id, sockets[msg.socket_index].wait, t[msg.id], msg.socket_index)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
log.info("socket:on_response:", msg.socket_index, t[msg.id], msg.result)
|
||||||
|
if type(socketcore.sock_destroy) == "function" then
|
||||||
|
if (msg.id == rtos.MSG_SOCK_CONN_CNF and msg.result ~= 0) or msg.id == rtos.MSG_SOCK_CLOSE_CNF then
|
||||||
|
socketcore.sock_destroy(msg.socket_index)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
coroutine.resume(sockets[msg.socket_index].co, msg.result == 0, "RESPONSE")
|
||||||
|
end
|
||||||
|
|
||||||
|
rtos.on(rtos.MSG_SOCK_CLOSE_CNF, on_response)
|
||||||
|
rtos.on(rtos.MSG_SOCK_CONN_CNF, on_response)
|
||||||
|
rtos.on(rtos.MSG_SOCK_SEND_CNF, on_response)
|
||||||
|
rtos.on(rtos.MSG_SOCK_CLOSE_IND, function(msg)
|
||||||
|
log.info("socket.rtos.MSG_SOCK_CLOSE_IND")
|
||||||
|
if not sockets[msg.socket_index] then
|
||||||
|
log.warn('close ind on nil socket', msg.socket_index, msg.id)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
if sockets[msg.socket_index].connected then
|
||||||
|
sockets[msg.socket_index].connected = false
|
||||||
|
if socketsConnected>0 then
|
||||||
|
socketsConnected = socketsConnected-1
|
||||||
|
end
|
||||||
|
sys.publish("SOCKET_ACTIVE", socketsConnected>0)
|
||||||
|
end
|
||||||
|
sockets[msg.socket_index].error = 'CLOSED'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
sys.publish("LIB_SOCKET_CLOSE_IND", sockets[msg.socket_index].ssl, sockets[msg.socket_index].protocol, sockets[msg.socket_index].address, sockets[msg.socket_index].port)
|
||||||
|
coroutine.resume(sockets[msg.socket_index].co, false, "CLOSED")
|
||||||
|
end)
|
||||||
|
rtos.on(rtos.MSG_SOCK_RECV_IND, function(msg)
|
||||||
|
if not sockets[msg.socket_index] then
|
||||||
|
log.warn('close ind on nil socket', msg.socket_index, msg.id)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
log.debug("socket.recv", msg.recv_len, sockets[msg.socket_index].rcvProcFnc)
|
||||||
|
ipDataFlowAdd(msg.recv_len+(sockets[msg.socket_index].protocol=="UDP" and 40 or 80))
|
||||||
|
if sockets[msg.socket_index].rcvProcFnc then
|
||||||
|
if sockets[msg.socket_index].ipv6 == true then
|
||||||
|
sockets[msg.socket_index].rcvProcFnc(socketcore.ipv6_recv, msg.socket_index, msg.recv_len)
|
||||||
|
else
|
||||||
|
sockets[msg.socket_index].rcvProcFnc(socketcore.sock_recv, msg.socket_index, msg.recv_len)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
if sockets[msg.socket_index].wait == "+RECEIVE" then
|
||||||
|
if sockets[msg.socket_index].ipv6 == true then
|
||||||
|
coroutine.resume(sockets[msg.socket_index].co, true, socketcore.ipv6_recv(msg.socket_index, msg.recv_len))
|
||||||
|
else
|
||||||
|
coroutine.resume(sockets[msg.socket_index].co, true, socketcore.sock_recv(msg.socket_index, msg.recv_len))
|
||||||
|
end
|
||||||
|
else
|
||||||
|
if #sockets[msg.socket_index].input > INDEX_MAX then
|
||||||
|
log.error("socket recv", "out of stack", "block")
|
||||||
|
|
||||||
|
sockets[msg.socket_index].isBlock = true
|
||||||
|
sockets[msg.socket_index].msg = msg
|
||||||
|
else
|
||||||
|
sockets[msg.socket_index].isBlock = false
|
||||||
|
if sockets[msg.socket_index].ipv6 == true then
|
||||||
|
table.insert(sockets[msg.socket_index].input, socketcore.ipv6_recv(msg.socket_index, msg.recv_len))
|
||||||
|
else
|
||||||
|
table.insert(sockets[msg.socket_index].input, socketcore.sock_recv(msg.socket_index, msg.recv_len))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
sys.publish("SOCKET_RECV", msg.socket_index)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function setTcpResendPara(retryCnt, retryMaxTimeout)
|
||||||
|
ril.request("AT+TCPUSERPARAM=6," .. (retryCnt or 4) .. ",7200," .. (retryMaxTimeout or 16))
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function setDnsParsePara(retryCnt, retryTimeoutMulti)
|
||||||
|
ril.request("AT*DNSTMOUT="..(retryCnt or 4)..","..(retryTimeoutMulti or 4))
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function printStatus()
|
||||||
|
for _, client in pairs(sockets) do
|
||||||
|
for k, v in pairs(client) do
|
||||||
|
log.info('socket.printStatus', 'client', client.id, k, v)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function setLowPower(tm)
|
||||||
|
ril.request("AT*RTIME="..tm)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
local function ipStatisTimerCb()
|
||||||
|
if ipDataFlow~=0 then
|
||||||
|
sys.publish("LIB_IP_STATIS_RPT",ipDataFlow)
|
||||||
|
ipDataFlow = 0
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function setIpStatis(interval)
|
||||||
|
if ipStatisInterval~=interval then
|
||||||
|
ipStatisInterval = interval
|
||||||
|
ipStatisTimerCb()
|
||||||
|
if interval==0 then
|
||||||
|
sys.timerStop(ipStatisTimerCb)
|
||||||
|
else
|
||||||
|
sys.timerLoopStart(ipStatisTimerCb,interval*1000)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
526
4G/tools/_temp/script/temp_script/sys.lua
Normal file
526
4G/tools/_temp/script/temp_script/sys.lua
Normal file
@@ -0,0 +1,526 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
require "utils"
|
||||||
|
require "log"
|
||||||
|
require "patch"
|
||||||
|
module(..., package.seeall)
|
||||||
|
|
||||||
|
|
||||||
|
SCRIPT_LIB_VER = "2.4.5"
|
||||||
|
|
||||||
|
|
||||||
|
local TASK_TIMER_ID_MAX = 0x1FFFFFFF
|
||||||
|
|
||||||
|
local MSG_TIMER_ID_MAX = 0x7FFFFFFF
|
||||||
|
|
||||||
|
|
||||||
|
local taskTimerId = 0
|
||||||
|
|
||||||
|
local msgId = TASK_TIMER_ID_MAX
|
||||||
|
|
||||||
|
local timerPool = {}
|
||||||
|
local taskTimerPool = {}
|
||||||
|
|
||||||
|
local para = {}
|
||||||
|
|
||||||
|
local loop = {}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function powerOn()
|
||||||
|
rtos.poweron(1)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function restart(r)
|
||||||
|
assert(r and r ~= "", "sys.restart cause null")
|
||||||
|
if errDump and errDump.appendErr and type(errDump.appendErr) == "function" then errDump.appendErr("restart[" .. r .. "];") end
|
||||||
|
log.warn("sys.restart", r)
|
||||||
|
rtos.restart()
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function wait(ms)
|
||||||
|
|
||||||
|
assert(ms > 0, "The wait time cannot be negative!")
|
||||||
|
|
||||||
|
if ms < 5 then ms = 5 end
|
||||||
|
|
||||||
|
if taskTimerId >= TASK_TIMER_ID_MAX then taskTimerId = 0 end
|
||||||
|
taskTimerId = taskTimerId + 1
|
||||||
|
local timerid = taskTimerId
|
||||||
|
taskTimerPool[coroutine.running()] = timerid
|
||||||
|
timerPool[timerid] = coroutine.running()
|
||||||
|
|
||||||
|
if 1 ~= rtos.timer_start(timerid, ms) then log.debug("rtos.timer_start error") return end
|
||||||
|
|
||||||
|
local message = {coroutine.yield()}
|
||||||
|
if #message ~= 0 then
|
||||||
|
rtos.timer_stop(timerid)
|
||||||
|
taskTimerPool[coroutine.running()] = nil
|
||||||
|
timerPool[timerid] = nil
|
||||||
|
return unpack(message)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function waitUntil(id, ms)
|
||||||
|
subscribe(id, coroutine.running())
|
||||||
|
local message = ms and {wait(ms)} or {coroutine.yield()}
|
||||||
|
unsubscribe(id, coroutine.running())
|
||||||
|
return message[1] ~= nil, unpack(message, 2, #message)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function sys.waitUntilMsg(id)
|
||||||
|
local co = sys.check_task()
|
||||||
|
sys.subscribe(id, co)
|
||||||
|
local message = {coroutine.yield()}
|
||||||
|
sys.unsubscribe(id, co)
|
||||||
|
return unpack(message, 2, #message)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function waitUntilExt(id, ms)
|
||||||
|
subscribe(id, coroutine.running())
|
||||||
|
local message = ms and {wait(ms)} or {coroutine.yield()}
|
||||||
|
unsubscribe(id, coroutine.running())
|
||||||
|
if message[1] ~= nil then return unpack(message) end
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function taskInit(fun, ...)
|
||||||
|
local co = coroutine.create(fun)
|
||||||
|
coroutine.resume(co, ...)
|
||||||
|
return co
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function init(mode, lprfnc)
|
||||||
|
|
||||||
|
assert(PROJECT and PROJECT ~= "" and VERSION and VERSION ~= "", "Undefine PROJECT or VERSION")
|
||||||
|
collectgarbage("setpause", 80)
|
||||||
|
|
||||||
|
|
||||||
|
uart.setup(uart.ATC, 0, 0, uart.PAR_NONE, uart.STOP_1)
|
||||||
|
log.info("poweron reason:", rtos.poweron_reason(), PROJECT, VERSION, SCRIPT_LIB_VER, rtos.get_version())
|
||||||
|
pcall(rtos.set_lua_info,"\r\n"..rtos.get_version().."\r\n"..(_G.PROJECT or "NO PROJECT").."\r\n"..(_G.VERSION or "NO VERSION"))
|
||||||
|
if type(rtos.get_build_time)=="function" then log.info("core build time", rtos.get_build_time()) end
|
||||||
|
if mode == 1 then
|
||||||
|
|
||||||
|
if rtos.poweron_reason() == rtos.POWERON_CHARGER then
|
||||||
|
|
||||||
|
rtos.poweron(0)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
local function cmpTable(t1, t2)
|
||||||
|
if not t2 then return #t1 == 0 end
|
||||||
|
if #t1 == #t2 then
|
||||||
|
for i = 1, #t1 do
|
||||||
|
if unpack(t1, i, i) ~= unpack(t2, i, i) then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function timerStop(val, ...)
|
||||||
|
|
||||||
|
local arg={ ... }
|
||||||
|
if type(val) == 'number' then
|
||||||
|
timerPool[val], para[val], loop[val] = nil
|
||||||
|
rtos.timer_stop(val)
|
||||||
|
else
|
||||||
|
for k, v in pairs(timerPool) do
|
||||||
|
|
||||||
|
if type(v) == 'table' and v.cb == val or v == val then
|
||||||
|
|
||||||
|
if cmpTable(arg, para[k]) then
|
||||||
|
rtos.timer_stop(k)
|
||||||
|
timerPool[k], para[k], loop[val] = nil
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function timerStopAll(fnc)
|
||||||
|
for k, v in pairs(timerPool) do
|
||||||
|
if type(v) == "table" and v.cb == fnc or v == fnc then
|
||||||
|
rtos.timer_stop(k)
|
||||||
|
timerPool[k], para[k], loop[k] = nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function timerStart(fnc, ms, ...)
|
||||||
|
|
||||||
|
local arg={ ... }
|
||||||
|
local argcnt=0
|
||||||
|
for i, v in pairs(arg) do
|
||||||
|
argcnt = argcnt+1
|
||||||
|
end
|
||||||
|
assert(fnc ~= nil, "sys.timerStart(first param) is nil !")
|
||||||
|
assert(ms > 0, "sys.timerStart(Second parameter) is <= zero !")
|
||||||
|
|
||||||
|
if ms < 5 then ms = 5 end
|
||||||
|
|
||||||
|
if argcnt == 0 then
|
||||||
|
timerStop(fnc)
|
||||||
|
else
|
||||||
|
timerStop(fnc, ...)
|
||||||
|
end
|
||||||
|
|
||||||
|
while true do
|
||||||
|
if msgId >= MSG_TIMER_ID_MAX then msgId = TASK_TIMER_ID_MAX end
|
||||||
|
msgId = msgId + 1
|
||||||
|
if timerPool[msgId] == nil then
|
||||||
|
timerPool[msgId] = fnc
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if rtos.timer_start(msgId, ms) ~= 1 then log.debug("rtos.timer_start error") return end
|
||||||
|
|
||||||
|
if argcnt ~= 0 then
|
||||||
|
para[msgId] = arg
|
||||||
|
end
|
||||||
|
|
||||||
|
return msgId
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function timerLoopStart(fnc, ms, ...)
|
||||||
|
local tid = timerStart(fnc, ms, ...)
|
||||||
|
if tid then loop[tid] = (ms<5 and 5 or ms) end
|
||||||
|
return tid
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function timerIsActive(val, ...)
|
||||||
|
local arg={ ... }
|
||||||
|
if type(val) == "number" then
|
||||||
|
return timerPool[val]
|
||||||
|
else
|
||||||
|
for k, v in pairs(timerPool) do
|
||||||
|
if v == val then
|
||||||
|
if cmpTable(arg, para[k]) then return true end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
local subscribers = {}
|
||||||
|
|
||||||
|
local messageQueue = {}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function subscribe(id, callback)
|
||||||
|
if type(id) ~= "string" or (type(callback) ~= "function" and type(callback) ~= "thread") then
|
||||||
|
log.warn("warning: sys.subscribe invalid parameter", id, callback)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
if not subscribers[id] then subscribers[id] = {count = 0} end
|
||||||
|
if not subscribers[id][callback] then
|
||||||
|
subscribers[id].count = subscribers[id].count + 1
|
||||||
|
subscribers[id][callback] = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function unsubscribe(id, callback)
|
||||||
|
if type(id) ~= "string" or (type(callback) ~= "function" and type(callback) ~= "thread") then
|
||||||
|
log.warn("warning: sys.unsubscribe invalid parameter", id, callback)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
if subscribers[id] then
|
||||||
|
if subscribers[id][callback] then
|
||||||
|
subscribers[id].count = subscribers[id].count - 1
|
||||||
|
subscribers[id][callback] = false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function publish(...)
|
||||||
|
local arg = { ... }
|
||||||
|
table.insert(messageQueue, arg)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
local function dispatch()
|
||||||
|
while true do
|
||||||
|
if #messageQueue == 0 then
|
||||||
|
|
||||||
|
|
||||||
|
for k, v in pairs(subscribers) do
|
||||||
|
if v.count == 0 then subscribers[k] = nil end
|
||||||
|
end
|
||||||
|
break
|
||||||
|
end
|
||||||
|
local message = table.remove(messageQueue, 1)
|
||||||
|
if subscribers[message[1]] then
|
||||||
|
for callback, flag in pairs(subscribers[message[1]]) do
|
||||||
|
if flag then
|
||||||
|
if type(callback) == "function" then
|
||||||
|
callback(unpack(message, 2, #message))
|
||||||
|
elseif type(callback) == "thread" then
|
||||||
|
coroutine.resume(callback, unpack(message))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if subscribers[message[1]] then
|
||||||
|
for callback, flag in pairs(subscribers[message[1]]) do
|
||||||
|
if not flag then
|
||||||
|
subscribers[message[1]][callback] = nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if subscribers[message[1]].count == 0 then
|
||||||
|
subscribers[message[1]] = nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
local handlers = {}
|
||||||
|
setmetatable(handlers, {__index = function() return function() end end, })
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
rtos.on = function(id, handler)
|
||||||
|
handlers[id] = handler
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function run()
|
||||||
|
while true do
|
||||||
|
|
||||||
|
dispatch()
|
||||||
|
|
||||||
|
local msg, param = rtos.receive(rtos.INF_TIMEOUT)
|
||||||
|
|
||||||
|
if msg == rtos.MSG_TIMER and timerPool[param] then
|
||||||
|
if param <= TASK_TIMER_ID_MAX then
|
||||||
|
local taskId = timerPool[param]
|
||||||
|
timerPool[param] = nil
|
||||||
|
if taskTimerPool[taskId] == param then
|
||||||
|
taskTimerPool[taskId] = nil
|
||||||
|
coroutine.resume(taskId)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
local cb = timerPool[param]
|
||||||
|
|
||||||
|
if not loop[param] then timerPool[param] = nil end
|
||||||
|
if para[param] ~= nil then
|
||||||
|
cb(unpack(para[param]))
|
||||||
|
if not loop[param] then para[param] = nil end
|
||||||
|
else
|
||||||
|
cb()
|
||||||
|
end
|
||||||
|
|
||||||
|
if loop[param] then rtos.timer_start(param, loop[param]) end
|
||||||
|
end
|
||||||
|
|
||||||
|
elseif type(msg) == "number" then
|
||||||
|
handlers[msg](param)
|
||||||
|
else
|
||||||
|
handlers[msg.id](msg)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
require "clib"
|
||||||
|
|
||||||
|
if type(rtos.openSoftDog)=="function" then
|
||||||
|
rtos.openSoftDog(60000)
|
||||||
|
sys.timerLoopStart(rtos.eatSoftDog,20000)
|
||||||
|
end
|
||||||
286
4G/tools/_temp/script/temp_script/utils.lua
Normal file
286
4G/tools/_temp/script/temp_script/utils.lua
Normal file
@@ -0,0 +1,286 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
module(..., package.seeall)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function string.toHex(str, separator)
|
||||||
|
return str:gsub('.', function(c)
|
||||||
|
return string.format("%02X" .. (separator or ""), string.byte(c))
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function string.fromHex(hex)
|
||||||
|
|
||||||
|
local hex = hex:gsub("[%s%p]", ""):upper()
|
||||||
|
return hex:gsub("%x%x", function(c)
|
||||||
|
return string.char(tonumber(c, 16))
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function string.toValue(str)
|
||||||
|
return string.fromHex(str:gsub("%x", "0%1"))
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function string.utf8Len(str)
|
||||||
|
local _, count = string.gsub(str, "[^\128-\193]", "")
|
||||||
|
return count
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function string.utf8ToTable(str)
|
||||||
|
local tab = {}
|
||||||
|
for uchar in string.gfind(str, "[%z\1-\127\194-\244][\128-\191]*") do
|
||||||
|
tab[#tab + 1] = uchar
|
||||||
|
end
|
||||||
|
return tab
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function string.rawurlEncode(str)
|
||||||
|
local t = str:utf8ToTable()
|
||||||
|
for i = 1, #t do
|
||||||
|
if #t[i] == 1 then
|
||||||
|
t[i] = string.gsub(string.gsub(t[i], "([^%w_%~%.%- ])", function(c) return string.format("%%%02X", string.byte(c)) end), " ", "%%20")
|
||||||
|
else
|
||||||
|
t[i] = string.gsub(t[i], ".", function(c) return string.format("%%%02X", string.byte(c)) end)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return table.concat(t)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function string.urlEncode(str)
|
||||||
|
local t = str:utf8ToTable()
|
||||||
|
for i = 1, #t do
|
||||||
|
if #t[i] == 1 then
|
||||||
|
t[i] = string.gsub(string.gsub(t[i], "([^%w_%*%.%- ])", function(c) return string.format("%%%02X", string.byte(c)) end), " ", "+")
|
||||||
|
else
|
||||||
|
t[i] = string.gsub(t[i], ".", function(c) return string.format("%%%02X", string.byte(c)) end)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return table.concat(t)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function table.gsort(t, f)
|
||||||
|
local a = {}
|
||||||
|
for n in pairs(t) do a[#a + 1] = n end
|
||||||
|
table.sort(a, f)
|
||||||
|
local i = 0
|
||||||
|
return function()
|
||||||
|
i = i + 1
|
||||||
|
return a[i], t[a[i]]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function table.rconcat(l)
|
||||||
|
if type(l) ~= "table" then return l end
|
||||||
|
local res = {}
|
||||||
|
for i = 1, #l do
|
||||||
|
res[i] =table.rconcat(l[i])
|
||||||
|
end
|
||||||
|
return table.concat(res)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function string.formatNumberThousands(num)
|
||||||
|
local k, formatted
|
||||||
|
formatted = tostring(tonumber(num))
|
||||||
|
while true do
|
||||||
|
formatted, k = string.gsub(formatted, "^(-?%d+)(%d%d%d)", '%1,%2')
|
||||||
|
if k == 0 then break end
|
||||||
|
end
|
||||||
|
return formatted
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function string.split(str, delimiter)
|
||||||
|
local strlist, tmp = {}, string.byte(delimiter)
|
||||||
|
if delimiter == "" then
|
||||||
|
for i = 1, #str do strlist[i] = str:sub(i, i) end
|
||||||
|
else
|
||||||
|
for substr in string.gmatch(str .. delimiter, "(.-)" .. (((tmp > 96 and tmp < 123) or (tmp > 64 and tmp < 91) or (tmp > 47 and tmp < 58)) and delimiter or "%" .. delimiter)) do
|
||||||
|
table.insert(strlist, substr)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return strlist
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function string.checkSum(str, num)
|
||||||
|
assert(type(str) == "string", "The first argument is not a string!")
|
||||||
|
local sum = 0
|
||||||
|
for i = 1, #str do
|
||||||
|
sum = sum + str:sub(i, i):byte()
|
||||||
|
end
|
||||||
|
if num == 2 then
|
||||||
|
return sum % 0x10000
|
||||||
|
else
|
||||||
|
return sum % 0x100
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function io.exists(path)
|
||||||
|
local file = io.open(path, "r")
|
||||||
|
if file then
|
||||||
|
io.close(file)
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function io.readFile(path)
|
||||||
|
local file = io.open(path, "rb")
|
||||||
|
if file then
|
||||||
|
local content = file:read("*a")
|
||||||
|
io.close(file)
|
||||||
|
return content
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function io.writeFile(path, content, mode)
|
||||||
|
local mode = mode or "w+b"
|
||||||
|
local file = io.open(path, mode)
|
||||||
|
if file then
|
||||||
|
if file:write(content) == nil then return false end
|
||||||
|
io.close(file)
|
||||||
|
return true
|
||||||
|
else
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function io.pathInfo(path)
|
||||||
|
local pos = string.len(path)
|
||||||
|
local extpos = pos + 1
|
||||||
|
while pos > 0 do
|
||||||
|
local b = string.byte(path, pos)
|
||||||
|
if b == 46 then
|
||||||
|
extpos = pos
|
||||||
|
elseif b == 47 then
|
||||||
|
break
|
||||||
|
end
|
||||||
|
pos = pos - 1
|
||||||
|
end
|
||||||
|
|
||||||
|
local dirname = string.sub(path, 1, pos)
|
||||||
|
local filename = string.sub(path, pos + 1)
|
||||||
|
extpos = extpos - pos
|
||||||
|
local basename = string.sub(filename, 1, extpos - 1)
|
||||||
|
local extname = string.sub(filename, extpos)
|
||||||
|
return {
|
||||||
|
dirname = dirname,
|
||||||
|
filename = filename,
|
||||||
|
basename = basename,
|
||||||
|
extname = extname
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function io.fileSize(path)
|
||||||
|
local size = 0
|
||||||
|
local file = io.open(path, "r")
|
||||||
|
if file then
|
||||||
|
local current = file:seek()
|
||||||
|
size = file:seek("end")
|
||||||
|
file:seek("set", current)
|
||||||
|
io.close(file)
|
||||||
|
end
|
||||||
|
return size
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function io.readStream(path, offset, len)
|
||||||
|
local file, str = io.open(path, "r")
|
||||||
|
if file then
|
||||||
|
local current = file:seek()
|
||||||
|
file:seek("set", offset)
|
||||||
|
str = file:read(len)
|
||||||
|
file:seek("set", current)
|
||||||
|
io.close(file)
|
||||||
|
end
|
||||||
|
return str
|
||||||
|
end
|
||||||
File diff suppressed because one or more lines are too long
@@ -47,7 +47,7 @@
|
|||||||
/* #define HAL_DMA2D_MODULE_ENABLED */
|
/* #define HAL_DMA2D_MODULE_ENABLED */
|
||||||
#define HAL_ETH_MODULE_ENABLED
|
#define HAL_ETH_MODULE_ENABLED
|
||||||
/* #define HAL_ETH_LEGACY_MODULE_ENABLED */
|
/* #define HAL_ETH_LEGACY_MODULE_ENABLED */
|
||||||
#define HAL_NAND_MODULE_ENABLED
|
/* #define HAL_NAND_MODULE_ENABLED */
|
||||||
/* #define HAL_NOR_MODULE_ENABLED */
|
/* #define HAL_NOR_MODULE_ENABLED */
|
||||||
/* #define HAL_OTFDEC_MODULE_ENABLED */
|
/* #define HAL_OTFDEC_MODULE_ENABLED */
|
||||||
/* #define HAL_SRAM_MODULE_ENABLED */
|
/* #define HAL_SRAM_MODULE_ENABLED */
|
||||||
@@ -81,7 +81,7 @@
|
|||||||
/* #define HAL_IRDA_MODULE_ENABLED */
|
/* #define HAL_IRDA_MODULE_ENABLED */
|
||||||
/* #define HAL_SMARTCARD_MODULE_ENABLED */
|
/* #define HAL_SMARTCARD_MODULE_ENABLED */
|
||||||
/* #define HAL_WWDG_MODULE_ENABLED */
|
/* #define HAL_WWDG_MODULE_ENABLED */
|
||||||
/* #define HAL_PCD_MODULE_ENABLED */
|
#define HAL_PCD_MODULE_ENABLED
|
||||||
/* #define HAL_HCD_MODULE_ENABLED */
|
/* #define HAL_HCD_MODULE_ENABLED */
|
||||||
/* #define HAL_DFSDM_MODULE_ENABLED */
|
/* #define HAL_DFSDM_MODULE_ENABLED */
|
||||||
/* #define HAL_DSI_MODULE_ENABLED */
|
/* #define HAL_DSI_MODULE_ENABLED */
|
||||||
|
|||||||
@@ -58,6 +58,7 @@ void USART1_IRQHandler(void);
|
|||||||
void USART3_IRQHandler(void);
|
void USART3_IRQHandler(void);
|
||||||
void TIM7_IRQHandler(void);
|
void TIM7_IRQHandler(void);
|
||||||
void ETH_IRQHandler(void);
|
void ETH_IRQHandler(void);
|
||||||
|
void OTG_FS_IRQHandler(void);
|
||||||
/* USER CODE BEGIN EFP */
|
/* USER CODE BEGIN EFP */
|
||||||
|
|
||||||
/* USER CODE END EFP */
|
/* USER CODE END EFP */
|
||||||
|
|||||||
@@ -1,233 +0,0 @@
|
|||||||
/* USER CODE BEGIN Header */
|
|
||||||
/**
|
|
||||||
******************************************************************************
|
|
||||||
* File Name : FMC.c
|
|
||||||
* Description : This file provides code for the configuration
|
|
||||||
* of the FMC peripheral.
|
|
||||||
******************************************************************************
|
|
||||||
* @attention
|
|
||||||
*
|
|
||||||
* Copyright (c) 2026 STMicroelectronics.
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* This software is licensed under terms that can be found in the LICENSE file
|
|
||||||
* in the root directory of this software component.
|
|
||||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
|
||||||
*
|
|
||||||
******************************************************************************
|
|
||||||
*/
|
|
||||||
/* USER CODE END Header */
|
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
|
||||||
#include "fmc.h"
|
|
||||||
|
|
||||||
/* USER CODE BEGIN 0 */
|
|
||||||
|
|
||||||
/* USER CODE END 0 */
|
|
||||||
|
|
||||||
NAND_HandleTypeDef hnand1;
|
|
||||||
|
|
||||||
/* FMC initialization function */
|
|
||||||
void MX_FMC_Init(void)
|
|
||||||
{
|
|
||||||
/* USER CODE BEGIN FMC_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE END FMC_Init 0 */
|
|
||||||
|
|
||||||
FMC_NAND_PCC_TimingTypeDef ComSpaceTiming = {0};
|
|
||||||
FMC_NAND_PCC_TimingTypeDef AttSpaceTiming = {0};
|
|
||||||
|
|
||||||
/* USER CODE BEGIN FMC_Init 1 */
|
|
||||||
|
|
||||||
/* USER CODE END FMC_Init 1 */
|
|
||||||
|
|
||||||
/** Perform the NAND1 memory initialization sequence
|
|
||||||
*/
|
|
||||||
hnand1.Instance = FMC_NAND_DEVICE;
|
|
||||||
/* hnand1.Init */
|
|
||||||
hnand1.Init.NandBank = FMC_NAND_BANK3;
|
|
||||||
hnand1.Init.Waitfeature = FMC_NAND_WAIT_FEATURE_ENABLE;
|
|
||||||
hnand1.Init.MemoryDataWidth = FMC_NAND_MEM_BUS_WIDTH_8;
|
|
||||||
hnand1.Init.EccComputation = FMC_NAND_ECC_DISABLE;
|
|
||||||
hnand1.Init.ECCPageSize = FMC_NAND_ECC_PAGE_SIZE_512BYTE;
|
|
||||||
hnand1.Init.TCLRSetupTime = 9;
|
|
||||||
hnand1.Init.TARSetupTime = 9;
|
|
||||||
/* hnand1.Config */
|
|
||||||
hnand1.Config.PageSize = 2048;
|
|
||||||
hnand1.Config.SpareAreaSize = 64;
|
|
||||||
hnand1.Config.BlockSize = 64;
|
|
||||||
hnand1.Config.BlockNbr = 2048;
|
|
||||||
hnand1.Config.PlaneNbr = 2;
|
|
||||||
hnand1.Config.PlaneSize = 4096;
|
|
||||||
hnand1.Config.ExtraCommandEnable = DISABLE;
|
|
||||||
/* ComSpaceTiming */
|
|
||||||
ComSpaceTiming.SetupTime = 9;
|
|
||||||
ComSpaceTiming.WaitSetupTime = 9;
|
|
||||||
ComSpaceTiming.HoldSetupTime = 10;
|
|
||||||
ComSpaceTiming.HiZSetupTime = 9;
|
|
||||||
/* AttSpaceTiming */
|
|
||||||
AttSpaceTiming.SetupTime = 9;
|
|
||||||
AttSpaceTiming.WaitSetupTime = 9;
|
|
||||||
AttSpaceTiming.HoldSetupTime = 10;
|
|
||||||
AttSpaceTiming.HiZSetupTime = 9;
|
|
||||||
|
|
||||||
if (HAL_NAND_Init(&hnand1, &ComSpaceTiming, &AttSpaceTiming) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler( );
|
|
||||||
}
|
|
||||||
|
|
||||||
/* USER CODE BEGIN FMC_Init 2 */
|
|
||||||
|
|
||||||
/* USER CODE END FMC_Init 2 */
|
|
||||||
}
|
|
||||||
|
|
||||||
static uint32_t FMC_Initialized = 0;
|
|
||||||
|
|
||||||
static void HAL_FMC_MspInit(void){
|
|
||||||
/* USER CODE BEGIN FMC_MspInit 0 */
|
|
||||||
|
|
||||||
/* USER CODE END FMC_MspInit 0 */
|
|
||||||
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
|
||||||
if (FMC_Initialized) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
FMC_Initialized = 1;
|
|
||||||
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
|
|
||||||
|
|
||||||
/** Initializes the peripherals clock
|
|
||||||
*/
|
|
||||||
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_FMC;
|
|
||||||
PeriphClkInitStruct.FmcClockSelection = RCC_FMCCLKSOURCE_D1HCLK;
|
|
||||||
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Peripheral clock enable */
|
|
||||||
__HAL_RCC_FMC_CLK_ENABLE();
|
|
||||||
|
|
||||||
/** FMC GPIO Configuration
|
|
||||||
PE7 ------> FMC_D4
|
|
||||||
PE8 ------> FMC_D5
|
|
||||||
PE9 ------> FMC_D6
|
|
||||||
PE10 ------> FMC_D7
|
|
||||||
PD11 ------> FMC_CLE
|
|
||||||
PD12 ------> FMC_ALE
|
|
||||||
PD14 ------> FMC_D0
|
|
||||||
PD15 ------> FMC_D1
|
|
||||||
PC6 ------> FMC_NWAIT
|
|
||||||
PC8 ------> FMC_NCE
|
|
||||||
PD0 ------> FMC_D2
|
|
||||||
PD1 ------> FMC_D3
|
|
||||||
PD4 ------> FMC_NOE
|
|
||||||
PD5 ------> FMC_NWE
|
|
||||||
*/
|
|
||||||
/* GPIO_InitStruct */
|
|
||||||
GPIO_InitStruct.Pin = GPIO_PIN_7|GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10;
|
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
||||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
|
|
||||||
GPIO_InitStruct.Alternate = GPIO_AF12_FMC;
|
|
||||||
|
|
||||||
HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
|
|
||||||
|
|
||||||
/* GPIO_InitStruct */
|
|
||||||
GPIO_InitStruct.Pin = GPIO_PIN_11|GPIO_PIN_12;
|
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
||||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
|
|
||||||
|
|
||||||
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
|
|
||||||
|
|
||||||
/* GPIO_InitStruct */
|
|
||||||
GPIO_InitStruct.Pin = GPIO_PIN_14|GPIO_PIN_15|GPIO_PIN_0|GPIO_PIN_1
|
|
||||||
|GPIO_PIN_4|GPIO_PIN_5;
|
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
||||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
|
|
||||||
GPIO_InitStruct.Alternate = GPIO_AF12_FMC;
|
|
||||||
|
|
||||||
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
|
|
||||||
|
|
||||||
/* GPIO_InitStruct */
|
|
||||||
GPIO_InitStruct.Pin = GPIO_PIN_6|GPIO_PIN_8;
|
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
||||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
|
|
||||||
GPIO_InitStruct.Alternate = GPIO_AF9_FMC;
|
|
||||||
|
|
||||||
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
|
|
||||||
|
|
||||||
/* USER CODE BEGIN FMC_MspInit 1 */
|
|
||||||
|
|
||||||
/* USER CODE END FMC_MspInit 1 */
|
|
||||||
}
|
|
||||||
|
|
||||||
void HAL_NAND_MspInit(NAND_HandleTypeDef* nandHandle){
|
|
||||||
/* USER CODE BEGIN NAND_MspInit 0 */
|
|
||||||
|
|
||||||
/* USER CODE END NAND_MspInit 0 */
|
|
||||||
HAL_FMC_MspInit();
|
|
||||||
/* USER CODE BEGIN NAND_MspInit 1 */
|
|
||||||
|
|
||||||
/* USER CODE END NAND_MspInit 1 */
|
|
||||||
}
|
|
||||||
|
|
||||||
static uint32_t FMC_DeInitialized = 0;
|
|
||||||
|
|
||||||
static void HAL_FMC_MspDeInit(void){
|
|
||||||
/* USER CODE BEGIN FMC_MspDeInit 0 */
|
|
||||||
|
|
||||||
/* USER CODE END FMC_MspDeInit 0 */
|
|
||||||
if (FMC_DeInitialized) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
FMC_DeInitialized = 1;
|
|
||||||
/* Peripheral clock enable */
|
|
||||||
__HAL_RCC_FMC_CLK_DISABLE();
|
|
||||||
|
|
||||||
/** FMC GPIO Configuration
|
|
||||||
PE7 ------> FMC_D4
|
|
||||||
PE8 ------> FMC_D5
|
|
||||||
PE9 ------> FMC_D6
|
|
||||||
PE10 ------> FMC_D7
|
|
||||||
PD11 ------> FMC_CLE
|
|
||||||
PD12 ------> FMC_ALE
|
|
||||||
PD14 ------> FMC_D0
|
|
||||||
PD15 ------> FMC_D1
|
|
||||||
PC6 ------> FMC_NWAIT
|
|
||||||
PC8 ------> FMC_NCE
|
|
||||||
PD0 ------> FMC_D2
|
|
||||||
PD1 ------> FMC_D3
|
|
||||||
PD4 ------> FMC_NOE
|
|
||||||
PD5 ------> FMC_NWE
|
|
||||||
*/
|
|
||||||
|
|
||||||
HAL_GPIO_DeInit(GPIOE, GPIO_PIN_7|GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10);
|
|
||||||
|
|
||||||
HAL_GPIO_DeInit(GPIOD, GPIO_PIN_11|GPIO_PIN_12|GPIO_PIN_14|GPIO_PIN_15
|
|
||||||
|GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_4|GPIO_PIN_5);
|
|
||||||
|
|
||||||
HAL_GPIO_DeInit(GPIOC, GPIO_PIN_6|GPIO_PIN_8);
|
|
||||||
|
|
||||||
/* USER CODE BEGIN FMC_MspDeInit 1 */
|
|
||||||
|
|
||||||
/* USER CODE END FMC_MspDeInit 1 */
|
|
||||||
}
|
|
||||||
|
|
||||||
void HAL_NAND_MspDeInit(NAND_HandleTypeDef* nandHandle){
|
|
||||||
/* USER CODE BEGIN NAND_MspDeInit 0 */
|
|
||||||
|
|
||||||
/* USER CODE END NAND_MspDeInit 0 */
|
|
||||||
HAL_FMC_MspDeInit();
|
|
||||||
/* USER CODE BEGIN NAND_MspDeInit 1 */
|
|
||||||
|
|
||||||
/* USER CODE END NAND_MspDeInit 1 */
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* @}
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @}
|
|
||||||
*/
|
|
||||||
@@ -59,6 +59,7 @@ osThreadId defaultTaskHandle;
|
|||||||
void StartDefaultTask(void const * argument);
|
void StartDefaultTask(void const * argument);
|
||||||
|
|
||||||
extern void MX_LWIP_Init(void);
|
extern void MX_LWIP_Init(void);
|
||||||
|
extern void MX_USB_DEVICE_Init(void);
|
||||||
void MX_FREERTOS_Init(void); /* (MISRA C 2004 rule 8.1) */
|
void MX_FREERTOS_Init(void); /* (MISRA C 2004 rule 8.1) */
|
||||||
|
|
||||||
/* GetIdleTaskMemory prototype (linked to static allocation support) */
|
/* GetIdleTaskMemory prototype (linked to static allocation support) */
|
||||||
@@ -171,6 +172,9 @@ void StartDefaultTask(void const * argument)
|
|||||||
{
|
{
|
||||||
/* init code for LWIP */
|
/* init code for LWIP */
|
||||||
MX_LWIP_Init();
|
MX_LWIP_Init();
|
||||||
|
|
||||||
|
/* init code for USB_DEVICE */
|
||||||
|
MX_USB_DEVICE_Init();
|
||||||
/* USER CODE BEGIN StartDefaultTask */
|
/* USER CODE BEGIN StartDefaultTask */
|
||||||
|
|
||||||
/* Infinite loop */
|
/* Infinite loop */
|
||||||
|
|||||||
@@ -49,9 +49,7 @@ void MX_GPIO_Init(void)
|
|||||||
__HAL_RCC_GPIOC_CLK_ENABLE();
|
__HAL_RCC_GPIOC_CLK_ENABLE();
|
||||||
__HAL_RCC_GPIOH_CLK_ENABLE();
|
__HAL_RCC_GPIOH_CLK_ENABLE();
|
||||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||||
__HAL_RCC_GPIOE_CLK_ENABLE();
|
|
||||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
__HAL_RCC_GPIOB_CLK_ENABLE();
|
||||||
__HAL_RCC_GPIOD_CLK_ENABLE();
|
|
||||||
__HAL_RCC_GPIOG_CLK_ENABLE();
|
__HAL_RCC_GPIOG_CLK_ENABLE();
|
||||||
|
|
||||||
/*Configure GPIO pin Output Level */
|
/*Configure GPIO pin Output Level */
|
||||||
|
|||||||
@@ -23,8 +23,8 @@
|
|||||||
#include "lwip.h"
|
#include "lwip.h"
|
||||||
#include "memorymap.h"
|
#include "memorymap.h"
|
||||||
#include "usart.h"
|
#include "usart.h"
|
||||||
|
#include "usb_device.h"
|
||||||
#include "gpio.h"
|
#include "gpio.h"
|
||||||
#include "fmc.h"
|
|
||||||
|
|
||||||
/* Private includes ----------------------------------------------------------*/
|
/* Private includes ----------------------------------------------------------*/
|
||||||
/* USER CODE BEGIN Includes */
|
/* USER CODE BEGIN Includes */
|
||||||
@@ -35,15 +35,6 @@
|
|||||||
/* Private typedef -----------------------------------------------------------*/
|
/* Private typedef -----------------------------------------------------------*/
|
||||||
/* USER CODE BEGIN PTD */
|
/* USER CODE BEGIN PTD */
|
||||||
|
|
||||||
extern NAND_HandleTypeDef hnand1;
|
|
||||||
|
|
||||||
#define NAND_PAGE_SIZE 2048 // ??????(??)
|
|
||||||
#define NAND_OOB_SIZE 64 // OOB ??(??)
|
|
||||||
#define NAND_BLOCK_SIZE 64 // ?? 64 ?(???)
|
|
||||||
|
|
||||||
// ????????(????,???? SRAM3 ? DTCM)
|
|
||||||
__attribute__((aligned(4))) uint8_t nand_write_buffer[NAND_PAGE_SIZE];
|
|
||||||
__attribute__((aligned(4))) uint8_t nand_read_buffer[NAND_PAGE_SIZE + NAND_OOB_SIZE];
|
|
||||||
|
|
||||||
/* USER CODE END PTD */
|
/* USER CODE END PTD */
|
||||||
|
|
||||||
@@ -177,14 +168,15 @@ void SystemClock_Config(void)
|
|||||||
/** Initializes the RCC Oscillators according to the specified parameters
|
/** Initializes the RCC Oscillators according to the specified parameters
|
||||||
* in the RCC_OscInitTypeDef structure.
|
* in the RCC_OscInitTypeDef structure.
|
||||||
*/
|
*/
|
||||||
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
|
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI48|RCC_OSCILLATORTYPE_HSE;
|
||||||
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
|
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
|
||||||
|
RCC_OscInitStruct.HSI48State = RCC_HSI48_ON;
|
||||||
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
||||||
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
|
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
|
||||||
RCC_OscInitStruct.PLL.PLLM = 5;
|
RCC_OscInitStruct.PLL.PLLM = 5;
|
||||||
RCC_OscInitStruct.PLL.PLLN = 192;
|
RCC_OscInitStruct.PLL.PLLN = 192;
|
||||||
RCC_OscInitStruct.PLL.PLLP = 2;
|
RCC_OscInitStruct.PLL.PLLP = 2;
|
||||||
RCC_OscInitStruct.PLL.PLLQ = 2;
|
RCC_OscInitStruct.PLL.PLLQ = 15;
|
||||||
RCC_OscInitStruct.PLL.PLLR = 2;
|
RCC_OscInitStruct.PLL.PLLR = 2;
|
||||||
RCC_OscInitStruct.PLL.PLLRGE = RCC_PLL1VCIRANGE_2;
|
RCC_OscInitStruct.PLL.PLLRGE = RCC_PLL1VCIRANGE_2;
|
||||||
RCC_OscInitStruct.PLL.PLLVCOSEL = RCC_PLL1VCOWIDE;
|
RCC_OscInitStruct.PLL.PLLVCOSEL = RCC_PLL1VCOWIDE;
|
||||||
|
|||||||
@@ -56,6 +56,7 @@
|
|||||||
|
|
||||||
/* External variables --------------------------------------------------------*/
|
/* External variables --------------------------------------------------------*/
|
||||||
extern ETH_HandleTypeDef heth;
|
extern ETH_HandleTypeDef heth;
|
||||||
|
extern PCD_HandleTypeDef hpcd_USB_OTG_FS;
|
||||||
extern DMA_HandleTypeDef hdma_usart1_rx;
|
extern DMA_HandleTypeDef hdma_usart1_rx;
|
||||||
extern DMA_HandleTypeDef hdma_usart3_rx;
|
extern DMA_HandleTypeDef hdma_usart3_rx;
|
||||||
extern UART_HandleTypeDef huart1;
|
extern UART_HandleTypeDef huart1;
|
||||||
@@ -248,6 +249,20 @@ void ETH_IRQHandler(void)
|
|||||||
/* USER CODE END ETH_IRQn 1 */
|
/* USER CODE END ETH_IRQn 1 */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function handles USB On The Go FS global interrupt.
|
||||||
|
*/
|
||||||
|
void OTG_FS_IRQHandler(void)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN OTG_FS_IRQn 0 */
|
||||||
|
|
||||||
|
/* USER CODE END OTG_FS_IRQn 0 */
|
||||||
|
HAL_PCD_IRQHandler(&hpcd_USB_OTG_FS);
|
||||||
|
/* USER CODE BEGIN OTG_FS_IRQn 1 */
|
||||||
|
|
||||||
|
/* USER CODE END OTG_FS_IRQn 1 */
|
||||||
|
}
|
||||||
|
|
||||||
/* USER CODE BEGIN 1 */
|
/* USER CODE BEGIN 1 */
|
||||||
|
|
||||||
/* USER CODE END 1 */
|
/* USER CODE END 1 */
|
||||||
|
|||||||
179
Core/IPort.ioc
179
Core/IPort.ioc
@@ -65,24 +65,6 @@ ETH.IPParameters=MediaInterface,TxDescAddress,RxDescAddress
|
|||||||
ETH.MediaInterface=HAL_ETH_RMII_MODE
|
ETH.MediaInterface=HAL_ETH_RMII_MODE
|
||||||
ETH.RxDescAddress=0x30040000
|
ETH.RxDescAddress=0x30040000
|
||||||
ETH.TxDescAddress=0x30040060
|
ETH.TxDescAddress=0x30040060
|
||||||
FMC.AttributeSpaceHiZSetupTime1=9
|
|
||||||
FMC.AttributeSpaceHoldSetupTime1=10
|
|
||||||
FMC.AttributeSpaceSetupTime1=9
|
|
||||||
FMC.AttributeSpaceWaitSetupTime1=9
|
|
||||||
FMC.CommonSpaceHiZSetupTime1=9
|
|
||||||
FMC.CommonSpaceHoldSetupTime1=10
|
|
||||||
FMC.CommonSpaceSetupTime1=9
|
|
||||||
FMC.CommonSpaceWaitSetupTime1=9
|
|
||||||
FMC.ECCPageSize1=FMC_NAND_ECC_PAGE_SIZE_512BYTE
|
|
||||||
FMC.IPParameters=TCLRSetupTime1,TARSetupTime1,ECCPageSize1,CommonSpaceSetupTime1,CommonSpaceWaitSetupTime1,CommonSpaceHoldSetupTime1,CommonSpaceHiZSetupTime1,AttributeSpaceSetupTime1,AttributeSpaceWaitSetupTime1,AttributeSpaceHoldSetupTime1,AttributeSpaceHiZSetupTime1,NandPageSize1,NandSpareAreaSize1,NandBlockSize1,NandBlockNbr1,NandPlaneNbr1,NandPlaneSize1
|
|
||||||
FMC.NandBlockNbr1=2048
|
|
||||||
FMC.NandBlockSize1=64
|
|
||||||
FMC.NandPageSize1=2048
|
|
||||||
FMC.NandPlaneNbr1=2
|
|
||||||
FMC.NandPlaneSize1=4096
|
|
||||||
FMC.NandSpareAreaSize1=64
|
|
||||||
FMC.TARSetupTime1=9
|
|
||||||
FMC.TCLRSetupTime1=9
|
|
||||||
FREERTOS.INCLUDE_uxTaskGetStackHighWaterMark=1
|
FREERTOS.INCLUDE_uxTaskGetStackHighWaterMark=1
|
||||||
FREERTOS.INCLUDE_vTaskDelayUntil=1
|
FREERTOS.INCLUDE_vTaskDelayUntil=1
|
||||||
FREERTOS.IPParameters=Tasks01,configENABLE_FPU,configUSE_COUNTING_SEMAPHORES,configTOTAL_HEAP_SIZE,configUSE_TICK_HOOK,configUSE_MALLOC_FAILED_HOOK,configGENERATE_RUN_TIME_STATS,configUSE_TRACE_FACILITY,configUSE_STATS_FORMATTING_FUNCTIONS,INCLUDE_vTaskDelayUntil,INCLUDE_uxTaskGetStackHighWaterMark,configMINIMAL_STACK_SIZE
|
FREERTOS.IPParameters=Tasks01,configENABLE_FPU,configUSE_COUNTING_SEMAPHORES,configTOTAL_HEAP_SIZE,configUSE_TICK_HOOK,configUSE_MALLOC_FAILED_HOOK,configGENERATE_RUN_TIME_STATS,configUSE_TRACE_FACILITY,configUSE_STATS_FORMATTING_FUNCTIONS,INCLUDE_vTaskDelayUntil,INCLUDE_uxTaskGetStackHighWaterMark,configMINIMAL_STACK_SIZE
|
||||||
@@ -134,66 +116,56 @@ Mcu.CPN=STM32H743IIT6
|
|||||||
Mcu.Family=STM32H7
|
Mcu.Family=STM32H7
|
||||||
Mcu.IP0=CORTEX_M7
|
Mcu.IP0=CORTEX_M7
|
||||||
Mcu.IP1=DEBUG
|
Mcu.IP1=DEBUG
|
||||||
Mcu.IP10=SYS
|
Mcu.IP10=USART1
|
||||||
Mcu.IP11=USART1
|
Mcu.IP11=USART3
|
||||||
Mcu.IP12=USART3
|
Mcu.IP12=USART6
|
||||||
Mcu.IP13=USART6
|
Mcu.IP13=USB_DEVICE
|
||||||
|
Mcu.IP14=USB_OTG_FS
|
||||||
Mcu.IP2=DMA
|
Mcu.IP2=DMA
|
||||||
Mcu.IP3=ETH
|
Mcu.IP3=ETH
|
||||||
Mcu.IP4=FMC
|
Mcu.IP4=FREERTOS
|
||||||
Mcu.IP5=FREERTOS
|
Mcu.IP5=LWIP
|
||||||
Mcu.IP6=LWIP
|
Mcu.IP6=MEMORYMAP
|
||||||
Mcu.IP7=MEMORYMAP
|
Mcu.IP7=NVIC
|
||||||
Mcu.IP8=NVIC
|
Mcu.IP8=RCC
|
||||||
Mcu.IP9=RCC
|
Mcu.IP9=SYS
|
||||||
Mcu.IPNb=14
|
Mcu.IPNb=15
|
||||||
Mcu.Name=STM32H743IITx
|
Mcu.Name=STM32H743IITx
|
||||||
Mcu.Package=LQFP176
|
Mcu.Package=LQFP176
|
||||||
Mcu.Pin0=PC14-OSC32_IN (OSC32_IN)
|
Mcu.Pin0=PC14-OSC32_IN (OSC32_IN)
|
||||||
Mcu.Pin1=PC15-OSC32_OUT (OSC32_OUT)
|
Mcu.Pin1=PC15-OSC32_OUT (OSC32_OUT)
|
||||||
Mcu.Pin10=PC4
|
Mcu.Pin10=PC4
|
||||||
Mcu.Pin11=PC5
|
Mcu.Pin11=PC5
|
||||||
Mcu.Pin12=PE7
|
Mcu.Pin12=PB10
|
||||||
Mcu.Pin13=PE8
|
Mcu.Pin13=PB11
|
||||||
Mcu.Pin14=PE9
|
Mcu.Pin14=PH12
|
||||||
Mcu.Pin15=PE10
|
Mcu.Pin15=PB12
|
||||||
Mcu.Pin16=PB10
|
Mcu.Pin16=PB13
|
||||||
Mcu.Pin17=PB11
|
Mcu.Pin17=PB14
|
||||||
Mcu.Pin18=PH12
|
Mcu.Pin18=PB15
|
||||||
Mcu.Pin19=PB12
|
Mcu.Pin19=PA11
|
||||||
Mcu.Pin2=PH0-OSC_IN (PH0)
|
Mcu.Pin2=PH0-OSC_IN (PH0)
|
||||||
Mcu.Pin20=PB13
|
Mcu.Pin20=PA12
|
||||||
Mcu.Pin21=PB14
|
Mcu.Pin21=PA13 (JTMS/SWDIO)
|
||||||
Mcu.Pin22=PB15
|
Mcu.Pin22=PA14 (JTCK/SWCLK)
|
||||||
Mcu.Pin23=PD11
|
Mcu.Pin23=PC10
|
||||||
Mcu.Pin24=PD12
|
Mcu.Pin24=PC11
|
||||||
Mcu.Pin25=PD14
|
Mcu.Pin25=PC12
|
||||||
Mcu.Pin26=PD15
|
Mcu.Pin26=PG9
|
||||||
Mcu.Pin27=PC6
|
Mcu.Pin27=PG14
|
||||||
Mcu.Pin28=PC8
|
Mcu.Pin28=VP_FREERTOS_VS_CMSIS_V1
|
||||||
Mcu.Pin29=PA13 (JTMS/SWDIO)
|
Mcu.Pin29=VP_LWIP_VS_Enabled
|
||||||
Mcu.Pin3=PH1-OSC_OUT (PH1)
|
Mcu.Pin3=PH1-OSC_OUT (PH1)
|
||||||
Mcu.Pin30=PA14 (JTCK/SWCLK)
|
Mcu.Pin30=VP_SYS_VS_tim7
|
||||||
Mcu.Pin31=PC10
|
Mcu.Pin31=VP_USB_DEVICE_VS_USB_DEVICE_CDC_FS
|
||||||
Mcu.Pin32=PC11
|
Mcu.Pin32=VP_MEMORYMAP_VS_MEMORYMAP
|
||||||
Mcu.Pin33=PC12
|
|
||||||
Mcu.Pin34=PD0
|
|
||||||
Mcu.Pin35=PD1
|
|
||||||
Mcu.Pin36=PD4
|
|
||||||
Mcu.Pin37=PD5
|
|
||||||
Mcu.Pin38=PG9
|
|
||||||
Mcu.Pin39=PG14
|
|
||||||
Mcu.Pin4=PC1
|
Mcu.Pin4=PC1
|
||||||
Mcu.Pin40=VP_FREERTOS_VS_CMSIS_V1
|
|
||||||
Mcu.Pin41=VP_LWIP_VS_Enabled
|
|
||||||
Mcu.Pin42=VP_SYS_VS_tim7
|
|
||||||
Mcu.Pin43=VP_MEMORYMAP_VS_MEMORYMAP
|
|
||||||
Mcu.Pin5=PA1
|
Mcu.Pin5=PA1
|
||||||
Mcu.Pin6=PA2
|
Mcu.Pin6=PA2
|
||||||
Mcu.Pin7=PH4
|
Mcu.Pin7=PH4
|
||||||
Mcu.Pin8=PH5
|
Mcu.Pin8=PH5
|
||||||
Mcu.Pin9=PA7
|
Mcu.Pin9=PA7
|
||||||
Mcu.PinsNb=44
|
Mcu.PinsNb=33
|
||||||
Mcu.ThirdPartyNb=0
|
Mcu.ThirdPartyNb=0
|
||||||
Mcu.UserConstants=
|
Mcu.UserConstants=
|
||||||
Mcu.UserName=STM32H743IITx
|
Mcu.UserName=STM32H743IITx
|
||||||
@@ -208,6 +180,7 @@ NVIC.ForceEnableDMAVector=false
|
|||||||
NVIC.HardFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false\:false
|
NVIC.HardFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false\:false
|
||||||
NVIC.MemoryManagement_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false\:false
|
NVIC.MemoryManagement_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false\:false
|
||||||
NVIC.NonMaskableInt_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false\:false
|
NVIC.NonMaskableInt_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false\:false
|
||||||
|
NVIC.OTG_FS_IRQn=true\:5\:0\:false\:false\:true\:true\:false\:true\:true
|
||||||
NVIC.PendSV_IRQn=true\:15\:0\:false\:false\:false\:true\:false\:false\:false
|
NVIC.PendSV_IRQn=true\:15\:0\:false\:false\:false\:true\:false\:false\:false
|
||||||
NVIC.PriorityGroup=NVIC_PRIORITYGROUP_4
|
NVIC.PriorityGroup=NVIC_PRIORITYGROUP_4
|
||||||
NVIC.SVCall_IRQn=true\:0\:0\:false\:false\:false\:false\:false\:false\:false
|
NVIC.SVCall_IRQn=true\:0\:0\:false\:false\:false\:false\:false\:false\:false
|
||||||
@@ -225,6 +198,10 @@ PA1.GPIOParameters=GPIO_Speed
|
|||||||
PA1.GPIO_Speed=GPIO_SPEED_FREQ_VERY_HIGH
|
PA1.GPIO_Speed=GPIO_SPEED_FREQ_VERY_HIGH
|
||||||
PA1.Mode=RMII
|
PA1.Mode=RMII
|
||||||
PA1.Signal=ETH_REF_CLK
|
PA1.Signal=ETH_REF_CLK
|
||||||
|
PA11.Mode=Device_Only
|
||||||
|
PA11.Signal=USB_OTG_FS_DM
|
||||||
|
PA12.Mode=Device_Only
|
||||||
|
PA12.Signal=USB_OTG_FS_DP
|
||||||
PA13\ (JTMS/SWDIO).Mode=Serial_Wire
|
PA13\ (JTMS/SWDIO).Mode=Serial_Wire
|
||||||
PA13\ (JTMS/SWDIO).Signal=DEBUG_JTMS-SWDIO
|
PA13\ (JTMS/SWDIO).Signal=DEBUG_JTMS-SWDIO
|
||||||
PA14\ (JTCK/SWCLK).Mode=Serial_Wire
|
PA14\ (JTCK/SWCLK).Mode=Serial_Wire
|
||||||
@@ -298,21 +275,6 @@ PC5.GPIOParameters=GPIO_Speed
|
|||||||
PC5.GPIO_Speed=GPIO_SPEED_FREQ_VERY_HIGH
|
PC5.GPIO_Speed=GPIO_SPEED_FREQ_VERY_HIGH
|
||||||
PC5.Mode=RMII
|
PC5.Mode=RMII
|
||||||
PC5.Signal=ETH_RXD1
|
PC5.Signal=ETH_RXD1
|
||||||
PC6.Signal=FMC_NWAIT
|
|
||||||
PC8.Mode=NandChipSelect3_1
|
|
||||||
PC8.Signal=FMC_NCE
|
|
||||||
PD0.Signal=FMC_D2_DA2
|
|
||||||
PD1.Signal=FMC_D3_DA3
|
|
||||||
PD11.Signal=FMC_A16_CLE
|
|
||||||
PD12.Signal=FMC_A17_ALE
|
|
||||||
PD14.Signal=FMC_D0_DA0
|
|
||||||
PD15.Signal=FMC_D1_DA1
|
|
||||||
PD4.Signal=FMC_NOE
|
|
||||||
PD5.Signal=FMC_NWE
|
|
||||||
PE10.Signal=FMC_D7_DA7
|
|
||||||
PE7.Signal=FMC_D4_DA4
|
|
||||||
PE8.Signal=FMC_D5_DA5
|
|
||||||
PE9.Signal=FMC_D6_DA6
|
|
||||||
PG14.Locked=true
|
PG14.Locked=true
|
||||||
PG14.Mode=Asynchronous
|
PG14.Mode=Asynchronous
|
||||||
PG14.Signal=USART6_TX
|
PG14.Signal=USART6_TX
|
||||||
@@ -375,7 +337,7 @@ ProjectManager.ToolChainLocation=
|
|||||||
ProjectManager.UAScriptAfterPath=
|
ProjectManager.UAScriptAfterPath=
|
||||||
ProjectManager.UAScriptBeforePath=
|
ProjectManager.UAScriptBeforePath=
|
||||||
ProjectManager.UnderRoot=false
|
ProjectManager.UnderRoot=false
|
||||||
ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false,2-MX_GPIO_Init-GPIO-false-HAL-true,3-MX_DMA_Init-DMA-false-HAL-true,4-MX_USART1_UART_Init-USART1-false-HAL-true,5-MX_LWIP_Init-LWIP-false-HAL-false,6-MX_USART3_UART_Init-USART3-false-HAL-true,7-MX_USART6_UART_Init-USART6-false-HAL-true,8-MX_FMC_Init-FMC-false-HAL-true,0-MX_CORTEX_M7_Init-CORTEX_M7-false-HAL-true
|
ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false,2-MX_GPIO_Init-GPIO-false-HAL-true,3-MX_DMA_Init-DMA-false-HAL-true,4-MX_USART1_UART_Init-USART1-false-HAL-true,5-MX_LWIP_Init-LWIP-false-HAL-false,6-MX_USART3_UART_Init-USART3-false-HAL-true,7-MX_USART6_UART_Init-USART6-false-HAL-true,8-MX_USB_DEVICE_Init-USB_DEVICE-false-HAL-false,0-MX_CORTEX_M7_Init-CORTEX_M7-false-HAL-true
|
||||||
RCC.ADCFreq_Value=50390625
|
RCC.ADCFreq_Value=50390625
|
||||||
RCC.AHB12Freq_Value=240000000
|
RCC.AHB12Freq_Value=240000000
|
||||||
RCC.AHB4Freq_Value=240000000
|
RCC.AHB4Freq_Value=240000000
|
||||||
@@ -393,20 +355,21 @@ RCC.D1PPRE=RCC_APB3_DIV2
|
|||||||
RCC.D2PPRE1=RCC_APB1_DIV2
|
RCC.D2PPRE1=RCC_APB1_DIV2
|
||||||
RCC.D2PPRE2=RCC_APB2_DIV2
|
RCC.D2PPRE2=RCC_APB2_DIV2
|
||||||
RCC.D3PPRE=RCC_APB4_DIV2
|
RCC.D3PPRE=RCC_APB4_DIV2
|
||||||
RCC.DFSDMACLkFreq_Value=480000000
|
RCC.DFSDMACLkFreq_Value=64000000
|
||||||
RCC.DFSDMFreq_Value=120000000
|
RCC.DFSDMFreq_Value=120000000
|
||||||
RCC.DIVM1=5
|
RCC.DIVM1=5
|
||||||
RCC.DIVN1=192
|
RCC.DIVN1=192
|
||||||
RCC.DIVP1Freq_Value=480000000
|
RCC.DIVP1Freq_Value=480000000
|
||||||
RCC.DIVP2Freq_Value=50390625
|
RCC.DIVP2Freq_Value=50390625
|
||||||
RCC.DIVP3Freq_Value=50390625
|
RCC.DIVP3Freq_Value=50390625
|
||||||
RCC.DIVQ1Freq_Value=480000000
|
RCC.DIVQ1=15
|
||||||
|
RCC.DIVQ1Freq_Value=64000000
|
||||||
RCC.DIVQ2Freq_Value=50390625
|
RCC.DIVQ2Freq_Value=50390625
|
||||||
RCC.DIVQ3Freq_Value=50390625
|
RCC.DIVQ3Freq_Value=50390625
|
||||||
RCC.DIVR1Freq_Value=480000000
|
RCC.DIVR1Freq_Value=480000000
|
||||||
RCC.DIVR2Freq_Value=50390625
|
RCC.DIVR2Freq_Value=50390625
|
||||||
RCC.DIVR3Freq_Value=50390625
|
RCC.DIVR3Freq_Value=50390625
|
||||||
RCC.FDCANFreq_Value=480000000
|
RCC.FDCANFreq_Value=64000000
|
||||||
RCC.FMCFreq_Value=240000000
|
RCC.FMCFreq_Value=240000000
|
||||||
RCC.FamilyName=M
|
RCC.FamilyName=M
|
||||||
RCC.HCLK3ClockFreq_Value=240000000
|
RCC.HCLK3ClockFreq_Value=240000000
|
||||||
@@ -415,7 +378,7 @@ RCC.HPRE=RCC_HCLK_DIV2
|
|||||||
RCC.HRTIMFreq_Value=240000000
|
RCC.HRTIMFreq_Value=240000000
|
||||||
RCC.I2C123Freq_Value=120000000
|
RCC.I2C123Freq_Value=120000000
|
||||||
RCC.I2C4Freq_Value=120000000
|
RCC.I2C4Freq_Value=120000000
|
||||||
RCC.IPParameters=ADCFreq_Value,AHB12Freq_Value,AHB4Freq_Value,APB1Freq_Value,APB2Freq_Value,APB3Freq_Value,APB4Freq_Value,AXIClockFreq_Value,CECFreq_Value,CKPERFreq_Value,CortexFreq_Value,CpuClockFreq_Value,D1CPREFreq_Value,D1PPRE,D2PPRE1,D2PPRE2,D3PPRE,DFSDMACLkFreq_Value,DFSDMFreq_Value,DIVM1,DIVN1,DIVP1Freq_Value,DIVP2Freq_Value,DIVP3Freq_Value,DIVQ1Freq_Value,DIVQ2Freq_Value,DIVQ3Freq_Value,DIVR1Freq_Value,DIVR2Freq_Value,DIVR3Freq_Value,FDCANFreq_Value,FMCFreq_Value,FamilyName,HCLK3ClockFreq_Value,HCLKFreq_Value,HPRE,HRTIMFreq_Value,I2C123Freq_Value,I2C4Freq_Value,LPTIM1Freq_Value,LPTIM2Freq_Value,LPTIM345Freq_Value,LPUART1Freq_Value,LTDCFreq_Value,MCO1PinFreq_Value,MCO2PinFreq_Value,PLLSourceVirtual,PWR_Regulator_Voltage_Scale,ProductRev,QSPIFreq_Value,RCC_TIM_PRescaler_Selection,RNGFreq_Value,RTCFreq_Value,SAI1Freq_Value,SAI23Freq_Value,SAI4AFreq_Value,SAI4BFreq_Value,SDMMCFreq_Value,SPDIFRXFreq_Value,SPI123Freq_Value,SPI45Freq_Value,SPI6Freq_Value,SWPMI1Freq_Value,SYSCLKFreq_VALUE,SYSCLKSource,SupplySource,Tim1OutputFreq_Value,Tim2OutputFreq_Value,TraceFreq_Value,USART16Freq_Value,USART234578Freq_Value,USBFreq_Value,VCO1OutputFreq_Value,VCO2OutputFreq_Value,VCO3OutputFreq_Value,VCOInput1Freq_Value,VCOInput2Freq_Value,VCOInput3Freq_Value
|
RCC.IPParameters=ADCFreq_Value,AHB12Freq_Value,AHB4Freq_Value,APB1Freq_Value,APB2Freq_Value,APB3Freq_Value,APB4Freq_Value,AXIClockFreq_Value,CECFreq_Value,CKPERFreq_Value,CortexFreq_Value,CpuClockFreq_Value,D1CPREFreq_Value,D1PPRE,D2PPRE1,D2PPRE2,D3PPRE,DFSDMACLkFreq_Value,DFSDMFreq_Value,DIVM1,DIVN1,DIVP1Freq_Value,DIVP2Freq_Value,DIVP3Freq_Value,DIVQ1,DIVQ1Freq_Value,DIVQ2Freq_Value,DIVQ3Freq_Value,DIVR1Freq_Value,DIVR2Freq_Value,DIVR3Freq_Value,FDCANFreq_Value,FMCFreq_Value,FamilyName,HCLK3ClockFreq_Value,HCLKFreq_Value,HPRE,HRTIMFreq_Value,I2C123Freq_Value,I2C4Freq_Value,LPTIM1Freq_Value,LPTIM2Freq_Value,LPTIM345Freq_Value,LPUART1Freq_Value,LTDCFreq_Value,MCO1PinFreq_Value,MCO2PinFreq_Value,PLLFRACN,PLLSourceVirtual,PWR_Regulator_Voltage_Scale,ProductRev,QSPIFreq_Value,RCC_TIM_PRescaler_Selection,RNGFreq_Value,RTCFreq_Value,SAI1Freq_Value,SAI23Freq_Value,SAI4AFreq_Value,SAI4BFreq_Value,SDMMCFreq_Value,SPDIFRXFreq_Value,SPI123Freq_Value,SPI45Freq_Value,SPI6Freq_Value,SWPMI1Freq_Value,SYSCLKFreq_VALUE,SYSCLKSource,SupplySource,Tim1OutputFreq_Value,Tim2OutputFreq_Value,TraceFreq_Value,USART16Freq_Value,USART234578Freq_Value,USBCLockSelection,USBFreq_Value,VCO1OutputFreq_Value,VCO2OutputFreq_Value,VCO3OutputFreq_Value,VCOInput1Freq_Value,VCOInput2Freq_Value,VCOInput3Freq_Value
|
||||||
RCC.LPTIM1Freq_Value=120000000
|
RCC.LPTIM1Freq_Value=120000000
|
||||||
RCC.LPTIM2Freq_Value=120000000
|
RCC.LPTIM2Freq_Value=120000000
|
||||||
RCC.LPTIM345Freq_Value=120000000
|
RCC.LPTIM345Freq_Value=120000000
|
||||||
@@ -423,6 +386,7 @@ RCC.LPUART1Freq_Value=120000000
|
|||||||
RCC.LTDCFreq_Value=50390625
|
RCC.LTDCFreq_Value=50390625
|
||||||
RCC.MCO1PinFreq_Value=64000000
|
RCC.MCO1PinFreq_Value=64000000
|
||||||
RCC.MCO2PinFreq_Value=480000000
|
RCC.MCO2PinFreq_Value=480000000
|
||||||
|
RCC.PLLFRACN=0
|
||||||
RCC.PLLSourceVirtual=RCC_PLLSOURCE_HSE
|
RCC.PLLSourceVirtual=RCC_PLLSOURCE_HSE
|
||||||
RCC.PWR_Regulator_Voltage_Scale=PWR_REGULATOR_VOLTAGE_SCALE0
|
RCC.PWR_Regulator_Voltage_Scale=PWR_REGULATOR_VOLTAGE_SCALE0
|
||||||
RCC.ProductRev=revV
|
RCC.ProductRev=revV
|
||||||
@@ -430,13 +394,13 @@ RCC.QSPIFreq_Value=240000000
|
|||||||
RCC.RCC_TIM_PRescaler_Selection=RCC_TIMPRES_DESACTIVATED
|
RCC.RCC_TIM_PRescaler_Selection=RCC_TIMPRES_DESACTIVATED
|
||||||
RCC.RNGFreq_Value=48000000
|
RCC.RNGFreq_Value=48000000
|
||||||
RCC.RTCFreq_Value=32000
|
RCC.RTCFreq_Value=32000
|
||||||
RCC.SAI1Freq_Value=480000000
|
RCC.SAI1Freq_Value=64000000
|
||||||
RCC.SAI23Freq_Value=480000000
|
RCC.SAI23Freq_Value=64000000
|
||||||
RCC.SAI4AFreq_Value=480000000
|
RCC.SAI4AFreq_Value=64000000
|
||||||
RCC.SAI4BFreq_Value=480000000
|
RCC.SAI4BFreq_Value=64000000
|
||||||
RCC.SDMMCFreq_Value=480000000
|
RCC.SDMMCFreq_Value=64000000
|
||||||
RCC.SPDIFRXFreq_Value=480000000
|
RCC.SPDIFRXFreq_Value=64000000
|
||||||
RCC.SPI123Freq_Value=480000000
|
RCC.SPI123Freq_Value=64000000
|
||||||
RCC.SPI45Freq_Value=120000000
|
RCC.SPI45Freq_Value=120000000
|
||||||
RCC.SPI6Freq_Value=120000000
|
RCC.SPI6Freq_Value=120000000
|
||||||
RCC.SWPMI1Freq_Value=120000000
|
RCC.SWPMI1Freq_Value=120000000
|
||||||
@@ -448,45 +412,26 @@ RCC.Tim2OutputFreq_Value=240000000
|
|||||||
RCC.TraceFreq_Value=480000000
|
RCC.TraceFreq_Value=480000000
|
||||||
RCC.USART16Freq_Value=120000000
|
RCC.USART16Freq_Value=120000000
|
||||||
RCC.USART234578Freq_Value=120000000
|
RCC.USART234578Freq_Value=120000000
|
||||||
RCC.USBFreq_Value=480000000
|
RCC.USBCLockSelection=RCC_USBCLKSOURCE_HSI48
|
||||||
|
RCC.USBFreq_Value=48000000
|
||||||
RCC.VCO1OutputFreq_Value=960000000
|
RCC.VCO1OutputFreq_Value=960000000
|
||||||
RCC.VCO2OutputFreq_Value=100781250
|
RCC.VCO2OutputFreq_Value=100781250
|
||||||
RCC.VCO3OutputFreq_Value=100781250
|
RCC.VCO3OutputFreq_Value=100781250
|
||||||
RCC.VCOInput1Freq_Value=5000000
|
RCC.VCOInput1Freq_Value=5000000
|
||||||
RCC.VCOInput2Freq_Value=781250
|
RCC.VCOInput2Freq_Value=781250
|
||||||
RCC.VCOInput3Freq_Value=781250
|
RCC.VCOInput3Freq_Value=781250
|
||||||
SH.FMC_A16_CLE.0=FMC_CLE,8b-dmux1
|
|
||||||
SH.FMC_A16_CLE.ConfNb=1
|
|
||||||
SH.FMC_A17_ALE.0=FMC_ALE,8b-dmux1
|
|
||||||
SH.FMC_A17_ALE.ConfNb=1
|
|
||||||
SH.FMC_D0_DA0.0=FMC_D0,8b-dmux1
|
|
||||||
SH.FMC_D0_DA0.ConfNb=1
|
|
||||||
SH.FMC_D1_DA1.0=FMC_D1,8b-dmux1
|
|
||||||
SH.FMC_D1_DA1.ConfNb=1
|
|
||||||
SH.FMC_D2_DA2.0=FMC_D2,8b-dmux1
|
|
||||||
SH.FMC_D2_DA2.ConfNb=1
|
|
||||||
SH.FMC_D3_DA3.0=FMC_D3,8b-dmux1
|
|
||||||
SH.FMC_D3_DA3.ConfNb=1
|
|
||||||
SH.FMC_D4_DA4.0=FMC_D4,8b-dmux1
|
|
||||||
SH.FMC_D4_DA4.ConfNb=1
|
|
||||||
SH.FMC_D5_DA5.0=FMC_D5,8b-dmux1
|
|
||||||
SH.FMC_D5_DA5.ConfNb=1
|
|
||||||
SH.FMC_D6_DA6.0=FMC_D6,8b-dmux1
|
|
||||||
SH.FMC_D6_DA6.ConfNb=1
|
|
||||||
SH.FMC_D7_DA7.0=FMC_D7,8b-dmux1
|
|
||||||
SH.FMC_D7_DA7.ConfNb=1
|
|
||||||
SH.FMC_NOE.0=FMC_NOE,8b-dmux1
|
|
||||||
SH.FMC_NOE.ConfNb=1
|
|
||||||
SH.FMC_NWAIT.0=FMC_NWAIT,Wait1
|
|
||||||
SH.FMC_NWAIT.ConfNb=1
|
|
||||||
SH.FMC_NWE.0=FMC_NWE,8b-dmux1
|
|
||||||
SH.FMC_NWE.ConfNb=1
|
|
||||||
USART1.IPParameters=VirtualMode-Asynchronous
|
USART1.IPParameters=VirtualMode-Asynchronous
|
||||||
USART1.VirtualMode-Asynchronous=VM_ASYNC
|
USART1.VirtualMode-Asynchronous=VM_ASYNC
|
||||||
USART3.IPParameters=VirtualMode-Asynchronous
|
USART3.IPParameters=VirtualMode-Asynchronous
|
||||||
USART3.VirtualMode-Asynchronous=VM_ASYNC
|
USART3.VirtualMode-Asynchronous=VM_ASYNC
|
||||||
USART6.IPParameters=VirtualMode-Asynchronous
|
USART6.IPParameters=VirtualMode-Asynchronous
|
||||||
USART6.VirtualMode-Asynchronous=VM_ASYNC
|
USART6.VirtualMode-Asynchronous=VM_ASYNC
|
||||||
|
USB_DEVICE.CLASS_NAME_FS=CDC
|
||||||
|
USB_DEVICE.IPParameters=VirtualModeFS,CLASS_NAME_FS,VirtualMode-CDC_FS
|
||||||
|
USB_DEVICE.VirtualMode-CDC_FS=Cdc
|
||||||
|
USB_DEVICE.VirtualModeFS=Cdc_FS
|
||||||
|
USB_OTG_FS.IPParameters=VirtualMode
|
||||||
|
USB_OTG_FS.VirtualMode=Device_Only
|
||||||
VP_FREERTOS_VS_CMSIS_V1.Mode=CMSIS_V1
|
VP_FREERTOS_VS_CMSIS_V1.Mode=CMSIS_V1
|
||||||
VP_FREERTOS_VS_CMSIS_V1.Signal=FREERTOS_VS_CMSIS_V1
|
VP_FREERTOS_VS_CMSIS_V1.Signal=FREERTOS_VS_CMSIS_V1
|
||||||
VP_LWIP_VS_Enabled.Mode=Enabled
|
VP_LWIP_VS_Enabled.Mode=Enabled
|
||||||
@@ -495,5 +440,7 @@ VP_MEMORYMAP_VS_MEMORYMAP.Mode=CurAppReg
|
|||||||
VP_MEMORYMAP_VS_MEMORYMAP.Signal=MEMORYMAP_VS_MEMORYMAP
|
VP_MEMORYMAP_VS_MEMORYMAP.Signal=MEMORYMAP_VS_MEMORYMAP
|
||||||
VP_SYS_VS_tim7.Mode=TIM7
|
VP_SYS_VS_tim7.Mode=TIM7
|
||||||
VP_SYS_VS_tim7.Signal=SYS_VS_tim7
|
VP_SYS_VS_tim7.Signal=SYS_VS_tim7
|
||||||
|
VP_USB_DEVICE_VS_USB_DEVICE_CDC_FS.Mode=CDC_FS
|
||||||
|
VP_USB_DEVICE_VS_USB_DEVICE_CDC_FS.Signal=USB_DEVICE_VS_USB_DEVICE_CDC_FS
|
||||||
board=custom
|
board=custom
|
||||||
rtos.0.ip=FREERTOS
|
rtos.0.ip=FREERTOS
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ void MX_LWIP_Init(void)
|
|||||||
IP_ADDRESS[0] = 10;
|
IP_ADDRESS[0] = 10;
|
||||||
IP_ADDRESS[1] = 12;
|
IP_ADDRESS[1] = 12;
|
||||||
IP_ADDRESS[2] = 19;
|
IP_ADDRESS[2] = 19;
|
||||||
IP_ADDRESS[3] = 100;
|
IP_ADDRESS[3] = 252;
|
||||||
NETMASK_ADDRESS[0] = 255;
|
NETMASK_ADDRESS[0] = 255;
|
||||||
NETMASK_ADDRESS[1] = 255;
|
NETMASK_ADDRESS[1] = 255;
|
||||||
NETMASK_ADDRESS[2] = 255;
|
NETMASK_ADDRESS[2] = 255;
|
||||||
|
|||||||
@@ -44,6 +44,23 @@ virtualFolder:
|
|||||||
- path: ../Middlewares/Third_Party/LwIP/src/apps/http/fs.c
|
- path: ../Middlewares/Third_Party/LwIP/src/apps/http/fs.c
|
||||||
- path: ../Middlewares/Third_Party/LwIP/src/apps/http/fsdata_custom.c
|
- path: ../Middlewares/Third_Party/LwIP/src/apps/http/fsdata_custom.c
|
||||||
folders: []
|
folders: []
|
||||||
|
- name: USB
|
||||||
|
files: []
|
||||||
|
folders:
|
||||||
|
- name: App
|
||||||
|
files:
|
||||||
|
- path: ../USB_DEVICE/App/usb_device.c
|
||||||
|
- path: ../USB_DEVICE/App/usb_device.h
|
||||||
|
- path: ../USB_DEVICE/App/usbd_cdc_if.c
|
||||||
|
- path: ../USB_DEVICE/App/usbd_cdc_if.h
|
||||||
|
- path: ../USB_DEVICE/App/usbd_desc.c
|
||||||
|
- path: ../USB_DEVICE/App/usbd_desc.h
|
||||||
|
folders: []
|
||||||
|
- name: Target
|
||||||
|
files:
|
||||||
|
- path: ../USB_DEVICE/Target/usbd_conf.c
|
||||||
|
- path: ../USB_DEVICE/Target/usbd_conf.h
|
||||||
|
folders: []
|
||||||
- name: User
|
- name: User
|
||||||
files: []
|
files: []
|
||||||
folders:
|
folders:
|
||||||
@@ -107,6 +124,9 @@ virtualFolder:
|
|||||||
- path: ../Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_tim_ex.c
|
- path: ../Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_tim_ex.c
|
||||||
- path: ../Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_uart.c
|
- path: ../Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_uart.c
|
||||||
- path: ../Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_uart_ex.c
|
- path: ../Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_uart_ex.c
|
||||||
|
- path: ../Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_pcd.c
|
||||||
|
- path: ../Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_pcd_ex.c
|
||||||
|
- path: ../Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_ll_usb.c
|
||||||
folders: []
|
folders: []
|
||||||
- name: CMSIS
|
- name: CMSIS
|
||||||
files:
|
files:
|
||||||
@@ -120,6 +140,20 @@ virtualFolder:
|
|||||||
- path: ../Drivers/BSP/Components/yt8512c/yt8512c.c
|
- path: ../Drivers/BSP/Components/yt8512c/yt8512c.c
|
||||||
- path: ../Drivers/BSP/Components/lan8742/lan8742.c
|
- path: ../Drivers/BSP/Components/lan8742/lan8742.c
|
||||||
folders: []
|
folders: []
|
||||||
|
- name: STM32_USB_Device_Library
|
||||||
|
files: []
|
||||||
|
folders:
|
||||||
|
- name: Core
|
||||||
|
files:
|
||||||
|
- path: ../Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_core.c
|
||||||
|
- path: ../Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_ctlreq.c
|
||||||
|
- path: ../Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_ioreq.c
|
||||||
|
folders: []
|
||||||
|
- name: CDC
|
||||||
|
files:
|
||||||
|
- path: ../Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Src/usbd_cdc.c
|
||||||
|
- path: ../Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Src/usbd_cdc_if_template.c
|
||||||
|
folders: []
|
||||||
- name: Middlewares
|
- name: Middlewares
|
||||||
files: []
|
files: []
|
||||||
folders:
|
folders:
|
||||||
@@ -284,9 +318,15 @@ targets:
|
|||||||
- RTE/_IPort
|
- RTE/_IPort
|
||||||
- ../Middlewares/Third_Party/Ykc
|
- ../Middlewares/Third_Party/Ykc
|
||||||
- ../Middlewares/Third_Party/cJSON
|
- ../Middlewares/Third_Party/cJSON
|
||||||
|
- ../USB_DEVICE/App
|
||||||
|
- ../USB_DEVICE/Target
|
||||||
|
- ../Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Inc
|
||||||
|
- ../Middlewares/ST/STM32_USB_Device_Library/Core/Inc
|
||||||
libList: []
|
libList: []
|
||||||
excludeList:
|
excludeList:
|
||||||
- <virtual_root>/User/Hal/_hal_myi2c.c
|
- <virtual_root>/User/Hal/_hal_myi2c.c
|
||||||
|
settings:
|
||||||
|
debugger: cortex-debug
|
||||||
toolchain: AC5
|
toolchain: AC5
|
||||||
toolchainConfigMap:
|
toolchainConfigMap:
|
||||||
AC5:
|
AC5:
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<ProjectOpt xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="project_optx.xsd">
|
<ProjectOpt xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="project_optx.xsd">
|
||||||
|
|
||||||
<SchemaVersion>1.0</SchemaVersion>
|
<SchemaVersion>1.0</SchemaVersion>
|
||||||
@@ -45,7 +45,7 @@
|
|||||||
<PageWidth>79</PageWidth>
|
<PageWidth>79</PageWidth>
|
||||||
<PageLength>66</PageLength>
|
<PageLength>66</PageLength>
|
||||||
<TabStop>8</TabStop>
|
<TabStop>8</TabStop>
|
||||||
<ListingPath></ListingPath>
|
<ListingPath />
|
||||||
</OPTLEX>
|
</OPTLEX>
|
||||||
<ListingPage>
|
<ListingPage>
|
||||||
<CreateCListing>1</CreateCListing>
|
<CreateCListing>1</CreateCListing>
|
||||||
@@ -104,16 +104,16 @@
|
|||||||
<bSchkAxf>0</bSchkAxf>
|
<bSchkAxf>0</bSchkAxf>
|
||||||
<bTchkAxf>0</bTchkAxf>
|
<bTchkAxf>0</bTchkAxf>
|
||||||
<nTsel>3</nTsel>
|
<nTsel>3</nTsel>
|
||||||
<sDll></sDll>
|
<sDll />
|
||||||
<sDllPa></sDllPa>
|
<sDllPa />
|
||||||
<sDlgDll></sDlgDll>
|
<sDlgDll />
|
||||||
<sDlgPa></sDlgPa>
|
<sDlgPa />
|
||||||
<sIfile></sIfile>
|
<sIfile />
|
||||||
<tDll></tDll>
|
<tDll />
|
||||||
<tDllPa></tDllPa>
|
<tDllPa />
|
||||||
<tDlgDll></tDlgDll>
|
<tDlgDll />
|
||||||
<tDlgPa></tDlgPa>
|
<tDlgPa />
|
||||||
<tIfile></tIfile>
|
<tIfile />
|
||||||
<pMon>BIN\CMSIS_AGDI.dll</pMon>
|
<pMon>BIN\CMSIS_AGDI.dll</pMon>
|
||||||
</DebugOpt>
|
</DebugOpt>
|
||||||
<TargetDriverDllRegistry>
|
<TargetDriverDllRegistry>
|
||||||
@@ -135,12 +135,12 @@
|
|||||||
<SetRegEntry>
|
<SetRegEntry>
|
||||||
<Number>0</Number>
|
<Number>0</Number>
|
||||||
<Key>ARMDBGFLAGS</Key>
|
<Key>ARMDBGFLAGS</Key>
|
||||||
<Name></Name>
|
<Name />
|
||||||
</SetRegEntry>
|
</SetRegEntry>
|
||||||
<SetRegEntry>
|
<SetRegEntry>
|
||||||
<Number>0</Number>
|
<Number>0</Number>
|
||||||
<Key>DLGUARM</Key>
|
<Key>DLGUARM</Key>
|
||||||
<Name></Name>
|
<Name />
|
||||||
</SetRegEntry>
|
</SetRegEntry>
|
||||||
<SetRegEntry>
|
<SetRegEntry>
|
||||||
<Number>0</Number>
|
<Number>0</Number>
|
||||||
@@ -235,19 +235,19 @@
|
|||||||
<newCpu>0</newCpu>
|
<newCpu>0</newCpu>
|
||||||
<uProt>0</uProt>
|
<uProt>0</uProt>
|
||||||
</DebugFlag>
|
</DebugFlag>
|
||||||
<LintExecutable></LintExecutable>
|
<LintExecutable />
|
||||||
<LintConfigFile></LintConfigFile>
|
<LintConfigFile />
|
||||||
<bLintAuto>0</bLintAuto>
|
<bLintAuto>0</bLintAuto>
|
||||||
<bAutoGenD>0</bAutoGenD>
|
<bAutoGenD>0</bAutoGenD>
|
||||||
<LntExFlags>0</LntExFlags>
|
<LntExFlags>0</LntExFlags>
|
||||||
<pMisraName></pMisraName>
|
<pMisraName />
|
||||||
<pszMrule></pszMrule>
|
<pszMrule />
|
||||||
<pSingCmds></pSingCmds>
|
<pSingCmds />
|
||||||
<pMultCmds></pMultCmds>
|
<pMultCmds />
|
||||||
<pMisraNamep></pMisraNamep>
|
<pMisraNamep />
|
||||||
<pszMrulep></pszMrulep>
|
<pszMrulep />
|
||||||
<pSingCmdsp></pSingCmdsp>
|
<pSingCmdsp />
|
||||||
<pMultCmdsp></pMultCmdsp>
|
<pMultCmdsp />
|
||||||
<DebugDescription>
|
<DebugDescription>
|
||||||
<Enable>1</Enable>
|
<Enable>1</Enable>
|
||||||
<EnableFlashSeq>1</EnableFlashSeq>
|
<EnableFlashSeq>1</EnableFlashSeq>
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -29,7 +29,7 @@
|
|||||||
; <o> Stack Size (in Bytes) <0x0-0xFFFFFFFF:8>
|
; <o> Stack Size (in Bytes) <0x0-0xFFFFFFFF:8>
|
||||||
; </h>
|
; </h>
|
||||||
|
|
||||||
Stack_Size EQU 0x2048
|
Stack_Size EQU 0x1000
|
||||||
|
|
||||||
AREA STACK, NOINIT, READWRITE, ALIGN=3
|
AREA STACK, NOINIT, READWRITE, ALIGN=3
|
||||||
Stack_Mem SPACE Stack_Size
|
Stack_Mem SPACE Stack_Size
|
||||||
@@ -40,7 +40,7 @@ __initial_sp
|
|||||||
; <o> Heap Size (in Bytes) <0x0-0xFFFFFFFF:8>
|
; <o> Heap Size (in Bytes) <0x0-0xFFFFFFFF:8>
|
||||||
; </h>
|
; </h>
|
||||||
|
|
||||||
Heap_Size EQU 0x20000
|
Heap_Size EQU 0x2000
|
||||||
|
|
||||||
AREA HEAP, NOINIT, READWRITE, ALIGN=3
|
AREA HEAP, NOINIT, READWRITE, ALIGN=3
|
||||||
__heap_base
|
__heap_base
|
||||||
|
|||||||
@@ -0,0 +1,184 @@
|
|||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
* @file usbd_cdc.h
|
||||||
|
* @author MCD Application Team
|
||||||
|
* @brief header file for the usbd_cdc.c file.
|
||||||
|
******************************************************************************
|
||||||
|
* @attention
|
||||||
|
*
|
||||||
|
* Copyright (c) 2015 STMicroelectronics.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This software is licensed under terms that can be found in the LICENSE file
|
||||||
|
* in the root directory of this software component.
|
||||||
|
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||||
|
*
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||||
|
#ifndef __USB_CDC_H
|
||||||
|
#define __USB_CDC_H
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Includes ------------------------------------------------------------------*/
|
||||||
|
#include "usbd_ioreq.h"
|
||||||
|
|
||||||
|
/** @addtogroup STM32_USB_DEVICE_LIBRARY
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup usbd_cdc
|
||||||
|
* @brief This file is the Header file for usbd_cdc.c
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/** @defgroup usbd_cdc_Exported_Defines
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
#ifndef CDC_IN_EP
|
||||||
|
#define CDC_IN_EP 0x81U /* EP1 for data IN */
|
||||||
|
#endif /* CDC_IN_EP */
|
||||||
|
#ifndef CDC_OUT_EP
|
||||||
|
#define CDC_OUT_EP 0x01U /* EP1 for data OUT */
|
||||||
|
#endif /* CDC_OUT_EP */
|
||||||
|
#ifndef CDC_CMD_EP
|
||||||
|
#define CDC_CMD_EP 0x82U /* EP2 for CDC commands */
|
||||||
|
#endif /* CDC_CMD_EP */
|
||||||
|
|
||||||
|
#ifndef CDC_HS_BINTERVAL
|
||||||
|
#define CDC_HS_BINTERVAL 0x10U
|
||||||
|
#endif /* CDC_HS_BINTERVAL */
|
||||||
|
|
||||||
|
#ifndef CDC_FS_BINTERVAL
|
||||||
|
#define CDC_FS_BINTERVAL 0x10U
|
||||||
|
#endif /* CDC_FS_BINTERVAL */
|
||||||
|
|
||||||
|
/* CDC Endpoints parameters: you can fine tune these values depending on the needed baudrates and performance. */
|
||||||
|
#define CDC_DATA_HS_MAX_PACKET_SIZE 512U /* Endpoint IN & OUT Packet size */
|
||||||
|
#define CDC_DATA_FS_MAX_PACKET_SIZE 64U /* Endpoint IN & OUT Packet size */
|
||||||
|
#define CDC_CMD_PACKET_SIZE 8U /* Control Endpoint Packet size */
|
||||||
|
|
||||||
|
#define USB_CDC_CONFIG_DESC_SIZ 67U
|
||||||
|
#define CDC_DATA_HS_IN_PACKET_SIZE CDC_DATA_HS_MAX_PACKET_SIZE
|
||||||
|
#define CDC_DATA_HS_OUT_PACKET_SIZE CDC_DATA_HS_MAX_PACKET_SIZE
|
||||||
|
|
||||||
|
#define CDC_DATA_FS_IN_PACKET_SIZE CDC_DATA_FS_MAX_PACKET_SIZE
|
||||||
|
#define CDC_DATA_FS_OUT_PACKET_SIZE CDC_DATA_FS_MAX_PACKET_SIZE
|
||||||
|
|
||||||
|
#define CDC_REQ_MAX_DATA_SIZE 0x7U
|
||||||
|
/*---------------------------------------------------------------------*/
|
||||||
|
/* CDC definitions */
|
||||||
|
/*---------------------------------------------------------------------*/
|
||||||
|
#define CDC_SEND_ENCAPSULATED_COMMAND 0x00U
|
||||||
|
#define CDC_GET_ENCAPSULATED_RESPONSE 0x01U
|
||||||
|
#define CDC_SET_COMM_FEATURE 0x02U
|
||||||
|
#define CDC_GET_COMM_FEATURE 0x03U
|
||||||
|
#define CDC_CLEAR_COMM_FEATURE 0x04U
|
||||||
|
#define CDC_SET_LINE_CODING 0x20U
|
||||||
|
#define CDC_GET_LINE_CODING 0x21U
|
||||||
|
#define CDC_SET_CONTROL_LINE_STATE 0x22U
|
||||||
|
#define CDC_SEND_BREAK 0x23U
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/** @defgroup USBD_CORE_Exported_TypesDefinitions
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
uint32_t bitrate;
|
||||||
|
uint8_t format;
|
||||||
|
uint8_t paritytype;
|
||||||
|
uint8_t datatype;
|
||||||
|
} USBD_CDC_LineCodingTypeDef;
|
||||||
|
|
||||||
|
typedef struct _USBD_CDC_Itf
|
||||||
|
{
|
||||||
|
int8_t (* Init)(void);
|
||||||
|
int8_t (* DeInit)(void);
|
||||||
|
int8_t (* Control)(uint8_t cmd, uint8_t *pbuf, uint16_t length);
|
||||||
|
int8_t (* Receive)(uint8_t *Buf, uint32_t *Len);
|
||||||
|
int8_t (* TransmitCplt)(uint8_t *Buf, uint32_t *Len, uint8_t epnum);
|
||||||
|
} USBD_CDC_ItfTypeDef;
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
uint32_t data[CDC_DATA_HS_MAX_PACKET_SIZE / 4U]; /* Force 32-bit alignment */
|
||||||
|
uint8_t CmdOpCode;
|
||||||
|
uint8_t CmdLength;
|
||||||
|
uint8_t *RxBuffer;
|
||||||
|
uint8_t *TxBuffer;
|
||||||
|
uint32_t RxLength;
|
||||||
|
uint32_t TxLength;
|
||||||
|
|
||||||
|
__IO uint32_t TxState;
|
||||||
|
__IO uint32_t RxState;
|
||||||
|
} USBD_CDC_HandleTypeDef;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/** @defgroup USBD_CORE_Exported_Macros
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_CORE_Exported_Variables
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
extern USBD_ClassTypeDef USBD_CDC;
|
||||||
|
#define USBD_CDC_CLASS &USBD_CDC
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USB_CORE_Exported_Functions
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
uint8_t USBD_CDC_RegisterInterface(USBD_HandleTypeDef *pdev,
|
||||||
|
USBD_CDC_ItfTypeDef *fops);
|
||||||
|
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
uint8_t USBD_CDC_SetTxBuffer(USBD_HandleTypeDef *pdev, uint8_t *pbuff,
|
||||||
|
uint32_t length, uint8_t ClassId);
|
||||||
|
uint8_t USBD_CDC_TransmitPacket(USBD_HandleTypeDef *pdev, uint8_t ClassId);
|
||||||
|
#else
|
||||||
|
uint8_t USBD_CDC_SetTxBuffer(USBD_HandleTypeDef *pdev, uint8_t *pbuff,
|
||||||
|
uint32_t length);
|
||||||
|
uint8_t USBD_CDC_TransmitPacket(USBD_HandleTypeDef *pdev);
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
uint8_t USBD_CDC_SetRxBuffer(USBD_HandleTypeDef *pdev, uint8_t *pbuff);
|
||||||
|
uint8_t USBD_CDC_ReceivePacket(USBD_HandleTypeDef *pdev);
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* __USB_CDC_H */
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
@@ -1,13 +1,12 @@
|
|||||||
/* USER CODE BEGIN Header */
|
|
||||||
/**
|
/**
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
* File Name : FMC.h
|
* @file usbd_cdc_if_template.h
|
||||||
* Description : This file provides code for the configuration
|
* @author MCD Application Team
|
||||||
* of the FMC peripheral.
|
* @brief Header for usbd_cdc_if_template.c file.
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
* @attention
|
* @attention
|
||||||
*
|
*
|
||||||
* Copyright (c) 2026 STMicroelectronics.
|
* Copyright (c) 2015 STMicroelectronics.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* This software is licensed under terms that can be found in the LICENSE file
|
* This software is licensed under terms that can be found in the LICENSE file
|
||||||
@@ -16,44 +15,29 @@
|
|||||||
*
|
*
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
/* USER CODE END Header */
|
|
||||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||||
#ifndef __FMC_H
|
#ifndef __USBD_CDC_IF_TEMPLATE_H
|
||||||
#define __FMC_H
|
#define __USBD_CDC_IF_TEMPLATE_H
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
/* Includes ------------------------------------------------------------------*/
|
||||||
#include "main.h"
|
#include "usbd_cdc.h"
|
||||||
|
|
||||||
/* USER CODE BEGIN Includes */
|
/* Exported types ------------------------------------------------------------*/
|
||||||
|
/* Exported constants --------------------------------------------------------*/
|
||||||
|
|
||||||
/* USER CODE END Includes */
|
extern USBD_CDC_ItfTypeDef USBD_CDC_Template_fops;
|
||||||
|
|
||||||
extern NAND_HandleTypeDef hnand1;
|
/* Exported macro ------------------------------------------------------------*/
|
||||||
|
/* Exported functions ------------------------------------------------------- */
|
||||||
/* USER CODE BEGIN Private defines */
|
|
||||||
|
|
||||||
/* USER CODE END Private defines */
|
|
||||||
|
|
||||||
void MX_FMC_Init(void);
|
|
||||||
void HAL_NAND_MspInit(NAND_HandleTypeDef* hnand);
|
|
||||||
void HAL_NAND_MspDeInit(NAND_HandleTypeDef* hnand);
|
|
||||||
|
|
||||||
/* USER CODE BEGIN Prototypes */
|
|
||||||
|
|
||||||
/* USER CODE END Prototypes */
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#endif /*__FMC_H */
|
|
||||||
|
|
||||||
/**
|
#endif /* __USBD_CDC_IF_TEMPLATE_H */
|
||||||
* @}
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @}
|
|
||||||
*/
|
|
||||||
@@ -0,0 +1,893 @@
|
|||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
* @file usbd_cdc.c
|
||||||
|
* @author MCD Application Team
|
||||||
|
* @brief This file provides the high layer firmware functions to manage the
|
||||||
|
* following functionalities of the USB CDC Class:
|
||||||
|
* - Initialization and Configuration of high and low layer
|
||||||
|
* - Enumeration as CDC Device (and enumeration for each implemented memory interface)
|
||||||
|
* - OUT/IN data transfer
|
||||||
|
* - Command IN transfer (class requests management)
|
||||||
|
* - Error management
|
||||||
|
*
|
||||||
|
******************************************************************************
|
||||||
|
* @attention
|
||||||
|
*
|
||||||
|
* Copyright (c) 2015 STMicroelectronics.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This software is licensed under terms that can be found in the LICENSE file
|
||||||
|
* in the root directory of this software component.
|
||||||
|
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||||
|
*
|
||||||
|
******************************************************************************
|
||||||
|
* @verbatim
|
||||||
|
*
|
||||||
|
* ===================================================================
|
||||||
|
* CDC Class Driver Description
|
||||||
|
* ===================================================================
|
||||||
|
* This driver manages the "Universal Serial Bus Class Definitions for Communications Devices
|
||||||
|
* Revision 1.2 November 16, 2007" and the sub-protocol specification of "Universal Serial Bus
|
||||||
|
* Communications Class Subclass Specification for PSTN Devices Revision 1.2 February 9, 2007"
|
||||||
|
* This driver implements the following aspects of the specification:
|
||||||
|
* - Device descriptor management
|
||||||
|
* - Configuration descriptor management
|
||||||
|
* - Enumeration as CDC device with 2 data endpoints (IN and OUT) and 1 command endpoint (IN)
|
||||||
|
* - Requests management (as described in section 6.2 in specification)
|
||||||
|
* - Abstract Control Model compliant
|
||||||
|
* - Union Functional collection (using 1 IN endpoint for control)
|
||||||
|
* - Data interface class
|
||||||
|
*
|
||||||
|
* These aspects may be enriched or modified for a specific user application.
|
||||||
|
*
|
||||||
|
* This driver doesn't implement the following aspects of the specification
|
||||||
|
* (but it is possible to manage these features with some modifications on this driver):
|
||||||
|
* - Any class-specific aspect relative to communication classes should be managed by user application.
|
||||||
|
* - All communication classes other than PSTN are not managed
|
||||||
|
*
|
||||||
|
* @endverbatim
|
||||||
|
*
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* BSPDependencies
|
||||||
|
- "stm32xxxxx_{eval}{discovery}{nucleo_144}.c"
|
||||||
|
- "stm32xxxxx_{eval}{discovery}_io.c"
|
||||||
|
EndBSPDependencies */
|
||||||
|
|
||||||
|
/* Includes ------------------------------------------------------------------*/
|
||||||
|
#include "usbd_cdc.h"
|
||||||
|
#include "usbd_ctlreq.h"
|
||||||
|
|
||||||
|
|
||||||
|
/** @addtogroup STM32_USB_DEVICE_LIBRARY
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/** @defgroup USBD_CDC
|
||||||
|
* @brief usbd core module
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_CDC_Private_TypesDefinitions
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/** @defgroup USBD_CDC_Private_Defines
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/** @defgroup USBD_CDC_Private_Macros
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/** @defgroup USBD_CDC_Private_FunctionPrototypes
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
static uint8_t USBD_CDC_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx);
|
||||||
|
static uint8_t USBD_CDC_DeInit(USBD_HandleTypeDef *pdev, uint8_t cfgidx);
|
||||||
|
static uint8_t USBD_CDC_Setup(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
|
||||||
|
static uint8_t USBD_CDC_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||||
|
static uint8_t USBD_CDC_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||||
|
static uint8_t USBD_CDC_EP0_RxReady(USBD_HandleTypeDef *pdev);
|
||||||
|
#ifndef USE_USBD_COMPOSITE
|
||||||
|
static uint8_t *USBD_CDC_GetFSCfgDesc(uint16_t *length);
|
||||||
|
static uint8_t *USBD_CDC_GetHSCfgDesc(uint16_t *length);
|
||||||
|
static uint8_t *USBD_CDC_GetOtherSpeedCfgDesc(uint16_t *length);
|
||||||
|
uint8_t *USBD_CDC_GetDeviceQualifierDescriptor(uint16_t *length);
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
|
#ifndef USE_USBD_COMPOSITE
|
||||||
|
/* USB Standard Device Descriptor */
|
||||||
|
__ALIGN_BEGIN static uint8_t USBD_CDC_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_DESC] __ALIGN_END =
|
||||||
|
{
|
||||||
|
USB_LEN_DEV_QUALIFIER_DESC,
|
||||||
|
USB_DESC_TYPE_DEVICE_QUALIFIER,
|
||||||
|
0x00,
|
||||||
|
0x02,
|
||||||
|
0x00,
|
||||||
|
0x00,
|
||||||
|
0x00,
|
||||||
|
0x40,
|
||||||
|
0x01,
|
||||||
|
0x00,
|
||||||
|
};
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_CDC_Private_Variables
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/* CDC interface class callbacks structure */
|
||||||
|
USBD_ClassTypeDef USBD_CDC =
|
||||||
|
{
|
||||||
|
USBD_CDC_Init,
|
||||||
|
USBD_CDC_DeInit,
|
||||||
|
USBD_CDC_Setup,
|
||||||
|
NULL, /* EP0_TxSent */
|
||||||
|
USBD_CDC_EP0_RxReady,
|
||||||
|
USBD_CDC_DataIn,
|
||||||
|
USBD_CDC_DataOut,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
#else
|
||||||
|
USBD_CDC_GetHSCfgDesc,
|
||||||
|
USBD_CDC_GetFSCfgDesc,
|
||||||
|
USBD_CDC_GetOtherSpeedCfgDesc,
|
||||||
|
USBD_CDC_GetDeviceQualifierDescriptor,
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
};
|
||||||
|
|
||||||
|
#ifndef USE_USBD_COMPOSITE
|
||||||
|
/* USB CDC device Configuration Descriptor */
|
||||||
|
__ALIGN_BEGIN static uint8_t USBD_CDC_CfgDesc[USB_CDC_CONFIG_DESC_SIZ] __ALIGN_END =
|
||||||
|
{
|
||||||
|
/* Configuration Descriptor */
|
||||||
|
0x09, /* bLength: Configuration Descriptor size */
|
||||||
|
USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */
|
||||||
|
USB_CDC_CONFIG_DESC_SIZ, /* wTotalLength */
|
||||||
|
0x00,
|
||||||
|
0x02, /* bNumInterfaces: 2 interfaces */
|
||||||
|
0x01, /* bConfigurationValue: Configuration value */
|
||||||
|
0x00, /* iConfiguration: Index of string descriptor
|
||||||
|
describing the configuration */
|
||||||
|
#if (USBD_SELF_POWERED == 1U)
|
||||||
|
0xC0, /* bmAttributes: Bus Powered according to user configuration */
|
||||||
|
#else
|
||||||
|
0x80, /* bmAttributes: Bus Powered according to user configuration */
|
||||||
|
#endif /* USBD_SELF_POWERED */
|
||||||
|
USBD_MAX_POWER, /* MaxPower (mA) */
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/* Interface Descriptor */
|
||||||
|
0x09, /* bLength: Interface Descriptor size */
|
||||||
|
USB_DESC_TYPE_INTERFACE, /* bDescriptorType: Interface */
|
||||||
|
/* Interface descriptor type */
|
||||||
|
0x00, /* bInterfaceNumber: Number of Interface */
|
||||||
|
0x00, /* bAlternateSetting: Alternate setting */
|
||||||
|
0x01, /* bNumEndpoints: One endpoint used */
|
||||||
|
0x02, /* bInterfaceClass: Communication Interface Class */
|
||||||
|
0x02, /* bInterfaceSubClass: Abstract Control Model */
|
||||||
|
0x01, /* bInterfaceProtocol: Common AT commands */
|
||||||
|
0x00, /* iInterface */
|
||||||
|
|
||||||
|
/* Header Functional Descriptor */
|
||||||
|
0x05, /* bLength: Endpoint Descriptor size */
|
||||||
|
0x24, /* bDescriptorType: CS_INTERFACE */
|
||||||
|
0x00, /* bDescriptorSubtype: Header Func Desc */
|
||||||
|
0x10, /* bcdCDC: spec release number */
|
||||||
|
0x01,
|
||||||
|
|
||||||
|
/* Call Management Functional Descriptor */
|
||||||
|
0x05, /* bFunctionLength */
|
||||||
|
0x24, /* bDescriptorType: CS_INTERFACE */
|
||||||
|
0x01, /* bDescriptorSubtype: Call Management Func Desc */
|
||||||
|
0x00, /* bmCapabilities: D0+D1 */
|
||||||
|
0x01, /* bDataInterface */
|
||||||
|
|
||||||
|
/* ACM Functional Descriptor */
|
||||||
|
0x04, /* bFunctionLength */
|
||||||
|
0x24, /* bDescriptorType: CS_INTERFACE */
|
||||||
|
0x02, /* bDescriptorSubtype: Abstract Control Management desc */
|
||||||
|
0x02, /* bmCapabilities */
|
||||||
|
|
||||||
|
/* Union Functional Descriptor */
|
||||||
|
0x05, /* bFunctionLength */
|
||||||
|
0x24, /* bDescriptorType: CS_INTERFACE */
|
||||||
|
0x06, /* bDescriptorSubtype: Union func desc */
|
||||||
|
0x00, /* bMasterInterface: Communication class interface */
|
||||||
|
0x01, /* bSlaveInterface0: Data Class Interface */
|
||||||
|
|
||||||
|
/* Endpoint 2 Descriptor */
|
||||||
|
0x07, /* bLength: Endpoint Descriptor size */
|
||||||
|
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */
|
||||||
|
CDC_CMD_EP, /* bEndpointAddress */
|
||||||
|
0x03, /* bmAttributes: Interrupt */
|
||||||
|
LOBYTE(CDC_CMD_PACKET_SIZE), /* wMaxPacketSize */
|
||||||
|
HIBYTE(CDC_CMD_PACKET_SIZE),
|
||||||
|
CDC_FS_BINTERVAL, /* bInterval */
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/* Data class interface descriptor */
|
||||||
|
0x09, /* bLength: Endpoint Descriptor size */
|
||||||
|
USB_DESC_TYPE_INTERFACE, /* bDescriptorType: */
|
||||||
|
0x01, /* bInterfaceNumber: Number of Interface */
|
||||||
|
0x00, /* bAlternateSetting: Alternate setting */
|
||||||
|
0x02, /* bNumEndpoints: Two endpoints used */
|
||||||
|
0x0A, /* bInterfaceClass: CDC */
|
||||||
|
0x00, /* bInterfaceSubClass */
|
||||||
|
0x00, /* bInterfaceProtocol */
|
||||||
|
0x00, /* iInterface */
|
||||||
|
|
||||||
|
/* Endpoint OUT Descriptor */
|
||||||
|
0x07, /* bLength: Endpoint Descriptor size */
|
||||||
|
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */
|
||||||
|
CDC_OUT_EP, /* bEndpointAddress */
|
||||||
|
0x02, /* bmAttributes: Bulk */
|
||||||
|
LOBYTE(CDC_DATA_FS_MAX_PACKET_SIZE), /* wMaxPacketSize */
|
||||||
|
HIBYTE(CDC_DATA_FS_MAX_PACKET_SIZE),
|
||||||
|
0x00, /* bInterval */
|
||||||
|
|
||||||
|
/* Endpoint IN Descriptor */
|
||||||
|
0x07, /* bLength: Endpoint Descriptor size */
|
||||||
|
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */
|
||||||
|
CDC_IN_EP, /* bEndpointAddress */
|
||||||
|
0x02, /* bmAttributes: Bulk */
|
||||||
|
LOBYTE(CDC_DATA_FS_MAX_PACKET_SIZE), /* wMaxPacketSize */
|
||||||
|
HIBYTE(CDC_DATA_FS_MAX_PACKET_SIZE),
|
||||||
|
0x00 /* bInterval */
|
||||||
|
};
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
|
static uint8_t CDCInEpAdd = CDC_IN_EP;
|
||||||
|
static uint8_t CDCOutEpAdd = CDC_OUT_EP;
|
||||||
|
static uint8_t CDCCmdEpAdd = CDC_CMD_EP;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_CDC_Private_Functions
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief USBD_CDC_Init
|
||||||
|
* Initialize the CDC interface
|
||||||
|
* @param pdev: device instance
|
||||||
|
* @param cfgidx: Configuration index
|
||||||
|
* @retval status
|
||||||
|
*/
|
||||||
|
static uint8_t USBD_CDC_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
||||||
|
{
|
||||||
|
UNUSED(cfgidx);
|
||||||
|
USBD_CDC_HandleTypeDef *hcdc;
|
||||||
|
|
||||||
|
hcdc = (USBD_CDC_HandleTypeDef *)USBD_malloc(sizeof(USBD_CDC_HandleTypeDef));
|
||||||
|
|
||||||
|
if (hcdc == NULL)
|
||||||
|
{
|
||||||
|
pdev->pClassDataCmsit[pdev->classId] = NULL;
|
||||||
|
return (uint8_t)USBD_EMEM;
|
||||||
|
}
|
||||||
|
|
||||||
|
(void)USBD_memset(hcdc, 0, sizeof(USBD_CDC_HandleTypeDef));
|
||||||
|
|
||||||
|
pdev->pClassDataCmsit[pdev->classId] = (void *)hcdc;
|
||||||
|
pdev->pClassData = pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
/* Get the Endpoints addresses allocated for this class instance */
|
||||||
|
CDCInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId);
|
||||||
|
CDCOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId);
|
||||||
|
CDCCmdEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_INTR, (uint8_t)pdev->classId);
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
|
if (pdev->dev_speed == USBD_SPEED_HIGH)
|
||||||
|
{
|
||||||
|
/* Open EP IN */
|
||||||
|
(void)USBD_LL_OpenEP(pdev, CDCInEpAdd, USBD_EP_TYPE_BULK,
|
||||||
|
CDC_DATA_HS_IN_PACKET_SIZE);
|
||||||
|
|
||||||
|
pdev->ep_in[CDCInEpAdd & 0xFU].is_used = 1U;
|
||||||
|
|
||||||
|
/* Open EP OUT */
|
||||||
|
(void)USBD_LL_OpenEP(pdev, CDCOutEpAdd, USBD_EP_TYPE_BULK,
|
||||||
|
CDC_DATA_HS_OUT_PACKET_SIZE);
|
||||||
|
|
||||||
|
pdev->ep_out[CDCOutEpAdd & 0xFU].is_used = 1U;
|
||||||
|
|
||||||
|
/* Set bInterval for CDC CMD Endpoint */
|
||||||
|
pdev->ep_in[CDCCmdEpAdd & 0xFU].bInterval = CDC_HS_BINTERVAL;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Open EP IN */
|
||||||
|
(void)USBD_LL_OpenEP(pdev, CDCInEpAdd, USBD_EP_TYPE_BULK,
|
||||||
|
CDC_DATA_FS_IN_PACKET_SIZE);
|
||||||
|
|
||||||
|
pdev->ep_in[CDCInEpAdd & 0xFU].is_used = 1U;
|
||||||
|
|
||||||
|
/* Open EP OUT */
|
||||||
|
(void)USBD_LL_OpenEP(pdev, CDCOutEpAdd, USBD_EP_TYPE_BULK,
|
||||||
|
CDC_DATA_FS_OUT_PACKET_SIZE);
|
||||||
|
|
||||||
|
pdev->ep_out[CDCOutEpAdd & 0xFU].is_used = 1U;
|
||||||
|
|
||||||
|
/* Set bInterval for CMD Endpoint */
|
||||||
|
pdev->ep_in[CDCCmdEpAdd & 0xFU].bInterval = CDC_FS_BINTERVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Open Command IN EP */
|
||||||
|
(void)USBD_LL_OpenEP(pdev, CDCCmdEpAdd, USBD_EP_TYPE_INTR, CDC_CMD_PACKET_SIZE);
|
||||||
|
pdev->ep_in[CDCCmdEpAdd & 0xFU].is_used = 1U;
|
||||||
|
|
||||||
|
hcdc->RxBuffer = NULL;
|
||||||
|
|
||||||
|
/* Init physical Interface components */
|
||||||
|
((USBD_CDC_ItfTypeDef *)pdev->pUserData[pdev->classId])->Init();
|
||||||
|
|
||||||
|
/* Init Xfer states */
|
||||||
|
hcdc->TxState = 0U;
|
||||||
|
hcdc->RxState = 0U;
|
||||||
|
|
||||||
|
if (hcdc->RxBuffer == NULL)
|
||||||
|
{
|
||||||
|
return (uint8_t)USBD_EMEM;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pdev->dev_speed == USBD_SPEED_HIGH)
|
||||||
|
{
|
||||||
|
/* Prepare Out endpoint to receive next packet */
|
||||||
|
(void)USBD_LL_PrepareReceive(pdev, CDCOutEpAdd, hcdc->RxBuffer,
|
||||||
|
CDC_DATA_HS_OUT_PACKET_SIZE);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Prepare Out endpoint to receive next packet */
|
||||||
|
(void)USBD_LL_PrepareReceive(pdev, CDCOutEpAdd, hcdc->RxBuffer,
|
||||||
|
CDC_DATA_FS_OUT_PACKET_SIZE);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (uint8_t)USBD_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief USBD_CDC_Init
|
||||||
|
* DeInitialize the CDC layer
|
||||||
|
* @param pdev: device instance
|
||||||
|
* @param cfgidx: Configuration index
|
||||||
|
* @retval status
|
||||||
|
*/
|
||||||
|
static uint8_t USBD_CDC_DeInit(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
||||||
|
{
|
||||||
|
UNUSED(cfgidx);
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
/* Get the Endpoints addresses allocated for this CDC class instance */
|
||||||
|
CDCInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId);
|
||||||
|
CDCOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId);
|
||||||
|
CDCCmdEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_INTR, (uint8_t)pdev->classId);
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
|
/* Close EP IN */
|
||||||
|
(void)USBD_LL_CloseEP(pdev, CDCInEpAdd);
|
||||||
|
pdev->ep_in[CDCInEpAdd & 0xFU].is_used = 0U;
|
||||||
|
|
||||||
|
/* Close EP OUT */
|
||||||
|
(void)USBD_LL_CloseEP(pdev, CDCOutEpAdd);
|
||||||
|
pdev->ep_out[CDCOutEpAdd & 0xFU].is_used = 0U;
|
||||||
|
|
||||||
|
/* Close Command IN EP */
|
||||||
|
(void)USBD_LL_CloseEP(pdev, CDCCmdEpAdd);
|
||||||
|
pdev->ep_in[CDCCmdEpAdd & 0xFU].is_used = 0U;
|
||||||
|
pdev->ep_in[CDCCmdEpAdd & 0xFU].bInterval = 0U;
|
||||||
|
|
||||||
|
/* DeInit physical Interface components */
|
||||||
|
if (pdev->pClassDataCmsit[pdev->classId] != NULL)
|
||||||
|
{
|
||||||
|
((USBD_CDC_ItfTypeDef *)pdev->pUserData[pdev->classId])->DeInit();
|
||||||
|
(void)USBD_free(pdev->pClassDataCmsit[pdev->classId]);
|
||||||
|
pdev->pClassDataCmsit[pdev->classId] = NULL;
|
||||||
|
pdev->pClassData = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (uint8_t)USBD_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief USBD_CDC_Setup
|
||||||
|
* Handle the CDC specific requests
|
||||||
|
* @param pdev: instance
|
||||||
|
* @param req: usb requests
|
||||||
|
* @retval status
|
||||||
|
*/
|
||||||
|
static uint8_t USBD_CDC_Setup(USBD_HandleTypeDef *pdev,
|
||||||
|
USBD_SetupReqTypedef *req)
|
||||||
|
{
|
||||||
|
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
uint16_t len;
|
||||||
|
uint8_t ifalt = 0U;
|
||||||
|
uint16_t status_info = 0U;
|
||||||
|
USBD_StatusTypeDef ret = USBD_OK;
|
||||||
|
|
||||||
|
if (hcdc == NULL)
|
||||||
|
{
|
||||||
|
return (uint8_t)USBD_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (req->bmRequest & USB_REQ_TYPE_MASK)
|
||||||
|
{
|
||||||
|
case USB_REQ_TYPE_CLASS:
|
||||||
|
if (req->wLength != 0U)
|
||||||
|
{
|
||||||
|
if ((req->bmRequest & 0x80U) != 0U)
|
||||||
|
{
|
||||||
|
((USBD_CDC_ItfTypeDef *)pdev->pUserData[pdev->classId])->Control(req->bRequest,
|
||||||
|
(uint8_t *)hcdc->data,
|
||||||
|
req->wLength);
|
||||||
|
|
||||||
|
len = MIN(CDC_REQ_MAX_DATA_SIZE, req->wLength);
|
||||||
|
(void)USBD_CtlSendData(pdev, (uint8_t *)hcdc->data, len);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
hcdc->CmdOpCode = req->bRequest;
|
||||||
|
hcdc->CmdLength = (uint8_t)MIN(req->wLength, USB_MAX_EP0_SIZE);
|
||||||
|
|
||||||
|
(void)USBD_CtlPrepareRx(pdev, (uint8_t *)hcdc->data, hcdc->CmdLength);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
((USBD_CDC_ItfTypeDef *)pdev->pUserData[pdev->classId])->Control(req->bRequest,
|
||||||
|
(uint8_t *)req, 0U);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case USB_REQ_TYPE_STANDARD:
|
||||||
|
switch (req->bRequest)
|
||||||
|
{
|
||||||
|
case USB_REQ_GET_STATUS:
|
||||||
|
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||||
|
{
|
||||||
|
(void)USBD_CtlSendData(pdev, (uint8_t *)&status_info, 2U);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
USBD_CtlError(pdev, req);
|
||||||
|
ret = USBD_FAIL;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case USB_REQ_GET_INTERFACE:
|
||||||
|
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||||
|
{
|
||||||
|
(void)USBD_CtlSendData(pdev, &ifalt, 1U);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
USBD_CtlError(pdev, req);
|
||||||
|
ret = USBD_FAIL;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case USB_REQ_SET_INTERFACE:
|
||||||
|
if (pdev->dev_state != USBD_STATE_CONFIGURED)
|
||||||
|
{
|
||||||
|
USBD_CtlError(pdev, req);
|
||||||
|
ret = USBD_FAIL;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case USB_REQ_CLEAR_FEATURE:
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
USBD_CtlError(pdev, req);
|
||||||
|
ret = USBD_FAIL;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
USBD_CtlError(pdev, req);
|
||||||
|
ret = USBD_FAIL;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (uint8_t)ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief USBD_CDC_DataIn
|
||||||
|
* Data sent on non-control IN endpoint
|
||||||
|
* @param pdev: device instance
|
||||||
|
* @param epnum: endpoint number
|
||||||
|
* @retval status
|
||||||
|
*/
|
||||||
|
static uint8_t USBD_CDC_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||||
|
{
|
||||||
|
USBD_CDC_HandleTypeDef *hcdc;
|
||||||
|
PCD_HandleTypeDef *hpcd = (PCD_HandleTypeDef *)pdev->pData;
|
||||||
|
|
||||||
|
if (pdev->pClassDataCmsit[pdev->classId] == NULL)
|
||||||
|
{
|
||||||
|
return (uint8_t)USBD_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
hcdc = (USBD_CDC_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
|
||||||
|
if ((pdev->ep_in[epnum & 0xFU].total_length > 0U) &&
|
||||||
|
((pdev->ep_in[epnum & 0xFU].total_length % hpcd->IN_ep[epnum & 0xFU].maxpacket) == 0U))
|
||||||
|
{
|
||||||
|
/* Update the packet total length */
|
||||||
|
pdev->ep_in[epnum & 0xFU].total_length = 0U;
|
||||||
|
|
||||||
|
/* Send ZLP */
|
||||||
|
(void)USBD_LL_Transmit(pdev, epnum, NULL, 0U);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
hcdc->TxState = 0U;
|
||||||
|
|
||||||
|
if (((USBD_CDC_ItfTypeDef *)pdev->pUserData[pdev->classId])->TransmitCplt != NULL)
|
||||||
|
{
|
||||||
|
((USBD_CDC_ItfTypeDef *)pdev->pUserData[pdev->classId])->TransmitCplt(hcdc->TxBuffer, &hcdc->TxLength, epnum);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (uint8_t)USBD_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief USBD_CDC_DataOut
|
||||||
|
* Data received on non-control Out endpoint
|
||||||
|
* @param pdev: device instance
|
||||||
|
* @param epnum: endpoint number
|
||||||
|
* @retval status
|
||||||
|
*/
|
||||||
|
static uint8_t USBD_CDC_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||||
|
{
|
||||||
|
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
|
||||||
|
if (pdev->pClassDataCmsit[pdev->classId] == NULL)
|
||||||
|
{
|
||||||
|
return (uint8_t)USBD_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Get the received data length */
|
||||||
|
hcdc->RxLength = USBD_LL_GetRxDataSize(pdev, epnum);
|
||||||
|
|
||||||
|
/* USB data will be immediately processed, this allow next USB traffic being
|
||||||
|
NAKed till the end of the application Xfer */
|
||||||
|
|
||||||
|
((USBD_CDC_ItfTypeDef *)pdev->pUserData[pdev->classId])->Receive(hcdc->RxBuffer, &hcdc->RxLength);
|
||||||
|
|
||||||
|
return (uint8_t)USBD_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief USBD_CDC_EP0_RxReady
|
||||||
|
* Handle EP0 Rx Ready event
|
||||||
|
* @param pdev: device instance
|
||||||
|
* @retval status
|
||||||
|
*/
|
||||||
|
static uint8_t USBD_CDC_EP0_RxReady(USBD_HandleTypeDef *pdev)
|
||||||
|
{
|
||||||
|
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
|
||||||
|
if (hcdc == NULL)
|
||||||
|
{
|
||||||
|
return (uint8_t)USBD_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((pdev->pUserData[pdev->classId] != NULL) && (hcdc->CmdOpCode != 0xFFU))
|
||||||
|
{
|
||||||
|
((USBD_CDC_ItfTypeDef *)pdev->pUserData[pdev->classId])->Control(hcdc->CmdOpCode,
|
||||||
|
(uint8_t *)hcdc->data,
|
||||||
|
(uint16_t)hcdc->CmdLength);
|
||||||
|
hcdc->CmdOpCode = 0xFFU;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (uint8_t)USBD_OK;
|
||||||
|
}
|
||||||
|
#ifndef USE_USBD_COMPOSITE
|
||||||
|
/**
|
||||||
|
* @brief USBD_CDC_GetFSCfgDesc
|
||||||
|
* Return configuration descriptor
|
||||||
|
* @param length : pointer data length
|
||||||
|
* @retval pointer to descriptor buffer
|
||||||
|
*/
|
||||||
|
static uint8_t *USBD_CDC_GetFSCfgDesc(uint16_t *length)
|
||||||
|
{
|
||||||
|
USBD_EpDescTypeDef *pEpCmdDesc = USBD_GetEpDesc(USBD_CDC_CfgDesc, CDC_CMD_EP);
|
||||||
|
USBD_EpDescTypeDef *pEpOutDesc = USBD_GetEpDesc(USBD_CDC_CfgDesc, CDC_OUT_EP);
|
||||||
|
USBD_EpDescTypeDef *pEpInDesc = USBD_GetEpDesc(USBD_CDC_CfgDesc, CDC_IN_EP);
|
||||||
|
|
||||||
|
if (pEpCmdDesc != NULL)
|
||||||
|
{
|
||||||
|
pEpCmdDesc->bInterval = CDC_FS_BINTERVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pEpOutDesc != NULL)
|
||||||
|
{
|
||||||
|
pEpOutDesc->wMaxPacketSize = CDC_DATA_FS_MAX_PACKET_SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pEpInDesc != NULL)
|
||||||
|
{
|
||||||
|
pEpInDesc->wMaxPacketSize = CDC_DATA_FS_MAX_PACKET_SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
|
*length = (uint16_t)sizeof(USBD_CDC_CfgDesc);
|
||||||
|
return USBD_CDC_CfgDesc;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief USBD_CDC_GetHSCfgDesc
|
||||||
|
* Return configuration descriptor
|
||||||
|
* @param length : pointer data length
|
||||||
|
* @retval pointer to descriptor buffer
|
||||||
|
*/
|
||||||
|
static uint8_t *USBD_CDC_GetHSCfgDesc(uint16_t *length)
|
||||||
|
{
|
||||||
|
USBD_EpDescTypeDef *pEpCmdDesc = USBD_GetEpDesc(USBD_CDC_CfgDesc, CDC_CMD_EP);
|
||||||
|
USBD_EpDescTypeDef *pEpOutDesc = USBD_GetEpDesc(USBD_CDC_CfgDesc, CDC_OUT_EP);
|
||||||
|
USBD_EpDescTypeDef *pEpInDesc = USBD_GetEpDesc(USBD_CDC_CfgDesc, CDC_IN_EP);
|
||||||
|
|
||||||
|
if (pEpCmdDesc != NULL)
|
||||||
|
{
|
||||||
|
pEpCmdDesc->bInterval = CDC_HS_BINTERVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pEpOutDesc != NULL)
|
||||||
|
{
|
||||||
|
pEpOutDesc->wMaxPacketSize = CDC_DATA_HS_MAX_PACKET_SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pEpInDesc != NULL)
|
||||||
|
{
|
||||||
|
pEpInDesc->wMaxPacketSize = CDC_DATA_HS_MAX_PACKET_SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
|
*length = (uint16_t)sizeof(USBD_CDC_CfgDesc);
|
||||||
|
return USBD_CDC_CfgDesc;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief USBD_CDC_GetOtherSpeedCfgDesc
|
||||||
|
* Return configuration descriptor
|
||||||
|
* @param length : pointer data length
|
||||||
|
* @retval pointer to descriptor buffer
|
||||||
|
*/
|
||||||
|
static uint8_t *USBD_CDC_GetOtherSpeedCfgDesc(uint16_t *length)
|
||||||
|
{
|
||||||
|
USBD_EpDescTypeDef *pEpCmdDesc = USBD_GetEpDesc(USBD_CDC_CfgDesc, CDC_CMD_EP);
|
||||||
|
USBD_EpDescTypeDef *pEpOutDesc = USBD_GetEpDesc(USBD_CDC_CfgDesc, CDC_OUT_EP);
|
||||||
|
USBD_EpDescTypeDef *pEpInDesc = USBD_GetEpDesc(USBD_CDC_CfgDesc, CDC_IN_EP);
|
||||||
|
|
||||||
|
if (pEpCmdDesc != NULL)
|
||||||
|
{
|
||||||
|
pEpCmdDesc->bInterval = CDC_FS_BINTERVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pEpOutDesc != NULL)
|
||||||
|
{
|
||||||
|
pEpOutDesc->wMaxPacketSize = CDC_DATA_FS_MAX_PACKET_SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pEpInDesc != NULL)
|
||||||
|
{
|
||||||
|
pEpInDesc->wMaxPacketSize = CDC_DATA_FS_MAX_PACKET_SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
|
*length = (uint16_t)sizeof(USBD_CDC_CfgDesc);
|
||||||
|
return USBD_CDC_CfgDesc;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief USBD_CDC_GetDeviceQualifierDescriptor
|
||||||
|
* return Device Qualifier descriptor
|
||||||
|
* @param length : pointer data length
|
||||||
|
* @retval pointer to descriptor buffer
|
||||||
|
*/
|
||||||
|
uint8_t *USBD_CDC_GetDeviceQualifierDescriptor(uint16_t *length)
|
||||||
|
{
|
||||||
|
*length = (uint16_t)sizeof(USBD_CDC_DeviceQualifierDesc);
|
||||||
|
|
||||||
|
return USBD_CDC_DeviceQualifierDesc;
|
||||||
|
}
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
/**
|
||||||
|
* @brief USBD_CDC_RegisterInterface
|
||||||
|
* @param pdev: device instance
|
||||||
|
* @param fops: CD Interface callback
|
||||||
|
* @retval status
|
||||||
|
*/
|
||||||
|
uint8_t USBD_CDC_RegisterInterface(USBD_HandleTypeDef *pdev,
|
||||||
|
USBD_CDC_ItfTypeDef *fops)
|
||||||
|
{
|
||||||
|
if (fops == NULL)
|
||||||
|
{
|
||||||
|
return (uint8_t)USBD_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
pdev->pUserData[pdev->classId] = fops;
|
||||||
|
|
||||||
|
return (uint8_t)USBD_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief USBD_CDC_SetTxBuffer
|
||||||
|
* @param pdev: device instance
|
||||||
|
* @param pbuff: Tx Buffer
|
||||||
|
* @param length: length of data to be sent
|
||||||
|
* @param ClassId: The Class ID
|
||||||
|
* @retval status
|
||||||
|
*/
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
uint8_t USBD_CDC_SetTxBuffer(USBD_HandleTypeDef *pdev,
|
||||||
|
uint8_t *pbuff, uint32_t length, uint8_t ClassId)
|
||||||
|
{
|
||||||
|
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef *)pdev->pClassDataCmsit[ClassId];
|
||||||
|
#else
|
||||||
|
uint8_t USBD_CDC_SetTxBuffer(USBD_HandleTypeDef *pdev,
|
||||||
|
uint8_t *pbuff, uint32_t length)
|
||||||
|
{
|
||||||
|
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
|
if (hcdc == NULL)
|
||||||
|
{
|
||||||
|
return (uint8_t)USBD_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
hcdc->TxBuffer = pbuff;
|
||||||
|
hcdc->TxLength = length;
|
||||||
|
|
||||||
|
return (uint8_t)USBD_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief USBD_CDC_SetRxBuffer
|
||||||
|
* @param pdev: device instance
|
||||||
|
* @param pbuff: Rx Buffer
|
||||||
|
* @retval status
|
||||||
|
*/
|
||||||
|
uint8_t USBD_CDC_SetRxBuffer(USBD_HandleTypeDef *pdev, uint8_t *pbuff)
|
||||||
|
{
|
||||||
|
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
|
||||||
|
if (hcdc == NULL)
|
||||||
|
{
|
||||||
|
return (uint8_t)USBD_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
hcdc->RxBuffer = pbuff;
|
||||||
|
|
||||||
|
return (uint8_t)USBD_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief USBD_CDC_TransmitPacket
|
||||||
|
* Transmit packet on IN endpoint
|
||||||
|
* @param pdev: device instance
|
||||||
|
* @param ClassId: The Class ID
|
||||||
|
* @retval status
|
||||||
|
*/
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
uint8_t USBD_CDC_TransmitPacket(USBD_HandleTypeDef *pdev, uint8_t ClassId)
|
||||||
|
{
|
||||||
|
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef *)pdev->pClassDataCmsit[ClassId];
|
||||||
|
#else
|
||||||
|
uint8_t USBD_CDC_TransmitPacket(USBD_HandleTypeDef *pdev)
|
||||||
|
{
|
||||||
|
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
|
USBD_StatusTypeDef ret = USBD_BUSY;
|
||||||
|
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
/* Get the Endpoints addresses allocated for this class instance */
|
||||||
|
CDCInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_BULK, ClassId);
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
|
if (hcdc == NULL)
|
||||||
|
{
|
||||||
|
return (uint8_t)USBD_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hcdc->TxState == 0U)
|
||||||
|
{
|
||||||
|
/* Tx Transfer in progress */
|
||||||
|
hcdc->TxState = 1U;
|
||||||
|
|
||||||
|
/* Update the packet total length */
|
||||||
|
pdev->ep_in[CDCInEpAdd & 0xFU].total_length = hcdc->TxLength;
|
||||||
|
|
||||||
|
/* Transmit next packet */
|
||||||
|
(void)USBD_LL_Transmit(pdev, CDCInEpAdd, hcdc->TxBuffer, hcdc->TxLength);
|
||||||
|
|
||||||
|
ret = USBD_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (uint8_t)ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief USBD_CDC_ReceivePacket
|
||||||
|
* prepare OUT Endpoint for reception
|
||||||
|
* @param pdev: device instance
|
||||||
|
* @retval status
|
||||||
|
*/
|
||||||
|
uint8_t USBD_CDC_ReceivePacket(USBD_HandleTypeDef *pdev)
|
||||||
|
{
|
||||||
|
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
/* Get the Endpoints addresses allocated for this class instance */
|
||||||
|
CDCOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId);
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
|
if (pdev->pClassDataCmsit[pdev->classId] == NULL)
|
||||||
|
{
|
||||||
|
return (uint8_t)USBD_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pdev->dev_speed == USBD_SPEED_HIGH)
|
||||||
|
{
|
||||||
|
/* Prepare Out endpoint to receive next packet */
|
||||||
|
(void)USBD_LL_PrepareReceive(pdev, CDCOutEpAdd, hcdc->RxBuffer,
|
||||||
|
CDC_DATA_HS_OUT_PACKET_SIZE);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Prepare Out endpoint to receive next packet */
|
||||||
|
(void)USBD_LL_PrepareReceive(pdev, CDCOutEpAdd, hcdc->RxBuffer,
|
||||||
|
CDC_DATA_FS_OUT_PACKET_SIZE);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (uint8_t)USBD_OK;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
@@ -0,0 +1,247 @@
|
|||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
* @file usbd_cdc_if_template.c
|
||||||
|
* @author MCD Application Team
|
||||||
|
* @brief Generic media access Layer.
|
||||||
|
******************************************************************************
|
||||||
|
* @attention
|
||||||
|
*
|
||||||
|
* Copyright (c) 2015 STMicroelectronics.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This software is licensed under terms that can be found in the LICENSE file
|
||||||
|
* in the root directory of this software component.
|
||||||
|
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||||
|
*
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* BSPDependencies
|
||||||
|
- "stm32xxxxx_{eval}{discovery}{nucleo_144}.c"
|
||||||
|
- "stm32xxxxx_{eval}{discovery}_io.c"
|
||||||
|
EndBSPDependencies */
|
||||||
|
|
||||||
|
/* Includes ------------------------------------------------------------------*/
|
||||||
|
#include "usbd_cdc_if_template.h"
|
||||||
|
|
||||||
|
/** @addtogroup STM32_USB_DEVICE_LIBRARY
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/** @defgroup USBD_CDC
|
||||||
|
* @brief usbd core module
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_CDC_Private_TypesDefinitions
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/** @defgroup USBD_CDC_Private_Defines
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/** @defgroup USBD_CDC_Private_Macros
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/** @defgroup USBD_CDC_Private_FunctionPrototypes
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
static int8_t TEMPLATE_Init(void);
|
||||||
|
static int8_t TEMPLATE_DeInit(void);
|
||||||
|
static int8_t TEMPLATE_Control(uint8_t cmd, uint8_t *pbuf, uint16_t length);
|
||||||
|
static int8_t TEMPLATE_Receive(uint8_t *pbuf, uint32_t *Len);
|
||||||
|
static int8_t TEMPLATE_TransmitCplt(uint8_t *pbuf, uint32_t *Len, uint8_t epnum);
|
||||||
|
|
||||||
|
USBD_CDC_ItfTypeDef USBD_CDC_Template_fops =
|
||||||
|
{
|
||||||
|
TEMPLATE_Init,
|
||||||
|
TEMPLATE_DeInit,
|
||||||
|
TEMPLATE_Control,
|
||||||
|
TEMPLATE_Receive,
|
||||||
|
TEMPLATE_TransmitCplt
|
||||||
|
};
|
||||||
|
|
||||||
|
USBD_CDC_LineCodingTypeDef linecoding =
|
||||||
|
{
|
||||||
|
115200, /* baud rate*/
|
||||||
|
0x00, /* stop bits-1*/
|
||||||
|
0x00, /* parity - none*/
|
||||||
|
0x08 /* nb. of bits 8*/
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Private functions ---------------------------------------------------------*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief TEMPLATE_Init
|
||||||
|
* Initializes the CDC media low layer
|
||||||
|
* @param None
|
||||||
|
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
|
||||||
|
*/
|
||||||
|
static int8_t TEMPLATE_Init(void)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
Add your initialization code here
|
||||||
|
*/
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief TEMPLATE_DeInit
|
||||||
|
* DeInitializes the CDC media low layer
|
||||||
|
* @param None
|
||||||
|
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
|
||||||
|
*/
|
||||||
|
static int8_t TEMPLATE_DeInit(void)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
Add your deinitialization code here
|
||||||
|
*/
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief TEMPLATE_Control
|
||||||
|
* Manage the CDC class requests
|
||||||
|
* @param Cmd: Command code
|
||||||
|
* @param Buf: Buffer containing command data (request parameters)
|
||||||
|
* @param Len: Number of data to be sent (in bytes)
|
||||||
|
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
|
||||||
|
*/
|
||||||
|
static int8_t TEMPLATE_Control(uint8_t cmd, uint8_t *pbuf, uint16_t length)
|
||||||
|
{
|
||||||
|
UNUSED(length);
|
||||||
|
|
||||||
|
switch (cmd)
|
||||||
|
{
|
||||||
|
case CDC_SEND_ENCAPSULATED_COMMAND:
|
||||||
|
/* Add your code here */
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CDC_GET_ENCAPSULATED_RESPONSE:
|
||||||
|
/* Add your code here */
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CDC_SET_COMM_FEATURE:
|
||||||
|
/* Add your code here */
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CDC_GET_COMM_FEATURE:
|
||||||
|
/* Add your code here */
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CDC_CLEAR_COMM_FEATURE:
|
||||||
|
/* Add your code here */
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CDC_SET_LINE_CODING:
|
||||||
|
linecoding.bitrate = (uint32_t)(pbuf[0] | (pbuf[1] << 8) | \
|
||||||
|
(pbuf[2] << 16) | (pbuf[3] << 24));
|
||||||
|
linecoding.format = pbuf[4];
|
||||||
|
linecoding.paritytype = pbuf[5];
|
||||||
|
linecoding.datatype = pbuf[6];
|
||||||
|
|
||||||
|
/* Add your code here */
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CDC_GET_LINE_CODING:
|
||||||
|
pbuf[0] = (uint8_t)(linecoding.bitrate);
|
||||||
|
pbuf[1] = (uint8_t)(linecoding.bitrate >> 8);
|
||||||
|
pbuf[2] = (uint8_t)(linecoding.bitrate >> 16);
|
||||||
|
pbuf[3] = (uint8_t)(linecoding.bitrate >> 24);
|
||||||
|
pbuf[4] = linecoding.format;
|
||||||
|
pbuf[5] = linecoding.paritytype;
|
||||||
|
pbuf[6] = linecoding.datatype;
|
||||||
|
|
||||||
|
/* Add your code here */
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CDC_SET_CONTROL_LINE_STATE:
|
||||||
|
/* Add your code here */
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CDC_SEND_BREAK:
|
||||||
|
/* Add your code here */
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief TEMPLATE_Receive
|
||||||
|
* Data received over USB OUT endpoint are sent over CDC interface
|
||||||
|
* through this function.
|
||||||
|
*
|
||||||
|
* @note
|
||||||
|
* This function will issue a NAK packet on any OUT packet received on
|
||||||
|
* USB endpoint until exiting this function. If you exit this function
|
||||||
|
* before transfer is complete on CDC interface (ie. using DMA controller)
|
||||||
|
* it will result in receiving more data while previous ones are still
|
||||||
|
* not sent.
|
||||||
|
*
|
||||||
|
* @param Buf: Buffer of data to be received
|
||||||
|
* @param Len: Number of data received (in bytes)
|
||||||
|
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
|
||||||
|
*/
|
||||||
|
static int8_t TEMPLATE_Receive(uint8_t *Buf, uint32_t *Len)
|
||||||
|
{
|
||||||
|
UNUSED(Buf);
|
||||||
|
UNUSED(Len);
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief TEMPLATE_TransmitCplt
|
||||||
|
* Data transmitted callback
|
||||||
|
*
|
||||||
|
* @note
|
||||||
|
* This function is IN transfer complete callback used to inform user that
|
||||||
|
* the submitted Data is successfully sent over USB.
|
||||||
|
*
|
||||||
|
* @param Buf: Buffer of data to be received
|
||||||
|
* @param Len: Number of data received (in bytes)
|
||||||
|
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
|
||||||
|
*/
|
||||||
|
static int8_t TEMPLATE_TransmitCplt(uint8_t *Buf, uint32_t *Len, uint8_t epnum)
|
||||||
|
{
|
||||||
|
UNUSED(Buf);
|
||||||
|
UNUSED(Len);
|
||||||
|
UNUSED(epnum);
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
@@ -0,0 +1,230 @@
|
|||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
* @file usbd_conf_template.h
|
||||||
|
* @author MCD Application Team
|
||||||
|
* @brief Header file for the usbd_conf_template.c file
|
||||||
|
******************************************************************************
|
||||||
|
* @attention
|
||||||
|
*
|
||||||
|
* Copyright (c) 2015 STMicroelectronics.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This software is licensed under terms that can be found in the LICENSE file
|
||||||
|
* in the root directory of this software component.
|
||||||
|
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||||
|
*
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||||
|
#ifndef __USBD_CONF_TEMPLATE_H
|
||||||
|
#define __USBD_CONF_TEMPLATE_H
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Includes ------------------------------------------------------------------*/
|
||||||
|
#include "stm32fxxx.h" /* replace 'stm32xxx' with your HAL driver header filename, ex: stm32f4xx.h */
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
/** @addtogroup STM32_USB_DEVICE_LIBRARY
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_CONF
|
||||||
|
* @brief USB device low level driver configuration file
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_CONF_Exported_Defines
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define USBD_MAX_NUM_INTERFACES 1U
|
||||||
|
#define USBD_MAX_NUM_CONFIGURATION 1U
|
||||||
|
#define USBD_MAX_STR_DESC_SIZ 0x100U
|
||||||
|
#define USBD_SELF_POWERED 1U
|
||||||
|
#define USBD_DEBUG_LEVEL 2U
|
||||||
|
/* #define USBD_USER_REGISTER_CALLBACK 1U */
|
||||||
|
|
||||||
|
/* ECM, RNDIS, DFU Class Config */
|
||||||
|
#define USBD_SUPPORT_USER_STRING_DESC 1U
|
||||||
|
|
||||||
|
/* BillBoard Class Config */
|
||||||
|
#define USBD_CLASS_USER_STRING_DESC 1U
|
||||||
|
#define USBD_CLASS_BOS_ENABLED 1U
|
||||||
|
#define USB_BB_MAX_NUM_ALT_MODE 0x2U
|
||||||
|
|
||||||
|
/* MSC Class Config */
|
||||||
|
#define MSC_MEDIA_PACKET 8192U
|
||||||
|
|
||||||
|
/* CDC Class Config */
|
||||||
|
#define USBD_CDC_INTERVAL 2000U
|
||||||
|
|
||||||
|
/* DFU Class Config */
|
||||||
|
/* #define USBD_DFU_VENDOR_CMD_ENABLED 1U */
|
||||||
|
/* #define USBD_DFU_VENDOR_EXIT_ENABLED 1U */
|
||||||
|
#define USBD_DFU_MAX_ITF_NUM 1U
|
||||||
|
#define USBD_DFU_XFERS_IZE 1024U
|
||||||
|
|
||||||
|
/* AUDIO Class Config */
|
||||||
|
#define USBD_AUDIO_FREQ 22100U
|
||||||
|
|
||||||
|
/* CustomHID Class Config */
|
||||||
|
#define CUSTOM_HID_HS_BINTERVAL 0x05U
|
||||||
|
#define CUSTOM_HID_FS_BINTERVAL 0x05U
|
||||||
|
#define USBD_CUSTOMHID_OUTREPORT_BUF_SIZE 0x02U
|
||||||
|
#define USBD_CUSTOM_HID_REPORT_DESC_SIZE 163U
|
||||||
|
|
||||||
|
/* #define USBD_CUSTOMHID_CTRL_REQ_GET_REPORT_ENABLED */
|
||||||
|
/* #define USBD_CUSTOMHID_OUT_PREPARE_RECEIVE_DISABLED */
|
||||||
|
/* #define USBD_CUSTOMHID_EP0_OUT_PREPARE_RECEIVE_DISABLED */
|
||||||
|
/* #define USBD_CUSTOMHID_CTRL_REQ_COMPLETE_CALLBACK_ENABLED */
|
||||||
|
|
||||||
|
/* VIDEO Class Config */
|
||||||
|
#define UVC_1_1 /* #define UVC_1_0 */
|
||||||
|
|
||||||
|
/* To be used only with YUY2 and NV12 Video format, shouldn't be defined for MJPEG format */
|
||||||
|
#define USBD_UVC_FORMAT_UNCOMPRESSED
|
||||||
|
|
||||||
|
#ifdef USBD_UVC_FORMAT_UNCOMPRESSED
|
||||||
|
#define UVC_BITS_PER_PIXEL 12U
|
||||||
|
#define UVC_UNCOMPRESSED_GUID UVC_GUID_NV12 /* UVC_GUID_YUY2 */
|
||||||
|
|
||||||
|
/* refer to Table 3-18 Color Matching Descriptor video class v1.1 */
|
||||||
|
#define UVC_COLOR_PRIMARIE 0x01U
|
||||||
|
#define UVC_TFR_CHARACTERISTICS 0x01U
|
||||||
|
#define UVC_MATRIX_COEFFICIENTS 0x04U
|
||||||
|
#endif /* USBD_UVC_FORMAT_UNCOMPRESSED */
|
||||||
|
|
||||||
|
/* Video Stream frame width and height */
|
||||||
|
#define UVC_WIDTH 176U
|
||||||
|
#define UVC_HEIGHT 144U
|
||||||
|
|
||||||
|
/* bEndpointAddress in Endpoint Descriptor */
|
||||||
|
#define UVC_IN_EP 0x81U
|
||||||
|
|
||||||
|
#define UVC_CAM_FPS_FS 10U
|
||||||
|
#define UVC_CAM_FPS_HS 5U
|
||||||
|
|
||||||
|
#define UVC_ISO_FS_MPS 512U
|
||||||
|
#define UVC_ISO_HS_MPS 512U
|
||||||
|
|
||||||
|
#define UVC_PACKET_SIZE UVC_ISO_FS_MPS
|
||||||
|
/* To be used with Device Only IP supporting double buffer mode */
|
||||||
|
/* #define UVC_HEADER_PACKET_CNT 0x02U */
|
||||||
|
/* #define UVC_PACKET_SIZE (UVC_ISO_FS_MPS * UVC_HEADER_PACKET_CNT) */
|
||||||
|
|
||||||
|
#define UVC_MAX_FRAME_SIZE (UVC_WIDTH * UVC_HEIGHT * 16U / 8U)
|
||||||
|
|
||||||
|
/** @defgroup USBD_Exported_Macros
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Memory management macros make sure to use static memory allocation */
|
||||||
|
/** Alias for memory allocation. */
|
||||||
|
#define USBD_malloc (void *)USBD_static_malloc
|
||||||
|
|
||||||
|
/** Alias for memory release. */
|
||||||
|
#define USBD_free USBD_static_free
|
||||||
|
|
||||||
|
/** Alias for memory set. */
|
||||||
|
#define USBD_memset memset
|
||||||
|
|
||||||
|
/** Alias for memory copy. */
|
||||||
|
#define USBD_memcpy memcpy
|
||||||
|
|
||||||
|
/** Alias for delay. */
|
||||||
|
#define USBD_Delay HAL_Delay
|
||||||
|
|
||||||
|
/* DEBUG macros */
|
||||||
|
#if (USBD_DEBUG_LEVEL > 0U)
|
||||||
|
#define USBD_UsrLog(...) do { \
|
||||||
|
printf(__VA_ARGS__); \
|
||||||
|
printf("\n"); \
|
||||||
|
} while (0)
|
||||||
|
#else
|
||||||
|
#define USBD_UsrLog(...) do {} while (0)
|
||||||
|
#endif /* (USBD_DEBUG_LEVEL > 0U) */
|
||||||
|
|
||||||
|
#if (USBD_DEBUG_LEVEL > 1U)
|
||||||
|
|
||||||
|
#define USBD_ErrLog(...) do { \
|
||||||
|
printf("ERROR: ") ; \
|
||||||
|
printf(__VA_ARGS__); \
|
||||||
|
printf("\n"); \
|
||||||
|
} while (0)
|
||||||
|
#else
|
||||||
|
#define USBD_ErrLog(...) do {} while (0)
|
||||||
|
#endif /* (USBD_DEBUG_LEVEL > 1U) */
|
||||||
|
|
||||||
|
#if (USBD_DEBUG_LEVEL > 2U)
|
||||||
|
#define USBD_DbgLog(...) do { \
|
||||||
|
printf("DEBUG : ") ; \
|
||||||
|
printf(__VA_ARGS__); \
|
||||||
|
printf("\n"); \
|
||||||
|
} while (0)
|
||||||
|
#else
|
||||||
|
#define USBD_DbgLog(...) do {} while (0)
|
||||||
|
#endif /* (USBD_DEBUG_LEVEL > 2U) */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/** @defgroup USBD_CONF_Exported_Types
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/** @defgroup USBD_CONF_Exported_Macros
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_CONF_Exported_Variables
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_CONF_Exported_FunctionsPrototype
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
/* Exported functions -------------------------------------------------------*/
|
||||||
|
void *USBD_static_malloc(uint32_t size);
|
||||||
|
void USBD_static_free(void *p);
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* __USBD_CONF_TEMPLATE_H */
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
@@ -0,0 +1,175 @@
|
|||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
* @file usbd_core.h
|
||||||
|
* @author MCD Application Team
|
||||||
|
* @brief Header file for usbd_core.c file
|
||||||
|
******************************************************************************
|
||||||
|
* @attention
|
||||||
|
*
|
||||||
|
* Copyright (c) 2015 STMicroelectronics.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This software is licensed under terms that can be found in the LICENSE file
|
||||||
|
* in the root directory of this software component.
|
||||||
|
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||||
|
*
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||||
|
#ifndef __USBD_CORE_H
|
||||||
|
#define __USBD_CORE_H
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Includes ------------------------------------------------------------------*/
|
||||||
|
#include "usbd_conf.h"
|
||||||
|
#include "usbd_def.h"
|
||||||
|
#include "usbd_ioreq.h"
|
||||||
|
#include "usbd_ctlreq.h"
|
||||||
|
|
||||||
|
/** @addtogroup STM32_USB_DEVICE_LIBRARY
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_CORE
|
||||||
|
* @brief This file is the Header file for usbd_core.c file
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/** @defgroup USBD_CORE_Exported_Defines
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
#ifndef USBD_DEBUG_LEVEL
|
||||||
|
#define USBD_DEBUG_LEVEL 0U
|
||||||
|
#endif /* USBD_DEBUG_LEVEL */
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/** @defgroup USBD_CORE_Exported_TypesDefinitions
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/** @defgroup USBD_CORE_Exported_Macros
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_CORE_Exported_Variables
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
#define USBD_SOF USBD_LL_SOF
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_CORE_Exported_FunctionsPrototype
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
USBD_StatusTypeDef USBD_Init(USBD_HandleTypeDef *pdev, USBD_DescriptorsTypeDef *pdesc, uint8_t id);
|
||||||
|
USBD_StatusTypeDef USBD_DeInit(USBD_HandleTypeDef *pdev);
|
||||||
|
USBD_StatusTypeDef USBD_Start(USBD_HandleTypeDef *pdev);
|
||||||
|
USBD_StatusTypeDef USBD_Stop(USBD_HandleTypeDef *pdev);
|
||||||
|
USBD_StatusTypeDef USBD_RegisterClass(USBD_HandleTypeDef *pdev, USBD_ClassTypeDef *pclass);
|
||||||
|
#if (USBD_USER_REGISTER_CALLBACK == 1U)
|
||||||
|
USBD_StatusTypeDef USBD_RegisterDevStateCallback(USBD_HandleTypeDef *pdev, USBD_DevStateCallbackTypeDef pUserCallback);
|
||||||
|
#endif /* USBD_USER_REGISTER_CALLBACK */
|
||||||
|
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
USBD_StatusTypeDef USBD_RegisterClassComposite(USBD_HandleTypeDef *pdev, USBD_ClassTypeDef *pclass,
|
||||||
|
USBD_CompositeClassTypeDef classtype, uint8_t *EpAddr);
|
||||||
|
|
||||||
|
USBD_StatusTypeDef USBD_UnRegisterClassComposite(USBD_HandleTypeDef *pdev);
|
||||||
|
uint8_t USBD_CoreGetEPAdd(USBD_HandleTypeDef *pdev, uint8_t ep_dir, uint8_t ep_type, uint8_t ClassId);
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
|
uint8_t USBD_CoreFindIF(USBD_HandleTypeDef *pdev, uint8_t index);
|
||||||
|
uint8_t USBD_CoreFindEP(USBD_HandleTypeDef *pdev, uint8_t index);
|
||||||
|
|
||||||
|
USBD_StatusTypeDef USBD_RunTestMode(USBD_HandleTypeDef *pdev);
|
||||||
|
USBD_StatusTypeDef USBD_SetClassConfig(USBD_HandleTypeDef *pdev, uint8_t cfgidx);
|
||||||
|
USBD_StatusTypeDef USBD_ClrClassConfig(USBD_HandleTypeDef *pdev, uint8_t cfgidx);
|
||||||
|
|
||||||
|
USBD_StatusTypeDef USBD_LL_SetupStage(USBD_HandleTypeDef *pdev, uint8_t *psetup);
|
||||||
|
USBD_StatusTypeDef USBD_LL_DataOutStage(USBD_HandleTypeDef *pdev, uint8_t epnum, uint8_t *pdata);
|
||||||
|
USBD_StatusTypeDef USBD_LL_DataInStage(USBD_HandleTypeDef *pdev, uint8_t epnum, uint8_t *pdata);
|
||||||
|
|
||||||
|
USBD_StatusTypeDef USBD_LL_Reset(USBD_HandleTypeDef *pdev);
|
||||||
|
USBD_StatusTypeDef USBD_LL_SetSpeed(USBD_HandleTypeDef *pdev, USBD_SpeedTypeDef speed);
|
||||||
|
USBD_StatusTypeDef USBD_LL_Suspend(USBD_HandleTypeDef *pdev);
|
||||||
|
USBD_StatusTypeDef USBD_LL_Resume(USBD_HandleTypeDef *pdev);
|
||||||
|
|
||||||
|
USBD_StatusTypeDef USBD_LL_SOF(USBD_HandleTypeDef *pdev);
|
||||||
|
USBD_StatusTypeDef USBD_LL_IsoINIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||||
|
USBD_StatusTypeDef USBD_LL_IsoOUTIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||||
|
|
||||||
|
USBD_StatusTypeDef USBD_LL_DevConnected(USBD_HandleTypeDef *pdev);
|
||||||
|
USBD_StatusTypeDef USBD_LL_DevDisconnected(USBD_HandleTypeDef *pdev);
|
||||||
|
|
||||||
|
/* USBD Low Level Driver */
|
||||||
|
USBD_StatusTypeDef USBD_LL_Init(USBD_HandleTypeDef *pdev);
|
||||||
|
USBD_StatusTypeDef USBD_LL_DeInit(USBD_HandleTypeDef *pdev);
|
||||||
|
USBD_StatusTypeDef USBD_LL_Start(USBD_HandleTypeDef *pdev);
|
||||||
|
USBD_StatusTypeDef USBD_LL_Stop(USBD_HandleTypeDef *pdev);
|
||||||
|
|
||||||
|
USBD_StatusTypeDef USBD_LL_OpenEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr,
|
||||||
|
uint8_t ep_type, uint16_t ep_mps);
|
||||||
|
|
||||||
|
USBD_StatusTypeDef USBD_LL_CloseEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr);
|
||||||
|
USBD_StatusTypeDef USBD_LL_FlushEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr);
|
||||||
|
USBD_StatusTypeDef USBD_LL_StallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr);
|
||||||
|
USBD_StatusTypeDef USBD_LL_ClearStallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr);
|
||||||
|
USBD_StatusTypeDef USBD_LL_SetUSBAddress(USBD_HandleTypeDef *pdev, uint8_t dev_addr);
|
||||||
|
|
||||||
|
USBD_StatusTypeDef USBD_LL_Transmit(USBD_HandleTypeDef *pdev, uint8_t ep_addr,
|
||||||
|
uint8_t *pbuf, uint32_t size);
|
||||||
|
|
||||||
|
USBD_StatusTypeDef USBD_LL_PrepareReceive(USBD_HandleTypeDef *pdev, uint8_t ep_addr,
|
||||||
|
uint8_t *pbuf, uint32_t size);
|
||||||
|
|
||||||
|
#ifdef USBD_HS_TESTMODE_ENABLE
|
||||||
|
USBD_StatusTypeDef USBD_LL_SetTestMode(USBD_HandleTypeDef *pdev, uint8_t testmode);
|
||||||
|
#endif /* USBD_HS_TESTMODE_ENABLE */
|
||||||
|
|
||||||
|
uint8_t USBD_LL_IsStallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr);
|
||||||
|
uint32_t USBD_LL_GetRxDataSize(USBD_HandleTypeDef *pdev, uint8_t ep_addr);
|
||||||
|
|
||||||
|
void USBD_LL_Delay(uint32_t Delay);
|
||||||
|
|
||||||
|
void *USBD_GetEpDesc(uint8_t *pConfDesc, uint8_t EpAddr);
|
||||||
|
USBD_DescHeaderTypeDef *USBD_GetNextDesc(uint8_t *pbuf, uint16_t *ptr);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* __USBD_CORE_H */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,101 @@
|
|||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
* @file usbd_req.h
|
||||||
|
* @author MCD Application Team
|
||||||
|
* @brief Header file for the usbd_req.c file
|
||||||
|
******************************************************************************
|
||||||
|
* @attention
|
||||||
|
*
|
||||||
|
* Copyright (c) 2015 STMicroelectronics.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This software is licensed under terms that can be found in the LICENSE file
|
||||||
|
* in the root directory of this software component.
|
||||||
|
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||||
|
*
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||||
|
#ifndef __USB_REQUEST_H
|
||||||
|
#define __USB_REQUEST_H
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Includes ------------------------------------------------------------------*/
|
||||||
|
#include "usbd_def.h"
|
||||||
|
|
||||||
|
|
||||||
|
/** @addtogroup STM32_USB_DEVICE_LIBRARY
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_REQ
|
||||||
|
* @brief header file for the usbd_req.c file
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_REQ_Exported_Defines
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/** @defgroup USBD_REQ_Exported_Types
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/** @defgroup USBD_REQ_Exported_Macros
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_REQ_Exported_Variables
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_REQ_Exported_FunctionsPrototype
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
USBD_StatusTypeDef USBD_StdDevReq(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
|
||||||
|
USBD_StatusTypeDef USBD_StdItfReq(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
|
||||||
|
USBD_StatusTypeDef USBD_StdEPReq(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
|
||||||
|
|
||||||
|
void USBD_CtlError(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
|
||||||
|
void USBD_ParseSetupRequest(USBD_SetupReqTypedef *req, uint8_t *pdata);
|
||||||
|
void USBD_GetString(uint8_t *desc, uint8_t *unicode, uint16_t *len);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* __USB_REQUEST_H */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
523
Core/Middlewares/ST/STM32_USB_Device_Library/Core/Inc/usbd_def.h
Normal file
523
Core/Middlewares/ST/STM32_USB_Device_Library/Core/Inc/usbd_def.h
Normal file
@@ -0,0 +1,523 @@
|
|||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
* @file usbd_def.h
|
||||||
|
* @author MCD Application Team
|
||||||
|
* @brief General defines for the usb device library
|
||||||
|
******************************************************************************
|
||||||
|
* @attention
|
||||||
|
*
|
||||||
|
* Copyright (c) 2015 STMicroelectronics.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This software is licensed under terms that can be found in the LICENSE file
|
||||||
|
* in the root directory of this software component.
|
||||||
|
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||||
|
*
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||||
|
#ifndef __USBD_DEF_H
|
||||||
|
#define __USBD_DEF_H
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Includes ------------------------------------------------------------------*/
|
||||||
|
#include "usbd_conf.h"
|
||||||
|
|
||||||
|
/** @addtogroup STM32_USBD_DEVICE_LIBRARY
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USB_DEF
|
||||||
|
* @brief general defines for the usb device library file
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USB_DEF_Exported_Defines
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef NULL
|
||||||
|
#define NULL 0U
|
||||||
|
#endif /* NULL */
|
||||||
|
|
||||||
|
#ifndef USBD_MAX_NUM_INTERFACES
|
||||||
|
#define USBD_MAX_NUM_INTERFACES 1U
|
||||||
|
#endif /* USBD_MAX_NUM_CONFIGURATION */
|
||||||
|
|
||||||
|
#ifndef USBD_MAX_NUM_CONFIGURATION
|
||||||
|
#define USBD_MAX_NUM_CONFIGURATION 1U
|
||||||
|
#endif /* USBD_MAX_NUM_CONFIGURATION */
|
||||||
|
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
#ifndef USBD_MAX_SUPPORTED_CLASS
|
||||||
|
#define USBD_MAX_SUPPORTED_CLASS 4U
|
||||||
|
#endif /* USBD_MAX_SUPPORTED_CLASS */
|
||||||
|
#else
|
||||||
|
#ifndef USBD_MAX_SUPPORTED_CLASS
|
||||||
|
#define USBD_MAX_SUPPORTED_CLASS 1U
|
||||||
|
#endif /* USBD_MAX_SUPPORTED_CLASS */
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
|
#ifndef USBD_MAX_CLASS_ENDPOINTS
|
||||||
|
#define USBD_MAX_CLASS_ENDPOINTS 5U
|
||||||
|
#endif /* USBD_MAX_CLASS_ENDPOINTS */
|
||||||
|
|
||||||
|
#ifndef USBD_MAX_CLASS_INTERFACES
|
||||||
|
#define USBD_MAX_CLASS_INTERFACES 5U
|
||||||
|
#endif /* USBD_MAX_CLASS_INTERFACES */
|
||||||
|
|
||||||
|
#ifndef USBD_LPM_ENABLED
|
||||||
|
#define USBD_LPM_ENABLED 0U
|
||||||
|
#endif /* USBD_LPM_ENABLED */
|
||||||
|
|
||||||
|
#ifndef USBD_SELF_POWERED
|
||||||
|
#define USBD_SELF_POWERED 1U
|
||||||
|
#endif /*USBD_SELF_POWERED */
|
||||||
|
|
||||||
|
#ifndef USBD_MAX_POWER
|
||||||
|
#define USBD_MAX_POWER 0x32U /* 100 mA */
|
||||||
|
#endif /* USBD_MAX_POWER */
|
||||||
|
|
||||||
|
#ifndef USBD_SUPPORT_USER_STRING_DESC
|
||||||
|
#define USBD_SUPPORT_USER_STRING_DESC 0U
|
||||||
|
#endif /* USBD_SUPPORT_USER_STRING_DESC */
|
||||||
|
|
||||||
|
#ifndef USBD_CLASS_USER_STRING_DESC
|
||||||
|
#define USBD_CLASS_USER_STRING_DESC 0U
|
||||||
|
#endif /* USBD_CLASS_USER_STRING_DESC */
|
||||||
|
|
||||||
|
#define USB_LEN_DEV_QUALIFIER_DESC 0x0AU
|
||||||
|
#define USB_LEN_DEV_DESC 0x12U
|
||||||
|
#define USB_LEN_CFG_DESC 0x09U
|
||||||
|
#define USB_LEN_IF_DESC 0x09U
|
||||||
|
#define USB_LEN_EP_DESC 0x07U
|
||||||
|
#define USB_LEN_OTG_DESC 0x03U
|
||||||
|
#define USB_LEN_LANGID_STR_DESC 0x04U
|
||||||
|
#define USB_LEN_OTHER_SPEED_DESC_SIZ 0x09U
|
||||||
|
|
||||||
|
#define USBD_IDX_LANGID_STR 0x00U
|
||||||
|
#define USBD_IDX_MFC_STR 0x01U
|
||||||
|
#define USBD_IDX_PRODUCT_STR 0x02U
|
||||||
|
#define USBD_IDX_SERIAL_STR 0x03U
|
||||||
|
#define USBD_IDX_CONFIG_STR 0x04U
|
||||||
|
#define USBD_IDX_INTERFACE_STR 0x05U
|
||||||
|
|
||||||
|
#define USB_REQ_TYPE_STANDARD 0x00U
|
||||||
|
#define USB_REQ_TYPE_CLASS 0x20U
|
||||||
|
#define USB_REQ_TYPE_VENDOR 0x40U
|
||||||
|
#define USB_REQ_TYPE_MASK 0x60U
|
||||||
|
|
||||||
|
#define USB_REQ_RECIPIENT_DEVICE 0x00U
|
||||||
|
#define USB_REQ_RECIPIENT_INTERFACE 0x01U
|
||||||
|
#define USB_REQ_RECIPIENT_ENDPOINT 0x02U
|
||||||
|
#define USB_REQ_RECIPIENT_MASK 0x03U
|
||||||
|
|
||||||
|
#define USB_REQ_GET_STATUS 0x00U
|
||||||
|
#define USB_REQ_CLEAR_FEATURE 0x01U
|
||||||
|
#define USB_REQ_SET_FEATURE 0x03U
|
||||||
|
#define USB_REQ_SET_ADDRESS 0x05U
|
||||||
|
#define USB_REQ_GET_DESCRIPTOR 0x06U
|
||||||
|
#define USB_REQ_SET_DESCRIPTOR 0x07U
|
||||||
|
#define USB_REQ_GET_CONFIGURATION 0x08U
|
||||||
|
#define USB_REQ_SET_CONFIGURATION 0x09U
|
||||||
|
#define USB_REQ_GET_INTERFACE 0x0AU
|
||||||
|
#define USB_REQ_SET_INTERFACE 0x0BU
|
||||||
|
#define USB_REQ_SYNCH_FRAME 0x0CU
|
||||||
|
|
||||||
|
#define USB_DESC_TYPE_DEVICE 0x01U
|
||||||
|
#define USB_DESC_TYPE_CONFIGURATION 0x02U
|
||||||
|
#define USB_DESC_TYPE_STRING 0x03U
|
||||||
|
#define USB_DESC_TYPE_INTERFACE 0x04U
|
||||||
|
#define USB_DESC_TYPE_ENDPOINT 0x05U
|
||||||
|
#define USB_DESC_TYPE_DEVICE_QUALIFIER 0x06U
|
||||||
|
#define USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION 0x07U
|
||||||
|
#define USB_DESC_TYPE_IAD 0x0BU
|
||||||
|
#define USB_DESC_TYPE_BOS 0x0FU
|
||||||
|
|
||||||
|
#define USB_CONFIG_REMOTE_WAKEUP 0x02U
|
||||||
|
#define USB_CONFIG_SELF_POWERED 0x01U
|
||||||
|
|
||||||
|
#define USB_FEATURE_EP_HALT 0x00U
|
||||||
|
#define USB_FEATURE_REMOTE_WAKEUP 0x01U
|
||||||
|
#define USB_FEATURE_TEST_MODE 0x02U
|
||||||
|
|
||||||
|
#define USB_DEVICE_CAPABITY_TYPE 0x10U
|
||||||
|
|
||||||
|
#define USB_CONF_DESC_SIZE 0x09U
|
||||||
|
#define USB_IF_DESC_SIZE 0x09U
|
||||||
|
#define USB_EP_DESC_SIZE 0x07U
|
||||||
|
#define USB_IAD_DESC_SIZE 0x08U
|
||||||
|
|
||||||
|
#define USB_HS_MAX_PACKET_SIZE 512U
|
||||||
|
#define USB_FS_MAX_PACKET_SIZE 64U
|
||||||
|
#define USB_MAX_EP0_SIZE 64U
|
||||||
|
|
||||||
|
/* Device Status */
|
||||||
|
#define USBD_STATE_DEFAULT 0x01U
|
||||||
|
#define USBD_STATE_ADDRESSED 0x02U
|
||||||
|
#define USBD_STATE_CONFIGURED 0x03U
|
||||||
|
#define USBD_STATE_SUSPENDED 0x04U
|
||||||
|
|
||||||
|
|
||||||
|
/* EP0 State */
|
||||||
|
#define USBD_EP0_IDLE 0x00U
|
||||||
|
#define USBD_EP0_SETUP 0x01U
|
||||||
|
#define USBD_EP0_DATA_IN 0x02U
|
||||||
|
#define USBD_EP0_DATA_OUT 0x03U
|
||||||
|
#define USBD_EP0_STATUS_IN 0x04U
|
||||||
|
#define USBD_EP0_STATUS_OUT 0x05U
|
||||||
|
#define USBD_EP0_STALL 0x06U
|
||||||
|
|
||||||
|
#define USBD_EP_TYPE_CTRL 0x00U
|
||||||
|
#define USBD_EP_TYPE_ISOC 0x01U
|
||||||
|
#define USBD_EP_TYPE_BULK 0x02U
|
||||||
|
#define USBD_EP_TYPE_INTR 0x03U
|
||||||
|
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
#define USBD_EP_IN 0x80U
|
||||||
|
#define USBD_EP_OUT 0x00U
|
||||||
|
#define USBD_FUNC_DESCRIPTOR_TYPE 0x24U
|
||||||
|
#define USBD_DESC_SUBTYPE_ACM 0x0FU
|
||||||
|
#define USBD_DESC_ECM_BCD_LOW 0x00U
|
||||||
|
#define USBD_DESC_ECM_BCD_HIGH 0x10U
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/** @defgroup USBD_DEF_Exported_TypesDefinitions
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
typedef struct usb_setup_req
|
||||||
|
{
|
||||||
|
uint8_t bmRequest;
|
||||||
|
uint8_t bRequest;
|
||||||
|
uint16_t wValue;
|
||||||
|
uint16_t wIndex;
|
||||||
|
uint16_t wLength;
|
||||||
|
} USBD_SetupReqTypedef;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
uint8_t bLength;
|
||||||
|
uint8_t bDescriptorType;
|
||||||
|
uint16_t wTotalLength;
|
||||||
|
uint8_t bNumInterfaces;
|
||||||
|
uint8_t bConfigurationValue;
|
||||||
|
uint8_t iConfiguration;
|
||||||
|
uint8_t bmAttributes;
|
||||||
|
uint8_t bMaxPower;
|
||||||
|
} __PACKED USBD_ConfigDescTypeDef;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
uint8_t bLength;
|
||||||
|
uint8_t bDescriptorType;
|
||||||
|
uint16_t wTotalLength;
|
||||||
|
uint8_t bNumDeviceCaps;
|
||||||
|
} USBD_BosDescTypeDef;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
uint8_t bLength;
|
||||||
|
uint8_t bDescriptorType;
|
||||||
|
uint8_t bEndpointAddress;
|
||||||
|
uint8_t bmAttributes;
|
||||||
|
uint16_t wMaxPacketSize;
|
||||||
|
uint8_t bInterval;
|
||||||
|
} __PACKED USBD_EpDescTypeDef;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
uint8_t bLength;
|
||||||
|
uint8_t bDescriptorType;
|
||||||
|
uint8_t bDescriptorSubType;
|
||||||
|
} USBD_DescHeaderTypeDef;
|
||||||
|
|
||||||
|
struct _USBD_HandleTypeDef;
|
||||||
|
|
||||||
|
typedef struct _Device_cb
|
||||||
|
{
|
||||||
|
uint8_t (*Init)(struct _USBD_HandleTypeDef *pdev, uint8_t cfgidx);
|
||||||
|
uint8_t (*DeInit)(struct _USBD_HandleTypeDef *pdev, uint8_t cfgidx);
|
||||||
|
/* Control Endpoints*/
|
||||||
|
uint8_t (*Setup)(struct _USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
|
||||||
|
uint8_t (*EP0_TxSent)(struct _USBD_HandleTypeDef *pdev);
|
||||||
|
uint8_t (*EP0_RxReady)(struct _USBD_HandleTypeDef *pdev);
|
||||||
|
/* Class Specific Endpoints*/
|
||||||
|
uint8_t (*DataIn)(struct _USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||||
|
uint8_t (*DataOut)(struct _USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||||
|
uint8_t (*SOF)(struct _USBD_HandleTypeDef *pdev);
|
||||||
|
uint8_t (*IsoINIncomplete)(struct _USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||||
|
uint8_t (*IsoOUTIncomplete)(struct _USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||||
|
|
||||||
|
uint8_t *(*GetHSConfigDescriptor)(uint16_t *length);
|
||||||
|
uint8_t *(*GetFSConfigDescriptor)(uint16_t *length);
|
||||||
|
uint8_t *(*GetOtherSpeedConfigDescriptor)(uint16_t *length);
|
||||||
|
uint8_t *(*GetDeviceQualifierDescriptor)(uint16_t *length);
|
||||||
|
#if (USBD_SUPPORT_USER_STRING_DESC == 1U)
|
||||||
|
uint8_t *(*GetUsrStrDescriptor)(struct _USBD_HandleTypeDef *pdev, uint8_t index, uint16_t *length);
|
||||||
|
#endif /* USBD_SUPPORT_USER_STRING_DESC */
|
||||||
|
|
||||||
|
} USBD_ClassTypeDef;
|
||||||
|
|
||||||
|
/* Following USB Device Speed */
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
USBD_SPEED_HIGH = 0U,
|
||||||
|
USBD_SPEED_FULL = 1U,
|
||||||
|
USBD_SPEED_LOW = 2U,
|
||||||
|
} USBD_SpeedTypeDef;
|
||||||
|
|
||||||
|
/* Following USB Device status */
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
USBD_OK = 0U,
|
||||||
|
USBD_BUSY,
|
||||||
|
USBD_EMEM,
|
||||||
|
USBD_FAIL,
|
||||||
|
} USBD_StatusTypeDef;
|
||||||
|
|
||||||
|
/* USB Device descriptors structure */
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
uint8_t *(*GetDeviceDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||||
|
uint8_t *(*GetLangIDStrDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||||
|
uint8_t *(*GetManufacturerStrDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||||
|
uint8_t *(*GetProductStrDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||||
|
uint8_t *(*GetSerialStrDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||||
|
uint8_t *(*GetConfigurationStrDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||||
|
uint8_t *(*GetInterfaceStrDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||||
|
#if (USBD_CLASS_USER_STRING_DESC == 1)
|
||||||
|
uint8_t *(*GetUserStrDescriptor)(USBD_SpeedTypeDef speed, uint8_t idx, uint16_t *length);
|
||||||
|
#endif /* USBD_CLASS_USER_STRING_DESC */
|
||||||
|
#if ((USBD_LPM_ENABLED == 1U) || (USBD_CLASS_BOS_ENABLED == 1))
|
||||||
|
uint8_t *(*GetBOSDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||||
|
#endif /* (USBD_LPM_ENABLED == 1U) || (USBD_CLASS_BOS_ENABLED == 1) */
|
||||||
|
} USBD_DescriptorsTypeDef;
|
||||||
|
|
||||||
|
/* USB Device handle structure */
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
uint32_t status;
|
||||||
|
uint32_t total_length;
|
||||||
|
uint32_t rem_length;
|
||||||
|
uint32_t maxpacket;
|
||||||
|
uint16_t is_used;
|
||||||
|
uint16_t bInterval;
|
||||||
|
} USBD_EndpointTypeDef;
|
||||||
|
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
CLASS_TYPE_NONE = 0,
|
||||||
|
CLASS_TYPE_HID = 1,
|
||||||
|
CLASS_TYPE_CDC = 2,
|
||||||
|
CLASS_TYPE_MSC = 3,
|
||||||
|
CLASS_TYPE_DFU = 4,
|
||||||
|
CLASS_TYPE_CHID = 5,
|
||||||
|
CLASS_TYPE_AUDIO = 6,
|
||||||
|
CLASS_TYPE_ECM = 7,
|
||||||
|
CLASS_TYPE_RNDIS = 8,
|
||||||
|
CLASS_TYPE_MTP = 9,
|
||||||
|
CLASS_TYPE_VIDEO = 10,
|
||||||
|
CLASS_TYPE_PRINTER = 11,
|
||||||
|
CLASS_TYPE_CCID = 12,
|
||||||
|
} USBD_CompositeClassTypeDef;
|
||||||
|
|
||||||
|
|
||||||
|
/* USB Device handle structure */
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
uint8_t add;
|
||||||
|
uint8_t type;
|
||||||
|
uint8_t size;
|
||||||
|
uint8_t is_used;
|
||||||
|
} USBD_EPTypeDef;
|
||||||
|
|
||||||
|
/* USB Device handle structure */
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
USBD_CompositeClassTypeDef ClassType;
|
||||||
|
uint32_t ClassId;
|
||||||
|
uint32_t Active;
|
||||||
|
uint32_t NumEps;
|
||||||
|
USBD_EPTypeDef Eps[USBD_MAX_CLASS_ENDPOINTS];
|
||||||
|
uint8_t *EpAdd;
|
||||||
|
uint32_t NumIf;
|
||||||
|
uint8_t Ifs[USBD_MAX_CLASS_INTERFACES];
|
||||||
|
uint32_t CurrPcktSze;
|
||||||
|
} USBD_CompositeElementTypeDef;
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
|
/* USB Device handle structure */
|
||||||
|
typedef struct _USBD_HandleTypeDef
|
||||||
|
{
|
||||||
|
uint8_t id;
|
||||||
|
uint32_t dev_config;
|
||||||
|
uint32_t dev_default_config;
|
||||||
|
uint32_t dev_config_status;
|
||||||
|
USBD_SpeedTypeDef dev_speed;
|
||||||
|
USBD_EndpointTypeDef ep_in[16];
|
||||||
|
USBD_EndpointTypeDef ep_out[16];
|
||||||
|
__IO uint32_t ep0_state;
|
||||||
|
uint32_t ep0_data_len;
|
||||||
|
__IO uint8_t dev_state;
|
||||||
|
__IO uint8_t dev_old_state;
|
||||||
|
uint8_t dev_address;
|
||||||
|
uint8_t dev_connection_status;
|
||||||
|
uint8_t dev_test_mode;
|
||||||
|
uint32_t dev_remote_wakeup;
|
||||||
|
uint8_t ConfIdx;
|
||||||
|
|
||||||
|
USBD_SetupReqTypedef request;
|
||||||
|
USBD_DescriptorsTypeDef *pDesc;
|
||||||
|
USBD_ClassTypeDef *pClass[USBD_MAX_SUPPORTED_CLASS];
|
||||||
|
void *pClassData;
|
||||||
|
void *pClassDataCmsit[USBD_MAX_SUPPORTED_CLASS];
|
||||||
|
void *pUserData[USBD_MAX_SUPPORTED_CLASS];
|
||||||
|
void *pData;
|
||||||
|
void *pBosDesc;
|
||||||
|
void *pConfDesc;
|
||||||
|
uint32_t classId;
|
||||||
|
uint32_t NumClasses;
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
USBD_CompositeElementTypeDef tclasslist[USBD_MAX_SUPPORTED_CLASS];
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
#if (USBD_USER_REGISTER_CALLBACK == 1U)
|
||||||
|
void (* DevStateCallback)(uint8_t dev_state, uint8_t cfgidx); /*!< User Notification callback */
|
||||||
|
#endif /* USBD_USER_REGISTER_CALLBACK */
|
||||||
|
} USBD_HandleTypeDef;
|
||||||
|
|
||||||
|
#if (USBD_USER_REGISTER_CALLBACK == 1U)
|
||||||
|
typedef void (*USBD_DevStateCallbackTypeDef)(uint8_t dev_state, uint8_t cfgidx); /*!< pointer to User callback function */
|
||||||
|
#endif /* USBD_USER_REGISTER_CALLBACK */
|
||||||
|
|
||||||
|
/* USB Device endpoint direction */
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
OUT = 0x00,
|
||||||
|
IN = 0x80,
|
||||||
|
} USBD_EPDirectionTypeDef;
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
NETWORK_CONNECTION = 0x00,
|
||||||
|
RESPONSE_AVAILABLE = 0x01,
|
||||||
|
CONNECTION_SPEED_CHANGE = 0x2A
|
||||||
|
} USBD_CDC_NotifCodeTypeDef;
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/** @defgroup USBD_DEF_Exported_Macros
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
__STATIC_INLINE uint16_t SWAPBYTE(uint8_t *addr)
|
||||||
|
{
|
||||||
|
uint16_t _SwapVal;
|
||||||
|
uint16_t _Byte1;
|
||||||
|
uint16_t _Byte2;
|
||||||
|
uint8_t *_pbuff = addr;
|
||||||
|
|
||||||
|
_Byte1 = *(uint8_t *)_pbuff;
|
||||||
|
_pbuff++;
|
||||||
|
_Byte2 = *(uint8_t *)_pbuff;
|
||||||
|
|
||||||
|
_SwapVal = (_Byte2 << 8) | _Byte1;
|
||||||
|
|
||||||
|
return _SwapVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifndef LOBYTE
|
||||||
|
#define LOBYTE(x) ((uint8_t)((x) & 0x00FFU))
|
||||||
|
#endif /* LOBYTE */
|
||||||
|
|
||||||
|
#ifndef HIBYTE
|
||||||
|
#define HIBYTE(x) ((uint8_t)(((x) & 0xFF00U) >> 8U))
|
||||||
|
#endif /* HIBYTE */
|
||||||
|
|
||||||
|
#ifndef MIN
|
||||||
|
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
|
||||||
|
#endif /* MIN */
|
||||||
|
|
||||||
|
#ifndef MAX
|
||||||
|
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
|
||||||
|
#endif /* MAX */
|
||||||
|
|
||||||
|
#if defined ( __GNUC__ )
|
||||||
|
#ifndef __weak
|
||||||
|
#define __weak __attribute__((weak))
|
||||||
|
#endif /* __weak */
|
||||||
|
#ifndef __packed
|
||||||
|
#define __packed __attribute__((__packed__))
|
||||||
|
#endif /* __packed */
|
||||||
|
#endif /* __GNUC__ */
|
||||||
|
|
||||||
|
|
||||||
|
/* In HS mode and when the DMA is used, all variables and data structures dealing
|
||||||
|
with the DMA during the transaction process should be 4-bytes aligned */
|
||||||
|
|
||||||
|
#if defined ( __GNUC__ ) && !defined (__CC_ARM) /* GNU Compiler */
|
||||||
|
#ifndef __ALIGN_END
|
||||||
|
#define __ALIGN_END __attribute__ ((aligned (4U)))
|
||||||
|
#endif /* __ALIGN_END */
|
||||||
|
#ifndef __ALIGN_BEGIN
|
||||||
|
#define __ALIGN_BEGIN
|
||||||
|
#endif /* __ALIGN_BEGIN */
|
||||||
|
#else
|
||||||
|
#ifndef __ALIGN_END
|
||||||
|
#define __ALIGN_END
|
||||||
|
#endif /* __ALIGN_END */
|
||||||
|
#ifndef __ALIGN_BEGIN
|
||||||
|
#if defined (__CC_ARM) /* ARM Compiler */
|
||||||
|
#define __ALIGN_BEGIN __align(4U)
|
||||||
|
#elif defined (__ICCARM__) /* IAR Compiler */
|
||||||
|
#define __ALIGN_BEGIN
|
||||||
|
#endif /* __CC_ARM */
|
||||||
|
#endif /* __ALIGN_BEGIN */
|
||||||
|
#endif /* __GNUC__ */
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_DEF_Exported_Variables
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_DEF_Exported_FunctionsPrototype
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* __USBD_DEF_H */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
* @file usbd_desc_template.h
|
||||||
|
* @author MCD Application Team
|
||||||
|
* @brief Header for usbd_desc_template.c module
|
||||||
|
******************************************************************************
|
||||||
|
* @attention
|
||||||
|
*
|
||||||
|
* Copyright (c) 2015 STMicroelectronics.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This software is licensed under terms that can be found in the LICENSE file
|
||||||
|
* in the root directory of this software component.
|
||||||
|
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||||
|
*
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||||
|
#ifndef __USBD_DESC_TEMPLATE_H
|
||||||
|
#define __USBD_DESC_TEMPLATE_H
|
||||||
|
|
||||||
|
/* Includes ------------------------------------------------------------------*/
|
||||||
|
#include "usbd_def.h"
|
||||||
|
|
||||||
|
/* Exported types ------------------------------------------------------------*/
|
||||||
|
/* Exported constants --------------------------------------------------------*/
|
||||||
|
#define DEVICE_ID1 (UID_BASE)
|
||||||
|
#define DEVICE_ID2 (UID_BASE + 0x4U)
|
||||||
|
#define DEVICE_ID3 (UID_BASE + 0x8U)
|
||||||
|
|
||||||
|
/*
|
||||||
|
* USB Billboard Class USER string desc Defines Template
|
||||||
|
* index should start form 0x10 to avoid using the reserved device string desc indexes
|
||||||
|
*/
|
||||||
|
#if (USBD_CLASS_USER_STRING_DESC == 1)
|
||||||
|
#define USBD_BB_IF_STRING_INDEX 0x10U
|
||||||
|
#define USBD_BB_URL_STRING_INDEX 0x11U
|
||||||
|
#define USBD_BB_ALTMODE0_STRING_INDEX 0x12U
|
||||||
|
#define USBD_BB_ALTMODE1_STRING_INDEX 0x13U
|
||||||
|
/* Add Specific USER string Desc */
|
||||||
|
#define USBD_BB_IF_STR_DESC (uint8_t *)"STM32 BillBoard Interface"
|
||||||
|
#define USBD_BB_URL_STR_DESC (uint8_t *)"www.st.com"
|
||||||
|
#define USBD_BB_ALTMODE0_STR_DESC (uint8_t *)"STM32 Alternate0 Mode"
|
||||||
|
#define USBD_BB_ALTMODE1_STR_DESC (uint8_t *)"STM32 Alternate1 Mode"
|
||||||
|
#endif /* USBD_CLASS_USER_STRING_DESC */
|
||||||
|
|
||||||
|
#define USB_SIZ_STRING_SERIAL 0x1AU
|
||||||
|
|
||||||
|
#if (USBD_LPM_ENABLED == 1)
|
||||||
|
#define USB_SIZ_BOS_DESC 0x0CU
|
||||||
|
#elif (USBD_CLASS_BOS_ENABLED == 1)
|
||||||
|
#define USB_SIZ_BOS_DESC 0x5DU
|
||||||
|
#endif /* USBD_LPM_ENABLED */
|
||||||
|
|
||||||
|
/* Exported macro ------------------------------------------------------------*/
|
||||||
|
/* Exported functions ------------------------------------------------------- */
|
||||||
|
extern USBD_DescriptorsTypeDef XXX_Desc; /* Replace 'XXX_Desc' with your active USB device class, ex: HID_Desc */
|
||||||
|
|
||||||
|
#endif /* __USBD_DESC_TEMPLATE_H*/
|
||||||
|
|
||||||
@@ -0,0 +1,113 @@
|
|||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
* @file usbd_ioreq.h
|
||||||
|
* @author MCD Application Team
|
||||||
|
* @brief Header file for the usbd_ioreq.c file
|
||||||
|
******************************************************************************
|
||||||
|
* @attention
|
||||||
|
*
|
||||||
|
* Copyright (c) 2015 STMicroelectronics.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This software is licensed under terms that can be found in the LICENSE file
|
||||||
|
* in the root directory of this software component.
|
||||||
|
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||||
|
*
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||||
|
#ifndef __USBD_IOREQ_H
|
||||||
|
#define __USBD_IOREQ_H
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Includes ------------------------------------------------------------------*/
|
||||||
|
#include "usbd_def.h"
|
||||||
|
#include "usbd_core.h"
|
||||||
|
|
||||||
|
/** @addtogroup STM32_USB_DEVICE_LIBRARY
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_IOREQ
|
||||||
|
* @brief header file for the usbd_ioreq.c file
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_IOREQ_Exported_Defines
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/** @defgroup USBD_IOREQ_Exported_Types
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/** @defgroup USBD_IOREQ_Exported_Macros
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_IOREQ_Exported_Variables
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_IOREQ_Exported_FunctionsPrototype
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
USBD_StatusTypeDef USBD_CtlSendData(USBD_HandleTypeDef *pdev,
|
||||||
|
uint8_t *pbuf, uint32_t len);
|
||||||
|
|
||||||
|
USBD_StatusTypeDef USBD_CtlContinueSendData(USBD_HandleTypeDef *pdev,
|
||||||
|
uint8_t *pbuf, uint32_t len);
|
||||||
|
|
||||||
|
USBD_StatusTypeDef USBD_CtlPrepareRx(USBD_HandleTypeDef *pdev,
|
||||||
|
uint8_t *pbuf, uint32_t len);
|
||||||
|
|
||||||
|
USBD_StatusTypeDef USBD_CtlContinueRx(USBD_HandleTypeDef *pdev,
|
||||||
|
uint8_t *pbuf, uint32_t len);
|
||||||
|
|
||||||
|
USBD_StatusTypeDef USBD_CtlSendStatus(USBD_HandleTypeDef *pdev);
|
||||||
|
USBD_StatusTypeDef USBD_CtlReceiveStatus(USBD_HandleTypeDef *pdev);
|
||||||
|
|
||||||
|
uint32_t USBD_GetRxCount(USBD_HandleTypeDef *pdev, uint8_t ep_addr);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* __USBD_IOREQ_H */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
@@ -0,0 +1,283 @@
|
|||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
* @file usbd_conf_template.c
|
||||||
|
* @author MCD Application Team
|
||||||
|
* @brief USB Device configuration and interface file
|
||||||
|
* This template should be copied to the user folder,
|
||||||
|
* renamed and customized following user needs.
|
||||||
|
******************************************************************************
|
||||||
|
* @attention
|
||||||
|
*
|
||||||
|
* Copyright (c) 2015 STMicroelectronics.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This software is licensed under terms that can be found in the LICENSE file
|
||||||
|
* in the root directory of this software component.
|
||||||
|
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||||
|
*
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Includes ------------------------------------------------------------------*/
|
||||||
|
#include "usbd_core.h"
|
||||||
|
#include "usbd_hid.h" /* Include class header file */
|
||||||
|
/* Private typedef -----------------------------------------------------------*/
|
||||||
|
/* Private define ------------------------------------------------------------*/
|
||||||
|
/* Private macro -------------------------------------------------------------*/
|
||||||
|
/* Private variables ---------------------------------------------------------*/
|
||||||
|
/* Private function prototypes -----------------------------------------------*/
|
||||||
|
/* Private functions ---------------------------------------------------------*/
|
||||||
|
/**
|
||||||
|
* @brief Initializes the Low Level portion of the Device driver.
|
||||||
|
* @param pdev: Device handle
|
||||||
|
* @retval USBD Status
|
||||||
|
*/
|
||||||
|
USBD_StatusTypeDef USBD_LL_Init(USBD_HandleTypeDef *pdev)
|
||||||
|
{
|
||||||
|
UNUSED(pdev);
|
||||||
|
|
||||||
|
return USBD_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief De-Initializes the Low Level portion of the Device driver.
|
||||||
|
* @param pdev: Device handle
|
||||||
|
* @retval USBD Status
|
||||||
|
*/
|
||||||
|
USBD_StatusTypeDef USBD_LL_DeInit(USBD_HandleTypeDef *pdev)
|
||||||
|
{
|
||||||
|
UNUSED(pdev);
|
||||||
|
|
||||||
|
return USBD_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Starts the Low Level portion of the Device driver.
|
||||||
|
* @param pdev: Device handle
|
||||||
|
* @retval USBD Status
|
||||||
|
*/
|
||||||
|
USBD_StatusTypeDef USBD_LL_Start(USBD_HandleTypeDef *pdev)
|
||||||
|
{
|
||||||
|
UNUSED(pdev);
|
||||||
|
|
||||||
|
return USBD_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Stops the Low Level portion of the Device driver.
|
||||||
|
* @param pdev: Device handle
|
||||||
|
* @retval USBD Status
|
||||||
|
*/
|
||||||
|
USBD_StatusTypeDef USBD_LL_Stop(USBD_HandleTypeDef *pdev)
|
||||||
|
{
|
||||||
|
UNUSED(pdev);
|
||||||
|
|
||||||
|
return USBD_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Opens an endpoint of the Low Level Driver.
|
||||||
|
* @param pdev: Device handle
|
||||||
|
* @param ep_addr: Endpoint Number
|
||||||
|
* @param ep_type: Endpoint Type
|
||||||
|
* @param ep_mps: Endpoint Max Packet Size
|
||||||
|
* @retval USBD Status
|
||||||
|
*/
|
||||||
|
USBD_StatusTypeDef USBD_LL_OpenEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr,
|
||||||
|
uint8_t ep_type, uint16_t ep_mps)
|
||||||
|
{
|
||||||
|
UNUSED(pdev);
|
||||||
|
UNUSED(ep_addr);
|
||||||
|
UNUSED(ep_type);
|
||||||
|
UNUSED(ep_mps);
|
||||||
|
|
||||||
|
return USBD_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Closes an endpoint of the Low Level Driver.
|
||||||
|
* @param pdev: Device handle
|
||||||
|
* @param ep_addr: Endpoint Number
|
||||||
|
* @retval USBD Status
|
||||||
|
*/
|
||||||
|
USBD_StatusTypeDef USBD_LL_CloseEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
|
||||||
|
{
|
||||||
|
UNUSED(pdev);
|
||||||
|
UNUSED(ep_addr);
|
||||||
|
|
||||||
|
return USBD_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Flushes an endpoint of the Low Level Driver.
|
||||||
|
* @param pdev: Device handle
|
||||||
|
* @param ep_addr: Endpoint Number
|
||||||
|
* @retval USBD Status
|
||||||
|
*/
|
||||||
|
USBD_StatusTypeDef USBD_LL_FlushEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
|
||||||
|
{
|
||||||
|
UNUSED(pdev);
|
||||||
|
UNUSED(ep_addr);
|
||||||
|
|
||||||
|
return USBD_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Sets a Stall condition on an endpoint of the Low Level Driver.
|
||||||
|
* @param pdev: Device handle
|
||||||
|
* @param ep_addr: Endpoint Number
|
||||||
|
* @retval USBD Status
|
||||||
|
*/
|
||||||
|
USBD_StatusTypeDef USBD_LL_StallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
|
||||||
|
{
|
||||||
|
UNUSED(pdev);
|
||||||
|
UNUSED(ep_addr);
|
||||||
|
|
||||||
|
return USBD_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Clears a Stall condition on an endpoint of the Low Level Driver.
|
||||||
|
* @param pdev: Device handle
|
||||||
|
* @param ep_addr: Endpoint Number
|
||||||
|
* @retval USBD Status
|
||||||
|
*/
|
||||||
|
USBD_StatusTypeDef USBD_LL_ClearStallEP(USBD_HandleTypeDef *pdev,
|
||||||
|
uint8_t ep_addr)
|
||||||
|
{
|
||||||
|
UNUSED(pdev);
|
||||||
|
UNUSED(ep_addr);
|
||||||
|
|
||||||
|
return USBD_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns Stall condition.
|
||||||
|
* @param pdev: Device handle
|
||||||
|
* @param ep_addr: Endpoint Number
|
||||||
|
* @retval Stall (1: Yes, 0: No)
|
||||||
|
*/
|
||||||
|
uint8_t USBD_LL_IsStallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
|
||||||
|
{
|
||||||
|
UNUSED(pdev);
|
||||||
|
UNUSED(ep_addr);
|
||||||
|
|
||||||
|
return 0U;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Assigns a USB address to the device.
|
||||||
|
* @param pdev: Device handle
|
||||||
|
* @param dev_addr: Endpoint Number
|
||||||
|
* @retval USBD Status
|
||||||
|
*/
|
||||||
|
USBD_StatusTypeDef USBD_LL_SetUSBAddress(USBD_HandleTypeDef *pdev,
|
||||||
|
uint8_t dev_addr)
|
||||||
|
{
|
||||||
|
UNUSED(pdev);
|
||||||
|
UNUSED(dev_addr);
|
||||||
|
|
||||||
|
return USBD_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Transmits data over an endpoint.
|
||||||
|
* @param pdev: Device handle
|
||||||
|
* @param ep_addr: Endpoint Number
|
||||||
|
* @param pbuf: Pointer to data to be sent
|
||||||
|
* @param size: Data size
|
||||||
|
* @retval USBD Status
|
||||||
|
*/
|
||||||
|
USBD_StatusTypeDef USBD_LL_Transmit(USBD_HandleTypeDef *pdev, uint8_t ep_addr,
|
||||||
|
uint8_t *pbuf, uint32_t size)
|
||||||
|
{
|
||||||
|
UNUSED(pdev);
|
||||||
|
UNUSED(ep_addr);
|
||||||
|
UNUSED(pbuf);
|
||||||
|
UNUSED(size);
|
||||||
|
|
||||||
|
return USBD_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Prepares an endpoint for reception.
|
||||||
|
* @param pdev: Device handle
|
||||||
|
* @param ep_addr: Endpoint Number
|
||||||
|
* @param pbuf: Pointer to data to be received
|
||||||
|
* @param size: Data size
|
||||||
|
* @retval USBD Status
|
||||||
|
*/
|
||||||
|
USBD_StatusTypeDef USBD_LL_PrepareReceive(USBD_HandleTypeDef *pdev,
|
||||||
|
uint8_t ep_addr, uint8_t *pbuf,
|
||||||
|
uint32_t size)
|
||||||
|
{
|
||||||
|
UNUSED(pdev);
|
||||||
|
UNUSED(ep_addr);
|
||||||
|
UNUSED(pbuf);
|
||||||
|
UNUSED(size);
|
||||||
|
|
||||||
|
return USBD_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns the last transferred packet size.
|
||||||
|
* @param pdev: Device handle
|
||||||
|
* @param ep_addr: Endpoint Number
|
||||||
|
* @retval Received Data Size
|
||||||
|
*/
|
||||||
|
uint32_t USBD_LL_GetRxDataSize(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
|
||||||
|
{
|
||||||
|
UNUSED(pdev);
|
||||||
|
UNUSED(ep_addr);
|
||||||
|
|
||||||
|
return 0U;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef USBD_HS_TESTMODE_ENABLE
|
||||||
|
/**
|
||||||
|
* @brief Set High speed Test mode.
|
||||||
|
* @param pdev: Device handle
|
||||||
|
* @param testmode: test mode
|
||||||
|
* @retval USBD Status
|
||||||
|
*/
|
||||||
|
USBD_StatusTypeDef USBD_LL_SetTestMode(USBD_HandleTypeDef *pdev, uint8_t testmode)
|
||||||
|
{
|
||||||
|
UNUSED(pdev);
|
||||||
|
UNUSED(testmode);
|
||||||
|
|
||||||
|
return USBD_OK;
|
||||||
|
}
|
||||||
|
#endif /* USBD_HS_TESTMODE_ENABLE */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Static single allocation.
|
||||||
|
* @param size: Size of allocated memory
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void *USBD_static_malloc(uint32_t size)
|
||||||
|
{
|
||||||
|
UNUSED(size);
|
||||||
|
static uint32_t mem[(sizeof(USBD_HID_HandleTypeDef) / 4) + 1]; /* On 32-bit boundary */
|
||||||
|
return mem;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Dummy memory free
|
||||||
|
* @param p: Pointer to allocated memory address
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void USBD_static_free(void *p)
|
||||||
|
{
|
||||||
|
UNUSED(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Delays routine for the USB Device Library.
|
||||||
|
* @param Delay: Delay in ms
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void USBD_LL_Delay(uint32_t Delay)
|
||||||
|
{
|
||||||
|
UNUSED(Delay);
|
||||||
|
}
|
||||||
|
|
||||||
1215
Core/Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_core.c
Normal file
1215
Core/Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_core.c
Normal file
File diff suppressed because it is too large
Load Diff
1058
Core/Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_ctlreq.c
Normal file
1058
Core/Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_ctlreq.c
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,454 @@
|
|||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
* @file usbd_desc_template.c
|
||||||
|
* @author MCD Application Team
|
||||||
|
* @brief This file provides the USBD descriptors and string formatting method.
|
||||||
|
* This template should be copied to the user folder,
|
||||||
|
* renamed and customized following user needs.
|
||||||
|
******************************************************************************
|
||||||
|
* @attention
|
||||||
|
*
|
||||||
|
* Copyright (c) 2015 STMicroelectronics.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This software is licensed under terms that can be found in the LICENSE file
|
||||||
|
* in the root directory of this software component.
|
||||||
|
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||||
|
*
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Includes ------------------------------------------------------------------*/
|
||||||
|
#include "usbd_core.h"
|
||||||
|
#include "usbd_desc.h"
|
||||||
|
#include "usbd_conf.h"
|
||||||
|
|
||||||
|
/* Private typedef -----------------------------------------------------------*/
|
||||||
|
/* Private define ------------------------------------------------------------*/
|
||||||
|
#define USBD_VID 0x0483
|
||||||
|
#define USBD_PID 0xaaaa /* Replace '0xaaaa' with your device product ID */
|
||||||
|
#define USBD_LANGID_STRING 0xbbb /* Replace '0xbbb' with your device language ID */
|
||||||
|
#define USBD_MANUFACTURER_STRING "xxxxx" /* Add your manufacturer string */
|
||||||
|
#define USBD_PRODUCT_HS_STRING "xxxxx" /* Add your product High Speed string */
|
||||||
|
#define USBD_PRODUCT_FS_STRING "xxxxx" /* Add your product Full Speed string */
|
||||||
|
#define USBD_CONFIGURATION_HS_STRING "xxxxx" /* Add your configuration High Speed string */
|
||||||
|
#define USBD_INTERFACE_HS_STRING "xxxxx" /* Add your Interface High Speed string */
|
||||||
|
#define USBD_CONFIGURATION_FS_STRING "xxxxx" /* Add your configuration Full Speed string */
|
||||||
|
#define USBD_INTERFACE_FS_STRING "xxxxx" /* Add your Interface Full Speed string */
|
||||||
|
|
||||||
|
/* Private macro -------------------------------------------------------------*/
|
||||||
|
/* Private function prototypes -----------------------------------------------*/
|
||||||
|
uint8_t *USBD_Class_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||||
|
uint8_t *USBD_Class_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||||
|
uint8_t *USBD_Class_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||||
|
uint8_t *USBD_Class_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||||
|
uint8_t *USBD_Class_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||||
|
uint8_t *USBD_Class_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||||
|
uint8_t *USBD_Class_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||||
|
|
||||||
|
#if (USBD_CLASS_USER_STRING_DESC == 1)
|
||||||
|
uint8_t *USBD_Class_UserStrDescriptor(USBD_SpeedTypeDef speed, uint8_t idx, uint16_t *length);
|
||||||
|
#endif /* USB_CLASS_USER_STRING_DESC */
|
||||||
|
|
||||||
|
#if ((USBD_LPM_ENABLED == 1) || (USBD_CLASS_BOS_ENABLED == 1))
|
||||||
|
uint8_t *USBD_USR_BOSDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||||
|
#endif /* (USBD_LPM_ENABLED == 1) || (USBD_CLASS_BOS_ENABLED == 1) */
|
||||||
|
|
||||||
|
/* Private variables ---------------------------------------------------------*/
|
||||||
|
USBD_DescriptorsTypeDef Class_Desc =
|
||||||
|
{
|
||||||
|
USBD_Class_DeviceDescriptor,
|
||||||
|
USBD_Class_LangIDStrDescriptor,
|
||||||
|
USBD_Class_ManufacturerStrDescriptor,
|
||||||
|
USBD_Class_ProductStrDescriptor,
|
||||||
|
USBD_Class_SerialStrDescriptor,
|
||||||
|
USBD_Class_ConfigStrDescriptor,
|
||||||
|
USBD_Class_InterfaceStrDescriptor,
|
||||||
|
#if (USBD_CLASS_USER_STRING_DESC == 1)
|
||||||
|
USBD_CLASS_UserStrDescriptor,
|
||||||
|
#endif /* USB_CLASS_USER_STRING_DESC */
|
||||||
|
|
||||||
|
#if ((USBD_LPM_ENABLED == 1) || (USBD_CLASS_BOS_ENABLED == 1))
|
||||||
|
USBD_USR_BOSDescriptor,
|
||||||
|
#endif /* (USBD_LPM_ENABLED == 1) || (USBD_CLASS_BOS_ENABLED == 1) */
|
||||||
|
};
|
||||||
|
|
||||||
|
/* USB Standard Device Descriptor */
|
||||||
|
#if defined ( __ICCARM__ ) /*!< IAR Compiler */
|
||||||
|
#pragma data_alignment=4
|
||||||
|
#endif /* __ICCARM__ */
|
||||||
|
__ALIGN_BEGIN uint8_t USBD_DeviceDesc[USB_LEN_DEV_DESC] __ALIGN_END =
|
||||||
|
{
|
||||||
|
0x12, /* bLength */
|
||||||
|
USB_DESC_TYPE_DEVICE, /* bDescriptorType */
|
||||||
|
#if ((USBD_LPM_ENABLED == 1) || (USBD_CLASS_BOS_ENABLED == 1))
|
||||||
|
0x01, /*bcdUSB */ /* changed to USB version 2.01
|
||||||
|
in order to support BOS Desc */
|
||||||
|
#else
|
||||||
|
0x00, /* bcdUSB */
|
||||||
|
#endif /* (USBD_LPM_ENABLED == 1) || (USBD_CLASS_BOS_ENABLED == 1) */
|
||||||
|
0x02,
|
||||||
|
0x00, /* bDeviceClass */
|
||||||
|
0x00, /* bDeviceSubClass */
|
||||||
|
0x00, /* bDeviceProtocol */
|
||||||
|
USB_MAX_EP0_SIZE, /* bMaxPacketSize */
|
||||||
|
LOBYTE(USBD_VID), /* idVendor */
|
||||||
|
HIBYTE(USBD_VID), /* idVendor */
|
||||||
|
LOBYTE(USBD_PID), /* idVendor */
|
||||||
|
HIBYTE(USBD_PID), /* idVendor */
|
||||||
|
0x00, /* bcdDevice rel. 2.00 */
|
||||||
|
0x02,
|
||||||
|
USBD_IDX_MFC_STR, /* Index of manufacturer string */
|
||||||
|
USBD_IDX_PRODUCT_STR, /* Index of product string */
|
||||||
|
USBD_IDX_SERIAL_STR, /* Index of serial number string */
|
||||||
|
USBD_MAX_NUM_CONFIGURATION /* bNumConfigurations */
|
||||||
|
}; /* USB_DeviceDescriptor */
|
||||||
|
|
||||||
|
|
||||||
|
/* USB Device LPM BOS descriptor */
|
||||||
|
#if (USBD_LPM_ENABLED == 1)
|
||||||
|
#if defined ( __ICCARM__ ) /*!< IAR Compiler */
|
||||||
|
#pragma data_alignment=4
|
||||||
|
#endif /* __ICCARM__ */
|
||||||
|
__ALIGN_BEGIN uint8_t USBD_BOSDesc[USB_SIZ_BOS_DESC] __ALIGN_END =
|
||||||
|
{
|
||||||
|
0x5,
|
||||||
|
USB_DESC_TYPE_BOS,
|
||||||
|
0xC,
|
||||||
|
0x0,
|
||||||
|
0x1, /* 1 device capability */
|
||||||
|
/* device capability */
|
||||||
|
0x7,
|
||||||
|
USB_DEVICE_CAPABITY_TYPE,
|
||||||
|
0x2,
|
||||||
|
0x6, /*LPM capability bit set */
|
||||||
|
0x0,
|
||||||
|
0x0,
|
||||||
|
0x0
|
||||||
|
};
|
||||||
|
#endif /* USBD_LPM_ENABLED */
|
||||||
|
|
||||||
|
/* USB Device Billboard BOS descriptor Template */
|
||||||
|
#if (USBD_CLASS_BOS_ENABLED == 1)
|
||||||
|
#if defined ( __ICCARM__ ) /*!< IAR Compiler */
|
||||||
|
#pragma data_alignment=4
|
||||||
|
#endif /* __ICCARM__ */
|
||||||
|
__ALIGN_BEGIN uint8_t USBD_BOSDesc[USB_SIZ_BOS_DESC] __ALIGN_END =
|
||||||
|
{
|
||||||
|
0x05, /* bLength */
|
||||||
|
USB_DESC_TYPE_BOS, /* Device Descriptor Type */
|
||||||
|
USB_SIZ_BOS_DESC, /* Total length of BOS descriptor and all of its sub descs */
|
||||||
|
0x00,
|
||||||
|
0x04, /* The number of separate device capability descriptors in the BOS */
|
||||||
|
|
||||||
|
/* ----------- Device Capability Descriptor: CONTAINER_ID ---------- */
|
||||||
|
0x14, /* bLength */
|
||||||
|
0x10, /* bDescriptorType: DEVICE CAPABILITY Type */
|
||||||
|
0x04, /* bDevCapabilityType: CONTAINER_ID */
|
||||||
|
0x00, /* bReserved */
|
||||||
|
0xa7, 0xd6, 0x1b, 0xfa, /* ContainerID: This is a Unique 128-bit number GUID */
|
||||||
|
0x91, 0xa6, 0xa8, 0x4e,
|
||||||
|
0xa8, 0x21, 0x9f, 0x2b,
|
||||||
|
0xaf, 0xf7, 0x94, 0xd4,
|
||||||
|
|
||||||
|
/* ----------- Device Capability Descriptor: BillBoard ---------- */
|
||||||
|
0x34, /* bLength */
|
||||||
|
0x10, /* bDescriptorType: DEVICE CAPABILITY Type */
|
||||||
|
0x0D, /* bDevCapabilityType: BILLBOARD_CAPABILITY */
|
||||||
|
USBD_BB_URL_STRING_INDEX, /* iAddtionalInfoURL: Index of string descriptor providing a URL where the user
|
||||||
|
can go to get more detailed information about the product and the various
|
||||||
|
Alternate Modes it supports */
|
||||||
|
|
||||||
|
0x02, /* bNumberOfAlternateModes: Number of Alternate modes supported. The
|
||||||
|
maximum value that this field can be set to is MAX_NUM_ALT_MODE. */
|
||||||
|
|
||||||
|
0x00, /* bPreferredAlternateMode: Index of the preferred Alternate Mode. System
|
||||||
|
software may use this information to provide the user with a better
|
||||||
|
user experience. */
|
||||||
|
|
||||||
|
0x00, 0x00, /* VCONN Power needed by the adapter for full functionality 000b = 1W */
|
||||||
|
|
||||||
|
0x01, 0x00, 0x00, 0x00, /* bmConfigured. 01b: Alternate Mode configuration not attempted or exited */
|
||||||
|
0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x21, 0x01, /* bcdVersion = 0x0121 */
|
||||||
|
0x00, /* bAdditionalFailureInfo */
|
||||||
|
0x00, /* bReserved */
|
||||||
|
LOBYTE(USBD_VID),
|
||||||
|
HIBYTE(USBD_VID), /* wSVID[0]: Standard or Vendor ID. This shall match one of the SVIDs
|
||||||
|
returned in response to a USB PD Discover SVIDs command */
|
||||||
|
|
||||||
|
0x00, /* bAlternateMode[0] Index of the Alternate Mode within the SVID as
|
||||||
|
returned in response to a Discover Modes command. Example:
|
||||||
|
0 first Mode entry
|
||||||
|
1 second mode entry */
|
||||||
|
|
||||||
|
USBD_BB_ALTMODE0_STRING_INDEX, /* iAlternateModeString[0]: Index of string descriptor describing protocol.
|
||||||
|
It is optional to support this string. */
|
||||||
|
LOBYTE(USBD_VID),
|
||||||
|
HIBYTE(USBD_VID), /* wSVID[1]: Standard or Vendor ID. This shall match one of the SVIDs
|
||||||
|
returned in response to a USB PD Discover SVIDs command */
|
||||||
|
|
||||||
|
0x01, /* bAlternateMode[1] Index of the Alternate Mode within the SVID as
|
||||||
|
returned in response to a Discover Modes command. Example:
|
||||||
|
0 first Mode entry
|
||||||
|
1 second Mode entry */
|
||||||
|
|
||||||
|
USBD_BB_ALTMODE1_STRING_INDEX, /* iAlternateModeString[1]: Index of string descriptor describing protocol.
|
||||||
|
It is optional to support this string. */
|
||||||
|
/* Alternate Mode Desc */
|
||||||
|
/* ----------- Device Capability Descriptor: BillBoard Alternate Mode Desc ---------- */
|
||||||
|
0x08, /* bLength */
|
||||||
|
0x10, /* bDescriptorType: Device Descriptor Type */
|
||||||
|
0x0F, /* bDevCapabilityType: BILLBOARD ALTERNATE MODE CAPABILITY */
|
||||||
|
0x00, /* bIndex: Index of Alternate Mode described in the Billboard Capability Desc */
|
||||||
|
0x10, 0x00, 0x00, 0x00, /* dwAlternateModeVdo: contents of the Mode VDO for the alternate mode
|
||||||
|
identified by bIndex */
|
||||||
|
|
||||||
|
0x08, /* bLength */
|
||||||
|
0x10, /* bDescriptorType: Device Descriptor Type */
|
||||||
|
0x0F, /* bDevCapabilityType: BILLBOARD ALTERNATE MODE CAPABILITY */
|
||||||
|
0x01, /* bIndex: Index of Alternate Mode described in the Billboard Capability Desc */
|
||||||
|
0x20, 0x00, 0x00, 0x00, /* dwAlternateModeVdo: contents of the Mode VDO for the alternate mode
|
||||||
|
identified by bIndex */
|
||||||
|
};
|
||||||
|
#endif /* USBD_CLASS_BOS_ENABLED */
|
||||||
|
|
||||||
|
|
||||||
|
/* USB Standard Device Descriptor */
|
||||||
|
#if defined ( __ICCARM__ ) /*!< IAR Compiler */
|
||||||
|
#pragma data_alignment=4
|
||||||
|
#endif /* __ICCARM__ */
|
||||||
|
__ALIGN_BEGIN uint8_t USBD_LangIDDesc[USB_LEN_LANGID_STR_DESC] __ALIGN_END =
|
||||||
|
{
|
||||||
|
USB_LEN_LANGID_STR_DESC,
|
||||||
|
USB_DESC_TYPE_STRING,
|
||||||
|
LOBYTE(USBD_LANGID_STRING),
|
||||||
|
HIBYTE(USBD_LANGID_STRING),
|
||||||
|
};
|
||||||
|
|
||||||
|
#if defined ( __ICCARM__ ) /*!< IAR Compiler */
|
||||||
|
#pragma data_alignment=4
|
||||||
|
#endif /* __ICCARM__ */
|
||||||
|
__ALIGN_BEGIN uint8_t USBD_StringSerial[USB_SIZ_STRING_SERIAL] =
|
||||||
|
{
|
||||||
|
USB_SIZ_STRING_SERIAL,
|
||||||
|
USB_DESC_TYPE_STRING,
|
||||||
|
};
|
||||||
|
|
||||||
|
#if defined ( __ICCARM__ ) /*!< IAR Compiler */
|
||||||
|
#pragma data_alignment=4
|
||||||
|
#endif /* __ICCARM__ */
|
||||||
|
__ALIGN_BEGIN uint8_t USBD_StrDesc[USBD_MAX_STR_DESC_SIZ] __ALIGN_END;
|
||||||
|
|
||||||
|
/* Private functions ---------------------------------------------------------*/
|
||||||
|
static void IntToUnicode(uint32_t value, uint8_t *pbuf, uint8_t len);
|
||||||
|
static void Get_SerialNum(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns the device descriptor.
|
||||||
|
* @param speed: Current device speed
|
||||||
|
* @param length: Pointer to data length variable
|
||||||
|
* @retval Pointer to descriptor buffer
|
||||||
|
*/
|
||||||
|
uint8_t *USBD_Class_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
|
||||||
|
{
|
||||||
|
UNUSED(speed);
|
||||||
|
|
||||||
|
*length = sizeof(USBD_DeviceDesc);
|
||||||
|
return (uint8_t *)USBD_DeviceDesc;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns the LangID string descriptor.
|
||||||
|
* @param speed: Current device speed
|
||||||
|
* @param length: Pointer to data length variable
|
||||||
|
* @retval Pointer to descriptor buffer
|
||||||
|
*/
|
||||||
|
uint8_t *USBD_Class_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
|
||||||
|
{
|
||||||
|
UNUSED(speed);
|
||||||
|
|
||||||
|
*length = sizeof(USBD_LangIDDesc);
|
||||||
|
return (uint8_t *)USBD_LangIDDesc;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns the product string descriptor.
|
||||||
|
* @param speed: Current device speed
|
||||||
|
* @param length: Pointer to data length variable
|
||||||
|
* @retval Pointer to descriptor buffer
|
||||||
|
*/
|
||||||
|
uint8_t *USBD_Class_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
|
||||||
|
{
|
||||||
|
if (speed == USBD_SPEED_HIGH)
|
||||||
|
{
|
||||||
|
USBD_GetString((uint8_t *)USBD_PRODUCT_HS_STRING, USBD_StrDesc, length);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
USBD_GetString((uint8_t *)USBD_PRODUCT_FS_STRING, USBD_StrDesc, length);
|
||||||
|
}
|
||||||
|
return USBD_StrDesc;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns the manufacturer string descriptor.
|
||||||
|
* @param speed: Current device speed
|
||||||
|
* @param length: Pointer to data length variable
|
||||||
|
* @retval Pointer to descriptor buffer
|
||||||
|
*/
|
||||||
|
uint8_t *USBD_Class_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
|
||||||
|
{
|
||||||
|
UNUSED(speed);
|
||||||
|
|
||||||
|
USBD_GetString((uint8_t *)USBD_MANUFACTURER_STRING, USBD_StrDesc, length);
|
||||||
|
return USBD_StrDesc;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns the serial number string descriptor.
|
||||||
|
* @param speed: Current device speed
|
||||||
|
* @param length: Pointer to data length variable
|
||||||
|
* @retval Pointer to descriptor buffer
|
||||||
|
*/
|
||||||
|
uint8_t *USBD_Class_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
|
||||||
|
{
|
||||||
|
UNUSED(speed);
|
||||||
|
|
||||||
|
*length = USB_SIZ_STRING_SERIAL;
|
||||||
|
|
||||||
|
/* Update the serial number string descriptor with the data from the unique ID*/
|
||||||
|
Get_SerialNum();
|
||||||
|
|
||||||
|
return (uint8_t *)USBD_StringSerial;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns the configuration string descriptor.
|
||||||
|
* @param speed: Current device speed
|
||||||
|
* @param length: Pointer to data length variable
|
||||||
|
* @retval Pointer to descriptor buffer
|
||||||
|
*/
|
||||||
|
uint8_t *USBD_Class_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
|
||||||
|
{
|
||||||
|
if (speed == USBD_SPEED_HIGH)
|
||||||
|
{
|
||||||
|
USBD_GetString((uint8_t *)USBD_CONFIGURATION_HS_STRING, USBD_StrDesc, length);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
USBD_GetString((uint8_t *)USBD_CONFIGURATION_FS_STRING, USBD_StrDesc, length);
|
||||||
|
}
|
||||||
|
return USBD_StrDesc;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns the interface string descriptor.
|
||||||
|
* @param speed: Current device speed
|
||||||
|
* @param length: Pointer to data length variable
|
||||||
|
* @retval Pointer to descriptor buffer
|
||||||
|
*/
|
||||||
|
uint8_t *USBD_Class_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
|
||||||
|
{
|
||||||
|
if (speed == USBD_SPEED_HIGH)
|
||||||
|
{
|
||||||
|
USBD_GetString((uint8_t *)USBD_INTERFACE_HS_STRING, USBD_StrDesc, length);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
USBD_GetString((uint8_t *)USBD_INTERFACE_FS_STRING, USBD_StrDesc, length);
|
||||||
|
}
|
||||||
|
return USBD_StrDesc;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Create the serial number string descriptor
|
||||||
|
* @param None
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
static void Get_SerialNum(void)
|
||||||
|
{
|
||||||
|
uint32_t deviceserial0;
|
||||||
|
uint32_t deviceserial1;
|
||||||
|
uint32_t deviceserial2;
|
||||||
|
|
||||||
|
deviceserial0 = *(uint32_t *)DEVICE_ID1;
|
||||||
|
deviceserial1 = *(uint32_t *)DEVICE_ID2;
|
||||||
|
deviceserial2 = *(uint32_t *)DEVICE_ID3;
|
||||||
|
|
||||||
|
deviceserial0 += deviceserial2;
|
||||||
|
|
||||||
|
if (deviceserial0 != 0U)
|
||||||
|
{
|
||||||
|
IntToUnicode(deviceserial0, &USBD_StringSerial[2], 8U);
|
||||||
|
IntToUnicode(deviceserial1, &USBD_StringSerial[18], 4U);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#if ((USBD_LPM_ENABLED == 1) || (USBD_CLASS_BOS_ENABLED == 1))
|
||||||
|
/**
|
||||||
|
* @brief USBD_USR_BOSDescriptor
|
||||||
|
* return the BOS descriptor
|
||||||
|
* @param speed : current device speed
|
||||||
|
* @param length : pointer to data length variable
|
||||||
|
* @retval pointer to descriptor buffer
|
||||||
|
*/
|
||||||
|
uint8_t *USBD_USR_BOSDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
|
||||||
|
{
|
||||||
|
*length = sizeof(USBD_BOSDesc);
|
||||||
|
return (uint8_t *)USBD_BOSDesc;
|
||||||
|
}
|
||||||
|
#endif /* (USBD_LPM_ENABLED == 1) || (USBD_CLASS_BOS_ENABLED == 1) */
|
||||||
|
|
||||||
|
|
||||||
|
#if (USBD_CLASS_USER_STRING_DESC == 1)
|
||||||
|
/**
|
||||||
|
* @brief Returns the Class User string descriptor.
|
||||||
|
* @param speed: Current device speed
|
||||||
|
* @param idx: index of string descriptor
|
||||||
|
* @param length: Pointer to data length variable
|
||||||
|
* @retval Pointer to descriptor buffer
|
||||||
|
*/
|
||||||
|
uint8_t *USBD_Class_UserStrDescriptor(USBD_SpeedTypeDef speed, uint8_t idx, uint16_t *length)
|
||||||
|
{
|
||||||
|
static uint8_t USBD_StrDesc[255];
|
||||||
|
|
||||||
|
return USBD_StrDesc;
|
||||||
|
}
|
||||||
|
#endif /* USBD_CLASS_USER_STRING_DESC */
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Convert Hex 32Bits value into char
|
||||||
|
* @param value: value to convert
|
||||||
|
* @param pbuf: pointer to the buffer
|
||||||
|
* @param len: buffer length
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
static void IntToUnicode(uint32_t value, uint8_t *pbuf, uint8_t len)
|
||||||
|
{
|
||||||
|
uint8_t idx = 0U;
|
||||||
|
|
||||||
|
for (idx = 0U ; idx < len ; idx ++)
|
||||||
|
{
|
||||||
|
if (((value >> 28)) < 0xAU)
|
||||||
|
{
|
||||||
|
pbuf[ 2U * idx] = (value >> 28) + '0';
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pbuf[2U * idx] = (value >> 28) + 'A' - 10U;
|
||||||
|
}
|
||||||
|
|
||||||
|
value = value << 4;
|
||||||
|
|
||||||
|
pbuf[2U * idx + 1] = 0U;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,224 @@
|
|||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
* @file usbd_ioreq.c
|
||||||
|
* @author MCD Application Team
|
||||||
|
* @brief This file provides the IO requests APIs for control endpoints.
|
||||||
|
******************************************************************************
|
||||||
|
* @attention
|
||||||
|
*
|
||||||
|
* Copyright (c) 2015 STMicroelectronics.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This software is licensed under terms that can be found in the LICENSE file
|
||||||
|
* in the root directory of this software component.
|
||||||
|
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||||
|
*
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Includes ------------------------------------------------------------------*/
|
||||||
|
#include "usbd_ioreq.h"
|
||||||
|
|
||||||
|
/** @addtogroup STM32_USB_DEVICE_LIBRARY
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/** @defgroup USBD_IOREQ
|
||||||
|
* @brief control I/O requests module
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_IOREQ_Private_TypesDefinitions
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/** @defgroup USBD_IOREQ_Private_Defines
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/** @defgroup USBD_IOREQ_Private_Macros
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/** @defgroup USBD_IOREQ_Private_Variables
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/** @defgroup USBD_IOREQ_Private_FunctionPrototypes
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/** @defgroup USBD_IOREQ_Private_Functions
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief USBD_CtlSendData
|
||||||
|
* send data on the ctl pipe
|
||||||
|
* @param pdev: device instance
|
||||||
|
* @param buff: pointer to data buffer
|
||||||
|
* @param len: length of data to be sent
|
||||||
|
* @retval status
|
||||||
|
*/
|
||||||
|
USBD_StatusTypeDef USBD_CtlSendData(USBD_HandleTypeDef *pdev,
|
||||||
|
uint8_t *pbuf, uint32_t len)
|
||||||
|
{
|
||||||
|
/* Set EP0 State */
|
||||||
|
pdev->ep0_state = USBD_EP0_DATA_IN;
|
||||||
|
pdev->ep_in[0].total_length = len;
|
||||||
|
|
||||||
|
#ifdef USBD_AVOID_PACKET_SPLIT_MPS
|
||||||
|
pdev->ep_in[0].rem_length = 0U;
|
||||||
|
#else
|
||||||
|
pdev->ep_in[0].rem_length = len;
|
||||||
|
#endif /* USBD_AVOID_PACKET_SPLIT_MPS */
|
||||||
|
|
||||||
|
/* Start the transfer */
|
||||||
|
(void)USBD_LL_Transmit(pdev, 0x00U, pbuf, len);
|
||||||
|
|
||||||
|
return USBD_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief USBD_CtlContinueSendData
|
||||||
|
* continue sending data on the ctl pipe
|
||||||
|
* @param pdev: device instance
|
||||||
|
* @param buff: pointer to data buffer
|
||||||
|
* @param len: length of data to be sent
|
||||||
|
* @retval status
|
||||||
|
*/
|
||||||
|
USBD_StatusTypeDef USBD_CtlContinueSendData(USBD_HandleTypeDef *pdev,
|
||||||
|
uint8_t *pbuf, uint32_t len)
|
||||||
|
{
|
||||||
|
/* Start the next transfer */
|
||||||
|
(void)USBD_LL_Transmit(pdev, 0x00U, pbuf, len);
|
||||||
|
|
||||||
|
return USBD_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief USBD_CtlPrepareRx
|
||||||
|
* receive data on the ctl pipe
|
||||||
|
* @param pdev: device instance
|
||||||
|
* @param buff: pointer to data buffer
|
||||||
|
* @param len: length of data to be received
|
||||||
|
* @retval status
|
||||||
|
*/
|
||||||
|
USBD_StatusTypeDef USBD_CtlPrepareRx(USBD_HandleTypeDef *pdev,
|
||||||
|
uint8_t *pbuf, uint32_t len)
|
||||||
|
{
|
||||||
|
/* Set EP0 State */
|
||||||
|
pdev->ep0_state = USBD_EP0_DATA_OUT;
|
||||||
|
pdev->ep_out[0].total_length = len;
|
||||||
|
|
||||||
|
#ifdef USBD_AVOID_PACKET_SPLIT_MPS
|
||||||
|
pdev->ep_out[0].rem_length = 0U;
|
||||||
|
#else
|
||||||
|
pdev->ep_out[0].rem_length = len;
|
||||||
|
#endif /* USBD_AVOID_PACKET_SPLIT_MPS */
|
||||||
|
|
||||||
|
/* Start the transfer */
|
||||||
|
(void)USBD_LL_PrepareReceive(pdev, 0U, pbuf, len);
|
||||||
|
|
||||||
|
return USBD_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief USBD_CtlContinueRx
|
||||||
|
* continue receive data on the ctl pipe
|
||||||
|
* @param pdev: device instance
|
||||||
|
* @param buff: pointer to data buffer
|
||||||
|
* @param len: length of data to be received
|
||||||
|
* @retval status
|
||||||
|
*/
|
||||||
|
USBD_StatusTypeDef USBD_CtlContinueRx(USBD_HandleTypeDef *pdev,
|
||||||
|
uint8_t *pbuf, uint32_t len)
|
||||||
|
{
|
||||||
|
(void)USBD_LL_PrepareReceive(pdev, 0U, pbuf, len);
|
||||||
|
|
||||||
|
return USBD_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief USBD_CtlSendStatus
|
||||||
|
* send zero lzngth packet on the ctl pipe
|
||||||
|
* @param pdev: device instance
|
||||||
|
* @retval status
|
||||||
|
*/
|
||||||
|
USBD_StatusTypeDef USBD_CtlSendStatus(USBD_HandleTypeDef *pdev)
|
||||||
|
{
|
||||||
|
/* Set EP0 State */
|
||||||
|
pdev->ep0_state = USBD_EP0_STATUS_IN;
|
||||||
|
|
||||||
|
/* Start the transfer */
|
||||||
|
(void)USBD_LL_Transmit(pdev, 0x00U, NULL, 0U);
|
||||||
|
|
||||||
|
return USBD_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief USBD_CtlReceiveStatus
|
||||||
|
* receive zero lzngth packet on the ctl pipe
|
||||||
|
* @param pdev: device instance
|
||||||
|
* @retval status
|
||||||
|
*/
|
||||||
|
USBD_StatusTypeDef USBD_CtlReceiveStatus(USBD_HandleTypeDef *pdev)
|
||||||
|
{
|
||||||
|
/* Set EP0 State */
|
||||||
|
pdev->ep0_state = USBD_EP0_STATUS_OUT;
|
||||||
|
|
||||||
|
/* Start the transfer */
|
||||||
|
(void)USBD_LL_PrepareReceive(pdev, 0U, NULL, 0U);
|
||||||
|
|
||||||
|
return USBD_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief USBD_GetRxCount
|
||||||
|
* returns the received data length
|
||||||
|
* @param pdev: device instance
|
||||||
|
* @param ep_addr: endpoint address
|
||||||
|
* @retval Rx Data blength
|
||||||
|
*/
|
||||||
|
uint32_t USBD_GetRxCount(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
|
||||||
|
{
|
||||||
|
return USBD_LL_GetRxDataSize(pdev, ep_addr);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
86
Core/Middlewares/ST/STM32_USB_Device_Library/LICENSE.txt
Normal file
86
Core/Middlewares/ST/STM32_USB_Device_Library/LICENSE.txt
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
This software component is provided to you as part of a software package and
|
||||||
|
applicable license terms are in the Package_license file. If you received this
|
||||||
|
software component outside of a package or without applicable license terms,
|
||||||
|
the terms of the SLA0044 license shall apply and are fully reproduced below:
|
||||||
|
|
||||||
|
SLA0044 Rev5/February 2018
|
||||||
|
|
||||||
|
Software license agreement
|
||||||
|
|
||||||
|
ULTIMATE LIBERTY SOFTWARE LICENSE AGREEMENT
|
||||||
|
|
||||||
|
BY INSTALLING, COPYING, DOWNLOADING, ACCESSING OR OTHERWISE USING THIS SOFTWARE
|
||||||
|
OR ANY PART THEREOF (AND THE RELATED DOCUMENTATION) FROM STMICROELECTRONICS
|
||||||
|
INTERNATIONAL N.V, SWISS BRANCH AND/OR ITS AFFILIATED COMPANIES
|
||||||
|
(STMICROELECTRONICS), THE RECIPIENT, ON BEHALF OF HIMSELF OR HERSELF, OR ON
|
||||||
|
BEHALF OF ANY ENTITY BY WHICH SUCH RECIPIENT IS EMPLOYED AND/OR ENGAGED AGREES
|
||||||
|
TO BE BOUND BY THIS SOFTWARE LICENSE AGREEMENT.
|
||||||
|
|
||||||
|
Under STMicroelectronics’ intellectual property rights, the redistribution,
|
||||||
|
reproduction and use in source and binary forms of the software or any part
|
||||||
|
thereof, with or without modification, are permitted provided that the following
|
||||||
|
conditions are met:
|
||||||
|
|
||||||
|
1. Redistribution of source code (modified or not) must retain any copyright
|
||||||
|
notice, this list of conditions and the disclaimer set forth below as items 10
|
||||||
|
and 11.
|
||||||
|
|
||||||
|
2. Redistributions in binary form, except as embedded into microcontroller or
|
||||||
|
microprocessor device manufactured by or for STMicroelectronics or a software
|
||||||
|
update for such device, must reproduce any copyright notice provided with the
|
||||||
|
binary code, this list of conditions, and the disclaimer set forth below as
|
||||||
|
items 10 and 11, in documentation and/or other materials provided with the
|
||||||
|
distribution.
|
||||||
|
|
||||||
|
3. Neither the name of STMicroelectronics nor the names of other contributors to
|
||||||
|
this software may be used to endorse or promote products derived from this
|
||||||
|
software or part thereof without specific written permission.
|
||||||
|
|
||||||
|
4. This software or any part thereof, including modifications and/or derivative
|
||||||
|
works of this software, must be used and execute solely and exclusively on or in
|
||||||
|
combination with a microcontroller or microprocessor device manufactured by or
|
||||||
|
for STMicroelectronics.
|
||||||
|
|
||||||
|
5. No use, reproduction or redistribution of this software partially or totally
|
||||||
|
may be done in any manner that would subject this software to any Open Source
|
||||||
|
Terms. “Open Source Terms” shall mean any open source license which requires as
|
||||||
|
part of distribution of software that the source code of such software is
|
||||||
|
distributed therewith or otherwise made available, or open source license that
|
||||||
|
substantially complies with the Open Source definition specified at
|
||||||
|
www.opensource.org and any other comparable open source license such as for
|
||||||
|
example GNU General Public License (GPL), Eclipse Public License (EPL), Apache
|
||||||
|
Software License, BSD license or MIT license.
|
||||||
|
|
||||||
|
6. STMicroelectronics has no obligation to provide any maintenance, support or
|
||||||
|
updates for the software.
|
||||||
|
|
||||||
|
7. The software is and will remain the exclusive property of STMicroelectronics
|
||||||
|
and its licensors. The recipient will not take any action that jeopardizes
|
||||||
|
STMicroelectronics and its licensors' proprietary rights or acquire any rights
|
||||||
|
in the software, except the limited rights specified hereunder.
|
||||||
|
|
||||||
|
8. The recipient shall comply with all applicable laws and regulations affecting
|
||||||
|
the use of the software or any part thereof including any applicable export
|
||||||
|
control law or regulation.
|
||||||
|
|
||||||
|
9. Redistribution and use of this software or any part thereof other than as
|
||||||
|
permitted under this license is void and will automatically terminate your
|
||||||
|
rights under this license.
|
||||||
|
|
||||||
|
10. THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS" AND
|
||||||
|
ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY RIGHTS, WHICH ARE
|
||||||
|
DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT SHALL
|
||||||
|
STMICROELECTRONICS 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.
|
||||||
|
|
||||||
|
11. EXCEPT AS EXPRESSLY PERMITTED HEREUNDER, NO LICENSE OR OTHER RIGHTS, WHETHER
|
||||||
|
EXPRESS OR IMPLIED, ARE GRANTED UNDER ANY PATENT OR OTHER INTELLECTUAL PROPERTY
|
||||||
|
RIGHTS OF STMICROELECTRONICS OR ANY THIRD PARTY.
|
||||||
|
|
||||||
101
Core/USB_DEVICE/App/usb_device.c
Normal file
101
Core/USB_DEVICE/App/usb_device.c
Normal file
@@ -0,0 +1,101 @@
|
|||||||
|
/* USER CODE BEGIN Header */
|
||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
* @file : usb_device.c
|
||||||
|
* @version : v1.0_Cube
|
||||||
|
* @brief : This file implements the USB Device
|
||||||
|
******************************************************************************
|
||||||
|
* @attention
|
||||||
|
*
|
||||||
|
* Copyright (c) 2026 STMicroelectronics.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This software is licensed under terms that can be found in the LICENSE file
|
||||||
|
* in the root directory of this software component.
|
||||||
|
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||||
|
*
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
/* USER CODE END Header */
|
||||||
|
|
||||||
|
/* Includes ------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#include "usb_device.h"
|
||||||
|
#include "usbd_core.h"
|
||||||
|
#include "usbd_desc.h"
|
||||||
|
#include "usbd_cdc.h"
|
||||||
|
#include "usbd_cdc_if.h"
|
||||||
|
|
||||||
|
/* USER CODE BEGIN Includes */
|
||||||
|
|
||||||
|
/* USER CODE END Includes */
|
||||||
|
|
||||||
|
/* USER CODE BEGIN PV */
|
||||||
|
/* Private variables ---------------------------------------------------------*/
|
||||||
|
|
||||||
|
/* USER CODE END PV */
|
||||||
|
|
||||||
|
/* USER CODE BEGIN PFP */
|
||||||
|
/* Private function prototypes -----------------------------------------------*/
|
||||||
|
|
||||||
|
/* USER CODE END PFP */
|
||||||
|
|
||||||
|
/* USB Device Core handle declaration. */
|
||||||
|
USBD_HandleTypeDef hUsbDeviceFS;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* -- Insert your variables declaration here --
|
||||||
|
*/
|
||||||
|
/* USER CODE BEGIN 0 */
|
||||||
|
|
||||||
|
/* USER CODE END 0 */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* -- Insert your external function declaration here --
|
||||||
|
*/
|
||||||
|
/* USER CODE BEGIN 1 */
|
||||||
|
|
||||||
|
/* USER CODE END 1 */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Init USB device Library, add supported class and start the library
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void MX_USB_DEVICE_Init(void)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN USB_DEVICE_Init_PreTreatment */
|
||||||
|
|
||||||
|
/* USER CODE END USB_DEVICE_Init_PreTreatment */
|
||||||
|
|
||||||
|
/* Init Device Library, add supported class and start the library. */
|
||||||
|
if (USBD_Init(&hUsbDeviceFS, &FS_Desc, DEVICE_FS) != USBD_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
if (USBD_RegisterClass(&hUsbDeviceFS, &USBD_CDC) != USBD_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
if (USBD_CDC_RegisterInterface(&hUsbDeviceFS, &USBD_Interface_fops_FS) != USBD_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
if (USBD_Start(&hUsbDeviceFS) != USBD_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* USER CODE BEGIN USB_DEVICE_Init_PostTreatment */
|
||||||
|
HAL_PWREx_EnableUSBVoltageDetector();
|
||||||
|
|
||||||
|
/* USER CODE END USB_DEVICE_Init_PostTreatment */
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
102
Core/USB_DEVICE/App/usb_device.h
Normal file
102
Core/USB_DEVICE/App/usb_device.h
Normal file
@@ -0,0 +1,102 @@
|
|||||||
|
/* USER CODE BEGIN Header */
|
||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
* @file : usb_device.h
|
||||||
|
* @version : v1.0_Cube
|
||||||
|
* @brief : Header for usb_device.c file.
|
||||||
|
******************************************************************************
|
||||||
|
* @attention
|
||||||
|
*
|
||||||
|
* Copyright (c) 2026 STMicroelectronics.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This software is licensed under terms that can be found in the LICENSE file
|
||||||
|
* in the root directory of this software component.
|
||||||
|
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||||
|
*
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
/* USER CODE END Header */
|
||||||
|
|
||||||
|
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||||
|
#ifndef __USB_DEVICE__H__
|
||||||
|
#define __USB_DEVICE__H__
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Includes ------------------------------------------------------------------*/
|
||||||
|
#include "stm32h7xx.h"
|
||||||
|
#include "stm32h7xx_hal.h"
|
||||||
|
#include "usbd_def.h"
|
||||||
|
|
||||||
|
/* USER CODE BEGIN INCLUDE */
|
||||||
|
|
||||||
|
/* USER CODE END INCLUDE */
|
||||||
|
|
||||||
|
/** @addtogroup USBD_OTG_DRIVER
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_DEVICE USBD_DEVICE
|
||||||
|
* @brief Device file for Usb otg low level driver.
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_DEVICE_Exported_Variables USBD_DEVICE_Exported_Variables
|
||||||
|
* @brief Public variables.
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Private variables ---------------------------------------------------------*/
|
||||||
|
/* USER CODE BEGIN PV */
|
||||||
|
|
||||||
|
/* USER CODE END PV */
|
||||||
|
|
||||||
|
/* Private function prototypes -----------------------------------------------*/
|
||||||
|
/* USER CODE BEGIN PFP */
|
||||||
|
|
||||||
|
/* USER CODE END PFP */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* -- Insert your variables declaration here --
|
||||||
|
*/
|
||||||
|
/* USER CODE BEGIN VARIABLES */
|
||||||
|
|
||||||
|
/* USER CODE END VARIABLES */
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_DEVICE_Exported_FunctionsPrototype USBD_DEVICE_Exported_FunctionsPrototype
|
||||||
|
* @brief Declaration of public functions for Usb device.
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** USB Device initialization function. */
|
||||||
|
void MX_USB_DEVICE_Init(void);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* -- Insert functions declaration here --
|
||||||
|
*/
|
||||||
|
/* USER CODE BEGIN FD */
|
||||||
|
|
||||||
|
/* USER CODE END FD */
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* __USB_DEVICE__H__ */
|
||||||
329
Core/USB_DEVICE/App/usbd_cdc_if.c
Normal file
329
Core/USB_DEVICE/App/usbd_cdc_if.c
Normal file
@@ -0,0 +1,329 @@
|
|||||||
|
/* USER CODE BEGIN Header */
|
||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
* @file : usbd_cdc_if.c
|
||||||
|
* @version : v1.0_Cube
|
||||||
|
* @brief : Usb device for Virtual Com Port.
|
||||||
|
******************************************************************************
|
||||||
|
* @attention
|
||||||
|
*
|
||||||
|
* Copyright (c) 2026 STMicroelectronics.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This software is licensed under terms that can be found in the LICENSE file
|
||||||
|
* in the root directory of this software component.
|
||||||
|
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||||
|
*
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
/* USER CODE END Header */
|
||||||
|
|
||||||
|
/* Includes ------------------------------------------------------------------*/
|
||||||
|
#include "usbd_cdc_if.h"
|
||||||
|
|
||||||
|
/* USER CODE BEGIN INCLUDE */
|
||||||
|
|
||||||
|
/* USER CODE END INCLUDE */
|
||||||
|
|
||||||
|
/* Private typedef -----------------------------------------------------------*/
|
||||||
|
/* Private define ------------------------------------------------------------*/
|
||||||
|
/* Private macro -------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/* USER CODE BEGIN PV */
|
||||||
|
/* Private variables ---------------------------------------------------------*/
|
||||||
|
|
||||||
|
/* USER CODE END PV */
|
||||||
|
|
||||||
|
/** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY
|
||||||
|
* @brief Usb device library.
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @addtogroup USBD_CDC_IF
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_CDC_IF_Private_TypesDefinitions USBD_CDC_IF_Private_TypesDefinitions
|
||||||
|
* @brief Private types.
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* USER CODE BEGIN PRIVATE_TYPES */
|
||||||
|
|
||||||
|
/* USER CODE END PRIVATE_TYPES */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_CDC_IF_Private_Defines USBD_CDC_IF_Private_Defines
|
||||||
|
* @brief Private defines.
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* USER CODE BEGIN PRIVATE_DEFINES */
|
||||||
|
/* USER CODE END PRIVATE_DEFINES */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_CDC_IF_Private_Macros USBD_CDC_IF_Private_Macros
|
||||||
|
* @brief Private macros.
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* USER CODE BEGIN PRIVATE_MACRO */
|
||||||
|
|
||||||
|
/* USER CODE END PRIVATE_MACRO */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_CDC_IF_Private_Variables USBD_CDC_IF_Private_Variables
|
||||||
|
* @brief Private variables.
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
/* Create buffer for reception and transmission */
|
||||||
|
/* It's up to user to redefine and/or remove those define */
|
||||||
|
/** Received data over USB are stored in this buffer */
|
||||||
|
uint8_t UserRxBufferFS[APP_RX_DATA_SIZE];
|
||||||
|
|
||||||
|
/** Data to send over USB CDC are stored in this buffer */
|
||||||
|
uint8_t UserTxBufferFS[APP_TX_DATA_SIZE];
|
||||||
|
|
||||||
|
/* USER CODE BEGIN PRIVATE_VARIABLES */
|
||||||
|
|
||||||
|
/* USER CODE END PRIVATE_VARIABLES */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_CDC_IF_Exported_Variables USBD_CDC_IF_Exported_Variables
|
||||||
|
* @brief Public variables.
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
extern USBD_HandleTypeDef hUsbDeviceFS;
|
||||||
|
|
||||||
|
/* USER CODE BEGIN EXPORTED_VARIABLES */
|
||||||
|
|
||||||
|
/* USER CODE END EXPORTED_VARIABLES */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_CDC_IF_Private_FunctionPrototypes USBD_CDC_IF_Private_FunctionPrototypes
|
||||||
|
* @brief Private functions declaration.
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
static int8_t CDC_Init_FS(void);
|
||||||
|
static int8_t CDC_DeInit_FS(void);
|
||||||
|
static int8_t CDC_Control_FS(uint8_t cmd, uint8_t* pbuf, uint16_t length);
|
||||||
|
static int8_t CDC_Receive_FS(uint8_t* pbuf, uint32_t *Len);
|
||||||
|
static int8_t CDC_TransmitCplt_FS(uint8_t *pbuf, uint32_t *Len, uint8_t epnum);
|
||||||
|
|
||||||
|
/* USER CODE BEGIN PRIVATE_FUNCTIONS_DECLARATION */
|
||||||
|
|
||||||
|
/* USER CODE END PRIVATE_FUNCTIONS_DECLARATION */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
USBD_CDC_ItfTypeDef USBD_Interface_fops_FS =
|
||||||
|
{
|
||||||
|
CDC_Init_FS,
|
||||||
|
CDC_DeInit_FS,
|
||||||
|
CDC_Control_FS,
|
||||||
|
CDC_Receive_FS,
|
||||||
|
CDC_TransmitCplt_FS
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Private functions ---------------------------------------------------------*/
|
||||||
|
/**
|
||||||
|
* @brief Initializes the CDC media low layer over the FS USB IP
|
||||||
|
* @retval USBD_OK if all operations are OK else USBD_FAIL
|
||||||
|
*/
|
||||||
|
static int8_t CDC_Init_FS(void)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN 3 */
|
||||||
|
/* Set Application Buffers */
|
||||||
|
USBD_CDC_SetTxBuffer(&hUsbDeviceFS, UserTxBufferFS, 0);
|
||||||
|
USBD_CDC_SetRxBuffer(&hUsbDeviceFS, UserRxBufferFS);
|
||||||
|
return (USBD_OK);
|
||||||
|
/* USER CODE END 3 */
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief DeInitializes the CDC media low layer
|
||||||
|
* @retval USBD_OK if all operations are OK else USBD_FAIL
|
||||||
|
*/
|
||||||
|
static int8_t CDC_DeInit_FS(void)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN 4 */
|
||||||
|
return (USBD_OK);
|
||||||
|
/* USER CODE END 4 */
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Manage the CDC class requests
|
||||||
|
* @param cmd: Command code
|
||||||
|
* @param pbuf: Buffer containing command data (request parameters)
|
||||||
|
* @param length: Number of data to be sent (in bytes)
|
||||||
|
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
|
||||||
|
*/
|
||||||
|
static int8_t CDC_Control_FS(uint8_t cmd, uint8_t* pbuf, uint16_t length)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN 5 */
|
||||||
|
switch(cmd)
|
||||||
|
{
|
||||||
|
case CDC_SEND_ENCAPSULATED_COMMAND:
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CDC_GET_ENCAPSULATED_RESPONSE:
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CDC_SET_COMM_FEATURE:
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CDC_GET_COMM_FEATURE:
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CDC_CLEAR_COMM_FEATURE:
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
/*******************************************************************************/
|
||||||
|
/* Line Coding Structure */
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
/* Offset | Field | Size | Value | Description */
|
||||||
|
/* 0 | dwDTERate | 4 | Number |Data terminal rate, in bits per second*/
|
||||||
|
/* 4 | bCharFormat | 1 | Number | Stop bits */
|
||||||
|
/* 0 - 1 Stop bit */
|
||||||
|
/* 1 - 1.5 Stop bits */
|
||||||
|
/* 2 - 2 Stop bits */
|
||||||
|
/* 5 | bParityType | 1 | Number | Parity */
|
||||||
|
/* 0 - None */
|
||||||
|
/* 1 - Odd */
|
||||||
|
/* 2 - Even */
|
||||||
|
/* 3 - Mark */
|
||||||
|
/* 4 - Space */
|
||||||
|
/* 6 | bDataBits | 1 | Number Data bits (5, 6, 7, 8 or 16). */
|
||||||
|
/*******************************************************************************/
|
||||||
|
case CDC_SET_LINE_CODING:
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CDC_GET_LINE_CODING:
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CDC_SET_CONTROL_LINE_STATE:
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CDC_SEND_BREAK:
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (USBD_OK);
|
||||||
|
/* USER CODE END 5 */
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Data received over USB OUT endpoint are sent over CDC interface
|
||||||
|
* through this function.
|
||||||
|
*
|
||||||
|
* @note
|
||||||
|
* This function will issue a NAK packet on any OUT packet received on
|
||||||
|
* USB endpoint until exiting this function. If you exit this function
|
||||||
|
* before transfer is complete on CDC interface (ie. using DMA controller)
|
||||||
|
* it will result in receiving more data while previous ones are still
|
||||||
|
* not sent.
|
||||||
|
*
|
||||||
|
* @param Buf: Buffer of data to be received
|
||||||
|
* @param Len: Number of data received (in bytes)
|
||||||
|
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
|
||||||
|
*/
|
||||||
|
static int8_t CDC_Receive_FS(uint8_t* Buf, uint32_t *Len)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN 6 */
|
||||||
|
// CDC_Transmit_FS(Buf, *Len);
|
||||||
|
USBD_CDC_SetRxBuffer(&hUsbDeviceFS, &Buf[0]);
|
||||||
|
USBD_CDC_ReceivePacket(&hUsbDeviceFS);
|
||||||
|
return (USBD_OK);
|
||||||
|
/* USER CODE END 6 */
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief CDC_Transmit_FS
|
||||||
|
* Data to send over USB IN endpoint are sent over CDC interface
|
||||||
|
* through this function.
|
||||||
|
* @note
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param Buf: Buffer of data to be sent
|
||||||
|
* @param Len: Number of data to be sent (in bytes)
|
||||||
|
* @retval USBD_OK if all operations are OK else USBD_FAIL or USBD_BUSY
|
||||||
|
*/
|
||||||
|
uint8_t CDC_Transmit_FS(uint8_t* Buf, uint16_t Len)
|
||||||
|
{
|
||||||
|
uint8_t result = USBD_OK;
|
||||||
|
/* USER CODE BEGIN 7 */
|
||||||
|
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*)hUsbDeviceFS.pClassData;
|
||||||
|
if (hcdc->TxState != 0){
|
||||||
|
return USBD_BUSY;
|
||||||
|
}
|
||||||
|
USBD_CDC_SetTxBuffer(&hUsbDeviceFS, Buf, Len);
|
||||||
|
result = USBD_CDC_TransmitPacket(&hUsbDeviceFS);
|
||||||
|
/* USER CODE END 7 */
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief CDC_TransmitCplt_FS
|
||||||
|
* Data transmitted callback
|
||||||
|
*
|
||||||
|
* @note
|
||||||
|
* This function is IN transfer complete callback used to inform user that
|
||||||
|
* the submitted Data is successfully sent over USB.
|
||||||
|
*
|
||||||
|
* @param Buf: Buffer of data to be received
|
||||||
|
* @param Len: Number of data received (in bytes)
|
||||||
|
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
|
||||||
|
*/
|
||||||
|
static int8_t CDC_TransmitCplt_FS(uint8_t *Buf, uint32_t *Len, uint8_t epnum)
|
||||||
|
{
|
||||||
|
uint8_t result = USBD_OK;
|
||||||
|
/* USER CODE BEGIN 13 */
|
||||||
|
UNUSED(Buf);
|
||||||
|
UNUSED(Len);
|
||||||
|
UNUSED(epnum);
|
||||||
|
/* USER CODE END 13 */
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* USER CODE BEGIN PRIVATE_FUNCTIONS_IMPLEMENTATION */
|
||||||
|
|
||||||
|
/* USER CODE END PRIVATE_FUNCTIONS_IMPLEMENTATION */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
131
Core/USB_DEVICE/App/usbd_cdc_if.h
Normal file
131
Core/USB_DEVICE/App/usbd_cdc_if.h
Normal file
@@ -0,0 +1,131 @@
|
|||||||
|
/* USER CODE BEGIN Header */
|
||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
* @file : usbd_cdc_if.h
|
||||||
|
* @version : v1.0_Cube
|
||||||
|
* @brief : Header for usbd_cdc_if.c file.
|
||||||
|
******************************************************************************
|
||||||
|
* @attention
|
||||||
|
*
|
||||||
|
* Copyright (c) 2026 STMicroelectronics.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This software is licensed under terms that can be found in the LICENSE file
|
||||||
|
* in the root directory of this software component.
|
||||||
|
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||||
|
*
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
/* USER CODE END Header */
|
||||||
|
|
||||||
|
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||||
|
#ifndef __USBD_CDC_IF_H__
|
||||||
|
#define __USBD_CDC_IF_H__
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Includes ------------------------------------------------------------------*/
|
||||||
|
#include "usbd_cdc.h"
|
||||||
|
|
||||||
|
/* USER CODE BEGIN INCLUDE */
|
||||||
|
|
||||||
|
/* USER CODE END INCLUDE */
|
||||||
|
|
||||||
|
/** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY
|
||||||
|
* @brief For Usb device.
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_CDC_IF USBD_CDC_IF
|
||||||
|
* @brief Usb VCP device module
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_CDC_IF_Exported_Defines USBD_CDC_IF_Exported_Defines
|
||||||
|
* @brief Defines.
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
/* Define size for the receive and transmit buffer over CDC */
|
||||||
|
#define APP_RX_DATA_SIZE 2048
|
||||||
|
#define APP_TX_DATA_SIZE 2048
|
||||||
|
/* USER CODE BEGIN EXPORTED_DEFINES */
|
||||||
|
|
||||||
|
/* USER CODE END EXPORTED_DEFINES */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_CDC_IF_Exported_Types USBD_CDC_IF_Exported_Types
|
||||||
|
* @brief Types.
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* USER CODE BEGIN EXPORTED_TYPES */
|
||||||
|
|
||||||
|
/* USER CODE END EXPORTED_TYPES */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_CDC_IF_Exported_Macros USBD_CDC_IF_Exported_Macros
|
||||||
|
* @brief Aliases.
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* USER CODE BEGIN EXPORTED_MACRO */
|
||||||
|
|
||||||
|
/* USER CODE END EXPORTED_MACRO */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_CDC_IF_Exported_Variables USBD_CDC_IF_Exported_Variables
|
||||||
|
* @brief Public variables.
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** CDC Interface callback. */
|
||||||
|
extern USBD_CDC_ItfTypeDef USBD_Interface_fops_FS;
|
||||||
|
|
||||||
|
/* USER CODE BEGIN EXPORTED_VARIABLES */
|
||||||
|
|
||||||
|
/* USER CODE END EXPORTED_VARIABLES */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_CDC_IF_Exported_FunctionsPrototype USBD_CDC_IF_Exported_FunctionsPrototype
|
||||||
|
* @brief Public functions declaration.
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
uint8_t CDC_Transmit_FS(uint8_t* Buf, uint16_t Len);
|
||||||
|
|
||||||
|
/* USER CODE BEGIN EXPORTED_FUNCTIONS */
|
||||||
|
|
||||||
|
/* USER CODE END EXPORTED_FUNCTIONS */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* __USBD_CDC_IF_H__ */
|
||||||
|
|
||||||
418
Core/USB_DEVICE/App/usbd_desc.c
Normal file
418
Core/USB_DEVICE/App/usbd_desc.c
Normal file
@@ -0,0 +1,418 @@
|
|||||||
|
/* USER CODE BEGIN Header */
|
||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
* @file : App/usbd_desc.c
|
||||||
|
* @version : v1.0_Cube
|
||||||
|
* @brief : This file implements the USB device descriptors.
|
||||||
|
******************************************************************************
|
||||||
|
* @attention
|
||||||
|
*
|
||||||
|
* Copyright (c) 2026 STMicroelectronics.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This software is licensed under terms that can be found in the LICENSE file
|
||||||
|
* in the root directory of this software component.
|
||||||
|
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||||
|
*
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
/* USER CODE END Header */
|
||||||
|
|
||||||
|
/* Includes ------------------------------------------------------------------*/
|
||||||
|
#include "usbd_core.h"
|
||||||
|
#include "usbd_desc.h"
|
||||||
|
#include "usbd_conf.h"
|
||||||
|
|
||||||
|
/* USER CODE BEGIN INCLUDE */
|
||||||
|
|
||||||
|
/* USER CODE END INCLUDE */
|
||||||
|
|
||||||
|
/* Private typedef -----------------------------------------------------------*/
|
||||||
|
/* Private define ------------------------------------------------------------*/
|
||||||
|
/* Private macro -------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/* USER CODE BEGIN PV */
|
||||||
|
/* Private variables ---------------------------------------------------------*/
|
||||||
|
|
||||||
|
/* USER CODE END PV */
|
||||||
|
|
||||||
|
/** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @addtogroup USBD_DESC
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_DESC_Private_TypesDefinitions USBD_DESC_Private_TypesDefinitions
|
||||||
|
* @brief Private types.
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* USER CODE BEGIN PRIVATE_TYPES */
|
||||||
|
|
||||||
|
/* USER CODE END PRIVATE_TYPES */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_DESC_Private_Defines USBD_DESC_Private_Defines
|
||||||
|
* @brief Private defines.
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define USBD_VID 1156
|
||||||
|
#define USBD_LANGID_STRING 1033
|
||||||
|
#define USBD_MANUFACTURER_STRING "JSBR"
|
||||||
|
#define USBD_PID_FS 22337
|
||||||
|
#define USBD_PRODUCT_STRING_FS "YKC Virtual ComPort"
|
||||||
|
#define USBD_CONFIGURATION_STRING_FS "CDC Config"
|
||||||
|
#define USBD_INTERFACE_STRING_FS "CDC Interface"
|
||||||
|
|
||||||
|
#define USB_SIZ_BOS_DESC 0x0C
|
||||||
|
|
||||||
|
/* USER CODE BEGIN PRIVATE_DEFINES */
|
||||||
|
|
||||||
|
/* USER CODE END PRIVATE_DEFINES */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* USER CODE BEGIN 0 */
|
||||||
|
|
||||||
|
/* USER CODE END 0 */
|
||||||
|
|
||||||
|
/** @defgroup USBD_DESC_Private_Macros USBD_DESC_Private_Macros
|
||||||
|
* @brief Private macros.
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* USER CODE BEGIN PRIVATE_MACRO */
|
||||||
|
|
||||||
|
/* USER CODE END PRIVATE_MACRO */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_DESC_Private_FunctionPrototypes USBD_DESC_Private_FunctionPrototypes
|
||||||
|
* @brief Private functions declaration.
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
static void Get_SerialNum(void);
|
||||||
|
static void IntToUnicode(uint32_t value, uint8_t * pbuf, uint8_t len);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_DESC_Private_FunctionPrototypes USBD_DESC_Private_FunctionPrototypes
|
||||||
|
* @brief Private functions declaration for FS.
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
uint8_t * USBD_FS_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||||
|
uint8_t * USBD_FS_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||||
|
uint8_t * USBD_FS_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||||
|
uint8_t * USBD_FS_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||||
|
uint8_t * USBD_FS_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||||
|
uint8_t * USBD_FS_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||||
|
uint8_t * USBD_FS_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_DESC_Private_Variables USBD_DESC_Private_Variables
|
||||||
|
* @brief Private variables.
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
USBD_DescriptorsTypeDef FS_Desc =
|
||||||
|
{
|
||||||
|
USBD_FS_DeviceDescriptor
|
||||||
|
, USBD_FS_LangIDStrDescriptor
|
||||||
|
, USBD_FS_ManufacturerStrDescriptor
|
||||||
|
, USBD_FS_ProductStrDescriptor
|
||||||
|
, USBD_FS_SerialStrDescriptor
|
||||||
|
, USBD_FS_ConfigStrDescriptor
|
||||||
|
, USBD_FS_InterfaceStrDescriptor
|
||||||
|
};
|
||||||
|
|
||||||
|
#if defined ( __ICCARM__ ) /* IAR Compiler */
|
||||||
|
#pragma data_alignment=4
|
||||||
|
#endif /* defined ( __ICCARM__ ) */
|
||||||
|
/** USB standard device descriptor. */
|
||||||
|
__ALIGN_BEGIN uint8_t USBD_FS_DeviceDesc[USB_LEN_DEV_DESC] __ALIGN_END =
|
||||||
|
{
|
||||||
|
0x12, /*bLength */
|
||||||
|
USB_DESC_TYPE_DEVICE, /*bDescriptorType*/
|
||||||
|
0x00, /*bcdUSB */
|
||||||
|
0x02,
|
||||||
|
0x02, /*bDeviceClass*/
|
||||||
|
0x02, /*bDeviceSubClass*/
|
||||||
|
0x00, /*bDeviceProtocol*/
|
||||||
|
USB_MAX_EP0_SIZE, /*bMaxPacketSize*/
|
||||||
|
LOBYTE(USBD_VID), /*idVendor*/
|
||||||
|
HIBYTE(USBD_VID), /*idVendor*/
|
||||||
|
LOBYTE(USBD_PID_FS), /*idProduct*/
|
||||||
|
HIBYTE(USBD_PID_FS), /*idProduct*/
|
||||||
|
0x00, /*bcdDevice rel. 2.00*/
|
||||||
|
0x02,
|
||||||
|
USBD_IDX_MFC_STR, /*Index of manufacturer string*/
|
||||||
|
USBD_IDX_PRODUCT_STR, /*Index of product string*/
|
||||||
|
USBD_IDX_SERIAL_STR, /*Index of serial number string*/
|
||||||
|
USBD_MAX_NUM_CONFIGURATION /*bNumConfigurations*/
|
||||||
|
};
|
||||||
|
|
||||||
|
/* USB_DeviceDescriptor */
|
||||||
|
/** BOS descriptor. */
|
||||||
|
#if (USBD_LPM_ENABLED == 1)
|
||||||
|
#if defined ( __ICCARM__ ) /* IAR Compiler */
|
||||||
|
#pragma data_alignment=4
|
||||||
|
#endif /* defined ( __ICCARM__ ) */
|
||||||
|
__ALIGN_BEGIN uint8_t USBD_FS_BOSDesc[USB_SIZ_BOS_DESC] __ALIGN_END =
|
||||||
|
{
|
||||||
|
0x5,
|
||||||
|
USB_DESC_TYPE_BOS,
|
||||||
|
0xC,
|
||||||
|
0x0,
|
||||||
|
0x1, /* 1 device capability*/
|
||||||
|
/* device capability*/
|
||||||
|
0x7,
|
||||||
|
USB_DEVICE_CAPABITY_TYPE,
|
||||||
|
0x2,
|
||||||
|
0x2, /* LPM capability bit set*/
|
||||||
|
0x0,
|
||||||
|
0x0,
|
||||||
|
0x0
|
||||||
|
};
|
||||||
|
#endif /* (USBD_LPM_ENABLED == 1) */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_DESC_Private_Variables USBD_DESC_Private_Variables
|
||||||
|
* @brief Private variables.
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if defined ( __ICCARM__ ) /* IAR Compiler */
|
||||||
|
#pragma data_alignment=4
|
||||||
|
#endif /* defined ( __ICCARM__ ) */
|
||||||
|
|
||||||
|
/** USB lang identifier descriptor. */
|
||||||
|
__ALIGN_BEGIN uint8_t USBD_LangIDDesc[USB_LEN_LANGID_STR_DESC] __ALIGN_END =
|
||||||
|
{
|
||||||
|
USB_LEN_LANGID_STR_DESC,
|
||||||
|
USB_DESC_TYPE_STRING,
|
||||||
|
LOBYTE(USBD_LANGID_STRING),
|
||||||
|
HIBYTE(USBD_LANGID_STRING)
|
||||||
|
};
|
||||||
|
|
||||||
|
#if defined ( __ICCARM__ ) /* IAR Compiler */
|
||||||
|
#pragma data_alignment=4
|
||||||
|
#endif /* defined ( __ICCARM__ ) */
|
||||||
|
/* Internal string descriptor. */
|
||||||
|
__ALIGN_BEGIN uint8_t USBD_StrDesc[USBD_MAX_STR_DESC_SIZ] __ALIGN_END;
|
||||||
|
|
||||||
|
#if defined ( __ICCARM__ ) /*!< IAR Compiler */
|
||||||
|
#pragma data_alignment=4
|
||||||
|
#endif
|
||||||
|
__ALIGN_BEGIN uint8_t USBD_StringSerial[USB_SIZ_STRING_SERIAL] __ALIGN_END = {
|
||||||
|
USB_SIZ_STRING_SERIAL,
|
||||||
|
USB_DESC_TYPE_STRING,
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_DESC_Private_Functions USBD_DESC_Private_Functions
|
||||||
|
* @brief Private functions.
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Return the device descriptor
|
||||||
|
* @param speed : Current device speed
|
||||||
|
* @param length : Pointer to data length variable
|
||||||
|
* @retval Pointer to descriptor buffer
|
||||||
|
*/
|
||||||
|
uint8_t * USBD_FS_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
|
||||||
|
{
|
||||||
|
UNUSED(speed);
|
||||||
|
*length = sizeof(USBD_FS_DeviceDesc);
|
||||||
|
return USBD_FS_DeviceDesc;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Return the LangID string descriptor
|
||||||
|
* @param speed : Current device speed
|
||||||
|
* @param length : Pointer to data length variable
|
||||||
|
* @retval Pointer to descriptor buffer
|
||||||
|
*/
|
||||||
|
uint8_t * USBD_FS_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
|
||||||
|
{
|
||||||
|
UNUSED(speed);
|
||||||
|
*length = sizeof(USBD_LangIDDesc);
|
||||||
|
return USBD_LangIDDesc;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Return the product string descriptor
|
||||||
|
* @param speed : Current device speed
|
||||||
|
* @param length : Pointer to data length variable
|
||||||
|
* @retval Pointer to descriptor buffer
|
||||||
|
*/
|
||||||
|
uint8_t * USBD_FS_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
|
||||||
|
{
|
||||||
|
if(speed == 0)
|
||||||
|
{
|
||||||
|
USBD_GetString((uint8_t *)USBD_PRODUCT_STRING_FS, USBD_StrDesc, length);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
USBD_GetString((uint8_t *)USBD_PRODUCT_STRING_FS, USBD_StrDesc, length);
|
||||||
|
}
|
||||||
|
return USBD_StrDesc;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Return the manufacturer string descriptor
|
||||||
|
* @param speed : Current device speed
|
||||||
|
* @param length : Pointer to data length variable
|
||||||
|
* @retval Pointer to descriptor buffer
|
||||||
|
*/
|
||||||
|
uint8_t * USBD_FS_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
|
||||||
|
{
|
||||||
|
UNUSED(speed);
|
||||||
|
USBD_GetString((uint8_t *)USBD_MANUFACTURER_STRING, USBD_StrDesc, length);
|
||||||
|
return USBD_StrDesc;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Return the serial number string descriptor
|
||||||
|
* @param speed : Current device speed
|
||||||
|
* @param length : Pointer to data length variable
|
||||||
|
* @retval Pointer to descriptor buffer
|
||||||
|
*/
|
||||||
|
uint8_t * USBD_FS_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
|
||||||
|
{
|
||||||
|
UNUSED(speed);
|
||||||
|
*length = USB_SIZ_STRING_SERIAL;
|
||||||
|
|
||||||
|
/* Update the serial number string descriptor with the data from the unique
|
||||||
|
* ID */
|
||||||
|
Get_SerialNum();
|
||||||
|
/* USER CODE BEGIN USBD_FS_SerialStrDescriptor */
|
||||||
|
|
||||||
|
/* USER CODE END USBD_FS_SerialStrDescriptor */
|
||||||
|
return (uint8_t *) USBD_StringSerial;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Return the configuration string descriptor
|
||||||
|
* @param speed : Current device speed
|
||||||
|
* @param length : Pointer to data length variable
|
||||||
|
* @retval Pointer to descriptor buffer
|
||||||
|
*/
|
||||||
|
uint8_t * USBD_FS_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
|
||||||
|
{
|
||||||
|
if(speed == USBD_SPEED_HIGH)
|
||||||
|
{
|
||||||
|
USBD_GetString((uint8_t *)USBD_CONFIGURATION_STRING_FS, USBD_StrDesc, length);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
USBD_GetString((uint8_t *)USBD_CONFIGURATION_STRING_FS, USBD_StrDesc, length);
|
||||||
|
}
|
||||||
|
return USBD_StrDesc;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Return the interface string descriptor
|
||||||
|
* @param speed : Current device speed
|
||||||
|
* @param length : Pointer to data length variable
|
||||||
|
* @retval Pointer to descriptor buffer
|
||||||
|
*/
|
||||||
|
uint8_t * USBD_FS_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
|
||||||
|
{
|
||||||
|
if(speed == 0)
|
||||||
|
{
|
||||||
|
USBD_GetString((uint8_t *)USBD_INTERFACE_STRING_FS, USBD_StrDesc, length);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
USBD_GetString((uint8_t *)USBD_INTERFACE_STRING_FS, USBD_StrDesc, length);
|
||||||
|
}
|
||||||
|
return USBD_StrDesc;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Create the serial number string descriptor
|
||||||
|
* @param None
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
static void Get_SerialNum(void)
|
||||||
|
{
|
||||||
|
uint32_t deviceserial0;
|
||||||
|
uint32_t deviceserial1;
|
||||||
|
uint32_t deviceserial2;
|
||||||
|
|
||||||
|
deviceserial0 = *(uint32_t *) DEVICE_ID1;
|
||||||
|
deviceserial1 = *(uint32_t *) DEVICE_ID2;
|
||||||
|
deviceserial2 = *(uint32_t *) DEVICE_ID3;
|
||||||
|
|
||||||
|
deviceserial0 += deviceserial2;
|
||||||
|
|
||||||
|
if (deviceserial0 != 0)
|
||||||
|
{
|
||||||
|
IntToUnicode(deviceserial0, &USBD_StringSerial[2], 8);
|
||||||
|
IntToUnicode(deviceserial1, &USBD_StringSerial[18], 4);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Convert Hex 32Bits value into char
|
||||||
|
* @param value: value to convert
|
||||||
|
* @param pbuf: pointer to the buffer
|
||||||
|
* @param len: buffer length
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
static void IntToUnicode(uint32_t value, uint8_t * pbuf, uint8_t len)
|
||||||
|
{
|
||||||
|
uint8_t idx = 0;
|
||||||
|
|
||||||
|
for (idx = 0; idx < len; idx++)
|
||||||
|
{
|
||||||
|
if (((value >> 28)) < 0xA)
|
||||||
|
{
|
||||||
|
pbuf[2 * idx] = (value >> 28) + '0';
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pbuf[2 * idx] = (value >> 28) + 'A' - 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
value = value << 4;
|
||||||
|
|
||||||
|
pbuf[2 * idx + 1] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
143
Core/USB_DEVICE/App/usbd_desc.h
Normal file
143
Core/USB_DEVICE/App/usbd_desc.h
Normal file
@@ -0,0 +1,143 @@
|
|||||||
|
/* USER CODE BEGIN Header */
|
||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
* @file : usbd_desc.c
|
||||||
|
* @version : v1.0_Cube
|
||||||
|
* @brief : Header for usbd_conf.c file.
|
||||||
|
******************************************************************************
|
||||||
|
* @attention
|
||||||
|
*
|
||||||
|
* Copyright (c) 2026 STMicroelectronics.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This software is licensed under terms that can be found in the LICENSE file
|
||||||
|
* in the root directory of this software component.
|
||||||
|
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||||
|
*
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
/* USER CODE END Header */
|
||||||
|
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||||
|
#ifndef __USBD_DESC__C__
|
||||||
|
#define __USBD_DESC__C__
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Includes ------------------------------------------------------------------*/
|
||||||
|
#include "usbd_def.h"
|
||||||
|
|
||||||
|
/* USER CODE BEGIN INCLUDE */
|
||||||
|
|
||||||
|
/* USER CODE END INCLUDE */
|
||||||
|
|
||||||
|
/** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_DESC USBD_DESC
|
||||||
|
* @brief Usb device descriptors module.
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_DESC_Exported_Constants USBD_DESC_Exported_Constants
|
||||||
|
* @brief Constants.
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
#define DEVICE_ID1 (UID_BASE)
|
||||||
|
#define DEVICE_ID2 (UID_BASE + 0x4)
|
||||||
|
#define DEVICE_ID3 (UID_BASE + 0x8)
|
||||||
|
|
||||||
|
#define USB_SIZ_STRING_SERIAL 0x1A
|
||||||
|
|
||||||
|
/* USER CODE BEGIN EXPORTED_CONSTANTS */
|
||||||
|
|
||||||
|
/* USER CODE END EXPORTED_CONSTANTS */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_DESC_Exported_Defines USBD_DESC_Exported_Defines
|
||||||
|
* @brief Defines.
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* USER CODE BEGIN EXPORTED_DEFINES */
|
||||||
|
|
||||||
|
/* USER CODE END EXPORTED_DEFINES */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_DESC_Exported_TypesDefinitions USBD_DESC_Exported_TypesDefinitions
|
||||||
|
* @brief Types.
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* USER CODE BEGIN EXPORTED_TYPES */
|
||||||
|
|
||||||
|
/* USER CODE END EXPORTED_TYPES */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_DESC_Exported_Macros USBD_DESC_Exported_Macros
|
||||||
|
* @brief Aliases.
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* USER CODE BEGIN EXPORTED_MACRO */
|
||||||
|
|
||||||
|
/* USER CODE END EXPORTED_MACRO */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_DESC_Exported_Variables USBD_DESC_Exported_Variables
|
||||||
|
* @brief Public variables.
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** Descriptor for the Usb device. */
|
||||||
|
extern USBD_DescriptorsTypeDef FS_Desc;
|
||||||
|
|
||||||
|
/* USER CODE BEGIN EXPORTED_VARIABLES */
|
||||||
|
|
||||||
|
/* USER CODE END EXPORTED_VARIABLES */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_DESC_Exported_FunctionsPrototype USBD_DESC_Exported_FunctionsPrototype
|
||||||
|
* @brief Public functions declaration.
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* USER CODE BEGIN EXPORTED_FUNCTIONS */
|
||||||
|
|
||||||
|
/* USER CODE END EXPORTED_FUNCTIONS */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* __USBD_DESC__C__ */
|
||||||
|
|
||||||
693
Core/USB_DEVICE/Target/usbd_conf.c
Normal file
693
Core/USB_DEVICE/Target/usbd_conf.c
Normal file
@@ -0,0 +1,693 @@
|
|||||||
|
/* USER CODE BEGIN Header */
|
||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
* @file : Target/usbd_conf.c
|
||||||
|
* @version : v1.0_Cube
|
||||||
|
* @brief : This file implements the board support package for the USB device library
|
||||||
|
******************************************************************************
|
||||||
|
* @attention
|
||||||
|
*
|
||||||
|
* Copyright (c) 2026 STMicroelectronics.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This software is licensed under terms that can be found in the LICENSE file
|
||||||
|
* in the root directory of this software component.
|
||||||
|
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||||
|
*
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
/* USER CODE END Header */
|
||||||
|
|
||||||
|
/* Includes ------------------------------------------------------------------*/
|
||||||
|
#include "stm32h7xx.h"
|
||||||
|
#include "stm32h7xx_hal.h"
|
||||||
|
#include "usbd_def.h"
|
||||||
|
#include "usbd_core.h"
|
||||||
|
#include "usbd_cdc.h"
|
||||||
|
|
||||||
|
/* USER CODE BEGIN Includes */
|
||||||
|
|
||||||
|
/* USER CODE END Includes */
|
||||||
|
|
||||||
|
/* Private typedef -----------------------------------------------------------*/
|
||||||
|
/* Private define ------------------------------------------------------------*/
|
||||||
|
/* Private macro -------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/* USER CODE BEGIN PV */
|
||||||
|
/* Private variables ---------------------------------------------------------*/
|
||||||
|
|
||||||
|
/* USER CODE END PV */
|
||||||
|
|
||||||
|
PCD_HandleTypeDef hpcd_USB_OTG_FS;
|
||||||
|
void Error_Handler(void);
|
||||||
|
|
||||||
|
/* External functions --------------------------------------------------------*/
|
||||||
|
|
||||||
|
/* USER CODE BEGIN 0 */
|
||||||
|
|
||||||
|
/* USER CODE END 0 */
|
||||||
|
|
||||||
|
/* USER CODE BEGIN PFP */
|
||||||
|
/* Private function prototypes -----------------------------------------------*/
|
||||||
|
USBD_StatusTypeDef USBD_Get_USB_Status(HAL_StatusTypeDef hal_status);
|
||||||
|
|
||||||
|
/* USER CODE END PFP */
|
||||||
|
|
||||||
|
/* Private functions ---------------------------------------------------------*/
|
||||||
|
|
||||||
|
/* USER CODE BEGIN 1 */
|
||||||
|
/* USER CODE END 1 */
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
LL Driver Callbacks (PCD -> USB Device Library)
|
||||||
|
*******************************************************************************/
|
||||||
|
/* MSP Init */
|
||||||
|
|
||||||
|
void HAL_PCD_MspInit(PCD_HandleTypeDef* pcdHandle)
|
||||||
|
{
|
||||||
|
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||||
|
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
|
||||||
|
if(pcdHandle->Instance==USB_OTG_FS)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN USB_OTG_FS_MspInit 0 */
|
||||||
|
|
||||||
|
/* USER CODE END USB_OTG_FS_MspInit 0 */
|
||||||
|
|
||||||
|
/** Initializes the peripherals clock
|
||||||
|
*/
|
||||||
|
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_USB;
|
||||||
|
PeriphClkInitStruct.UsbClockSelection = RCC_USBCLKSOURCE_HSI48;
|
||||||
|
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Enable USB Voltage detector
|
||||||
|
*/
|
||||||
|
HAL_PWREx_EnableUSBVoltageDetector();
|
||||||
|
|
||||||
|
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||||
|
/**USB_OTG_FS GPIO Configuration
|
||||||
|
PA11 ------> USB_OTG_FS_DM
|
||||||
|
PA12 ------> USB_OTG_FS_DP
|
||||||
|
*/
|
||||||
|
GPIO_InitStruct.Pin = GPIO_PIN_11|GPIO_PIN_12;
|
||||||
|
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||||||
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||||
|
GPIO_InitStruct.Alternate = GPIO_AF10_OTG1_FS;
|
||||||
|
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||||
|
|
||||||
|
/* Peripheral clock enable */
|
||||||
|
__HAL_RCC_USB_OTG_FS_CLK_ENABLE();
|
||||||
|
|
||||||
|
/* Peripheral interrupt init */
|
||||||
|
HAL_NVIC_SetPriority(OTG_FS_IRQn, 5, 0);
|
||||||
|
HAL_NVIC_EnableIRQ(OTG_FS_IRQn);
|
||||||
|
/* USER CODE BEGIN USB_OTG_FS_MspInit 1 */
|
||||||
|
|
||||||
|
/* USER CODE END USB_OTG_FS_MspInit 1 */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void HAL_PCD_MspDeInit(PCD_HandleTypeDef* pcdHandle)
|
||||||
|
{
|
||||||
|
if(pcdHandle->Instance==USB_OTG_FS)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN USB_OTG_FS_MspDeInit 0 */
|
||||||
|
|
||||||
|
/* USER CODE END USB_OTG_FS_MspDeInit 0 */
|
||||||
|
/* Peripheral clock disable */
|
||||||
|
__HAL_RCC_USB_OTG_FS_CLK_DISABLE();
|
||||||
|
|
||||||
|
/**USB_OTG_FS GPIO Configuration
|
||||||
|
PA11 ------> USB_OTG_FS_DM
|
||||||
|
PA12 ------> USB_OTG_FS_DP
|
||||||
|
*/
|
||||||
|
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_11|GPIO_PIN_12);
|
||||||
|
|
||||||
|
/* Peripheral interrupt Deinit*/
|
||||||
|
HAL_NVIC_DisableIRQ(OTG_FS_IRQn);
|
||||||
|
|
||||||
|
/* USER CODE BEGIN USB_OTG_FS_MspDeInit 1 */
|
||||||
|
|
||||||
|
/* USER CODE END USB_OTG_FS_MspDeInit 1 */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Setup stage callback
|
||||||
|
* @param hpcd: PCD handle
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
|
||||||
|
static void PCD_SetupStageCallback(PCD_HandleTypeDef *hpcd)
|
||||||
|
#else
|
||||||
|
void HAL_PCD_SetupStageCallback(PCD_HandleTypeDef *hpcd)
|
||||||
|
#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
|
||||||
|
{
|
||||||
|
USBD_LL_SetupStage((USBD_HandleTypeDef*)hpcd->pData, (uint8_t *)hpcd->Setup);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Data Out stage callback.
|
||||||
|
* @param hpcd: PCD handle
|
||||||
|
* @param epnum: Endpoint number
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
|
||||||
|
static void PCD_DataOutStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum)
|
||||||
|
#else
|
||||||
|
void HAL_PCD_DataOutStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum)
|
||||||
|
#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
|
||||||
|
{
|
||||||
|
USBD_LL_DataOutStage((USBD_HandleTypeDef*)hpcd->pData, epnum, hpcd->OUT_ep[epnum].xfer_buff);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Data In stage callback.
|
||||||
|
* @param hpcd: PCD handle
|
||||||
|
* @param epnum: Endpoint number
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
|
||||||
|
static void PCD_DataInStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum)
|
||||||
|
#else
|
||||||
|
void HAL_PCD_DataInStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum)
|
||||||
|
#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
|
||||||
|
{
|
||||||
|
USBD_LL_DataInStage((USBD_HandleTypeDef*)hpcd->pData, epnum, hpcd->IN_ep[epnum].xfer_buff);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief SOF callback.
|
||||||
|
* @param hpcd: PCD handle
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
|
||||||
|
static void PCD_SOFCallback(PCD_HandleTypeDef *hpcd)
|
||||||
|
#else
|
||||||
|
void HAL_PCD_SOFCallback(PCD_HandleTypeDef *hpcd)
|
||||||
|
#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
|
||||||
|
{
|
||||||
|
USBD_LL_SOF((USBD_HandleTypeDef*)hpcd->pData);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Reset callback.
|
||||||
|
* @param hpcd: PCD handle
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
|
||||||
|
static void PCD_ResetCallback(PCD_HandleTypeDef *hpcd)
|
||||||
|
#else
|
||||||
|
void HAL_PCD_ResetCallback(PCD_HandleTypeDef *hpcd)
|
||||||
|
#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
|
||||||
|
{
|
||||||
|
USBD_SpeedTypeDef speed = USBD_SPEED_FULL;
|
||||||
|
|
||||||
|
if ( hpcd->Init.speed == PCD_SPEED_HIGH)
|
||||||
|
{
|
||||||
|
speed = USBD_SPEED_HIGH;
|
||||||
|
}
|
||||||
|
else if ( hpcd->Init.speed == PCD_SPEED_FULL)
|
||||||
|
{
|
||||||
|
speed = USBD_SPEED_FULL;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
/* Set Speed. */
|
||||||
|
USBD_LL_SetSpeed((USBD_HandleTypeDef*)hpcd->pData, speed);
|
||||||
|
|
||||||
|
/* Reset Device. */
|
||||||
|
USBD_LL_Reset((USBD_HandleTypeDef*)hpcd->pData);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Suspend callback.
|
||||||
|
* When Low power mode is enabled the debug cannot be used (IAR, Keil doesn't support it)
|
||||||
|
* @param hpcd: PCD handle
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
|
||||||
|
static void PCD_SuspendCallback(PCD_HandleTypeDef *hpcd)
|
||||||
|
#else
|
||||||
|
void HAL_PCD_SuspendCallback(PCD_HandleTypeDef *hpcd)
|
||||||
|
#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
|
||||||
|
{
|
||||||
|
/* Inform USB library that core enters in suspend Mode. */
|
||||||
|
USBD_LL_Suspend((USBD_HandleTypeDef*)hpcd->pData);
|
||||||
|
__HAL_PCD_GATE_PHYCLOCK(hpcd);
|
||||||
|
/* Enter in STOP mode. */
|
||||||
|
/* USER CODE BEGIN 2 */
|
||||||
|
if (hpcd->Init.low_power_enable)
|
||||||
|
{
|
||||||
|
/* Set SLEEPDEEP bit and SleepOnExit of Cortex System Control Register. */
|
||||||
|
SCB->SCR |= (uint32_t)((uint32_t)(SCB_SCR_SLEEPDEEP_Msk | SCB_SCR_SLEEPONEXIT_Msk));
|
||||||
|
}
|
||||||
|
/* USER CODE END 2 */
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Resume callback.
|
||||||
|
* When Low power mode is enabled the debug cannot be used (IAR, Keil doesn't support it)
|
||||||
|
* @param hpcd: PCD handle
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
|
||||||
|
static void PCD_ResumeCallback(PCD_HandleTypeDef *hpcd)
|
||||||
|
#else
|
||||||
|
void HAL_PCD_ResumeCallback(PCD_HandleTypeDef *hpcd)
|
||||||
|
#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN 3 */
|
||||||
|
|
||||||
|
/* USER CODE END 3 */
|
||||||
|
USBD_LL_Resume((USBD_HandleTypeDef*)hpcd->pData);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief ISOOUTIncomplete callback.
|
||||||
|
* @param hpcd: PCD handle
|
||||||
|
* @param epnum: Endpoint number
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
|
||||||
|
static void PCD_ISOOUTIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum)
|
||||||
|
#else
|
||||||
|
void HAL_PCD_ISOOUTIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum)
|
||||||
|
#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
|
||||||
|
{
|
||||||
|
USBD_LL_IsoOUTIncomplete((USBD_HandleTypeDef*)hpcd->pData, epnum);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief ISOINIncomplete callback.
|
||||||
|
* @param hpcd: PCD handle
|
||||||
|
* @param epnum: Endpoint number
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
|
||||||
|
static void PCD_ISOINIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum)
|
||||||
|
#else
|
||||||
|
void HAL_PCD_ISOINIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum)
|
||||||
|
#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
|
||||||
|
{
|
||||||
|
USBD_LL_IsoINIncomplete((USBD_HandleTypeDef*)hpcd->pData, epnum);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Connect callback.
|
||||||
|
* @param hpcd: PCD handle
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
|
||||||
|
static void PCD_ConnectCallback(PCD_HandleTypeDef *hpcd)
|
||||||
|
#else
|
||||||
|
void HAL_PCD_ConnectCallback(PCD_HandleTypeDef *hpcd)
|
||||||
|
#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
|
||||||
|
{
|
||||||
|
USBD_LL_DevConnected((USBD_HandleTypeDef*)hpcd->pData);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Disconnect callback.
|
||||||
|
* @param hpcd: PCD handle
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
|
||||||
|
static void PCD_DisconnectCallback(PCD_HandleTypeDef *hpcd)
|
||||||
|
#else
|
||||||
|
void HAL_PCD_DisconnectCallback(PCD_HandleTypeDef *hpcd)
|
||||||
|
#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
|
||||||
|
{
|
||||||
|
USBD_LL_DevDisconnected((USBD_HandleTypeDef*)hpcd->pData);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
LL Driver Interface (USB Device Library --> PCD)
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Initializes the low level portion of the device driver.
|
||||||
|
* @param pdev: Device handle
|
||||||
|
* @retval USBD status
|
||||||
|
*/
|
||||||
|
USBD_StatusTypeDef USBD_LL_Init(USBD_HandleTypeDef *pdev)
|
||||||
|
{
|
||||||
|
/* Init USB Ip. */
|
||||||
|
if (pdev->id == DEVICE_FS) {
|
||||||
|
/* Link the driver to the stack. */
|
||||||
|
hpcd_USB_OTG_FS.pData = pdev;
|
||||||
|
pdev->pData = &hpcd_USB_OTG_FS;
|
||||||
|
|
||||||
|
hpcd_USB_OTG_FS.Instance = USB_OTG_FS;
|
||||||
|
hpcd_USB_OTG_FS.Init.dev_endpoints = 9;
|
||||||
|
hpcd_USB_OTG_FS.Init.speed = PCD_SPEED_FULL;
|
||||||
|
hpcd_USB_OTG_FS.Init.dma_enable = DISABLE;
|
||||||
|
hpcd_USB_OTG_FS.Init.phy_itface = PCD_PHY_EMBEDDED;
|
||||||
|
hpcd_USB_OTG_FS.Init.Sof_enable = DISABLE;
|
||||||
|
hpcd_USB_OTG_FS.Init.low_power_enable = DISABLE;
|
||||||
|
hpcd_USB_OTG_FS.Init.lpm_enable = DISABLE;
|
||||||
|
hpcd_USB_OTG_FS.Init.battery_charging_enable = DISABLE;
|
||||||
|
hpcd_USB_OTG_FS.Init.vbus_sensing_enable = DISABLE;
|
||||||
|
hpcd_USB_OTG_FS.Init.use_dedicated_ep1 = DISABLE;
|
||||||
|
if (HAL_PCD_Init(&hpcd_USB_OTG_FS) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler( );
|
||||||
|
}
|
||||||
|
|
||||||
|
#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
|
||||||
|
/* Register USB PCD CallBacks */
|
||||||
|
HAL_PCD_RegisterCallback(&hpcd_USB_OTG_FS, HAL_PCD_SOF_CB_ID, PCD_SOFCallback);
|
||||||
|
HAL_PCD_RegisterCallback(&hpcd_USB_OTG_FS, HAL_PCD_SETUPSTAGE_CB_ID, PCD_SetupStageCallback);
|
||||||
|
HAL_PCD_RegisterCallback(&hpcd_USB_OTG_FS, HAL_PCD_RESET_CB_ID, PCD_ResetCallback);
|
||||||
|
HAL_PCD_RegisterCallback(&hpcd_USB_OTG_FS, HAL_PCD_SUSPEND_CB_ID, PCD_SuspendCallback);
|
||||||
|
HAL_PCD_RegisterCallback(&hpcd_USB_OTG_FS, HAL_PCD_RESUME_CB_ID, PCD_ResumeCallback);
|
||||||
|
HAL_PCD_RegisterCallback(&hpcd_USB_OTG_FS, HAL_PCD_CONNECT_CB_ID, PCD_ConnectCallback);
|
||||||
|
HAL_PCD_RegisterCallback(&hpcd_USB_OTG_FS, HAL_PCD_DISCONNECT_CB_ID, PCD_DisconnectCallback);
|
||||||
|
|
||||||
|
HAL_PCD_RegisterDataOutStageCallback(&hpcd_USB_OTG_FS, PCD_DataOutStageCallback);
|
||||||
|
HAL_PCD_RegisterDataInStageCallback(&hpcd_USB_OTG_FS, PCD_DataInStageCallback);
|
||||||
|
HAL_PCD_RegisterIsoOutIncpltCallback(&hpcd_USB_OTG_FS, PCD_ISOOUTIncompleteCallback);
|
||||||
|
HAL_PCD_RegisterIsoInIncpltCallback(&hpcd_USB_OTG_FS, PCD_ISOINIncompleteCallback);
|
||||||
|
#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
|
||||||
|
/* USER CODE BEGIN TxRx_Configuration */
|
||||||
|
HAL_PCDEx_SetRxFiFo(&hpcd_USB_OTG_FS, 0x80);
|
||||||
|
HAL_PCDEx_SetTxFiFo(&hpcd_USB_OTG_FS, 0, 0x40);
|
||||||
|
HAL_PCDEx_SetTxFiFo(&hpcd_USB_OTG_FS, 1, 0x80);
|
||||||
|
/* USER CODE END TxRx_Configuration */
|
||||||
|
}
|
||||||
|
return USBD_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief De-Initializes the low level portion of the device driver.
|
||||||
|
* @param pdev: Device handle
|
||||||
|
* @retval USBD status
|
||||||
|
*/
|
||||||
|
USBD_StatusTypeDef USBD_LL_DeInit(USBD_HandleTypeDef *pdev)
|
||||||
|
{
|
||||||
|
HAL_StatusTypeDef hal_status = HAL_OK;
|
||||||
|
USBD_StatusTypeDef usb_status = USBD_OK;
|
||||||
|
|
||||||
|
hal_status = HAL_PCD_DeInit(pdev->pData);
|
||||||
|
|
||||||
|
usb_status = USBD_Get_USB_Status(hal_status);
|
||||||
|
|
||||||
|
return usb_status;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Starts the low level portion of the device driver.
|
||||||
|
* @param pdev: Device handle
|
||||||
|
* @retval USBD status
|
||||||
|
*/
|
||||||
|
USBD_StatusTypeDef USBD_LL_Start(USBD_HandleTypeDef *pdev)
|
||||||
|
{
|
||||||
|
HAL_StatusTypeDef hal_status = HAL_OK;
|
||||||
|
USBD_StatusTypeDef usb_status = USBD_OK;
|
||||||
|
|
||||||
|
hal_status = HAL_PCD_Start(pdev->pData);
|
||||||
|
|
||||||
|
usb_status = USBD_Get_USB_Status(hal_status);
|
||||||
|
|
||||||
|
return usb_status;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Stops the low level portion of the device driver.
|
||||||
|
* @param pdev: Device handle
|
||||||
|
* @retval USBD status
|
||||||
|
*/
|
||||||
|
USBD_StatusTypeDef USBD_LL_Stop(USBD_HandleTypeDef *pdev)
|
||||||
|
{
|
||||||
|
HAL_StatusTypeDef hal_status = HAL_OK;
|
||||||
|
USBD_StatusTypeDef usb_status = USBD_OK;
|
||||||
|
|
||||||
|
hal_status = HAL_PCD_Stop(pdev->pData);
|
||||||
|
|
||||||
|
usb_status = USBD_Get_USB_Status(hal_status);
|
||||||
|
|
||||||
|
return usb_status;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Opens an endpoint of the low level driver.
|
||||||
|
* @param pdev: Device handle
|
||||||
|
* @param ep_addr: Endpoint number
|
||||||
|
* @param ep_type: Endpoint type
|
||||||
|
* @param ep_mps: Endpoint max packet size
|
||||||
|
* @retval USBD status
|
||||||
|
*/
|
||||||
|
USBD_StatusTypeDef USBD_LL_OpenEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr, uint8_t ep_type, uint16_t ep_mps)
|
||||||
|
{
|
||||||
|
HAL_StatusTypeDef hal_status = HAL_OK;
|
||||||
|
USBD_StatusTypeDef usb_status = USBD_OK;
|
||||||
|
|
||||||
|
hal_status = HAL_PCD_EP_Open(pdev->pData, ep_addr, ep_mps, ep_type);
|
||||||
|
|
||||||
|
usb_status = USBD_Get_USB_Status(hal_status);
|
||||||
|
|
||||||
|
return usb_status;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Closes an endpoint of the low level driver.
|
||||||
|
* @param pdev: Device handle
|
||||||
|
* @param ep_addr: Endpoint number
|
||||||
|
* @retval USBD status
|
||||||
|
*/
|
||||||
|
USBD_StatusTypeDef USBD_LL_CloseEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
|
||||||
|
{
|
||||||
|
HAL_StatusTypeDef hal_status = HAL_OK;
|
||||||
|
USBD_StatusTypeDef usb_status = USBD_OK;
|
||||||
|
|
||||||
|
hal_status = HAL_PCD_EP_Close(pdev->pData, ep_addr);
|
||||||
|
|
||||||
|
usb_status = USBD_Get_USB_Status(hal_status);
|
||||||
|
|
||||||
|
return usb_status;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Flushes an endpoint of the Low Level Driver.
|
||||||
|
* @param pdev: Device handle
|
||||||
|
* @param ep_addr: Endpoint number
|
||||||
|
* @retval USBD status
|
||||||
|
*/
|
||||||
|
USBD_StatusTypeDef USBD_LL_FlushEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
|
||||||
|
{
|
||||||
|
HAL_StatusTypeDef hal_status = HAL_OK;
|
||||||
|
USBD_StatusTypeDef usb_status = USBD_OK;
|
||||||
|
|
||||||
|
hal_status = HAL_PCD_EP_Flush(pdev->pData, ep_addr);
|
||||||
|
|
||||||
|
usb_status = USBD_Get_USB_Status(hal_status);
|
||||||
|
|
||||||
|
return usb_status;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Sets a Stall condition on an endpoint of the Low Level Driver.
|
||||||
|
* @param pdev: Device handle
|
||||||
|
* @param ep_addr: Endpoint number
|
||||||
|
* @retval USBD status
|
||||||
|
*/
|
||||||
|
USBD_StatusTypeDef USBD_LL_StallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
|
||||||
|
{
|
||||||
|
HAL_StatusTypeDef hal_status = HAL_OK;
|
||||||
|
USBD_StatusTypeDef usb_status = USBD_OK;
|
||||||
|
|
||||||
|
hal_status = HAL_PCD_EP_SetStall(pdev->pData, ep_addr);
|
||||||
|
|
||||||
|
usb_status = USBD_Get_USB_Status(hal_status);
|
||||||
|
|
||||||
|
return usb_status;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Clears a Stall condition on an endpoint of the Low Level Driver.
|
||||||
|
* @param pdev: Device handle
|
||||||
|
* @param ep_addr: Endpoint number
|
||||||
|
* @retval USBD status
|
||||||
|
*/
|
||||||
|
USBD_StatusTypeDef USBD_LL_ClearStallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
|
||||||
|
{
|
||||||
|
HAL_StatusTypeDef hal_status = HAL_OK;
|
||||||
|
USBD_StatusTypeDef usb_status = USBD_OK;
|
||||||
|
|
||||||
|
hal_status = HAL_PCD_EP_ClrStall(pdev->pData, ep_addr);
|
||||||
|
|
||||||
|
usb_status = USBD_Get_USB_Status(hal_status);
|
||||||
|
|
||||||
|
return usb_status;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns Stall condition.
|
||||||
|
* @param pdev: Device handle
|
||||||
|
* @param ep_addr: Endpoint number
|
||||||
|
* @retval Stall (1: Yes, 0: No)
|
||||||
|
*/
|
||||||
|
uint8_t USBD_LL_IsStallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
|
||||||
|
{
|
||||||
|
PCD_HandleTypeDef *hpcd = (PCD_HandleTypeDef*) pdev->pData;
|
||||||
|
|
||||||
|
if((ep_addr & 0x80) == 0x80)
|
||||||
|
{
|
||||||
|
return hpcd->IN_ep[ep_addr & 0x7F].is_stall;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return hpcd->OUT_ep[ep_addr & 0x7F].is_stall;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Assigns a USB address to the device.
|
||||||
|
* @param pdev: Device handle
|
||||||
|
* @param dev_addr: Device address
|
||||||
|
* @retval USBD status
|
||||||
|
*/
|
||||||
|
USBD_StatusTypeDef USBD_LL_SetUSBAddress(USBD_HandleTypeDef *pdev, uint8_t dev_addr)
|
||||||
|
{
|
||||||
|
HAL_StatusTypeDef hal_status = HAL_OK;
|
||||||
|
USBD_StatusTypeDef usb_status = USBD_OK;
|
||||||
|
|
||||||
|
hal_status = HAL_PCD_SetAddress(pdev->pData, dev_addr);
|
||||||
|
|
||||||
|
usb_status = USBD_Get_USB_Status(hal_status);
|
||||||
|
|
||||||
|
return usb_status;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Transmits data over an endpoint.
|
||||||
|
* @param pdev: Device handle
|
||||||
|
* @param ep_addr: Endpoint number
|
||||||
|
* @param pbuf: Pointer to data to be sent
|
||||||
|
* @param size: Data size
|
||||||
|
* @retval USBD status
|
||||||
|
*/
|
||||||
|
USBD_StatusTypeDef USBD_LL_Transmit(USBD_HandleTypeDef *pdev, uint8_t ep_addr, uint8_t *pbuf, uint32_t size)
|
||||||
|
{
|
||||||
|
HAL_StatusTypeDef hal_status = HAL_OK;
|
||||||
|
USBD_StatusTypeDef usb_status = USBD_OK;
|
||||||
|
|
||||||
|
hal_status = HAL_PCD_EP_Transmit(pdev->pData, ep_addr, pbuf, size);
|
||||||
|
|
||||||
|
usb_status = USBD_Get_USB_Status(hal_status);
|
||||||
|
|
||||||
|
return usb_status;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Prepares an endpoint for reception.
|
||||||
|
* @param pdev: Device handle
|
||||||
|
* @param ep_addr: Endpoint number
|
||||||
|
* @param pbuf: Pointer to data to be received
|
||||||
|
* @param size: Data size
|
||||||
|
* @retval USBD status
|
||||||
|
*/
|
||||||
|
USBD_StatusTypeDef USBD_LL_PrepareReceive(USBD_HandleTypeDef *pdev, uint8_t ep_addr, uint8_t *pbuf, uint32_t size)
|
||||||
|
{
|
||||||
|
HAL_StatusTypeDef hal_status = HAL_OK;
|
||||||
|
USBD_StatusTypeDef usb_status = USBD_OK;
|
||||||
|
|
||||||
|
hal_status = HAL_PCD_EP_Receive(pdev->pData, ep_addr, pbuf, size);
|
||||||
|
|
||||||
|
usb_status = USBD_Get_USB_Status(hal_status);
|
||||||
|
|
||||||
|
return usb_status;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns the last transferred packet size.
|
||||||
|
* @param pdev: Device handle
|
||||||
|
* @param ep_addr: Endpoint number
|
||||||
|
* @retval Received Data Size
|
||||||
|
*/
|
||||||
|
uint32_t USBD_LL_GetRxDataSize(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
|
||||||
|
{
|
||||||
|
return HAL_PCD_EP_GetRxCount((PCD_HandleTypeDef*) pdev->pData, ep_addr);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef USBD_HS_TESTMODE_ENABLE
|
||||||
|
/**
|
||||||
|
* @brief Set High speed Test mode.
|
||||||
|
* @param pdev: Device handle
|
||||||
|
* @param testmode: test mode
|
||||||
|
* @retval USBD Status
|
||||||
|
*/
|
||||||
|
USBD_StatusTypeDef USBD_LL_SetTestMode(USBD_HandleTypeDef *pdev, uint8_t testmode)
|
||||||
|
{
|
||||||
|
UNUSED(pdev);
|
||||||
|
UNUSED(testmode);
|
||||||
|
|
||||||
|
return USBD_OK;
|
||||||
|
}
|
||||||
|
#endif /* USBD_HS_TESTMODE_ENABLE */
|
||||||
|
/**
|
||||||
|
* @brief Static single allocation.
|
||||||
|
* @param size: Size of allocated memory
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void *USBD_static_malloc(uint32_t size)
|
||||||
|
{
|
||||||
|
UNUSED(size);
|
||||||
|
static uint32_t mem[(sizeof(USBD_CDC_HandleTypeDef)/4)+1];/* On 32-bit boundary */
|
||||||
|
return mem;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Dummy memory free
|
||||||
|
* @param p: Pointer to allocated memory address
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void USBD_static_free(void *p)
|
||||||
|
{
|
||||||
|
UNUSED(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Delays routine for the USB device library.
|
||||||
|
* @param Delay: Delay in ms
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void USBD_LL_Delay(uint32_t Delay)
|
||||||
|
{
|
||||||
|
HAL_Delay(Delay);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns the USB status depending on the HAL status:
|
||||||
|
* @param hal_status: HAL status
|
||||||
|
* @retval USB status
|
||||||
|
*/
|
||||||
|
USBD_StatusTypeDef USBD_Get_USB_Status(HAL_StatusTypeDef hal_status)
|
||||||
|
{
|
||||||
|
USBD_StatusTypeDef usb_status = USBD_OK;
|
||||||
|
|
||||||
|
switch (hal_status)
|
||||||
|
{
|
||||||
|
case HAL_OK :
|
||||||
|
usb_status = USBD_OK;
|
||||||
|
break;
|
||||||
|
case HAL_ERROR :
|
||||||
|
usb_status = USBD_FAIL;
|
||||||
|
break;
|
||||||
|
case HAL_BUSY :
|
||||||
|
usb_status = USBD_BUSY;
|
||||||
|
break;
|
||||||
|
case HAL_TIMEOUT :
|
||||||
|
usb_status = USBD_FAIL;
|
||||||
|
break;
|
||||||
|
default :
|
||||||
|
usb_status = USBD_FAIL;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return usb_status;
|
||||||
|
}
|
||||||
173
Core/USB_DEVICE/Target/usbd_conf.h
Normal file
173
Core/USB_DEVICE/Target/usbd_conf.h
Normal file
@@ -0,0 +1,173 @@
|
|||||||
|
/* USER CODE BEGIN Header */
|
||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
* @file : usbd_conf.h
|
||||||
|
* @version : v1.0_Cube
|
||||||
|
* @brief : Header for usbd_conf.c file.
|
||||||
|
******************************************************************************
|
||||||
|
* @attention
|
||||||
|
*
|
||||||
|
* Copyright (c) 2026 STMicroelectronics.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This software is licensed under terms that can be found in the LICENSE file
|
||||||
|
* in the root directory of this software component.
|
||||||
|
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||||
|
*
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
/* USER CODE END Header */
|
||||||
|
|
||||||
|
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||||
|
#ifndef __USBD_CONF__H__
|
||||||
|
#define __USBD_CONF__H__
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Includes ------------------------------------------------------------------*/
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include "main.h"
|
||||||
|
#include "stm32h7xx.h"
|
||||||
|
#include "stm32h7xx_hal.h"
|
||||||
|
|
||||||
|
/* USER CODE BEGIN INCLUDE */
|
||||||
|
|
||||||
|
/* USER CODE END INCLUDE */
|
||||||
|
|
||||||
|
/** @addtogroup USBD_OTG_DRIVER
|
||||||
|
* @brief Driver for Usb device.
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_CONF USBD_CONF
|
||||||
|
* @brief Configuration file for Usb otg low level driver.
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_CONF_Exported_Variables USBD_CONF_Exported_Variables
|
||||||
|
* @brief Public variables.
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_CONF_Exported_Defines USBD_CONF_Exported_Defines
|
||||||
|
* @brief Defines for configuration of the Usb device.
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*---------- -----------*/
|
||||||
|
#define USBD_MAX_NUM_INTERFACES 1U
|
||||||
|
/*---------- -----------*/
|
||||||
|
#define USBD_MAX_NUM_CONFIGURATION 1U
|
||||||
|
/*---------- -----------*/
|
||||||
|
#define USBD_MAX_STR_DESC_SIZ 512U
|
||||||
|
/*---------- -----------*/
|
||||||
|
#define USBD_DEBUG_LEVEL 0U
|
||||||
|
/*---------- -----------*/
|
||||||
|
#define USBD_LPM_ENABLED 1U
|
||||||
|
/*---------- -----------*/
|
||||||
|
#define USBD_SELF_POWERED 1U
|
||||||
|
|
||||||
|
/****************************************/
|
||||||
|
/* #define for FS and HS identification */
|
||||||
|
#define DEVICE_FS 0
|
||||||
|
#define DEVICE_HS 1
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_CONF_Exported_Macros USBD_CONF_Exported_Macros
|
||||||
|
* @brief Aliases.
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
/* Memory management macros make sure to use static memory allocation */
|
||||||
|
/** Alias for memory allocation. */
|
||||||
|
|
||||||
|
#define USBD_malloc (void *)USBD_static_malloc
|
||||||
|
|
||||||
|
/** Alias for memory release. */
|
||||||
|
#define USBD_free USBD_static_free
|
||||||
|
|
||||||
|
/** Alias for memory set. */
|
||||||
|
#define USBD_memset memset
|
||||||
|
|
||||||
|
/** Alias for memory copy. */
|
||||||
|
#define USBD_memcpy memcpy
|
||||||
|
|
||||||
|
/** Alias for delay. */
|
||||||
|
#define USBD_Delay HAL_Delay
|
||||||
|
|
||||||
|
/* DEBUG macros */
|
||||||
|
|
||||||
|
#if (USBD_DEBUG_LEVEL > 0)
|
||||||
|
#define USBD_UsrLog(...) printf(__VA_ARGS__);\
|
||||||
|
printf("\n");
|
||||||
|
#else
|
||||||
|
#define USBD_UsrLog(...)
|
||||||
|
#endif /* (USBD_DEBUG_LEVEL > 0U) */
|
||||||
|
|
||||||
|
#if (USBD_DEBUG_LEVEL > 1)
|
||||||
|
|
||||||
|
#define USBD_ErrLog(...) printf("ERROR: ");\
|
||||||
|
printf(__VA_ARGS__);\
|
||||||
|
printf("\n");
|
||||||
|
#else
|
||||||
|
#define USBD_ErrLog(...)
|
||||||
|
#endif /* (USBD_DEBUG_LEVEL > 1U) */
|
||||||
|
|
||||||
|
#if (USBD_DEBUG_LEVEL > 2)
|
||||||
|
#define USBD_DbgLog(...) printf("DEBUG : ");\
|
||||||
|
printf(__VA_ARGS__);\
|
||||||
|
printf("\n");
|
||||||
|
#else
|
||||||
|
#define USBD_DbgLog(...)
|
||||||
|
#endif /* (USBD_DEBUG_LEVEL > 2U) */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_CONF_Exported_Types USBD_CONF_Exported_Types
|
||||||
|
* @brief Types.
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_CONF_Exported_FunctionsPrototype USBD_CONF_Exported_FunctionsPrototype
|
||||||
|
* @brief Declaration of public functions for Usb device.
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Exported functions -------------------------------------------------------*/
|
||||||
|
void *USBD_static_malloc(uint32_t size);
|
||||||
|
void USBD_static_free(void *p);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* __USBD_CONF__H__ */
|
||||||
|
|
||||||
@@ -92,5 +92,6 @@ void HeartBeat_Sign(void)
|
|||||||
});
|
});
|
||||||
RUN_EVERY(500, tick_E, {
|
RUN_EVERY(500, tick_E, {
|
||||||
Send_Display_Data();
|
Send_Display_Data();
|
||||||
|
CDC_Transmit_FS((uint8_t*)"123", 3);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user