筆者最近取得一個有趣的套件,是國內(nèi)開發(fā)者不陌生的STM32系列之一的IoT開發(fā)工具包- STM32F746G-DISCOVERY(DISCO-F746NG)探索套件。它的功能相當完整,其運算核心是基于 Arm Cortex-M7 的 STM32F746NG微控制器,具備強大的運算能力。它同時整合了4.3吋的彩色電容式觸控屏幕、USB OTG、Audio Codec、Micro SD 插槽、雙數(shù)字麥克風(fēng),也內(nèi)建以太網(wǎng)絡(luò)10/100Mb來延伸網(wǎng)絡(luò)應(yīng)用,從而簡化應(yīng)用程序的開發(fā),能快速驗證產(chǎn)品與想法。
繼承STM32的優(yōu)良傳統(tǒng),此套件也支持易于開發(fā)的Arduino IDE環(huán)境,讓原本使用Arduino的Maker可以快速上手,更可以直接使用兼容于Arduino開源函式庫,共享相關(guān)社群的開發(fā)資源。不僅如此,這個套件提供兼容于ARDUINO Uno V3的擴充插槽,讓擴展能力大幅提升。
本開發(fā)板引出的GPIO如下圖:
Arduino 開發(fā)環(huán)境安裝
看到這樣強大的功能與完善的支持接口,你是不是和筆者一樣躍躍欲試了呢?別急,先把Arduino開發(fā)環(huán)境安裝起來吧。
(1) 請先下載Arduino IDE開發(fā)環(huán)境
https://www.arduino.cc/en/software
(2) 為Arduino IDE安裝STM32的支持,從Github下載最新的版本,解壓縮至
C:Program Files (x86)Arduinohardware
https://github.com/fw-box/STM32GENERIC
(注:這個路徑依照你的Arduino安裝路徑可能略有不同)
(3) 安裝編譯程序arm-none-eabi-gcc,從開發(fā)板管理員搜尋并安裝Arduino SAMD Boards (32-bits Arm Cortex-M0+) 版本1.8.11
(4) 編譯STM32GENERIC時會有錯誤,請使用patch檔覆寫arm-none-eabi-gcc里的原始碼,共有4個檔會被覆寫。
Patch文件下載路徑:
https://github.com/fw-box/arm-none-eabi
解壓縮并覆寫到
C:UsersmynameAppDataLocalArduino15packagesarduino oolsarm-none-eabi-gcc7-2017q4arm-none-eabi
(注:myname要改成你的使用者名稱)
(5) 下載下列4個必需的函式庫并解壓縮至
C:UsersmynameDocumentsArduinolibraries
(注:myname要改成你的使用者名稱)
https://github.com/adafruit/Adafruit-GFX-Library
https://github.com/fw-box/Adafruit_BusIO
https://github.com/stm32duino/LwIP
https://github.com/fw-box/STM32Ethernet
下載方法如下圖,下載下來會是一個壓縮文件。解壓縮一個新的函式庫至libraries后,需要重新啟動Arduino IDE來掃描加載新的函式庫。
下載并安裝開發(fā)板的驅(qū)動程序
請到ST官網(wǎng)介紹此套件的「工具與軟件」區(qū),找到ST-LINK驅(qū)動程序,
https://www.st.com/zh/evaluation-tools/32f746gdiscovery.html?fbclid=IwAR2Kjh0Qf59IpkKOTpz7iNKo6AX13nPNFPWxFGhgnGSilr07reN2-XJTyZU#tools-software
按下下圖紅框內(nèi)的連結(jié)后會跳出注冊畫面,注冊后www.st.com會發(fā)送下載的網(wǎng)址到注冊信箱。下載后解壓縮,并以系統(tǒng)管理員身份執(zhí)行stlink_winusb_install.bat安裝驅(qū)動程序。
編譯刻錄設(shè)定
選擇開發(fā)板Discovery F746NG;Upload method改成Mass Storage:
開始上傳(刻錄)前,請用mini USB線連接PC與開發(fā)板的USB ST-LINK。然后把串行端口改成新出現(xiàn)的COM port,上圖的范例是COM20。
程序范例
安裝好了,我們來執(zhí)行幾個程序范例吧。
1. 數(shù)位GPIO read, write
這功能與一般Arduino模式一樣,按鈕USER_BTN是背面的藍色按鈕,可供用戶自定義功能。
LED_BUILTIN在黑色按鈕旁邊,范例程序運作后會開始閃爍,按下藍色按鈕后閃爍速度會變快。
1. void setup()
2. {
3. pinMode(USER_BTN, INPUT);
4. pinMode(LED_BUILTIN, OUTPUT);
5. }
6.
7. void loop()
8. {
9. digitalWrite( LED_BUILTIN , HIGH ); // led on
10.
11. if ( digitalRead( USER_BTN ) )
12. delay(10); // blink faster if button is pressed
13. else
14. delay(100);
15.
16. digitalWrite( LED_BUILTIN, LOW ); // led off
17. delay(100);
18. }
程序代碼來源 : UserButton.ino
https://github.com/danieleff/STM32GENERIC/blob/master/STM32/libraries/BoardExamples/examples/Discovery746NG/UserButton/UserButton.ino
2. ADC讀取
此套件ADC的分辨率最高為12 bits,數(shù)值范圍是0 ~ 4096。為保持與Arduino UNO的兼容性,A0 ~ A5皆有被定義,可以直接使用。程序代碼中P開頭的GPIO名是為本開發(fā)板所定義,A0可以用PA0取代、A1可以用PF10取代,其它GPIO對應(yīng)如程序代碼所示。此范例會不斷地把A0讀到的數(shù)值寫到串行端口,請開啟串行端口監(jiān)控窗口查看結(jié)果。
// thesetup routine runs once when you press reset:
2. void setup() {
3. // initialize serial communication at115200 bits per second:
4. Serial.begin(115200);
5. delay(1000);
6.
7. // configure the ADC for 12 Bits
8. analogReadResolution(12);
9.
10. Serial.println();
11. Serial.printf("PA0:%d, A0:%d ",PA0, A0);
12. Serial.printf("PF10:%d, A1:%d ",PF10, A1);
13. Serial.printf("PF9:%d, A2:%d ",PF9, A2);
14. Serial.printf("PF8:%d, A3:%d ",PF8, A3);
15. Serial.printf("PF7:%d, A4:%d ",PF7, A4);
16. Serial.printf("PF6:%d, A5:%d ",PF6, A5);
17. }
18.
19. //the loop routine runs over and over again forever:
20. voidloop() {
21. // read the input on analog pin 0:
22. int sensorValue = analogRead(PA0);
23. // print out the value you read:
24. Serial.printf("PA0=%d ",sensorValue);
25. delay(1000); // delay in between reads forstability
26. }
程序代碼來源 : AnalogtReadSerial_12bit.ino
https://github.com/danieleff/STM32GENERIC/blob/master/STM32/libraries/BoardExamples/examples/Discovery746NG/AnalogtReadSerial_12bit/AnalogtReadSerial_12bit.ino
3. 使用SDRAM
DISCO-F746NG擁有8MB(64 Mbits)可用的SDRAM,但系統(tǒng)會用掉一些,所以無法完整配置8MB內(nèi)存。下列程序代碼是配置7MB的內(nèi)存的范例。
1. voidsetup()
2. {
3. Serial.begin(115200);
4. }
5. void loop()
6. {
7. uint32_t size = 7 * 1024 * 1024; // 7MB
8. Serial.printf("Allocating %dbuffer ", size);
9.
10. uint8_t *data = (uint8_t*)malloc(size);
11. if (data == NULL)
12. Serial.println("Mallocfailed!");
13. else
14. Serial.println("Success");
15.
16. free(data);
17. delay(5000);
18. }
I2C存取
請把I2C模塊的SCL、SDA接至下面的腳位– I2C1_SCL、I2C1_SDA,記得模塊的3V3、GND也要接上。
以下程序會掃描出模塊的I2C地址。請注意在呼叫Wire.begin();之前要先呼叫Wire.stm32SetInstance(I2C1); Wire.stm32SetSDA(PB9);Wire.stm32SetSCL(PB8); 來設(shè)定I2C連接的腳位,因為DISCO-F746NG擁有4組I2C(I2C1 ~ I2C4),對應(yīng)到Arduino UNO擴充插槽I2C腳位的是I2C1。
#include
2.
3. void setup()
4. {
5. Wire.stm32SetInstance(I2C1);
6. Wire.stm32SetSDA(PB9);
7. Wire.stm32SetSCL(PB8);
8. Wire.begin();
9.
10. Serial.begin(115200);
11. delay(5000);
12. Serial.println(" I2C Scanner");
13. }
14.
15. voidloop()
16. {
17. byte error, address;
18. int nDevices;
19.
20. Serial.println("Scanning...");
21. delay(2000);
22.
23. nDevices = 0;
24. for (address = 1; address < 127;address++ ) {
25. // The i2c_scanner uses the return valueof
26. // the Write.endTransmisstion to see if
27. // a device did acknowledge to theaddress.
28. Wire.beginTransmission(address);
29. Wire.write(0);
30. error = Wire.endTransmission();
31.
32. if (error == 0) {
33. Serial.print("I2C device found ataddress 0x");
34. if (address < 16) Serial.print("0");
35. Serial.print(address, HEX);
36. Serial.println(" !");
37. nDevices++;
38. }
39. else if (error == 4) {
40. Serial.print("no device found ataddress 0x");
41. if (address < 16)Serial.print("0");
42. Serial.println(address, HEX);
43. }
44. }
45. if (nDevices == 0) {
46. Serial.println("No I2C devicesfound ");
47. Serial.println("Did you configure thechip select for your device? ");
48. }
49. else
50. Serial.println("done ");
51.
52. delay(5000); // wait 5 seconds for next scan
53. }
程序代碼修改自 : I2cScanner.ino
https://github.com/danieleff/STM32GENERIC/blob/master/STM32/libraries/BoardExamples/examples/all_boards/I2cScanner/I2cScanner.ino
繪圖與觸控屏幕
觸控IC接在I2C3的位置,所以要先做I2C的初始化。因為篇幅的關(guān)系,僅列出主程序,請從Github取得stm32_ub_touch_480x272.h與stm32_ub_touch_480x272.cpp,與主程序放在同一個目錄。
https://github.com/danieleff/STM32GENERIC/tree/master/STM32/libraries/BoardExamples/examples/Discovery746NG/TFT/TouchDisplay
1. #include
2. #include "stm32_ub_touch_480x272.h"http:// 觸控屏幕
3. #include "LTDC_F746_Discovery.h" //繪圖
4.
5. LTDC_F746_Discovery tft;
6.
7. uint8_t UB_I2C3_ReadByte(uint8_taddressI2cDevice, uint8_t registerId)
8. {
9. uint8_t result;
10. addressI2cDevice = addressI2cDevice>> 1;
11.
12. Wire.beginTransmission(addressI2cDevice );
13. Wire.write( registerId );
14. uint8_t error;
15. error = Wire.endTransmission();
16.
17. Wire.requestFrom( addressI2cDevice,(uint8_t) 1 , (uint8_t) true );
18.
19. while ( Wire.available() < 1 );
20.
21. result = Wire.read() ;
22.
23. if (error)Serial.println("I2Cerror");
24.
25. return result;
26. }
27.
28. voidsetup()
29. {
30. Serial.begin(115200);
31. delay(1000);
32.
33. Wire.stm32SetInstance(I2C3);
34. Wire.stm32SetSDA(PH8);
35. Wire.stm32SetSCL(PH7);
36.
37. Wire.begin();
38.
39. UB_Touch_Init();
40.
41. // The buffer is memory mapped
42. // You can directly draw on the display bywriting to the buffer
43. uint16_t *buffer = (uint16_t*)malloc(2*LTDC_F746_ROKOTECH.width * LTDC_F746_ROKOTECH.height);
44.
45. tft.begin((uint16_t *)buffer);
46. tft.fillScreen(LTDC_WHITE);
47. }
48.
49. voidloop()
50. {
51. UB_Touch_Read();
52.
53. int x = Touch_Data.xp;
54. int y = Touch_Data.yp;
55.
56. Serial.printf("(%d, %d) ", x, y);
57. tft.fillCircle(x, y, 3, LTDC_BLUE);
58.
59. delay(10);
60. }
程序代碼修改自 : TouchDisplay.ino
https://github.com/danieleff/STM32GENERIC/blob/master/STM32/libraries/BoardExamples/examples/Discovery746NG/TFT/TouchDisplay/TouchDisplay.ino
程序執(zhí)行畫面,用手指在觸控屏幕上畫圖,類似小畫家的效果。
透過Ethernet連接至因特網(wǎng)
以下是一個使用HTTP GET聯(lián)機至http://example.com的范例,執(zhí)行后會把Server的響應(yīng)顯示在串行端口監(jiān)控窗口。
1. #include
2. #include
3.
4. EthernetClient client;
5.
6. // random MAC address
7. byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE,0xED };
8.
9. void setup() {
10. Serial.begin(115200);
11.
12. Serial.println("Connecting toEthernet");
13.
14. if (!Ethernet.begin(mac)) {
15. Serial.println("ERROR: Could notconnect to ethernet!");
16. while(1);
17. }
18.
19. Serial.println("Connecting toexample.com");
20.
21. if (!client.connect("example.com",80)) {
22. Serial.println("ERROR: Could notconnect to example.com!");
23. while(1);
24. }
25.
26. Serial.println("Connected, sendingrequest");
27.
28. client.println("GET /HTTP/1.1");
29. client.println("Host:example.com");
30. client.println();
31. client.flush();
32.
33. Serial.println("Request sent,printing response");
34. }
35.
36. voidloop() {
37. if (client.available()) {
38. char c = client.read();
39. Serial.print(c);
40. }
41.
42. if (!client.connected()) {
43. Serial.println();
44.Serial.println("disconnecting.");
45. client.stop();
46. while (1);
47. }
48. }
更多范例
可以從以下位置找到更多范例:
Arduino ID選單的檔案=>范例=>DiscoveryF746NG的范例
結(jié)語
DISCO-F746NG使用Arm架構(gòu)的M7微控制器,效能強大,運作起來相當流暢,而且本身已經(jīng)具備彩色觸控屏幕、Audio、麥克風(fēng)與Ethernet,不用再另外接模塊。筆者測試過其觸控定位功能,相當精準且反應(yīng)快速,很適合擔任顯示與人機互動的主機。再加上它支持易入門的Arduino IDE,開發(fā)者可在網(wǎng)絡(luò)上找到很多參考數(shù)據(jù),不怕碰到問題時搜尋不到解決方法。
看完本文的介紹,你是不是發(fā)現(xiàn)這個套件相當適合來實現(xiàn)你心中「某個」創(chuàng)意的原型設(shè)計呢?
-
微控制器
+關(guān)注
關(guān)注
48文章
7844瀏覽量
153348 -
以太網(wǎng)
+關(guān)注
關(guān)注
40文章
5547瀏覽量
174193 -
Arduino
+關(guān)注
關(guān)注
188文章
6485瀏覽量
189691 -
套件
+關(guān)注
關(guān)注
0文章
21瀏覽量
22239
原文標題:上手DISCO-F746NG探索套件,Arduino也兼容!
文章出處:【微信號:易心Microbit編程,微信公眾號:易心Microbit編程】歡迎添加關(guān)注!文章轉(zhuǎn)載請注明出處。
發(fā)布評論請先 登錄
相關(guān)推薦
stm32f746g-disco顯示白屏的原因有哪些?
轉(zhuǎn):將STM32F746G-Disco開發(fā)板做助聽器
STM32F746Disco開發(fā)板的MicroPython固件
STM32F411E-DISCO,STM32F411系列探索套件
STM32F746G-DISCO是什么
Discovery_kit_for_STM32F7_Series_with_STM32F746NG_MCU
微雪電子32F746GDISCOVERY STM32F7開發(fā)板簡介

基于STM32F746G-DISCO微控制器的參考設(shè)計

評論