ã¿ãªããããã«ã¡ã¯ïŒ çŸããIDEã§èšè¿°ãããã³ãŒãããããã»ããµãŸãã¯ãã€ã¯ãã³ã³ãããŒã©ãŒã§æ¶åå¯èœãªäžé£ã®ãã€ãã«ã©ã®ããã«å€ãããšæããŸããïŒ ã ããç§ã¯å人çã«ã¯ããŸãããŸããã ããèªäœã§ããŸãæ©èœããŸãã [ãã¡ã€ã«ã®è¿œå ]ãã¿ã³ãã¯ãªãã¯ããŸãã-IDEèªäœããããžã§ã¯ãã«ãœãŒã¹ãè¿œå ããã³ã³ãã€ã©ãšãªã³ã«ãŒèªäœãåŒã³åºããŸãã èªåã§ã³ãŒããæžããäºçŽ°ãªããšãèããªãã§ãã ããã
ããããããããã¹ãŠã®æé»ã®äºæãè¡šé¢ã«çŸããŠãæªå€¢ã®äžã§å€¢ãèŠå§ããããšããããŸãã æãåçŽãªHello Worldã§ããããã³ãããã®äžã«ã¯ãã¹ã ãŒãºã§å¿«é©ãªåããæäŸããããŸããŸãªéåžžã«èå³æ·±ãã®ã¢ããããŸãã ãã€ã¯ãã³ã³ãããŒã©ãŒã®äžçãäŸå€ã§ã¯ãããŸããã
ä»æ¥ã¯ç§ã®ãããžã§ã¯ãã®ãã«ãã·ã¹ãã ã®äº€æã«çŠç¹ãåãããŸãã ããŸããŸãªçç±ãããç§ã¯Arduinoãšå¯æ¥ã«é¢ä¿ããŠãããåããå€ããããšãã§ãããã®ãæ¢ãå¿ èŠããããŸããã ç«ã®äžã§ãArduinoã·ã¹ãã ãã«ãããSTM32ãã€ã¯ãã³ã³ãããŒã©ãŒãšCMakeã䜿çšããstm32duinoãã¬ãŒã ã¯ãŒã¯ã®ãã¡ãŒã ãŠã§ã¢ã¢ã»ã³ããªãžã®ç§»è¡ã®ç§ã®çµéšã説æãããŠããŸãã
ãã«ãã·ã¹ãã Arduino
Arduinoã奜ããªã®ã¯ããã€ã¯ãã³ã³ãããŒã©ã®äžçã«ã¹ã ãŒãºã«å ¥ãããšãã§ããããã§ãã ããããå€ãã®äººãèšãããã«ãããã¯åå¿è åãã§ãããå€ããå°ãªããçå£ãªãããžã§ã¯ãã«ã¯ãarduinoã¯é©ããŠããŸããã ç§ã¯ã«ããŽãªãŒã«ãªããããªãããarduinoã¯åžããšãžã£ãºã ãšèšãããã ç©äºãæŽçããŸãããã
ã ãããç§ã¯Arduinoã§æ¬¡ã®ããšã匷調ããŸãïŒ
- Arduino IDE-ãšãã£ã¿ãã³ã³ãã€ã©ãããã³1ã»ããã®ã©ã€ãã©ãªã»ããã å°ããªãããžã§ã¯ããããã°ããéå§ããããã€ã³ã¿ãŒãããããããŠã³ããŒããããããžã§ã¯ããçµã¿ç«ãŠããããããšãã§ããŸãã è¿œå ã®è³éãã€ã³ã¹ããŒã«ããå¿ èŠã¯ãããŸãã-ãã¹ãŠãç®±ããåºããŠããã§ãã
- ArduinoããŒã -ATMegaããã»ããµïŒãŸãã¯Atmelã®ãã®ä»ïŒã«åºã¥ãããŒãã®ãªãŒãã³ãœãŒã¹èšèšã ããŒãã¯å€ããå°ãªããæšæºåãããŠãããå€ãã®ã·ãŒã«ããšåšèŸºæ©åšããããŸãã
- Arduinoãã¬ãŒã ã¯ãŒã¯ -ãã€ã¯ãã³ã³ãããŒã©ãŒã®äœã¬ãã«ã®ããžãã¯ãšã¬ãžã¹ã¿ãŒãé ãC ++ã¯ã©ã¹ãã€ã³ã¿ãŒãã§ãŒã¹ãããã³ã©ã€ãã©ãªãŒã®ã»ããã ãŠãŒã¶ãŒã«ã¯ã䟿å©ã§ããªãé«ã¬ãã«ã®äœæ¥çšã€ã³ã¿ãŒãã§ã€ã¹ãæäŸãããŸãã
ãããã®åéšåã¯ãä»ã®éšåããç¬ç«ããŠããŸãã ãã®ãããArduinoIDEã§ã¯ãä»ã®ãã€ã¯ãã³ã³ãããŒã©ãŒïŒããšãã°ãESP8266ïŒã§èšè¿°ããããéã«ArduinoIDEãæŸæ£ããŠãAtmel StudioãEclipseããŸãã¯vimã®ã©ããã§Arduinoã®é åããã¹ãŠåŠã¶ããšãã§ããŸãã äžéšã®ããŒãã¯ãArduinoããŒãïŒã¯ã¢ããã³ãã¿ãŒãã©ã€ãã³ã³ãããŒã©ãŒãªã©ïŒãšã¯ããŸã䌌ãŠããŸããããArduinoã¹ã±ãããç°¡åã«è¿œå ã§ããŸãã ãŸããéã«ãArduinoããŒãã¯ãã¢CãŸãã¯ã¢ã»ã³ãã©ãŒã§ããã°ã©ã ã§ããŸãã Arduinoãã¬ãŒã ã¯ãŒã¯ã«é¢ããŠã¯ãå€ãã®ãã€ã¯ãã³ã³ãããŒã©ãŒïŒ STM32 ã TI ïŒã«ç§»æ€ãããŠããããããã®äžçã«å ¥ããããå€ã蚱容ã¬ãã«ãŸã§äžããŠããããšã«æ³šæããŠãã ããã
äžå€®ã«ã¯stm32f103c6ïŒå®éã«ã¯stm32f103cbïŒäžã®ããŒãããããå³åŽã«ã¯arduino nanoããããŸãã ããããã®åçïŒ ããã§ã¯ã stm32duino ã®è³ªåãå°ãæ·±ã圱é¿ãåããŠããŸãïŒ
ç§ã®ãããžã§ã¯ãã§ã¯ãç§ã¯ããã«Arduino IDEãæŸæ£ããŠããã䜿ãæ £ããAtmel Studioãæ¯æããŸããã ãŸã ãåšèŸºæ©åšãšã¡ã¢ãªãå°ãå€ãããã匷åãªãã©ãããã©ãŒã ãšããŠSTM32ãæ¯æããŠãArduinoããŒããæåŠããŸããã ç§ã¯æ¬åœã«Arduinoãã¬ãŒã ã¯ãŒã¯ãæåŠããããããŸãã-ããã¯éåžžã«çŸããã䟿å©ã§ãããªããå¿ èŠãšãããã¹ãŠãæäŸããŸãã STM32ãã€ã¯ãã³ã³ãããŒã©ãŒçšã®ArduinoããŒãã§ããstm32duinoã䜿çšããŸãã ãããã SPL ïŒã¬ãžã¹ã¿ãŒã«å¯Ÿããæ£çµ±æŽŸã®æœè±¡åãšSTèªäœããã®ã³ã³ãããŒã©ãŒã®ã¹ã¿ããã£ã³ã°ïŒã¯äœãšãå ¥ããŸããã§ãã-ã³ãŒãã倧ããããŠãã§ãã
ããããarduino- buildã·ã¹ãã ã«ã¯å¥ã®éåžžã«æé»çãªéšåããããŸã ã ãã®æé»æ§ã¯ããã¹ãŠãã©ã®ããã«æ©èœããããèããŠç解ããããªãå Žåã«ãå°èŠæš¡ãããžã§ã¯ãã«ãšã£ãŠå€§ããªãã©ã¹ã«ãªããŸãã ãã¡ã€ã«ãšã©ã€ãã©ãªãè¿œå ããã ãã§ããã¹ãŠãåéãããŸãã åå¿è ã«ãšã£ãŠã¯ããããäžçªã§ãã ãããããããžã§ã¯ããå°ãã§ã倧ãããªããããã€ãã®ã©ã€ãã©ãªãè¿œå ãããã³ã³ãã€ã©ã®åŸ®èª¿æŽãå¿ ââèŠã«ãªããšãarduinoã®ãã«ãã·ã¹ãã ãå¹²æžãå§ããŸãã ããã«ç§ã®ãããžã§ã¯ãã«å¹²æžãããã®ã®ãªã¹ãããããŸã
- ãœãŒã¹ããã£ã¬ã¯ããªã«ãœãŒãã§ããªã
ãœãŒã¹ã³ãŒããã»ãã®æ°åã§ããå Žåãç°¡åã«ããã²ãŒãã§ããŸãã ãããžã§ã¯ãå ã®ãã¡ã€ã«æ°ãæ°åãè¶ ããå Žåããããããã¹ãŠããŒãã«ãã³ãããã®ã¯åŸçã§ã¯ãããŸããã ãããžã§ã¯ãã®ããŸããŸãªã³ã³ããŒãã³ããŸãã¯ç¬ç«ããéšåãããŸããŸãªãã£ã¬ã¯ããªã«å解ããå¿ èŠã«å¿ããŠã€ã³ã¯ã«ãŒããã¹ãç»é²ãããšäŸ¿å©ã§ãã
æ®å¿µãªãããArduinoã§ã¯ããœãŒã¹ãç°ãªããã£ã¬ã¯ããªã«å解ããããšã¯ã§ããŸããããŸãã¯ãå°ãªããšãäœããã®åœ¢ã§IDEã®ãã¡ã€ã«ãã°ã«ãŒãåããããšã¯ã§ããŸããã Arduinoãã«ãã·ã¹ãã ã¯ããã¹ãŠã®ãã¡ã€ã«ãåããã£ã¬ã¯ããªã«ããããšãæå³ããŸãã ããã«ããããžã§ã¯ãã®ãœãŒã¹ã³ãŒãã¯ãã¡ã€ã³ã¹ã±ãããã¡ã€ã«ãšåããã£ã¬ã¯ããªã§ãã¡ã€ã«ãèŠã€ãããšããäºå®ã«ãã£ãŠæ£ç¢ºã«æ¥ç¶ãããŸãã ãšããã§ãã¹ã±ããã眮ãããŠãããã£ã¬ã¯ããªèªäœãããšã«ããåŒã³åºãããã¹ãã§ã¯ãããŸãã-ã¹ã±ãããšãŸã£ããåãããã«åŒã³åºãããã¹ãã§ãã
- ã©ã€ãã©ãªãã€ã³ã¹ããŒã«ããå¿
èŠããããŸã
ãŸããããã¯1åéãã®æäœã§ããããããžã§ã¯ããã¢ã»ã³ãã«ããããã®åå¥ã®æ瀺ãèšè¿°ããå¿ èŠããããŸããããããã©ã€ãã©ãªãããŠã³ããŒãããããã«çœ®ããŠããã®ããã«æ§æããŸãã
ã©ã€ãã©ãªã«äœããã®å€æŽãå ããå¿ èŠãããå ŽåããããŸãïŒééããä¿®æ£ããããèªåã§äœæ¥ããããïŒããããŠãå°ãªããšãgithubã§åå²ããå¿ èŠããããŸãã ãŸãããããžã§ã¯ãã®å€§æåã®ã¢ã»ã³ããªæé ã§ã¯ãå ã®ã©ã€ãã©ãªãæ©èœããªãããšãèšè¿°ããŸãã
ããããå¥ã®æ¹æ³ã§ã ã©ã€ãã©ãªããããžã§ã¯ãã®ãœãŒã¹ã³ãŒãã®æšªã«ããããŒãžã§ã³ç®¡çã·ã¹ãã ã«é 眮ããããšã¯ã§ããŸãããã©ã€ãã©ãªããããžã§ã¯ãã«æ¥ç¶ããããšã¯ã§ããŸããã
- ã©ã€ãã©ãªèšå®ã¯ã©ã€ãã©ãªèªäœã§æ§æãããŸã
倧åã³ã³ãã¥ãŒã¿çšã®ã©ã€ãã©ãªã§ã¯ããã¹ãŠãå®çŸ©ã§æ§æãããŸãã ã©ã€ãã©ãªå šäœãæäŸãããã¯ã©ã€ã¢ã³ãã¯èªåã®è£éã§ããã䜿çšããŸãã
Arduinoã©ã€ãã©ãªã§ã¯ãããã¯åœãŠã¯ãŸããŸããã éåžžãã©ã€ãã©ãªã«ã¯ãèªåã§ãã¡ã€ã«ãäœæããç¹å®ã®èšå®ãæå¹ãŸãã¯ç¡å¹ã«ããåšèŸºæ©åšãžã®ãªã³ã¯ãä¿®æ£ããå¿ èŠãããããããŒãã¡ã€ã«ãå«ãŸããŠããŸãã ãããããã®ã©ã€ãã©ãªã䜿çšããè€æ°ã®ãããžã§ã¯ããããããã©ã¡ãŒã¿ãŒãç°ãªãå Žåã¯ã©ããªããŸããïŒ çµå±ãã©ã€ãã©ãªã¯å ±æãã£ã¬ã¯ããªã«ã€ã³ã¹ããŒã«ããããããããžã§ã¯ãã®å€æŽã¯å¥ã®ãããžã§ã¯ãã«åœ±é¿ãåãŒããŸãã
ãŸããæ§æãã¡ã€ã«ã®ããŒãžã§ã³ç®¡çã®åé¡ã¯æªè§£æ±ºã®ãŸãŸã§ã
- ãããžã§ã¯ãã¯åžžã«å
šäœãšããŠåæ§ç¯ãããŸã
1ã€ã®ãã¡ã€ã«ã§å°ããªå€æŽããã£ããšããŠãããã¹ãŠã®ãã¡ã€ã«ãåã³ã³ãã€ã«ããããŸã§åŸ ã€å¿ èŠããããŸãã ç§ã®å ŽåãçŽ1åã§ãã
ããã¯ãã¹ãŠãç®ã«èŠããé²æ©ããªãããšã«ãã£ãŠããã«æªåããŸãã åäœãããã©ããã¯æ確ã§ã¯ãããŸããã ãã«ããæåããå Žåããã«ãã·ã¹ãã ã¯ãã¡ãŒã ãŠã§ã¢ã®ãµã€ãºãæžã蟌ã¿ãŸãã ãã ãããšã©ãŒãçºçããå ŽåïŒããšãã°ããã©ãã·ã¥ã¡ã¢ãªã®ãµã€ãºãè¶ ããå ŽåïŒããã«ãã·ã¹ãã ã¯ããããŸã£ããå ±åããŸããã
- æåŸã«ãã³ã³ãã€ã«ããŒãæè»ã«å€æŽããããšã¯ã§ããŸãã
æé©åèšå®ãå€æŽã§ããŸããã ãããŠãããªãã¯åŸ®èª¿æŽãå¿ããããšãã§ããŸãã ç§ã¯äœãèšãããšãã§ããŸã-ããªãã¯ã€ã³ã¯ã«ãŒããã¹ãç»é²ããããå®çŸ©ããããšã¯ã§ããŸããïŒ
æ£è ã®æ€æ»
ãããã£ãŠãArduinoãã«ãã·ã¹ãã ã®åé¡ã¯æããã§ãã ããã§ããžãã¹ãæ確ã«ããã«ã¯ãããè¯ããã®ãèãåºãå¿ èŠããããŸãã ããããå¥ã®ãã«ãã·ã¹ãã ã«ç§»ãåã«ããŸãArduinoèªäœããããžã§ã¯ãããã«ãããæ¹æ³ãç解ããå¿ èŠããããŸãã ãããŠãããã¯éåžžã«èå³æ·±ãåããããŸãã
ãŸãããã«ãã·ã¹ãã ã¯-o nulããŒã䜿çšããŠã¹ã±ãããã¡ã€ã«ïŒ.inoïŒããã«ãããããšããŸãïŒäœãæžã蟌ãŸããã³ã³ãã€ã«ãšã©ãŒã®ã¿ãåéããŸãïŒã ã³ã³ãã€ã©ãããããŒãèŠã€ããããªãå Žåããã«ãã·ã¹ãã ã¯ã€ã³ã¹ããŒã«ãããŠããã©ã€ãã©ãªã§ãã®ããããŒãæ¢ããŸãã -ãããå Žåã-Iã¹ã€ããïŒãªãã·ã§ã³ã®ã€ã³ã¯ã«ãŒããã¹ïŒãè¿œå ããããäžåºŠãã«ããè©Šã¿ãŸãã ãã«ãã·ã¹ãã ãå¥ã®ããããŒãèŠã€ããããªãå Žåãæäœãç¹°ãè¿ãããŸãã -Iã¹ã€ããã®ãã¹ãå«ãè¡ãèç©ããããããžã§ã¯ãå ã®æ¬¡ã®ãã¡ã€ã«ã«é©çšãããŸãã
-Iã¹ã€ããã®ããªãã¯ã«å ããŠããã«ãã·ã¹ãã ã¯ã©ã€ãã©ãªèªäœãã¢ã»ã³ãã«ããŸãã ãããè¡ãããã«ã圌女ã¯ã©ã€ãã©ãªãã£ã¬ã¯ããªå ã®ãã¹ãŠã®* .cããã³* .cppãã¡ã€ã«ãã³ã³ãã€ã«ããããšããŸãã ã©ã€ãã©ãªã®ããããŒäŸåé¢ä¿ã¯ããã§ã«èª¬æããæ¹æ³ã§è§£æ±ºãããŸãã ã©ã€ãã©ãªã¯ããã¹ãŠã®ãã¡ã€ã«ã䜿çšãããŠããªããŠããå šäœãšããŠã³ã³ãã€ã«ãããŸãã ãããŠããªã³ã«ãŒãè¶ éåãã¹ããŒããã®ã¯è¯ãããšã§ãã ããã§ãªãå Žåã¯ïŒ
ãããã£ãŠãã°ããŒãã«ãªããžã§ã¯ããã©ã€ãã©ãªïŒããšãã°ãSerialãŸãã¯SPIã¯ã©ã¹ïŒã§å®£èšãããŠããå Žåããã®ã³ãŒããå®éã«äœ¿çšãããŠããªããŠãããã®ãªããžã§ã¯ãã®ã³ãŒãã¯åžžã«ãã¡ãŒã ãŠã§ã¢ã«å ¥ããŸãã ã€ãŸã 誀ã£ãŠè¿œå ããã#includeãã£ã¬ã¯ãã£ãã«ããããã¡ãŒã ãŠã§ã¢ã«æ°ããäœåã«è¿œå ãããå¯èœæ§ããããŸãã
ããããããã ãã§ã¯ãããŸããã ãã¹ãŠã®äŸåé¢ä¿ãã³ã³ãã€ã«ããããšãã³ã³ãã€ã«ãã³ãŒãçæãæé©åãããã³ãã¹ãŠã®ãžã£ãºã«é©åãªããŒã䜿çšããŠãã³ã³ãã€ã«ããã»ã¹ãããäžåºŠéå§ãããŸãã äžè¬ã«ãåãã¡ã€ã«ã¯å°ãªããšã2åã³ã³ãã€ã«ãããç¹ã«å€±æãããã¡ã€ã«ïŒ.inoãªã©ïŒã¯ããããžã§ã¯ãã«å«ãŸããã©ã€ãã©ãªã®æ°ã ãã³ã³ãã€ã«ã§ããŸãã
ããããçš®é¡ã®ã·ã¹ãã ïŒå²ã蟌ã¿ãã¯ãã«ãããŒãã®åºæ¬çãªåæåïŒããããžã§ã¯ãã§ã³ã³ãã€ã«ãããŸãã 幞ããªããšã«ãã³ã³ãã€ã«ããããã¡ã€ã«ã®äžéšã¯ã.aéçã©ã€ãã©ãªã«ã³ã³ãã€ã«ãããŸãã ããããããã¯ãå®éãstm32duinoã®äœæè ã«ããã·ã£ãŒãããºã ã§ããä»ã®ã©ã€ãã©ãªã§ã¯ããã¹ãŠããã¡ã€ã«ããšã«è¡ãããŸãã
ã©ã€ãã©ãªã1ã2åããå°ããªArduinoãããžã§ã¯ãã®å Žåãã¢ã»ã³ããªã«å¯Ÿãããã®ã¢ãããŒãã¯ããŸããªãŒããŒããããçã¿åºããŸããã ãããã25åã®cppãã¡ã€ã«ãš5åã®ã©ã€ãã©ãªãããªãç§ã®ãããžã§ã¯ãã¯ãã»ãŒ1åéã³ã³ãã€ã«ããå§ããŸããã ããŒã«ãã§ãŒã³ã®ã³ã³ãã€ã©ããªã³ã«ãŒãããã³ãã®ä»ã®ããã°ã©ã ãäœåèµ·åããããç¥ã£ãŠããŸããïŒ 240å!!!
ããã«ãããããããã¢ã»ã³ããªèªäœã«ã¯è»äºçãªãã®ã¯äœããããŸããã ç§ã¯ãarduinoãªãã§ã¯ç¹°ãè¿ããªãããã€ãã®é ãããã¢ã»ã³ããªã¡ã«ããºã ãæããŠããŸããã å®éããã¹ãŠã¯ãç¹å®ã®ããŒã®ã»ããã䜿çšããŠã³ã³ãã€ã©ãŒãšãªã³ã«ãŒãé 次åŒã³åºããŠåéãããŸãã ãã®ãããå¥ã®ãã«ãã·ã¹ãã ã§ãåãããšãç¹°ãè¿ãããŸãã
STM32ããã³stm32duinoãã¬ãŒã ã¯ãŒã¯ã§ãã«ãããéã«ããã«ãã·ã¹ãã ã®äœæ¥ã調æ»ããããšã¯æ³šç®ã«å€ããŸãã ããããATMegaã³ã³ãããŒã©ãŒã®åŸæ¥ã®arduinoã§ãã«ãããå Žåããã¹ãŠãã»ãŒåãã§ãïŒå°ãã ãåçŽã§ãïŒ
CMakeãè©Šã
ã¯ãŒã¯ã·ã§ããã®ååã¯ãCMakeãèŠãããšãå§ããŸãã-圌ãã¯ãã§ã«Arduinoãããžã§ã¯ããçµã¿ç«ãŠãããã®æ¢è£œã®ããŒã«ãæã£ãŠããŸãã ã ãããç§ã¯CMakeãã€ã³ã¹ããŒã«ããäŸããæå°éã®ãããžã§ã¯ããåããCMakeList.txtãå°ãæåºããŸããã ããããCMakeãéå§ãããšãã«ãæ§æ段éïŒã³ã³ãã€ã©ãŒããªã³ã«ãŒãªã©ããã§ãã¯ããããšãïŒã§ld.exeã§ã¯ã©ãã·ã¥ããŸããã äœãèµ·ãã£ãŠããã®ããæ£ç¢ºã«ç解ããè©Šã¿ã¯å€±æã«çµãããŸãã-å¥ã«èµ·åãããåããªã³ã©ã€ã³ã³ãã³ãã¯åé¡ãªãå®è¡ãããŸããã ç§ã¯ãããåé¿ããæ¹æ³ãç解ããŠããŸããã§ããã
解決çãæ¢ããŠãããŒã«ãã§ãŒã³ãã¡ã€ã«ã泚ææ·±ã調ã¹ããšãããããããŸã£ããæãäžããŠããªãã£ãããšãããããŸããã å®éã®arduinoã«ã¯ãã³ã³ãã€ã©ïŒå¿ ãããAVRãšã¯éããŸããïŒã§ããŒããè¿œå ã§ãããã©ã°ã€ã³ã·ã¹ãã ããããŸãããç§ãç 究ããŠããããŒã«ãã§ãŒã³ã®1ã€ã¯ AVRå°çšã§ãã ããã«ã2ã3çš®é¡ã®æšæºããŒããã䜿çšã§ããŸããã
2çªç®ã®ããŒã«ãã§ãŒã³ã¯ããè¯ãèŠããŸããã 圌ã¯ãboards.txtãªã©ã®Arduinoãã¡ã€ã«ã解æããoptionsãã£ã¬ã¯ããªã調ã¹ãå©çšå¯èœãªãã¹ãŠã®ã¢ã»ã³ããªãªãã·ã§ã³ãããŒããããã³ããã»ããµãåéããŸããã ããã«ãããããããäœããç§ãæ··ä¹±ãããŸããã åºå£ã§ãç§ã¯åã³arduinoã¹ã¿ã€ã«ã®ã¢ããªã¹ãæã«å ¥ãããšæãããŸããã ARMã³ã³ãã€ã©ãAVRã®ä»£ããã«æ©èœãããã©ããã¯ããŸãæ確ã§ã¯ãããŸããã§ããã ããã«ãã©ã€ãã©ãªãå¶åŸ¡ããæ¹æ³ã¯ãŸã æ確ã§ã¯ãããŸããã
äžè¬ã«ããã®ããŒã«ãã§ãŒã³ã«ã€ããŠæªãããšãèšãããšã¯ã§ããŸããã åçŽã«ãã¡ã€ã¯ã¢ãããã¡ã€ã«ãçæããéã«ã¯ã©ãã·ã¥ãç¡å¹ã«ããããšãªããä»ã®å Žæã§è§£æ±ºçãæ¢ãããšã«ããŸããã
ã¯ãŒã³ãã¯ã¹
è¯ãIDEã§ã³ãŒããæžãã®ã倧奜ãã§ãã ã€ã³ã¿ãŒãããã¯ãSTM32ã§æã人æ°ã®ããIDEïŒKeilãIARãCooCoxïŒãšåŒã°ããããšããããããŸãã æåã®2ã€ã¯æåã§ã䜿ããããã®ãããã¯ã«é¢ããè³ªçŽ ãªã¬ãã¥ãŒããããŸãã ããããCooCoxã¯é«ãè©äŸ¡ãããŠããŸãã ãŸããEclipseã«åºã¥ããŠæ§ç¯ãããŠãããšããäºå®ã«ãã£ãŠè³ãããŠãããç§ã¯ãã£ãšåœŒã«äŒãããã£ãã ããã«ããããã«ãããã»ã¹ã埮調æŽã§ããããã«æããŸããã æ²ããããšã«ãç§ã¯ééã£ãŠãããšèšããŸãã
CooCoxãã€ã³ã¹ããŒã«ããã®ã§ãã³ã³ãã€ã©ããªããŠãé©ããã äžè¬ã«ãããã¯ç解ã§ããŸã-IDEã¯å¥åã§ãããã³ã³ãã€ã©ã¯å¥åã§ãã Visual Studioã§äœå¹Žã䜿çšããåŸããããã¯çããããšã§ãã ãŸãã倧äžå€«ãããã¯ã³ã³ãã€ã©ãŒãåå¥ã®ã€ã³ã¹ããŒã©ãŒãšããŠã€ã³ã¹ããŒã«ããããšã§ç°¡åã«è§£æ±ºã§ããŸãããæåã¯ã³ã³ãã€ã©ãŒãAtmel StudioããåããŸããã
ãããŠãåé¡ãå§ãŸããŸããã 1æéãLEDã®ç¹æ» ãéå§ããããšããŸããã ã€ã³ã¿ãŒãããã§ã¯ãããŸããŸãªçšåºŠã®ã³ã³ãã€ã«ã®ãªãã·ã§ã³ãçŽ12åèŠã€ãããŸããã ã©ãã§ééããããã®ã§ããããïŒ ãããã ã³ã³ãã€ã«ãå¡ãã€ã¶ã-åäœããŸããã ãããžã§ã¯ããæ°ååäœæããŸãããã圹ã«ç«ã¡ãŸããã§ããã ãã®çµæã圌ã¯ããã¢ã®æ瀺ãã®ãã®ã«åŸã£ãŠããã¹ãŠã®æ瀺ãæ確ãã€éèªçã«å®è¡ããŸããã ãã¡ãŒã ãŠã§ã¢ã¯UARTãä»ããŠããŠã³ããŒããããã·ã¹ãã ããŒãããŒããŒãšé»çã楜ããç¹æ» ããŸããã
åé¡ã®åå ã§ããstm32duino / libmaple USBããŒãããŒããŒãéé£ããããšæããŸãããSTM32ã³ã³ãããŒã©ãŒã®åæåããã»ã¹ã®èª€è§£ãèªããæ¹ãåççã§ãã 質åãç解ããã®ã§ãå¥ã®èšäºã§ ãçºèŠãã«ã€ããŠèª¬æããŸãã ã äžèšã§èšãã°ãåé¡ã¯ãã¡ãŒã ãŠã§ã¢ã®èª€ã£ãéå§ã¢ãã¬ã¹ã«ãããŸããã ããŒãããŒããŒã䜿çšããå Žåããã¡ãŒã ãŠã§ã¢ã¯ç°ãªãéå§ã¢ãã¬ã¹ã§çµã¿ç«ãŠãå¿ èŠããããŸãã å®éããã®ãã©ã¡ãŒã¿ãŒã¯åŸæ¥ã®arduinoã«ã¯ãããŸããããSTM32ãã€ã¯ãã³ã³ãããŒã©ãŒã«ãšã£ãŠã¯éåžžã«éèŠã§ãã
STM32ããŒãããŒããŒã«é¢ããèå¯
ãã¡ãããUARTãä»ããŠãã©ãã·ã¥ããããšã¯å¯èœã§ãããããã¯ãŸã hemoã§ãã STãã©ãã·ã¥ãã¢ã³ã¹ãã¬ãŒã¿ãŒã§ã¯ãåžžã«ããŒããžã£ã³ããŒãåãæ¿ããŠãããŠã¹ã§å€ãã¯ãªãã¯ããå¿
èŠããããŸãã ç§ã¯äžåœã®ST-Linkãæã£ãŠããŸãããããæ¥ç¶ãããããéããŠçž«ãããããŠãããºããããšãã§ããŸããã æ¬åœã«ã€ã³ãµãŒããããããã°ãå¿
èŠãªãšãã«ããã«å°éããã§ãããã
ããããçŸæç¹ã§ã¯ãããã€ãã®çç±ããUSBçµç±ã®ãã¡ãŒã ãŠã§ã¢ãæã䟿å©ã ãšèããŠããŸãã ãšã«ãããé»æºãšUSBã·ãªã¢ã«çšã®USBã±ãŒãã«ãæ¥ç¶ããŸããã ãŸããããã«USB倧容éã¹ãã¬ãŒãžãç©æ¥µçã«éžæããäºå®ã§ãã æçµçã«ãUSBã¯å®æããããã€ã¹ã«ãåºåãããŸãã ã§ã¯ããªãUSBçµç±ã§ãã©ãã·ã¥ããã®ã§ã¯ãªããè¿œå ã®ã³ã³ããŒãã³ãã䜿çšããã®ã§ããããïŒ
ããããçŸæç¹ã§ã¯ãããã€ãã®çç±ããUSBçµç±ã®ãã¡ãŒã ãŠã§ã¢ãæã䟿å©ã ãšèããŠããŸãã ãšã«ãããé»æºãšUSBã·ãªã¢ã«çšã®USBã±ãŒãã«ãæ¥ç¶ããŸããã ãŸããããã«USB倧容éã¹ãã¬ãŒãžãç©æ¥µçã«éžæããäºå®ã§ãã æçµçã«ãUSBã¯å®æããããã€ã¹ã«ãåºåãããŸãã ã§ã¯ããªãUSBçµç±ã§ãã©ãã·ã¥ããã®ã§ã¯ãªããè¿œå ã®ã³ã³ããŒãã³ãã䜿çšããã®ã§ããããïŒ
æ§æ管çã®ãããã¯ã«æ»ããŸããå ·äœçã«ã¯ãã©ã€ãã©ãªãä¿åããå Žæãšæ¹æ³ã«ã€ããŠèª¬æããŸãã ãç§ã¯ãã¹ãŠãç§ãšäžç·ã«éã¶ããšãããªãã·ã§ã³ã«åŒãå¯ããããŸãã ãªããžããªå ã®ãã¹ãŠã®ã©ã€ãã©ãªã®å€æŽïŒæ§æãå«ãïŒãããŒãžã§ã³ç®¡çããããšæããŸãã ãã¡ãããå€å žçãªUnixãããããããŸãããåäžçŽã®ããã§ãã ããããèŠè¿ãã«äœã䜿ãã¹ãã§ããããïŒ ã1ã€ã®ããŒã ã§ãœãŒã¹ã³ãŒããåŒãåºããæ§ç¯ããMKã«ã¢ããããŒãããããšããã¹ã¿ã€ã«ã®ãœãªã¥ãŒã·ã§ã³ãå¿ èŠã§ãã
é·ãéãgitã§ãµãã¢ãžã¥ãŒã«ãšãµãããªãŒãåŠçããããšããŸããã ç§ã«ãšã£ãŠãGitããã¡ããšäœ¿çšããããšããªã人ãšããŠã¯ãäœãæ確ã§ã¯ãããŸããã ç§ã¯Git Bookã®æåã®æ°ç« ãèªãã§ããŸããããããã«æ··ä¹±ããŸããã ç§ã¯ãããã®åé¡ã«ã€ããŠããçµéšè±å¯ãªååã«å©ããæ±ããŸãããã圌ãã¯ããã«æãæ²ããããã¯ããã«æ確ã«ãªããŸããã§ããã ãµãããªãŒãä»ããŠè¡ãããšã«ããŸãã ã äœãç§ãè ãããæ³åã§ããŸããã
ãªããžããªã«å¿ èŠãªãã¡ã€ã«ãçŽæ¥ååŸããããããµãããªãŒãæ°ã«å ¥ã£ãã ãããŠãããããç·šéããæ©èœãåããŠããŸãã ãã ãããµãã¢ãžã¥ãŒã«ã§ã¯ãå€æŽãå¥ã®ãªããžããªã®ã©ããã«ä¿åããå¿ èŠããããŸãã ãã°ä¿®æ£ã®ããã«ããã劥åœã§ããå ŽåïŒç°¡åã«åå²ããŠä¿®æ£ãã¡ã€ã³ãªããžããªã«ããã·ã¥ã§ããŸãïŒãã©ã€ãã©ãªèšå®ãä¿åããããã«ããã¯å°ãªããšãå¥åŠã§ãã ç°ãªããªããžããªã«ãã1ã€ã®ãããžã§ã¯ãã®å€æŽãããŒãžã§ã³ç®¡çããããšã¯æãŸãããããŸããã
ããã§ãSTM32F1xxã·ãªãŒãºã³ã³ãããŒã©ãŒã®stm32duinoãã¬ããžããªã«è¿œå ããŸããã ãµã³ãã«ãšã©ã€ãã©ãªã䜿çšããŠãå®å šã«åŒ·åãããŸããã æ£çŽã«èšããšãç§ã¯ãã®æ§é ã奜ãã§ã¯ãªãããããããã¹ãŠãå¿ èŠãšããŠããããã§ã¯ãããŸããã ããããç§ã¯ãããå¥ã®æ¹æ³ã§ããããŠãããåŸã§ä¿æããæ¹æ³ãç¥ããŸããã CooCoxãããžã§ã¯ãã§å¥œããªããã«ãã¹ãŠã®ãã¡ã€ã«ãã¬ã€ã¢ãŠããããšããäºå®ã«ãã£ãŠè£ãããŸããã
ãã®çµæãå¿ èŠãªãã¹ãŠã®ãã¡ã€ã«ããããžã§ã¯ãã«åã蟌ã¿ãArduinoãšåãå®çŸ©ãèšå®ããŠããªã³ã¯ããã»ã¹ãéå§ããŸããã ééã£ãŠè¡ã£ãã ã·ã³ãã«ããªãå Žåãã©ã®ãœãŒã¹ã宣èšãããŠãããã調ã¹ããã®ãœãŒã¹ã®ã¿ãè¿œå ããŸããã éåžžã«èå³æ·±ãçµéšã§ãã éäžã§ããããäœã§ã©ãã«ããã®ãïŒstm32duino / libmapleãæå³ããïŒãšããã§ã®åäœãç解ããŸããã
åè¿°ããããã«ãARMïŒSTM32ïŒã§ã®ã¢ã»ã³ããªã¯ãAVRã§ã®ã¢ã»ã³ããªãããè€éã§ãã åé¡ã¯ãã³ã³ãã€ã©ãããäžè¬çã§ãããéåžžã«çŽ°ããèšå®ã§ããããšã§ãã äžæ¹ã§ãããã¯é©åã§ãããã¢ã»ã³ããªããã»ã¹ã調æŽã§ããŸããä»æ¹ã§ã¯ãæ§æãå€§å¹ ã«è€éã«ãªããŸãã ãã®ãããããã§ã¯ãªã³ã«ã¹ã¯ãªãããè¿œå ã§äœ¿çšãããŸããçµæã®ãã€ããªã«ã©ã®ã»ã¯ã·ã§ã³ãé 眮ãããããããã®ã»ã¯ã·ã§ã³ãã©ãã«ããããããããã©ã®ãããã®ã¹ããŒã¹ãåãããèšè¿°ããç¹å¥ãªãã¡ã€ã«ã§ãã
äœã¬ãã«ã®ã³ãŒãã¯ããªã³ã«ã¹ã¯ãªããã§å®£èšãããæåãåç §ã§ããéããŸãåæ§ã§ããããšãå€æããŸããã ãªã³ã«ãŒãæšæºèšå®ã§åŒã³åºãããå Žåããããã®æåã¯èŠã€ãããŸããã ãã®åé¡ã解決ããããã«ããªã³ã«èšå®ããŒãžã§ã[ã¡ã¢ãªãŠã£ã³ããŠããã¡ã¢ãªã¬ã€ã¢ãŠãã䜿çšãã]ã®ãã§ãã¯ãå€ããŸãã-ã¹ãã£ãã¿ãã¡ã€ã«ãã£ãŒã«ããéããŸããã ããã§ãArduinoãã«ãã·ã¹ãã ïŒ STM32F1 / variant / generic_gd32f103c / ld / bootloader_20.ld ïŒã§äœ¿çšããããªã³ã«ãŒã¹ã¯ãªãããç»é²ããŸããã ãã®åŸããã¹ãŠãããã«ãªã³ã¯ãããŸããã
ããããããã§äžæå¿«ãªé©ããç§ãåŸ ã£ãŠããŸãã-çµã¿ç«ãŠããããã¡ãŒã ãŠã§ã¢ã¯ããã«115kbãåããŸããïŒarduinoã§ã¯56kã§ããïŒã ããã«ããã¹ãŠã®ãã£ã©ã¯ã¿ãŒãããã§æ··åããããã¡ãŒã ãŠã§ã¢ã«ã¯å€ãã®C ++ã©ã³ã¿ã€ã ãå«ãŸããŠããŸãã-rttiãmanglersãabiãexecutionsããããŠãŸã äžå¿ èŠãªå€ãã®ãã®ã ArduinoãšCooCoxãäœæããåããŒã®ããã¥ã¡ã³ããåžããªã³ã«ãŒã³ãã³ãã©ã€ã³ãæ¯èŒããå¿ èŠããããŸããã
CooCoxã§ã¯ãCã³ã³ãã€ã©ãšC ++ã³ã³ãã€ã©ãéžæã§ããªãããšãå€æããŸããã ãã®ãããåã³ã³ãã€ã©ãåå¥ã«æ§æããããšã¯ã§ããŸããã ãã®ãããC ++ã³ãŒãã¯gccïŒg ++ã§ã¯ãªãïŒã䜿çšããŠã³ã³ãã€ã«ãããããã©ã«ãã§å€§éã®ã³ãŒããrttiãABIãªã©ã«ãªã³ã¯ããŸãã ãããŠã骚ã¯ããã»ã©ç°¡åã§ã¯ãªãããã§ãã ã³ã³ãã€ã©ã®è¿œå ãã©ã°çšã®ãã£ãŒã«ãããããŸããã-fno-rttiãªã©ãè¿œå ãããšãgccã¯ããã«èªãå§ããŸãã
ã€ã³ã¿ãŒãããã§ã¯ã人ã ã¯CooCoxã«2çªç®ã®ããŒãžã§ã³ãæäŸããŸããããã§ã«å€ãã®èšå®ããããCã³ãŒããšC ++ã³ãŒããåºå¥ã§ãããã¡ã€ã«ã¿ã€ãããšã«æ£ããã³ã³ãã€ã©ãåŒã³åºããŸãã ãã ããåæã«ãã³ã³ãã€ã©ãŒããšã«åå¥ã«ããŒãæ§æããããšã¯ã§ããŸããã ãã®ããã-fno-rttiããŒã¯g ++ã ãã«è¿œå ããããšã¯ã§ããŸãããgccã«ãéä¿¡ãããŸãã
äžè¬ã«ã2çªç®ã®CooCoxã¯ãã®ãŸãŸã§ã¯å ¥å ŽããŸããã§ãã-å©äŸ¿æ§ãç ç²ã«ããŠãé åçãªUIãå€ãããŸãã ã¡ãªã¿ã«ãæåã®UIã¯UIã®ç¹ã§ãåªããŠããŸããã100äžã®èšå®ãããããã«ãã³ã³ãœãŒã«ã®ãã©ã³ãã¯å€æŽã§ããŸããïŒå®å šãªEclipseã§ã¯å¯èœã§ããïŒã
CMakeããäžåºŠ
CooCoxã®ãããªããç¥ãããããŒã«ã§ã¯ãã³ã³ãã€ã©ãŒã®ç°¡åãªæ§æãã§ããªããããnafigã䜿çšããŸãã æäžå±€ã«è¡ãããã¹ãŠãæã§æžããŸãã ãŸããããªãã®æã§...ãã¡ãããã¡ã€ã¯ãã¡ã€ã«ã§ã
ååãã»ãŒ10幎åã«è£žã®ã¡ã€ã¯ãã¡ã€ã«ãäœæããŸããã ç§ã¯ãã§ã«ãã¹ãŠã®åŸ®åŠããå¿ããŸããããããã¯éåžžã«æè¬ã®ãªãä»äºã§ããããšã確ãã«èŠããŠããŸãã 颚å€ãããªæ§æãšééããç¯ããããã ãããŠãããã¯éåžžã«ããŒã¿ãã«ã§ã¯ãããŸããã CMakeãããäžåºŠè©ŠããŠã¿ãããšã«ããŸããããarduinoããŒã«ãã§ãŒã³ã§ã¯ãªããSTM32ã§è©ŠããŠã¿ãŸããã ãããŠããã¹ãŠã®ã«ãŒã«ã䜿çšããŠãmakeãeclipseãã³ã³ãã€ã©ãCMakeãMinGW32ãåå¥ã«ã€ã³ã¹ããŒã«ããŸããã
ç§ã¯ã¿ã«ãã§ãŒã³ãèŠãŸããã§ããã ããã¯ãç§ãäžè¬çãªã¢ã€ãã¢ãåŸããšããããç®ãåŒããããããŒã«ãã§ãŒã³èªäœã¯ããããåã£ã ã ç§ã¯ãããæ®éã®å±±ã«èšçœ®ããã®ã§ã¯ãªããæºåž¯ããããšã決ããŸããã ããã«ããã¹ãŠãå¿ èŠãšããããã§ã¯ãããŸããããå ±éã®å€æ°ãšããã·ãŒãžã£ã宣èšãããŠããgcc_stm32.cmakeãšãã³ã³ãããŒã©ãŒãã©ã¡ãŒã¿ãŒãèšè¿°ãããŠããgcc_stm32f1.cmakeã® 2ã€ã®ãã¡ã€ã«ã ããå¿ èŠã§ãã
ç§ãæã£ãŠãããã¹ãŠã®ã©ã€ãã©ãªã¯ãïŒçè«çã«ã¯ïŒã¡ã€ã³ãªããžããªãšåæãããã£ã¬ã¯ããªã«ãããŸãïŒæ¹æ³ãç解ãããïŒã ãããã£ãŠãCMakeList.txtãåã©ã€ãã©ãªã«è¿œå ããã®ã¯ãã©ããããããäžå¿«ã§ãã ã©ã€ãã©ãªãã£ã¬ã¯ããªã«äžè¬çãªCMakeList.txtã1ã€äœæãããã®äžã®ãã¹ãŠã®ã©ã€ãã©ãªã®ã¢ã»ã³ããªãèšè¿°ããããšã«ããŸããã åã©ã€ãã©ãªã¯ã¢ãŒã«ã€ãïŒéçã©ã€ãã©ãªïŒã«åéããããã¹ãŠããã€ããªã§ãªã³ã¯ãããŸãã
ã©ã€ãã©ãªãæ§ç¯ããããã®CMakeã¹ã¯ãªããïŒãã¹ãŠã®ã©ã€ãã©ãªã«1ã€ã®ã¹ã¯ãªããïŒ
# Not pushing this file down to libraries in order to keep source tree as is (not populating with extra files, such as CMakeList.txt) # # Below each section represents a library with its own settings ################### # NeoGPS ################### SET(NEOGPS_SRC NeoGPS/DMS.cpp NeoGPS/GPSTime.cpp NeoGPS/Location.cpp NeoGPS/NeoTime.cpp NeoGPS/NMEAGPS.cpp ) ADD_LIBRARY(NeoGPS STATIC ${NEOGPS_SRC}) ################### # FreeRTOS ################### SET(FREERTOS_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/STM32duino/libraries/FreeRTOS821) SET(FREERTOS_SRC ${FREERTOS_SRC_DIR}/MapleFreeRTOS821.cpp ${FREERTOS_SRC_DIR}/utility/heap_1.c ${FREERTOS_SRC_DIR}/utility/list.c ${FREERTOS_SRC_DIR}/utility/port.c ${FREERTOS_SRC_DIR}/utility/queue.c ${FREERTOS_SRC_DIR}/utility/tasks.c ) ADD_LIBRARY(FreeRTOS STATIC ${FREERTOS_SRC}) ################### # Adafruit GFX library ################### ADD_LIBRARY(AdafruitGFX STATIC AdafruitGFX/Adafruit_GFX.cpp ) ################### # Adafruit SSD1306 library ################### ADD_LIBRARY(AdafruitSSD1306 STATIC STM32duino/libraries/Adafruit_SSD1306/Adafruit_SSD1306_STM32.cpp ) TARGET_INCLUDE_DIRECTORIES(AdafruitSSD1306 PRIVATE STM32duino/libraries/Wire STM32duino/libraries/SPI/src #In fact it should not depend on it AdafruitGFX )
æ¬äœã¢ã»ã³ããªã«ã¯ã以äžã§èª¬æããéèŠãªãã®ãããã€ããããŸãã ãããŸã§ã®ãšããã CMakeLists.txtå šäœãæäŸããŸãã
ãããžã§ã¯ãã®äž»èŠéšåã®ãã«ãã¹ã¯ãªãã
# Build rules for GPS logger target. # App specific compiler/linker settings are also defined here SET(SOURCE_FILES # Screens and screen management stuff Screens/AltitudeScreen.cpp Screens/AltitudeScreen.h Screens/CurrentPositionScreen.cpp Screens/CurrentPositionScreen.h Screens/CurrentTimeScreen.cpp Screens/CurrentTimeScreen.h Screens/DebugScreen.cpp Screens/DebugScreen.h Screens/OdometerActionScreen.cpp Screens/OdometerActionScreen.h Screens/OdometerScreen.cpp Screens/OdometerScreen.h Screens/ParentScreen.cpp Screens/ParentScreen.h Screens/SatellitesScreen.cpp Screens/SatellitesScreen.h Screens/Screen.cpp Screens/Screen.h Screens/ScreenManager.cpp Screens/ScreenManager.h Screens/SelectorScreen.cpp Screens/SelectorScreen.h Screens/SettingsGroupScreen.cpp Screens/SettingsGroupScreen.h Screens/SpeedScreen.cpp Screens/SpeedScreen.h Screens/TimeZoneScreen.cpp Screens/TimeZoneScreen.h 8x12Font.cpp Buttons.cpp FontTest.cpp GPSDataModel.cpp GPSLogger.cpp GPSOdometer.cpp GPSSatellitesData.cpp GPSThread.cpp IdleThread.cpp TimeFont.cpp Utils.cpp ) INCLUDE_DIRECTORIES( . ${GPSLOGGER_LIBS_DIR}/AdafruitGFX ${GPSLOGGER_LIBS_DIR}/NeoGPS ${GPSLOGGER_LIBS_DIR}/STM32duino/libraries/Adafruit_SSD1306 ${GPSLOGGER_LIBS_DIR}/STM32duino/libraries/SPI/src ${GPSLOGGER_LIBS_DIR}/STM32duino/libraries/FreeRTOS821 ) # Do not link to libc or newlib-nano - we are not using anything from that SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --specs=nosys.specs") ADD_EXECUTABLE(GPSLogger ${SOURCE_FILES}) TARGET_LINK_LIBRARIES(GPSLogger NeoGPS FreeRTOS AdafruitGFX AdafruitSSD1306 ArduinoLibs STM32duino ) STM32_SET_TARGET_PROPERTIES(GPSLogger) STM32_PRINT_SIZE_OF_TARGETS(GPSLogger) # Additional handy targets STM32_ADD_HEX_BIN_TARGETS(GPSLogger) STM32_ADD_DUMP_TARGET(GPSLogger)
CMakeèªäœã®ãã©ã¡ãŒã¿ãŒã«ã€ããŠã¯ã stm32-cmakeã®äŸã§ã¯ ã䜿çšããããŒã«ãã§ãŒã³ãã¡ã€ã«ãæå®ããããšããå§ãããŸãã ããã¯ãã¡ã€ã¯ãã¡ã€ã«ãçæããCMakeåŒã³åºãäžã«å¥ã®ããŒã§å®è¡ãããŸãã ããããç°ãªããã©ãããã©ãŒã ãã³ã³ãã€ã©ãŒåãã«ãããžã§ã¯ãããã«ãããäºå®ã¯ãããŸããã ãããã£ãŠãå¿ èŠãªããŒã«ãã§ãŒã³ãã¡ã€ã«ãžã®ãªã³ã¯ãã¡ã€ã³CMakeLists.txtã«ç»é²ããŸããã
# Load the toolchain file that uses vars above SET(CMAKE_TOOLCHAIN_FILE cmake/gcc_stm32.cmake)
ãã ããã³ã³ãã€ã©ã¯èªåçã«æšæž¬ããŸããã ããæ£ç¢ºã«ã¯ãUnixïŒ/ usrã®ããã©ã«ãã®ãã¹ã§æ€çŽ¢ãããŸãïŒã§æšæž¬ããŠããŸããããWindowsã§ã¯æ瀺çã«æå®ããå¿ èŠããããŸãã äžè¬ã«ãç§ã®ã³ãã³ãã©ã€ã³ïŒWindowsã®ã¹ã©ãã·ã¥ãUnixã«å€æŽããããšãå¿ããªãã§ãã ãã-CMakeã¯ããããæ°ã«å ¥ããªãïŒ
cmake -G "MinGW Makefiles" "-DTOOLCHAIN_PREFIX=C:/Program Files (x86)/GNU Tools ARM Embedded/5.4 2016q3" .
ã¡ã€ã¯ã¢ãããã¡ã€ã«ãçæããããããžã§ã¯ãã®ãã«ããéå§ã§ããŸãã ã³ã³ãã€ã«ã«ç¹å¥ãªåé¡ã¯ãããŸããã§ããã ãããããã®åŸã匷åãªãªã³ã«ãŒããžãã¯ãšã®éããå§ãŸããŸããã 以äžã¯ãç§ãéäžã§è§£æ±ºããåã ã®åé¡ã®ãªã¹ãã§ãã
åé¡ïŒã©ã€ãã©ãªéã®çžäºäŸåé¢ä¿
stm32duinoãã¬ãŒã ã¯ãŒã¯ã¯ããªã倧ããã§ãã ã©ã€ãã©ãªçšã®CMakeList.txtãäœæãã段éã§ããArduino APIïŒstm32duinoèªäœïŒããšãã¥ã¬ãŒãããéšåãšãããŒããŠã§ã¢ã¢ãã¹ãã©ã¯ã·ã§ã³ã¬ã€ã€ãŒïŒHALïŒã§ãããã€ã¯ãã³ã³ãããŒã©ã®äœã¬ãã«éšåãé ãlibmapleããšãã¥ã¬ãŒããã2ã€ã®ã©ã€ãã©ãªã«åå²ããããšããŸããã ãããã«ãããããã¯ç§ã«ãšã£ãŠçã«ããªã£ãŠããããã«æããŸããã ãããããªã³ã¯ããã«ã¯åé¡ãããããšãå€æããŸããã stm32duinoã¯libmapleã®äžã«æ§ç¯ãããŠãããšæããŸãããã2çªç®ã«ã¯æäžå±€ãžã®åŒã³åºãããããŸããã
åè«ã¯ããªã³ã«ãŒãã©ã€ãã©ãªãäžåºŠã«1ã€ãã€åéãã以åã®ã©ã€ãã©ãªã«æ»ããªããšããããšã§ãã 2çªç®ã®ã©ã€ãã©ãªãæåã®ã©ã€ãã©ãªãåŒã³åºãå Žåããªã³ã«ãŒã¯æåã®ã©ã€ãã©ãªãå床ãªã³ã¯ããå¿ èŠãããããšãç解ããŸããã ãããã£ãŠãæªè§£æ±ºã®æåãçºçããŸãã ãããžã§ã¯ãã§ã¯2ã€ã®ã©ã€ãã©ãªã1ã€ã«çµåããå¿ èŠããããŸããã
ãããããã®åŸããªã³ã«ã®åäœãå€æŽããç¹å¥ãªããŒ-Wlã-start-group / --end-groupããªã³ã«ã«ããããšãããããŸããã 圌ãã¯åœŒã«æ°åå³æžé€šãééãããã ãã§ãã ãŸã è©ŠããŠããŸããã
stm32duinoãšlibmapleããã«ãããCMakeã¹ã¯ãªãã
################### # STM32duino, libmaple and system layer # Has to be as a single library, otherwise linker does not resolve all crossreferences # Unused files are commented on the list ################### SET(LIBMAPLE_SRC STM32duino/variants/generic_stm32f103c/board.cpp STM32duino/variants/generic_stm32f103c/wirish/boards.cpp STM32duino/variants/generic_stm32f103c/wirish/boards_setup.cpp STM32duino/variants/generic_stm32f103c/wirish/start.S STM32duino/variants/generic_stm32f103c/wirish/start_c.c STM32duino/variants/generic_stm32f103c/wirish/syscalls.c STM32duino/cores/maple/cxxabi-compat.cpp # STM32duino/cores/maple/ext_interrupts.cpp STM32duino/cores/maple/HardwareSerial.cpp # STM32duino/cores/maple/HardwareTimer.cpp # STM32duino/cores/maple/IPAddress.cpp STM32duino/cores/maple/main.cpp # STM32duino/cores/maple/new.cpp STM32duino/cores/maple/Print.cpp # STM32duino/cores/maple/pwm.cpp # STM32duino/cores/maple/Stream.cpp # STM32duino/cores/maple/tone.cpp STM32duino/cores/maple/usb_serial.cpp # STM32duino/cores/maple/wirish_analog.cpp STM32duino/cores/maple/wirish_digital.cpp # STM32duino/cores/maple/wirish_math.cpp # STM32duino/cores/maple/wirish_shift.cpp STM32duino/cores/maple/wirish_time.cpp # STM32duino/cores/maple/WString.cpp # STM32duino/cores/maple/hooks.c STM32duino/cores/maple/itoa.c # STM32duino/cores/maple/stm32f1/util_hooks.c # STM32duino/cores/maple/stm32f1/wiring_pulse_f1.cpp STM32duino/cores/maple/stm32f1/wirish_debug.cpp STM32duino/cores/maple/stm32f1/wirish_digital_f1.cpp STM32duino/cores/maple/libmaple/adc.c STM32duino/cores/maple/libmaple/adc_f1.c # STM32duino/cores/maple/libmaple/bkp_f1.c # STM32duino/cores/maple/libmaple/dac.c # STM32duino/cores/maple/libmaple/dma.c # STM32duino/cores/maple/libmaple/dma_f1.c # STM32duino/cores/maple/libmaple/exc.S # STM32duino/cores/maple/libmaple/exti.c # STM32duino/cores/maple/libmaple/exti_f1.c STM32duino/cores/maple/libmaple/flash.c # STM32duino/cores/maple/libmaple/fsmc_f1.c STM32duino/cores/maple/libmaple/gpio.c STM32duino/cores/maple/libmaple/gpio_f1.c STM32duino/cores/maple/libmaple/i2c.c STM32duino/cores/maple/libmaple/i2c_f1.c STM32duino/cores/maple/libmaple/iwdg.c STM32duino/cores/maple/libmaple/nvic.c # STM32duino/cores/maple/libmaple/pwr.c STM32duino/cores/maple/libmaple/rcc.c STM32duino/cores/maple/libmaple/rcc_f1.c # STM32duino/cores/maple/libmaple/spi.c # STM32duino/cores/maple/libmaple/spi_f1.c STM32duino/cores/maple/libmaple/systick.c STM32duino/cores/maple/libmaple/timer.c # STM32duino/cores/maple/libmaple/timer_f1.c STM32duino/cores/maple/libmaple/usart.c STM32duino/cores/maple/libmaple/usart_f1.c STM32duino/cores/maple/libmaple/usart_private.c STM32duino/cores/maple/libmaple/util.c STM32duino/cores/maple/libmaple/stm32f1/performance/isrs.S STM32duino/cores/maple/libmaple/stm32f1/performance/vector_table.S STM32duino/cores/maple/libmaple/usb/stm32f1/usb.c STM32duino/cores/maple/libmaple/usb/stm32f1/usb_cdcacm.c STM32duino/cores/maple/libmaple/usb/stm32f1/usb_reg_map.c STM32duino/cores/maple/libmaple/usb/usb_lib/usb_core.c STM32duino/cores/maple/libmaple/usb/usb_lib/usb_init.c STM32duino/cores/maple/libmaple/usb/usb_lib/usb_mem.c STM32duino/cores/maple/libmaple/usb/usb_lib/usb_regs.c ) ADD_LIBRARY(STM32duino STATIC ${LIBMAPLE_SRC}) TARGET_INCLUDE_DIRECTORIES(STM32duino PRIVATE STM32duino/system/libmaple/usb/stm32f1 STM32duino/system/libmaple/usb/usb_lib ) TARGET_COMPILE_DEFINITIONS(STM32duino PRIVATE -DVECT_TAB_ADDR=${VECT_TAB_ADDR} -DGENERIC_BOOTLOADER -DBOARD_maple )
åé¡ïŒã·ã¹ãã ã³ãŒã«ããªã³ã¯ããªã
ããã«ãæšæºã©ã€ãã©ãªãšæ£åžžã«ãªã³ã¯ããããšã¯ã§ããŸããã§ãã-_sbrkïŒïŒã_ openïŒïŒ/ _ closeïŒïŒã_ readïŒïŒ/ _ writeïŒïŒãããã³äœããã®çç±ã§æšæºã©ã€ãã©ãªããçªãåºãŠããä»ã®ããã€ããæ¬ èœããŠããŸããã
å®éããããã¯STM32duino \ variant \ generic_stm32f103c \ wirish \ syscalls.cã«äºçŽ°ãªå®è£ ãæã£ãŠããŸãããåãçç±ã§ãªã³ã¯ããŸããã§ããïŒstm32duinoããªã³ã¯ãããšãã«ãããã®é¢æ°ïŒåŒ±ããšå®£èšãããŠããŸãïŒã¯äžèŠã§ãããæšãŠãããŸãã æšæºã©ã€ãã©ãªã¯ããªã³ã¯ããã»ã¹ã®æåŸã§æé»çã«æ¥ç¶ããããããã®æåãèŠæ±ãå§ããŸããããªã³ã«ãŒã¯æ»ããŸããã ãã¡ãããsyscalls.cãã¡ã€ã«ãä»ã®ãã¹ãŠã®åŸã«åå¥ã«ãªã³ã¯ã§ããŸãããçŽç²ã«ã¹ããŒãã®èå³ãããã©ãããæ¥ãã®ããææ¡ãå§ããŸããã
äžéšã®ã·ã¹ãã ã³ãŒã«ã®ç°¡åãªå®è£
__weak int _open(const char *path, int flags, ...) { return 1; } __weak int _close(int fd) { return 0; } __weak int _fstat(int fd, struct stat *st) { st->st_mode = S_IFCHR; return 0; } __weak int _isatty(int fd) { return 1; } __weak int isatty(int fd) { return 1; } __weak int _lseek(int fd, off_t pos, int whence) { return -1; } __weak unsigned char getch(void) { return 0; } __weak int _read(int fd, char *buf, size_t cnt) { *buf = getch(); return 1; } __weak void putch(unsigned char c) { }
ç§ãç解ããŠããããã«ãarm-gccã³ã³ãã€ã©ã¯éåžžã«åŒ·åã§ãããæ¢åã®ãã€ã¯ãã³ã³ãããŒã©ãšããã»ããµã®ããªãã®ååã§ã³ã³ãã€ã«ã§ããŸãã ããããå°ããªã¡ã¢ãªãæèŒããå°åã®ãã€ã¯ãã³ã³ãããŒã©ãŒããŸãã¯Linuxããããããšãã§ããåããç³ãã«ãªãå¯èœæ§ãããããããã©ãããã©ãŒã ã®æ©èœãèæ ®ããŠçµã¿ç«ãŠãå¿ èŠããããŸãã ãããã£ãŠããªã³ã«ãŒã«ã¯ãç¹å®ã®ãã©ãããã©ãŒã ã«ãªã³ã¯ããå¿ èŠããããã®ãæ£ç¢ºã«èšè¿°ãã* .specsãã¡ã€ã«ã®ã»ããããããŸãïŒããã¯ãªã³ã«ãŒã¹ã¯ãªããã«è¿œå ãããŸãïŒã
ãã®ãããããã©ã«ãã§ã¯ãæšæºã©ã€ãã©ãªã¯ãããžã§ã¯ãïŒãã®å Žåã¯newlib-nanoïŒã«ãªã³ã¯ãããŠããŸãã 倧åã³ã³ãã¥ãŒã¿ãŒã®libcãã·ã¹ãã ã³ãŒã«ãšã«ãŒãã«ã«äŸåããŠããå Žåã®ã¿ãnewlib-nanoã®å ŽåããŠãŒã¶ãŒã¯ãããã®ã·ã¹ãã ã³ãŒã«ãæäŸããå¿ èŠããããŸãã ãããã£ãŠããªã³ã«ã§ã¯ãããããšåã_sbrkïŒïŒã_ openïŒïŒ/ _ closeïŒïŒã_ readïŒïŒ/ _ writeïŒïŒã®å®£èšãå¿ èŠã§ãã
ãã®åé¡ã¯ããªã³ã«ãŒèšå®ã«--specs = nosys.specsããŒãè¿œå ããããšã§è§£æ±ºããŸããã ãã®ããŒã¯ãæšæºã©ã€ãã©ãªã®äžéšã®ãªã³ã¯ãç¡å¹ã«ãªã£ãŠããã¹ããã¯ãã¡ã€ã«ããªã³ã«ã«ç€ºããŸãã
# Do not link to libc or newlib-nano - we are not using anything from that SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --specs=nosys.specs")
åé¡ïŒåæåã³ãŒãããªã³ã¯ããªã
ããæç¹ã§ã_initïŒïŒé¢æ°ã®åé¡ãæããã«ãªããŸããã newlib-nanoãããã®é¢æ°ã®åŒã³åºãããããŸãããã³ãŒãã§ã¯ãã®ã·ã³ãã«ã¯ã©ãã«ã宣èšãããŠããŸããã ããã§ã®ãã¶ã€ã³ã®èãæ¹ã¯æ¬¡ã®ãšããã ãšæããŸãã
- ãªã»ãããŸãã¯é»æºæå
¥åŸãæäœã¬ãã«ã®èµ·åãå®è¡ãããŸãã libmapleã®å Žåãããã¯STM32duino \ variant \ generic_stm32f103c \ wirish \ start.Sã§ãã ãã®ã³ãŒãã®ã¿ã¹ã¯ã¯ãå¶åŸ¡ãåæåé¢æ°ã«è»¢éããããšã§ã
start.S.type __start__, %function __start__: .fnstart ldr r1,=__msp_init mov sp,r1 ldr r1,=start_c bx r1 .pool .cantunwind .fnend
- 次ã®ã¹ãããã¯ãã¡ã¢ãªãæºåããããšã§ãã ããã§ã.bssã»ã¯ã·ã§ã³ïŒãŒãã§åããããå€æ°ïŒãæ¶å»ãã.dataã»ã¯ã·ã§ã³ã®å€æ°ã«åæå€ãå
¥åããŸãã³ãŒãã¯ããã¡ã€ã«STM32duino \ variant \ generic_stm32f103c \ wirish \ start_c.cã«ãããŸã
start_c.cvoid __attribute__((noreturn)) start_c(void) { struct rom_img_cfg *img_cfg = (struct rom_img_cfg*)&_lm_rom_img_cfgp; int *src = img_cfg->img_start; int *dst = (int*)&__data_start__; int exit_code; /* Initialize .data, if necessary. */ if (src != dst) { int *end = (int*)&__data_end__; while (dst < end) { *dst++ = *src++; } } /* Zero .bss. */ dst = (int*)&__bss_start__; while (dst < (int*)&__bss_end__) { *dst++ = 0; } /* Run initializers. */ __libc_init_array(); /* Jump to main. */ exit_code = main(0, 0, 0); if (exit) { exit(exit_code); } /* If exit is NULL, make sure we don't return. */ for (;;) continue; }
- ãã®åŸãå¶åŸ¡ã¯newlib-nanoãã__libc_init_arrayïŒïŒé¢æ°ã«è»¢éãããŸãã ãã®é¢æ°ã§ã¯ãã°ããŒãã«ãªããžã§ã¯ãã³ã³ã¹ãã©ã¯ã¿ãŒã ãã§ãªããããŒããåæåããããã®premainïŒïŒããã³initïŒïŒé¢æ°ãå«ãåæååãåŒã³åºãããŸãã
__libc_init_arrayïŒïŒ/* Iterate over all the init routines. */ void __libc_init_array (void) { size_t count; size_t i; count = __preinit_array_end - __preinit_array_start; for (i = 0; i < count; i++) __preinit_array_start[i] (); _init (); count = __init_array_end - __init_array_start; for (i = 0; i < count; i++) __init_array_start[i] (); }
premainïŒïŒããã³initïŒïŒ// Force init to be called *first*, ie before static object allocation. // Otherwise, statically allocated objects that need libmaple may fail. __attribute__(( constructor (101))) void premain() { init(); } void init(void) { setup_flash(); setup_clocks(); setup_nvic(); systick_init(SYSTICK_RELOAD_VAL); wirish::priv::board_setup_gpio(); setup_adcs(); setup_timers(); wirish::priv::board_setup_usb(); wirish::priv::series_init(); boardInit(); }
- åæã«ã__ libc_init_arrayïŒïŒã䜿çšãããšãåæåã®ç¹å®ã®æ®µéã®éã«ãŠãŒã¶ãŒå®çŸ©é¢æ°ãããã¯ããŠåŒã³åºãããšãã§ããŸãã ãããŠããã®é¢æ°ã¯_initïŒïŒãšåŒã°ããã¹ãã§ãã åã®ã»ã¯ã·ã§ã³ã®ä»ã®ã·ã¹ãã ã³ãŒã«ãšåæ§ã«ããã®é¢æ°ã¯ä»ã®èª°ããæäŸããå¿
èŠããããŸãã
- 次ã«mainïŒïŒãåŒã³åºãããŸãããçŸæç¹ã§ã¯ããã«ã¯èå³ããããŸããã
ç§ãç解ããŠããããã«ã_initïŒïŒé¢æ°ã¯éžæãããã©ãããã©ãŒã ã«å¿ããŠçœ®æããå¿ èŠããããŸããããšãã°ããã®å®è£ ã¯æ¬¡ã®ãšããã§ãã<ARM Toolchain> \ lib \ gcc \ arm-none-eabi \ 5.4.1 \ armv7-m \ crti.o Arduinoã¯ãªãããã®æ¹æ³ã§æé»çã«ãã®ãªããžã§ã¯ããæ¥ç¶ããŸããããã®ãã¡ã€ã«ã¯ç§ã®ããã«ãã«ã¢ããããŸããã§ããã ããã¯ããããã-specs = nosys.specsããŒã䜿çšããŠæšæºã©ã€ãã©ãªã®äžéšãç¡å¹ã«ããããã§ãã ããããã®æšå¥šã§ã空ã®å®è£ ãlibmapleã³ãŒãã«è¿œå ããŸããã
void __attribute__ ((weak)) _init(void) {}
è¯ãæå³ã§ã¯ããã®é¢æ°ã¯ç©ºã«ããªãã§ãã ããã premainïŒïŒãè¡ãããšãè¡ãå¿ èŠããããŸã-ããŒããåæåããŸãã ããããstm32duinoã®äœæè ã¯ç°ãªã決å®ãããŸããã
äžè¬ã«ããã¹ãŠããªã³ã¯ãããŠããŸãããããã¡ãŒã ãŠã§ã¢ã¯ãŸã éåžžã«å€§èã§ãã-120kb以äžã ããã§äœèšãªãã®ãç解ããå¿ èŠããããŸããã ãããè¡ãã«ã¯ãããŒã«ãã§ãŒã³ã®ã¹ã¯ãªãããæ éã«ç 究ããæ¢ã«ã¢ã»ã³ãã«ããããã®ãå解ããå¿ èŠããããŸããã
åé¡ïŒã³ãŒãã»ã¯ã·ã§ã³ã誀ã£ãŠå®çŸ©ãããŠãã
æåã«ç®ãåŒããã®ã¯ãéå§ã¢ãã¬ã¹ã§ãã éå§ã¢ãã¬ã¹ã¯0x00000000ãŸãã¯0x00008000ã®ããããã§ãããã0x08002000ã§ããããšã¯ééããããŸããã STM32 CMakeããŒã«ãã§ãŒã³ãæ éã«ç 究ããçµæãå¿ èŠãªãã©ã¡ãŒã¿ãŒããªã³ã«ã¹ã¯ãªããã§èšå®ãããŠããããšã«æ°ä»ããŸããã ããã¯ããŒã«ãã§ãŒã³ã«ãä»å±ããŠããŸãã ãã®ã¹ã¯ãªããã®ã¿ãããã©ã«ãã§ã¯äœ¿çšãããŸããããå¥ã®ã³ãã³ãSTM32_SET_TARGET_PROPERTIESïŒïŒã«å«ãŸããŠããŸãã éå§ã¢ãã¬ã¹ãä¿®æ£ããããã¡ãŒã ãŠã§ã¢ã¯100kã«ãŸã§æžããŸããã
# Flash offset due to bootloader SET(VECT_TAB_ADDR "0x08002000") SET(STM32_FLASH_ORIGIN "0x08002000") ADD_EXECUTABLE(GPSLogger ${SOURCE_FILES}) STM32_SET_TARGET_PROPERTIES(GPSLogger)
ããã§ãã³ãŒãã®ãã¡ãŒã ãŠã§ã¢ã®æåã«å²ã蟌ã¿ãã¯ã¿ãŒã®ããŒãã«ããããŸããã§ããã ãã¡ã€ã«å ã®ã»ã¯ã·ã§ã³ã®èª¬æããå€æãããšãããŒãã«ã¯å¥ã®ã»ã¯ã·ã§ã³.isr_vectorã«ãããŸãããäœããã®çç±ã§ãã®ãµã€ãºã¯ãŒãã§ãã
1æéãç§ã¯ãªã³ã«ãŒã¹ã¯ãªãããç解ããããšããŠããŸããã ããããããã€ãã®éåžžã«åŒ·åãªäœã¬ãã«ã®éè¡ãããã§è¡ãããŸããããã€ãã®ã»ã¯ã·ã§ã³ã決å®ãããã³ãŒããžã®äœããã®åç §ããããŸãã ç¹ã«ãç§ãç解ããŠããããã«ãå²ã蟌ã¿ãã¯ãã«ã®ããŒãã«ãå«ãã»ã¯ã·ã§ã³ã¯ãã³ãŒãã®ã©ããã«ããæ¹æ³ã§èª¬æããå¿ èŠããããŸãïŒããããCMSISã«ãããŸãã ã€ãŸã ç§ã®ééãã¯ãlibmapleããã®åæåã³ãŒãã§æ±çšãªã³ã«ãŒã¹ã¯ãªããã䜿çšããããšããŠããããšã§ããã³ãŒããšããŒã¿ã»ã¯ã·ã§ã³ã®ååãšé 眮ã¯ç°ãªããŸãã
解決çã¯ãlibmapleãããªã³ã¯ã¹ã¯ãªãããæ瀺çã«æå®ããããšã§ããïŒ STM32duino / variant / generic_stm32f103c / ld / bootloader_20.ld ïŒ
# Using Maple's linker script that corresponds maple/stm32duino code SET(STM32_LINKER_SCRIPT ${GPSLOGGER_LIBS_DIR}/STM32duino/variants/generic_stm32f103c/ld/bootloader_20.ld) LINK_DIRECTORIES(${GPSLOGGER_LIBS_DIR}/STM32duino/variants/generic_stm32f103c/ld)
åé¡ïŒäžé©åãªæé©åèšå®
ããããããã¯æ®å¿µã§ãã ãªã³ã«ã¯ãçæãããã³ãŒãããã©ãã·ã¥ãã©ã€ãã«åããããšãã§ããªããšèšã£ãã å€æ°ã®äžèŠãªããã¯ããã¡ãŒã ãŠã§ã¢ã«äŸµå ¥ãããšããäºå®ã«å ããŠãCMakeã¯ããã©ã«ãã§ããŒã²ã³æ§æã§åéããããšãå€æããŸããã ãããã°æ§æã§ã¯ãæé©åã¯-O2ïŒé床ã®æé©åïŒã§ããããªãªãŒã¹æ§æã§ã¯-OsïŒãµã€ãºã®æé©åïŒã§ãã ãªãªãŒã¹æ§æã«åãæ¿ããŸããããããã§ãããŸããããŸããã§ãããããŒã«ãã§ãŒã³ã¯-fltoãã©ã°ïŒLink Time OptimizationïŒãèšå®ããŸããããã¯stm32duinoã®ååã§ã¯ãã«ããããŸããã
äžè¬ã«ãç§ã¯2ã€ã®æ§æãããã¹ãŠã®ãã¹ããåããŸããã ãªãªãŒã¹æ§æããã-Osã¹ã€ããã䜿çšããŸããã ãããã°ãã-gãåããŸãããããã¯ããããã°æ å ±ãbinarã«è¿œå ããŸãã ãšã«ããããã®æ å ±ã¯ãã¡ãŒã ãŠã§ã¢ã«ã¯å ¥ããŸãããå解ããæ¹ãã¯ããã«äŸ¿å©ã§ãã
# TODO: It would be nice to use -flto for all of these 3 settings (except for asm one) SET(CMAKE_C_FLAGS_RELEASE "-Os -g" CACHE INTERNAL "c compiler flags release") SET(CMAKE_CXX_FLAGS_RELEASE "-Os -g" CACHE INTERNAL "cxx compiler flags release") SET(CMAKE_ASM_FLAGS_RELEASE "-g" CACHE INTERNAL "asm compiler flags release") SET(CMAKE_EXE_LINKER_FLAGS_RELEASE "" CACHE INTERNAL "linker flags release")
ãã¡ãŒã ãŠã§ã¢ã®ãµã€ãºãããã«å°ããããã«ã¯ãæ£ããã³ã³ãã€ã«ããŒãšã³ãŒãçæããŒã®éžæãããã³å ã®ãã«ãã·ã¹ãã ã瀺ãå¿ èŠãªãã¹ãŠã®å®çŸ©ã®ç¹°ãè¿ããå¿ èŠã§ãã ããäžåºŠãããŒã®ãªã¹ãå šäœãæ¯èŒããŠããããžã§ã¯ãã«ã«ããã«ãè¿œå ããããšã«ããŸããã
- -DDEBUG_LEVEL = DEBUG_NONEã¯ã libmapleå ã®ãã®ã³ã°ãç¡å¹ã«ããŸãã å®çŸ©ãããšãçµæã®ãã¡ãŒã ãŠã§ã¢ããçŽãããã€ããåé€ãããŸã
- -fno-rtti -fno-exceptions-倧éã®ã³ãŒãïŒåãRTTIãäŸå€ãABIãªã©ïŒãåé€ããŸãã åœç¶ããããã®ãã©ã°ã¯g ++
- -fno-unroll-loops -ffast-math -ftree-vectorizeã®çµã¿åããã¯ãå°ãã³ã³ãã¯ããªã³ãŒãïŒãã¡ãŒã ãŠã§ã¢å šäœã§100ã200ãã€ãïŒãçæããã ãã§ãã
ããã«ç§ã®ããŒããããæçµçã«ã³ã³ãã€ã©ã«æž¡ããŸãïŒ
SET(CMAKE_C_FLAGS "-mthumb -fno-builtin -mcpu=cortex-m3 -Wall -std=gnu99 -ffunction-sections -fdata-sections -fomit-frame-pointer -mabi=aapcs -fno-unroll-loops -ffast-math -ftree-vectorize -nostdlib -march=armv7-m --param max-inline-insns-single=500" CACHE INTERNAL "c compiler flags") SET(CMAKE_CXX_FLAGS "-mthumb -fno-builtin -mcpu=cortex-m3 -Wall -std=c++11 -ffunction-sections -fdata-sections -fomit-frame-pointer -mabi=aapcs -fno-unroll-loops -ffast-math -ftree-vectorize -fno-rtti -fno-exceptions -nostdlib -fno-use-cxa-atexit -march=armv7-m --param max-inline-insns-single=500" CACHE INTERNAL "cxx compiler flags") SET(CMAKE_ASM_FLAGS "-mthumb -mcpu=cortex-m3 -x assembler-with-cpp" CACHE INTERNAL "asm compiler flags") SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--gc-sections -mthumb -mcpu=cortex-m3 -march=armv7-m -mabi=aapcs -Wl,--warn-common -Wl,--warn-section-align" CACHE INTERNAL "executable linker flags")
ãã«ãã·ã¹ãã ã«å¯Ÿããåå©
ãã¡ãŒã ãŠã§ã¢ã®çµæã¯48ãããã€ãã§ãã ArduinoããŒãžã§ã³ã¯56kbã§ããã éãã¯ãmalloc / freeããã³é¢é£ããé¢æ°ãäžè¶³ããŠããããã§ãããããã¯ãŸã 䜿çšããŠããŸããã å®å šãªåæ§ç¯ã«ã¯ãarduinoã§1åãããã®ã«17ç§ããããŸãã ããã1ã2ç§ã§ã€ã³ã¯ãªã¡ã³ã¿ã«ã¢ã»ã³ããªã
çå®ã®ç¬éãšãããã§äœãèµ·ãã£ãã®ããèšå ¥ããŠã¿ãŠãã ããã æ£çŽã«èšããšãã¿ã³ããªã³ãGoogleãCMakeã®äŒç€Ÿã§ãã®ãããªé·ããã³ã¹ãããåŸããã¡ãŒã ãŠã§ã¢ãããã«èµ·åããããšã«éåžžã«é©ããŸããã ãã®éçãå°ãªããšãé»çã§ç¹æ» ããããªãçç±ãç解ããããã«ããã©ãã¯ããã¯ã¹ã¢ãŒãã§ã®ããŒããããã°ã®ãã1é±éãæåŸ ããŠããŸããã
çŸããã®ããã«ãåŒã³åºãSTM32_PRINT_SIZE_OF_TARGETSïŒïŒãè¿œå ããŸãã-ã¢ã»ã³ããªåŸãã¡ã¢ãªã®çµ±èšãã³ã³ãœãŒã«ã«æžã蟌ãŸããŸãã ã¡ã¢ãªæ¶è²»ãæ¥å¢ãããã©ãããããã«ç¢ºèªã§ããŸãã
ãŸãããã¡ãŒã ãŠã§ã¢ãå解ããããã®ã¿ãŒã²ãããè¿œå ããŸããïŒçŸæç¹ã§ã¯ãã¡ã€ã³ãã©ã³ãstm32-cmakeã§æ¢ã«æäŸãããŠããŸã ïŒã ããã«ã³ã³ãã€ã©ãè¡ã£ãããšããã«ãããŠããã«ç¢ºèªããã®ã¯éåžžã«äŸ¿å©ã§ãããã¡ãŒã ãŠã§ã¢ãçªç¶å€§ãããªã£ãŠããŸã£ãã®ã§ãã
FUNCTION(STM32_ADD_DUMP_TARGET TARGET) IF(EXECUTABLE_OUTPUT_PATH) SET(FILENAME "${EXECUTABLE_OUTPUT_PATH}/${TARGET}") ELSE() SET(FILENAME "${TARGET}") ENDIF() ADD_CUSTOM_TARGET(${TARGET}.dump DEPENDS ${TARGET} COMMAND ${CMAKE_OBJDUMP} -x -D -S -s ${FILENAME} | ${CMAKE_CPPFILT} > ${FILENAME}.dump) ENDFUNCTION()
QtCreator
äžèšã®ã¢ã»ã³ããªããã»ã¹å šäœãã³ã³ãœãŒã«ã§ç°¡åã«å®è¡ããŸããã 次ã«ãIDEãæ¥ç¶ããŸãã ãã§ã«Eclipseã«ã€ããŠç¥ããããšèšã£ãŠããŸããããã€ã³ã¹ããŒã«ãããšããããã¯ã²ã©ãã¢ã³ã¹ã¿ãŒã®ããã«èŠããŸããã ããããæãéèŠãªããšã¯ãã¯ãŒã¯ã·ã§ããã®æŠå¿µãç解ããŠããªãã£ãããšã§ãã ç§ã®ç解ã§ã¯ããããžã§ã¯ããéããšããã®ãããžã§ã¯ãã®ãã¹ãŠã®ãã¡ã€ã«ãããã«è¡šç€ºãããŸãã Eclipseã¯å€ãã®äœåãªèº«äœã®åããããªããã°ãªããŸããã§ããã äžèšã§èšãã°ã圌ã¯ã¡ããã©å ¥ã£ãŠããŸããã§ããããç§ã¯ééããªã圌ã«ããäžåºŠæ»ãã€ããã§ãã
ç§ã¯ãã€ãŠQt Creatorã§ããã°ã©ãã³ã°ããããšãæãåºããŸããããããã¯æªããªãããã§ãã Qt Creator 4.2.2ãã€ã³ã¹ããŒã«ããåŸãCMakeãããžã§ã¯ãã®æ¥ç¶æ¹æ³ãã°ãŒã°ã«ã§èª¿ã¹å§ããŸããã ã€ã³ã¿ãŒãããäžã®æ瀺ã«åŸã£ãŠãCMakeLists.txtãã¡ã€ã«ãåã«éãããŠã£ã¶ãŒãã®æ瀺ã«åŸãããšããå§ãããŸããã ãŸã第äžã«ã圌ã¯ããŒã«ïŒãããïŒã®ã€ã³ã¹ããŒã«ãææ¡ããŸããã ã²ã©ãã«ã¹ã¿ã ã¢ã»ã³ããªãèãããšãããªãåççã§ãã
Qt Creatorã¯ãã®ãããªããããèªããŸãã圌ãã¯ã³ã³ãã€ã©ãå ¬éãããŠããªããšèšããŸãã ããããããªãããããèšå®ãããšãããã¯ãŸã èªããŸã-CMakeèªäœãèšå®ããã³ã³ãã€ã©ïŒarm-gccïŒã¯ãïŒåãã§ãã£ãŠãïŒå¯Ÿå¿ãããã£ãŒã«ãã§éžæããããã®ãšäžèŽããŸããã ãã ãã圌ã¯ãã¹ãŠãæ£åžžã«æ§ç¯ããŸãã
ãããžã§ã¯ãã®ã»ããã¢ããæã«ãéåžžã«éèŠãªç¬éã1ã€çºçããŸããã CMakeãããžã§ã¯ããã€ã³ããŒããããšãCMakeLists.txtã®ã¿ãã€ã³ããŒããããŸããã ãããžã§ã¯ãã«ãœãŒã¹ã³ãŒãã¯è¿œå ãããŠããŸããã ç§ã¯æ°æ©ã€ã³ã¿ãŒããããå匷ããŸãã-圹ã«ç«ã¡ãŸããã§ããã ãã¹ãŠã¯ãã¹ãŠã®äººã«æå¹ã§ãããç§ã«ã¯æå¹ã§ã¯ãããŸããã åé¡ã¯ã«ã¹ã¿ã ããŒã«ãã§ãŒã³ã«ãããšæããŸããããMinGW32ã®æãåçŽãªHello Worldã¯åãæ¹æ³ã§ã€ã³ããŒããããŸããã§ããã
ãœãªã¥ãŒã·ã§ã³ã¯QtCreatorèªäœã«ãã£ãŠææ¡ãããŸããã ç§ãäœæããããŒã«ãããã®ããŒã«ã¯ãééã£ãã¿ã€ãã®CMakeãžã§ãã¬ãŒã¿ãŒãéžæãããšèšã£ãŠããŸãã ã³ãŒããããã¯ãéžæããå¿ èŠããããŸã-ããããªããšãQt Creatorã¯ãããžã§ã¯ãã解æã§ããŸããã æ£ãããžã§ãã¬ãŒã¿ãŒãã€ã³ã¹ããŒã«ãããšããã¹ãŠã®ãã¡ã€ã«ãšãµããã£ã¬ã¯ããªããããžã§ã¯ããŠã£ã³ããŠã«è¡šç€ºãããŸããã
ããã§ããã¡ã€ã«éãç°¡åã«ç§»åã§ããŸããããªãŒãã³ã³ããªãŒãã¯ãŸã æ©èœããŠããŸããã å®éãã©ããªã«å¥åŠã«èãããŠããQt Creatorã¯CMakeLists.txtã§æå®ãããå å«ãã¹ãåã«ç¡èŠããŸããã ã€ãŸã ã¢ã»ã³ããªã¯æ£åžžã«åäœãããšãã£ã¿ãŒã§ã¯ãïŒinclude'ovã®ã»ãšãã©ããšã©ãŒïŒãã®ãããªãã¡ã€ã«ã¯ãããŸããïŒãšããŠåŒ·èª¿è¡šç€ºãããŸãã åããã£ã¬ã¯ããªããã®äœæ¥ã®ã¿ãå«ãŸããŸãã ãã¹ãŠã®èšå®ãç»ããæ°æéã°ãŒã°ã«ã§æ€çŽ¢ããŸããããçããèŠã€ãããŸããã§ããã
æŽæ° ïŒã³ã¡ã³ãã§ã¯ããªãŒãã³ã³ããªãŒãã¯ã³ã³ãã€ã©ãŒãä»ããŠæ©èœããããšã瀺åããŸããã ãããã£ãŠããããèšå®ã§æ£ããã³ã³ãã€ã©ãèšå®ããããšãéèŠã§ãã ãã ããQt Creatorã¯äŸç¶ãšããŠèªããŸããããªãŒãã³ã³ããªãŒãã¯æ©èœããŸãã
ããã¹ããšãã£ã¿ãæ¬æ ŒçãªIDEã«ããæã䟿å©ãªããšã®1ã€ã¯ããã¡ãŒã ãŠã§ã¢ã®èªåå ¥åãšèµ·åã§ãã ç§ã¯ãã®ããã«ããŸããã ç§ã«ãšã£ãŠã®äž»ãªãã«ãã¯GPSLogger.binã¿ãŒã²ããã§ãããå€å žçãªãã¹ãŠã§ã¯ãããŸããã ãã®ã¿ãŒã²ããã¯ã.elfãã¡ã€ã«ãã.binãã¡ã€ã«ãäœæããŸãããã®ãã¡ã€ã«ã¯ãæ¢ã«ã³ã³ãããŒã©ãŒã«æ¿å ¥ã§ããŸãã å±éæé ã«ããããã¡ãŒã ãŠã§ã¢ã®ããã©ããããèµ·åããŸãã
pingåŒã³åºãã®ããªãã¯ã«æ³šæããŠãã ããããã®ã¿ã¹ã¯ã¯ãå å¡«ãšéå§ã®éã«1ç§ã®äŒæ¢ãèšããããšã§ãããã以å€ã®å Žåããã€ã¯ãã³ã³ãããŒã©ã¯USBãåèµ·åããŠåæåããæéããããŸããã
ãã©ã³ããŒãïŒå®è¡ïŒãšããŠãã¿ãŒããã«ãšãã¥ã¬ãŒã¿ã䜿çšãããšäŸ¿å©ã§ããããšãããããŸããããã®ããšã«ããããããã°åºåãã·ãªã¢ã«ã§ãã£ããã§ããŸããã€ãŸãå®éãããŒãåŸã®ãã¡ãŒã ãŠã§ã¢ã¯èªåçã«èµ·åããŸããã·ãªãŒãºã«æžãããŠãããã®ãèŠãããã©ããã ããéžæããŸãã
ããããä»æ¥ã®ãããã°ã«ã€ããŠã¯ããã§ã¯ãããŸããã第äžã«ãããã«ã€ããŠã¯ãã§ã«äœåºŠãæžãããŠããŸãããæ°ãããã®ãçºæãããšã¯æããŸããã次ã«ããããã¬ãŒã䜿çšããŸããããã®ãããžã§ã¯ãã§ã¯ãã€ã³ãµãŒããããããã°ãå¿ èŠãšããããŒãããªãã§ã©ã«ã䜿çšããŸãããããã€ãã®UARTãšI2Cã®ã¿ã䜿çšããŠããŸãããã®ããããã°ã®å°å·ããã£ããŒã¹ããããšã¯ããªãå¯èœã§ãããããŠç¬¬äžã«ãç§ã¯ãŸã äžã¶æéã³ãŒããæžããŠããŸãã-ç§ã¯ãã¹ãŠãã«ãã·ã¹ãã ãšIDEãæ±ã£ãŠããŸããããš1é±éã2é±éãããŠãããã¬ãŒã«é£ã³èŸŒã¿ãããšã¯æããŸããã誰ãå¿ èŠã-Googleãããã¬ãããŸããŸãªIDEã«ãã蟌ãããšã«é¢ããå€ãã®èšäºããããŸãã
ãããã«
ã¢ã»ã³ããªãã¥ãŒããªã¢ã«ãäœæãããšããç®æšã¯èšå®ããŸããã§ãããããããç§ã®ãããžã§ã¯ãã«é©ãããã«ãã·ã¹ãã ãèŠã€ããããã«ãããã§ç§ã®çã¿ãšèŠãã¿ã«ã€ããŠèª¬æããŸãããã®èšäºã§ã¯ãSTM32ã³ã³ãããŒã©ãŒã§ãããžã§ã¯ãããã«ãããããã«CMakeã«åãæ¿ããçµéšãè¿°ã¹ãŸããã
libmapleã«åºã¥ããstm32duinoãã¬ãŒã ã¯ãŒã¯ã䜿çšããŸããããã¯éåžžã«æšæºçãªãã¬ãŒã ã¯ãŒã¯ã§ã¯ãªããããå€ãã®å°é£ãšéèŠãªç¬éããããŸãããäœæ¥ã®éçšã§ãããŒãã®åæåæ¹æ³ãlibcæ§é ãšãããäŸåãããã®ãã³ãŒãã»ã¯ã·ã§ã³ã§ã¡ã¢ãªã誰ãã©ã®ããã«åæ£ããããªã©ããªã³ã«ã®è€éããç解ããŸãããéåžžããããã¯CRTãã³ã³ãã€ã©ãIDEã®è žã«é ãããŠããŸããããã®å Žåããããã®ãã¥ã¢ã³ã¹ãæ確ã«æãäžããå¿ èŠããããŸããã
ãã®èšäºã§èª¬æããã·ã£ãŒãããºã ã®ã»ãšãã©ã¯ãSTM32å°çšã®ã¢ã»ã³ããªã«é¢é£ããŠããããšã«æ³šæããŠãã ãããATMegaã®åŸæ¥ã®arduinoãšã¢ã»ã³ããªã¯ç°¡åã§ããããããå€ãã®ã¢ã€ãã¢ã¯ãã©ãããã©ãŒã ã«é¢ä¿ãªãåããŸãŸã§ããææ ®æ·±ãèªè ã¯ãç§ã®èšäºã«ãå€ãã®æçšãªãã®ãèŠã€ãããšæããŸãã
ãããããç§ã¯ç¹å®ã®ããšãå®å šã«é瀺ãããã誀ã£ãå€æããããããŸããã§ããããŸããç§ã¯ãšã©ãŒã®å¯èœæ§ãæé€ããŸããããããã«ãããç§ã¯å»ºèšçãªæ¹å€ãåãå ¥ããŠããŸãã