èæ¯
CLionã¯ãC / C ++éçºç°å¢ã§ãããIntelliJ IDEAããã³ããã«å¿ããŠAndroid Studioã«è¿ããã®ã§ãã
ãã®IDEã䜿çšããŠãã€ã¯ãã³ã³ãããŒã©ãŒãã¡ãŒã ãŠã§ã¢ãäœæããæ¹æ³ã®æŠèŠã説æããããã°æçš¿ã®ç¿»èš³ããã³ãã¥ããã£ã®æ³šç®ãéããŠããŸãã
çŽ1幎ååãç§ã¯è±èªã§ããã°èšäºãæžããJetBrains CLionã䜿çšããŠãã€ã¯ãã³ã³ãããŒã©ãŒãããã°ã©ã ããæ¹æ³ã説æããŸããã
èŠããã«ãåœæç§ã¯STM32-Discoveryã·ãªãŒãºããŒãã®1ã€ã䜿çšããŸããã ãªã³ããŒãããã°ã©ãã¯ãSEGGER JLinkãšäºææ§ãããããã«å€æŽãããŸããã STM32CubeMXã³ãŒããžã§ãã¬ãŒã¿ãŒãGCC ARMããŒã«ãã§ãŒã³ãSEGGER Ozoneãããã¬ãŒã䜿çšãããŸããã ãã®ãã¹ãŠã§ãç§ã¯LEDãç¹æ» ãããããšã«æåããŸãã:)ã
ãã®ãããªããŒã«ã®ã»ããã¯å šäœãšããŠæ©èœããŸããããããã°ã©ããŒã®ãã©ãã·ã¥ãå€éšãããã¬ãŒã®èµ·åãå¿ èŠã§ããïŒçŽ æŽãããCLionãããå Žåããªãå¿ èŠãªã®ã§ããïŒïŒãããã«ãSEGGERã¯ãã®ãããªãã©ãã·ã¥ãããããã°ã©ããŒã«ããªãå³ããã©ã€ã»ã³ã¹å¶éã課ããŸãã
åœç¶ããããã®åé¡ã¯ãã¹ãŠç§ãæºè¶³ããããã®ã§ã¯ãªããããè¯ã解決çãèŠã€ããããšããŸããã 幞ããªããšã«ãé²æ©ã¯æ¢ãŸã£ãŠããããé·å¹Žã«ããã£ãŠCLionãšCubeMXã®äž¡æ¹ãå€§å¹ ã«æ¹åãããŠãããæãéèŠãªããšãšããŠãCLionã¯ãªã¢ãŒãGDBããµããŒãããŠããŸãã ãã€ã¯ãã³ã³ãããŒã©ã®ãã¡ãŒã ãŠã§ã¢ãã¢ããããŒãããã³ãããã°ããããã®ãœãããŠã§ã¢ãšããŠãOpenOCDïŒOpen On-Chip-DebuggerïŒã䜿çšããããšãçŸå®çã«ãªããŸããã ãã®ããã«ããŠãSEGGERã©ã€ã»ã³ã¹ã®å¶éãåãé€ãããªãŒãã³ãœãŒã¹ããŒã«ãåªå ããããšãã§ããŸãã ããã°ã©ããŒããã©ãã·ã¥ããå¿ èŠã¯ãããããŸãããã¿ãŒã²ããããã€ã¹ããã©ãã·ã¥ããå Žåã§ãããã¢ããŒãããã®ãŸãŸäœ¿çšã§ããŸãïŒST NucleoãŸãã¯DiscoveryããŒãã®ããã¥ã¡ã³ããåç §ïŒã
ãã¹ãŠãããã©CLionã§å®è¡ã§ããŸãããããããžã§ã¯ãã®ã»ããã¢ãããéåžžã«è€éã ã£ããããæçµçã«ç¬èªã®ãã©ã°ã€ã³ãäœæãããšããã¢ã€ãã¢ãæãä»ããŸãããããã«ããããã¹ãŠã®ããŒã«ãçžäºã«ãªã³ã¯ã§ããŸãã ãã®ããããã©ã°ã€ã³ãããŒã¿çã«ããJetBrainsãªããžããªã«å ¬éãããã¹ãŠãã©ã®ããã«æ©èœãããã瀺ãæºåãã§ããŸããã ããšãã°ãST Microelectronicsã®æã人æ°ã®ãããã¶ãŒããŒãã®1ã€ã§ããSTM32F4-Discoveryã䜿çšããŠãå°ããªãã¢ãããžã§ã¯ããäœæããŸãïŒé©ãïŒLEDãç¹æ» ãããŸãïŒïŒã STM32 NucleoãDiscoveryããŸãã¯EVALã·ãªãŒãºã®åããŒãã«ã¯LEDããããããããããªå€æŽãå ããåãäŸãå®è¡ã§ããŸãã
ããŒã«ããã
ã¯ã©ã€ãªã³
ãŸããå®éã«ã¯IDEãå¿ èŠã§ãã CLionã¯JetBrains Webãµã€ãããããŠã³ããŒãã§ããŸãã ã€ã³ã¹ããŒã©ãŒãå®è¡ããŠãæ瀺ã«åŸã£ãŠãã ããã ã©ã€ã»ã³ã¹ãå¿ èŠã«ãªããŸãããæåã®æéãã©ã€ã¢ã«ã§ååã§ãã ã€ã³ã¹ããŒã«æé ã¯ãã¡ã ã
ãã©ã°ã€ã³
CLionèšå®ã®[ ãã©ã°ã€ã³ ]ã¿ããéãã[ ãªããžããªã®åç §... ]ãã¯ãªãã¯ããŠã openocdããŒã¯ãŒãã§ãã©ã°ã€ã³ãèŠã€ããŸãã 次ã«ãCLion ãã€ã³ã¹ããŒã«ããŠåèµ·åããŸãã
ããã§ãå¥ã®å®è¡æ§æãCLionã«è¡šç€ºããã[ ããŒã« ]ã¡ãã¥ãŒã®2ã€ã®è¿œå é ç®ãèšå®ã®å¥ã®ã¿ãã衚瀺ãããŸãã
ããŒã«ãã§ãŒã³
ããŒã«ãã§ãŒã³ã¯ãããã°ã©ã ãšãã¡ãŒã ãŠã§ã¢ãæ§ç¯ããããã®ã¯ãã¹ãã©ãããã©ãŒã ããŒã«ãããã§ãã ã¯ãã¹ãã©ãããã©ãŒã -ããã¯ãã³ã³ãã€ã«ãPCãŸãã¯Macã§è¡ããããã«ãçµæãã¿ãŒã²ããããã€ã¹ã§ã®ã¿æ©èœããããšãæå³ããŸãã ç§ãã¡ã®å Žåãããã¯ARMäºæã®MKã§ãã
CLion ClangãŸãã¯GCCãç¡æã§ãµããŒãããŠãããã®ããåžè²©ã®ããŒã«ãã§ãŒã³ïŒKeilãIARãRaisonanceãªã©ïŒãªã©ãããã€ãã®ç°ãªãããŒã«ãã§ãŒã³ããããŸãã ç§ã¯å ¬åŒãœãŒã¹ããããŠã³ããŒãããGCCã䜿çšããŠããŸã- https://developer.arm.com/open-source/gnu-toolchain/gnu-rm ã€ã³ã¹ããŒã«åŸã«ãããŒã«ãã§ãŒã³ãã·ã¹ãã ãã¹ã«å«ããå¿ èŠãããããšã«æ³šæããŠãã ããã ããã確èªããã«ã¯ãã³ãã³ãã©ã€ã³ããarm-none-eabi-gccãå®è¡ããŸãã
Openocd
OpenOCDã¯ãå€ãã®ãµããŒããããŠããããã°ã©ããŒã®1ã€ã䜿çšããŠãããŸããŸãªMKã®ããŒããŠã§ã¢ãããã°ããµããŒããããããã¬ãŒã§ãã ãŸããFPGAãšãã©ãã·ã¥ã¡ã¢ãªããã©ãã·ã¥ã§ããŸãã ãããã£ãŠãST補åã«éãããèšå€§ãªæ°ã®ç°ãªããããã䜿çšããå¯èœæ§ããããŸãã
OpenOCDã®ãã¹ãŠã®æ©èœã®ãã¡ããã©ã°ã€ã³ã¯æ¬¡ã®3ã€ã䜿çšããŸãã
ST-Link / V2ãã©ãã·ã£ãŒã®ãµããŒã
ARM Cortex Mã³ã¢ã§MKããµããŒã
- ãªã¢ãŒãGDBãããã³ã«ããµããŒã
OpenOCDã¯å ¬åŒã«ã¯ãœãŒã¹åœ¢åŒã§é åžãããŠããŸããããã¹ãŠã®äžè¬çãªãã©ãããã©ãŒã çšã®åå ¬åŒãã«ãããããŸãã 詳现ã¯ãã¡ããã芧ãã ããïŒ http://openocd.org/getting-openocd/ ã Windowsã§ã¯ãST-LINK / V2çšã®ãã©ã€ããŒãå¿ èŠã§ãã éåžžããã©ã€ããŒã¯Windowsçšã®OpenOCDã¢ã»ã³ããªã«å«ãŸããŠããŸãããMKããã©ãã·ã¥ããããã®éåžžã«äŸ¿å©ãªãŠãŒãã£ãªãã£ãšå ±ã«ãSTãµã€ãããçŽæ¥ããŠã³ããŒãããããšãã§ããŸãã http://www.st.com/en/development-tools/stsw-link004.html
STM32CubeMX
STM32CubeMXã¯ãSTM32 MKçšã®ç¡æã®ã³ãŒããžã§ãã¬ãŒã¿ãŒã§ãã ãã®äžã§ã端æ«ãåšèŸºæ©åšãCPUã¯ããã¯ãªã©ãèšå®ã§ããŸãã ãããã¯ãã¹ãŠãéåžžã«äŸ¿å©ãªããžã¥ã¢ã«ãšãã£ã¿ãŒã§è¡ãããŸãã ãã®åŸãCubeã¯ãœãŒã¹ã³ãŒãã®ããã¯ããŒã³ãã€ãŸããå¿ èŠãªãã¹ãŠã®.cããã³.hãã¡ã€ã«ãšããµããŒããããŠããIDEã®ãããžã§ã¯ããã¡ã€ã«ïŒæ²ããããªCLionã¯å«ãŸããŠããŸããïŒãäœæããŸãã ãã¥ãŒãã¯ããšãã£ã¿ãŒãžã§ãã¬ãŒã¿ãŒèªäœãšãããããããŒããžã§ãã¬ãŒã¿ãŒã§æ§æãããŸãã ããã¡ãŒã ãŠã§ã¢ããã±ãŒãžããMKãã¡ããªããšã«1ã€ã ãžã§ãã¬ãŒã¿ãŒèªäœã¯ã ããããããŠã³ããŒãã§ããŸã ã
ããå§ããŸããã
STmovskiy MKã®æã人æ°ã®ãããã¶ãŒããŒãã®1ã€ã¯STM32F4-Discoveryã§ãã äŸãšããŠåãäžããŸãã æèŒãããŠããã®ã¯ããªã匷åãªïŒããããšã³ãã§ã¯ãããŸãããïŒMK-STM32F407ãST-LINK / V2ãšäºææ§ã®ãããã¡ãŒã ãŠã§ã¢ãããã³4ã€ã®å¶åŸ¡ãããLEDã§ãã ãã€ã¯ãé³å£°åºåãå é床èšãUSBããããŸããããã®èšäºã§ã¯ãããã«ã€ããŠæãäžããããšã¯ããŸãããLEDã®ã¿ãæ±ããŸãã STM32 DiscoveryãEvalããŸãã¯Nucleoã·ãªãŒãºã®ä»ã®ããŒããæ¢ã«ãæã¡ã®å Žåãããã¯éèŠã§ã¯ãããŸãããã©ã®ããŒãã§ãåãããšãã§ããŸãã å°ãªããšã1ã€ã®LEDããããŸãã
ããŒãã®ã»ããã¢ãã
ãã¹ãŠã®ããŒã«ãã€ã³ã¹ããŒã«ããããæåŸã«STM32F4-Discoveryã®ãæ¹åããããã©ãã·ã£ãŒããäœæããŸãããã ãŸãæåã«ãCubeMXãèµ·åããŸãã èµ·åæã«ããããã¯ãŒã¯ããå©çšå¯èœãªMKãšããŒãã®ãªã¹ããããŠã³ããŒããããã®åŸãä»»æã®MKãéžæã§ããŸãã åœç¶ãããŒãã«ãã£ãšèå³ããããŸãã ãããŒãã»ã¬ã¯ã¿ãã«ç§»åããSTM32F4DISCOVERYãèŠã€ããŠããã«ã¯ãªãã¯ããŸãã
ãã®åŸããšãã£ã¿ãŒãéããMKãããèªäœã衚瀺ãããŸãã3ã€ã®ã¿ãã䜿çšããŠããã³ã¢ãŒããåšèŸºæ©åšãããã³ããã»ããµã¯ããã¯åè·¯ãæ§æã§ããŸãã æåŸã®4çªç®ã®ã¿ãã§ã¯äœãæ§æã§ããŸããããæ§æã«å¿ããŠãããã®ãšãã«ã®ãŒæ¶è²»éãèšç®ã§ããŸãã
ããåºãã®MKããã§ã¯ãªããããŒãããå§ããã®ã§ããã§ã«äœããè¡ãããŠããŸãã ç¹ã«ãLEDã«å¿ èŠãªGPIOãèšå®ããLD3 ... LD6ãšããååãä»ããŸããã ãããžã§ã¯ãèªäœãæ§æããã³ãŒããçæããã ãã§ãã ãããžã§ã¯ããã©ã«ããŒããããžã§ã¯ãèªäœã®ååãéžæããSW4STM32ãããŒã«ãã§ãŒã³/ IDEãšããŠèšå®ããå¿ èŠããããŸãã
ããã§ãèšå®ãéããŠ[ã³ãŒãã®çæ]ãã¯ãªãã¯ããå¿ èŠããããŸãã ã®ã¢ãã¿ã³ã ã³ãŒãçæãçµäºããããæåŸã®ãã€ã¢ãã°ãéããŸãïŒããããžã§ã¯ããéãããã¿ã³ã«ã¯è§Šããªãã§ãã ããïŒã
æåŸã«ãçµæã®å¹ŽãCLionã§éãããšãã§ããŸãã ã¡ã€ã³ã¡ãã¥ãŒããã ãã¡ã€ã«ã->ãã€ã³ããŒã ããéžæããããããããããç»é¢ããã ãœãŒã¹ãããããžã§ã¯ãã ã€ã³ããŒã ããéžæããŸãã ã€ã³ããŒãããã»ã¹äžãCLIonã¯ç¢ºèªãã€ã¢ãã°ãŸãã¯ãšã©ãŒã衚瀺ããããšããããŸãããç¡èŠããŠãã ããã ãããžã§ã¯ããæçµçã«ã€ã³ããŒãããããã ã¡ãã¥ãŒãã [ ããŒã«]-> [ STM32CubeMXãããžã§ã¯ãã§CMakeãããžã§ã¯ããæŽæ°]ãéžæããŸãã
ãã®æç¹ã§ããã©ã°ã€ã³ã¯CMakeLists.txtãå®å
šã«æžãæããããŒã«ãã§ãŒã³ãšå¿
èŠãªãã¹ãŠã®ã¹ã¯ãªãããæ¥ç¶ããŸãã ããã§ãCLionã¯ãããžã§ã¯ããã³ã³ãã€ã«ããã³ã¢ã»ã³ãã«ã§ããããã«ãªããŸãã ããã«ããã©ã°ã€ã³ã¯ãæ°ããå®è¡æ§æãæ§æããŠãã³ã³ãã€ã«æžã¿ãããžã§ã¯ããåããŠãããã°ããŸãã
ãã©ã°ã€ã³ãã©ã¡ãŒã¿ãŒã®æ§æã
CLionèšå®ãå床éããŸããä»åã¯ã BuildãExecutionãDeploymentã°ã«ãŒãã®OpenOCD Supportã¿ããéããŸãã
ããã§ãOpenOCDã眮ãããŠãããã©ã«ããŒãšããŒãã®æ§æãã¡ã€ã«ãæå®ããå¿ èŠããããŸãã ãã©ã°ã€ã³ã¯ã·ã¹ãã ãã¹èªäœã§OpenOCDãèŠã€ããããšããŸãããæ£ç¢ºãªå Žæãæ瀺çã«ç»é²ããå¿ èŠãããå ŽåããããŸãã ã»ãšãã©ã®å ŽåãããŒãèšå®ãšGDBãžã®ãã¹ãå€æŽããå¿ èŠã¯ãããŸããããMacãŠãŒã¶ãŒã«ã¯å¥ã®gdbãå¿ èŠã§ãã ããšãã°ãããŒã«ãã§ãŒã³ããarm-none-eabi-gdbãååŸã§ããŸãã
æåŸã«è¡ãããšã¯ãé©åãªãã€ã¢ãã°ã䜿çšããŠããŒãæ§æãã¡ã€ã«ãéžæããããšã§ãã ãããã®ãã¡ã€ã«ã¯ãOpenOCDã€ã³ã¹ããŒã«ã®ããŒããµããã©ã«ããŒã«ãããŸãã ãã®ãããžã§ã¯ãã®æé©ãªéžæã¯ãæããã«stm32f4discovery.cfgã§ãã
ã³ãŒããè¿œå ããŸã
ããã§å¿ èŠãªãã¹ãŠã®èšå®ãå®äºããŸãããã³ãŒããèšè¿°ã§ããŸãã main.cãéããç¡éã®whileã«ãŒããèŠã€ããŠãããã«æ°è¡ãè¿œå ããŸããè¡106ã111ãåç §ããŠãã ããã
ãããã®ç·ã¯ã300ããªç§ããšã«LEDã®ã©ã³ãã ãªçµã¿åãããç¹ç¯ããŸãã
ããã€ãã®#pragmaãã£ã¬ã¯ãã£ã ïŒè¡100ã101ã113ïŒãè¿œå ããŠãCLionã®èŠåãåãé€ãããšãã§ããŸããç¡éã«ãŒãã¯ãéåžžã®ãCããã°ã©ã ã§ã¯äœ¿çšãããªããããIDEã¯ãããã奜ã¿ãŸããã
ã¹ã¿ãŒãã®éµïŒ
ã¡ã€ã³ïŒïŒæ¬äœå ã®ã©ããã«ãã¬ãŒã¯ãã€ã³ãã眮ãããã¹ãŠãéå§ããæãæ¥ãŸããïŒ CLionã¯ãããžã§ã¯ããã¢ã»ã³ãã«ããããŒãã«ããŒããããããã¬ãŒãèµ·åããŠMKããªã»ããããŸãã ããã§ããããã°ã«ãã¬ãŒã¯ãã€ã³ããšãŠã©ããã䜿çšã§ããŸãã
3åèªãããã1åèŠãæ¹ãè¯ãïŒ
次ã¯ïŒ
å°æ¬ãããèªè ãäžèšã®ãã¹ãŠãå®è¡ã§ããå Žåããã¡ãŒã ãŠã§ã¢ã®ç°¡åãªäŸãæ©èœããŸãã ããããããã«ã³ãŒããæžãæ¹æ³ã¯ïŒ ããŠãããã§ããã€ãã®QïŒAã®ãã³ãããããŸãã
QïŒã©ã®ããŒãããµããŒããããŠããŸããïŒ
AïŒå€ããå°ãªãããSTMicroelectronics STM32 DiscoveryãNucleoããŸãã¯EVALã·ãªãŒãºã®ãã¢ããŒãã¯ãã¹ãŠåäœããã¯ãã§ãã
QïŒMKã®ããŒããŠã§ã¢æ§æãå€æŽããå¿
èŠãããå Žåã¯ã©ãããã°ããã§ããïŒ
AïŒSTM32CubeMXãå床起åãããããžã§ã¯ããéããŠãå¿
èŠãªå€æŽãå ããåã³ãŒãã£ã³ã°ããŸãã IDEã®ãã©ã°ã€ã³ã¯ããããžã§ã¯ããæŽæ°ããå¿
èŠããããã©ãããå°ããŸãã ãã¯ãããšçããŠãã ããã
QïŒäœææã«äžæžããããªãããã«ãäœæããã³ãŒããä¿è·ããã«ã¯ã©ãããã°ããã§ããïŒ
AïŒåžžã«æ¬äŒŒã³ã¡ã³ãã®éã«ã³ãŒããæžã
/* USER CODE BEGIN ??? */
/* USER CODE BEGIN ??? */
ããã³/* USER CODE END ??? */
/* USER CODE END ??? */
ã
Cubeã¯ãã³ãŒããçæãããšãã«ãããã®ãã©ã°ã¡ã³ãã«è§ŠããŸããã èªåçã«è¿œå ããã#includeãã£ã¬ã¯ãã£ãããã®ãããªå Žæã«è»¢éããããšãå¿ããªãã§ãã ããã 倧éã®ã³ãŒãã«å¯Ÿããå¥ã®ã¢ãããŒãã¯ãåå¥ã®.c / .hãã¡ã€ã«ã§ãã
QïŒå€éšã©ã€ãã©ãªãè¿œå ããFPUãæ¥ç¶ãã CMakeLists.txtã§ãã®ä»ã®å€æŽãè¡ãå¿
èŠããããŸãã ããããã©ã®ããã«ïŒ
AïŒ CMakeLists.txt㯠ããã³ãã¬ãŒãã®ãã©ã°ã€ã³ã«ãã£ãŠèªåçã«æžãæããããŸããçŽæ¥å€æŽããªãã§ãã ããã ãã³ãã¬ãŒãèªäœã¯ãããžã§ã¯ããã¡ã€ã«éã§èªåçã«èšé²ããããããããã§å€æŽãå ããŠãããã¡ãã¥ãŒé
ç®[ ããŒã« ] -> [STM32CubeMXã§CMakeãããžã§ã¯ããæŽæ° ]ã䜿çšããŠãããžã§ã¯ããæŽæ°ããå¿
èŠããããŸãã
QïŒARMããŒã¹ã®éçºã«ã¯CLionã䜿çšãããã®ã§ãããSTM32ã§ã¯äœ¿çšããŸããã ãã®ãã©ã°ã€ã³ã䜿çšã§ããŸããïŒ
AïŒããããããã§ãã ãã¹ãŠåãããŒã«ïŒSTM32CubeMXãé€ãïŒãã€ã³ã¹ããŒã«ããŠãããç¬èªã®CMakeLists.txt ïŒ ãã³ãã¬ãŒãã¯ãã¡ã ïŒããªã³ã«ãŒçšã®ã¹ã¯ãªãããããã³ããŒãæ§æãã¡ã€ã«ãäœæããå¿
èŠããããŸãã ãã¹ãŠã®æºåãã§ãããã[ ããŒã«] -> [ CMake] -> [ ãã£ãã·ã¥ã®ãªã»ãããšãããžã§ã¯ãã®ãªããŒã]ãéžæãã å®è¡æ§æã¿ã€ãOpenOCDã®ããŠã³ããŒããšå®è¡ãäœæããŸãã ãã©ã°ã€ã³ã®ãŠãŒã¶ãŒã® 1人ããAtmel SAM E70ã«å¯ŸããŠããããã¹ãŠè¡ããŸããã
QïŒéçºã«ã¯CLionãšãã©ã°ã€ã³ã䜿çšãããã®ã§ãããARMã«ã¯äœ¿çšããŸããã å¯èœã§ããïŒ
AïŒMKãGCCã§ãµããŒããããŠããå Žåããã¡ãŒã ãŠã§ã¢ã¯OpenOCDãšäºææ§ããããŸããå°ãªããšãè©ŠããŠã¿ãŠãã ããã é©åãªããŒã«ãã§ãŒã³ã䜿çšããŠãåã®åçãåç
§ããŠãã ããã
QïŒé©åãªããŒãæ§æãã¡ã€ã«ãèŠã€ãããŸããã ããã€ãã®åå¥ã®æ§æãã¡ã€ã«ã䜿çšã§ããŸããïŒ
AïŒããŒãæ§æãã¡ã€ã«ã¯ãããããçµã¿åãããŠäœæã§ããŸãã ãããžã§ã¯ãã«å
¥ããŠããµã³ãã«ã®æšæºã®1ã€ãååŸããŸãã
QïŒæ°ã«å
¥ã£ãŠããŸãïŒ ãããžã§ã¯ããäœããã®åœ¢ã§ãµããŒããããããããžã§ã¯ãã«åå ãããã§ããŸããïŒ
AïŒ ãã¡ããã§ãïŒ