全能電路設計實戰

2016年1月16日 星期六

什麼是Bare Metal 開發 ?


Bare Metal or Bare Machine 開發指的是在沒有OS作業系統的環境下來開發程式, 在這種環境下所開發出來的產物, 像是BIOS程式, Boot Loader 這類的程式。

藉由Bare Metal 開發, 我們可以學些什麼? 
  1. ARM 的CPU架構及組合語言
  2. ARM例外處理機制
  3. 從何處位址開機 ?  CPU initialize & DRAM controller initialize 
  4. How to Execute Code ? 如何撰寫Linker Script 
  5. SoC 與ARM 的關聯性, 
  6. 在沒有OS情況下要如何撰寫程式, 包含Application或 Chip Driver

相關文章:


 arm bootloader





2016年1月14日 星期四

USB韌體設計ScreenShot




如果您設計的MCU Device其應用必須是和PC連接,您可以用的界面只剩下USB




USB HID 界面實作

USB Device Descriptor- Endproint

2016年1月9日 星期六

CMSIS-RTOS API



CMSIS-RTOS它是一種作業系統軟體設計架構,  藉由CMSIS RTOS的架構可以用來隠藏底層不同作業系統的差異性。上層應用程式要想利用到OS提供的功能時, CMSIS RTOS 提供一個標準的API供上層來呼叫使用,這個API就如同Linux System call概念一樣。(The CMSIS-RTOS API is a generic RTOS interface for ARM® Cortex®-M processor-based devices)

CMSIS-RTOS 的API界面提作為底層 Real Time kernel (RTOS)與上層應用程式的一個標準介面,並使用一套標準的API, 如此可以讓上層程式不用管底層RTOS的差異, 如此程式碼可以跑在不用RTOS上, 也縮短學習新的RTOS的曲線。

不同RTOS都各自實現自己關於多工處理,例如排程、記憶體管理等功能,但希望有中介層界面存在,使用RTOS API 不必再管底層RTOS是那一套,所有函式呼叫都相同。而CMSIS-RTOS 正是一種基於 ARM® Cortex®-M processor-based 的RTOS中介層界面。


API_Structure.png



啓用MDK SEMIHOST的功能



啓用MDK 的SEMIHOST功能, 以進行Debug, 如此使用C標準I/O函式庫的 printf, 就可以在console (UART) 輸出, 方便程式開發與Debug。待功能確認OK後, 再拿掉printf , 因為printf會delay 程式的, 影響到timing的控制。

1.) 於MDK專案中新增 retarget.c

..\..\..\..\Library\StdDriver\src\retarget.c



2) 在選單中, Flash-> "Configure Flash Tools...", 出現底下畫面後,在C/C++頁籤中的Proprocess Symbols 定義 DEBUG_ENABLE_SEMIHOST



3) 程式編譯後, 選擇Debug->Start/Stop debug session來執行程式 。並於工具選單選擇UART#1 輸出


4) 右下角就會看到printf 輸出









2016年1月8日 星期五

VBA Email via Gmail CDO Method - Microsoft Access Programmers

Sub SendMailFromGmail() Dim iMsg As Object Dim iConf As Object Dim Flds As Variant Set iMsg = CreateObject("CDO.Message") Set iConf = CreateObject("CDO.Configuration") iConf.Load -1 Set Flds = iConf.Fields With Flds .Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True .Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 .Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "test@gmail.com" .Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "test132" .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com" 'smtp mail server .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 'stmp server .Update End With With iMsg Set .Configuration = iConf .To = "test@gmail.com" .From = "test@gmail.com" .Subject = "Hello" & Time .TextBody = "Hi Dude" .Send End With Set iMsg = Nothing Set iConf = Nothing End Sub

Access DLookup,DCount 函式


Access DLookup 函式


用途: 
 一個快速的函式, 可以在一個表格中比對某一欄位是否為某值, 若找到後傳回該列的某一欄位值。

DLookup("field","table",Criteria')



Dim varX As Variant
varX = DLookup("[CompanyName]","Shippers", "[ShipperID] = 1")

---------------------------------
  Private Sub combo_string2id()
   
   job_name = Me.JOBTYPE1.Value
   Me.JOBTYPE1.Value = DLookup("jobtype_id", "index_jobtype", "jobtype_name='" & job_name & "'")
  
  End Sub
  
  '-----------------------
    Private Sub combo_id2string()

      
   job_id = Me.JOBTYPE1.Value
   Me.JOBTYPE1.Value = DLookup("jobtype_name", "index_jobtype", "jobtype_id='" & job_id & "'")
  
  End Sub

------------

也可以用底下程式來實現DLookup,其中ComboBox.Column(1, i) 表示為第i列第1欄的值 (欄是從0開始算)
Dim i As Integer

For i = 0 To ComboBox.ListCount-1
    If ComboBox.Column(1, i) = "ittraining" Then   
        ComboBox.Value = ComboBox.ItemData(i)
        Exit For
    End If
Next i


Access DCount 函式

用途: 
 一個快速的函式, 可以在一個表格中,根據Criteria的設定, 在table中計數的field的數量。

Dcount("field","table",Criteria')

利用Dcount的函式, 在查詢的結果, 增加一欄位作為序號。


中間那個"table"可以是別的查詢的結果, 另外要產生序號,如底下方式, 必須要找出這個"field"在
"table"中本身是沒有重覆的。

RowNum: DCount("[產品編號]","[產品資料]","[產品編號]<=" & [產品編號])






Access VBA : Changing Subform RecordSource Programmatically


Changing Subform RecordSource Programmatically



Private Sub Command37_Click()

  Dim strFilter As String
   strFilter = ""
  child_qry10.Form.RecordSource = "客戶查詢"   '  Saved Query Object  or SQL string

    ' 加入篩選條件 strFilter 
 child_qry10.Form.Filter = strFilter
 child_qry10.Form.FilterOn = True
 child_qry10.Form.Requery
End Sub


---------------------------------------------------
' 篩選特定欄位的值 (字串或數值)
strFilter = "TEACHER = """ & "T001" & """"

' 篩選以今天到今天以後30天範圍
strFilter = strFilter & "StartDate between #" & Date & "# And #" & Date + 30 & "#"


'   篩選特定日期範圍
 strFilter = strFilter & "StartDate between #" & "2015/5/1" & "# And #" & "2015/5/31" & "#"

[Access VBA] Send Email from Access VBA

Private Sub Command0_Click()


Dim olApp As Object
Dim objMail As Object

On Error Resume Next 'Keep going if there is an error


Set olApp = GetObject(, "Outlook.Application") 'See if Outlook is open


If Err Then 'Outlook is not open
Set olApp = CreateObject("Outlook.Application") 'Create a new instance of Outlook
End If

'Create e-mail item
Set objMail = olApp.CreateItem(olMailItem)


With objMail

'Set body format to HTML
.BodyFormat = olFormatHTML

.To = "your email; your second email"
.Subject = "Subject"
.HTMLBody = "<HTML><H2>The body of this message will appear in HTML.</H2><BODY>Type the message text here. </BODY></HTML>"
'.Send     ' 直接寄出
.Display  ' 顯示outlook

End With


參考資料: http://msdn.microsoft.com/en-us/library/office/ff861332.aspx

[Access VBA] 如何滙出資料到Excel


Q1: 
 in  VBA code , 

  Dim appExcel As Excel.Application

 why ?? 在執行的時候會出現 "使用者自訂型態尚未定義"

Answer: 

    在工具->設定引用項目  ,選擇 Microsoft Excel 12.0 Object Library