ä»æ¥ã¯ãCMSISã§ããå¹ççãªã³ãŒããèšè¿°ããæ¹æ³ãšãããã»ããµé床ãæ£ããèšç®ããæ¹æ³ãšãã2ã€ã®éèŠãªè³ªåã«å¯ŸåŠããŸãã 2çªç®ã®ããŒãããå§ããŠãLPC1114ã§çºçããããã»ã¹ã調ã¹ãŠãã¯ããã¯åšæ³¢æ°ãçæããŸãã
ã¯ããã¯åšæ³¢æ°ã¯ããã»ããµã®ãåŽåãã®äž»ãªåå ã§ããããã®çºçåšã¯äººã®å¿ãšæ¯èŒã§ããŸãã ããã»ããµã®ç°ãªãã³ã³ããŒãã³ãã¯ç°ãªãåšæ³¢æ°ã䜿çšã§ããŸãããéåžžã¯åãæ°Žæ¶ïŒãŸãã¯å ±æ¯åšïŒããçºçããŸãã
ã»ãšãã©ã®ããã»ããµã«ã¯ãå ±æ¯åšãå èµãããŠãããå€éšå ±æ¯åšãŸãã¯æ°Žæ¶ãæ¥ç¶ã§ããŸãã ãªããããè¡ãããã®ã§ããïŒ åºæ¬çã«ãããã»ããµã®ã³ã¹ããåæžããŸãã éåžžãå èµã®å ±æ¯åšã«ã¯çŽ1ïŒ ã®èª€å·®ããããããã¯å€ãã®ã¿ã¹ã¯ã«ã¯ååãããããŸãããããã®ãããªç²ŸåºŠã蚱容ã§ããªãã»ã©å€ãã®ã¿ã¹ã¯ããããŸãã å®éãããšãã°ãå èµã®å ±æ¯åšã§æéãããããšã1æ¥ãããã®ãšã©ãŒã¯14åã«éããå¯èœæ§ããããŸãã ãããã¯ãŒã¯äžã§çŽ30åã«1åãã±ãããéä¿¡ããå Žå-ããã¯é倧ãªãšã©ãŒã§ã¯ãããŸããã ã¢ã©ãŒã ãäœæããå Žåã®å¥ã®ããšã
ïŒ LPC111xãŠãŒã¶ãŒããã¥ã¢ã«ããã®ç»åïŒ
ã³ã³ããŒãã³ãã«åå²ãããã¯ããã¯ãžã§ãã¬ãŒã¿ãŒã®æŠèŠå³ãäžã«ç€ºããŸãã 次ã«ããããããåå¥ã«æ±ããŸãã
âµã¡ã€ã³åšæ³¢æ°
MAINCLKSEL
ã¯ãåºæ¬åšæ³¢æ°ãèšå®ããŸããããã¯ãä»ã®ã»ãšãã©ã®äººãäŸåããŸãã ããã€ãã®ãœãŒã¹ã®1ã€ã«åºã¥ãããšãã§ããŸãã
ãŸããIRC-å éšå ±æ¯åšã§ãã åäœåšæ³¢æ°ã¯12 MHzã§ãïŒå®éãå°ããªå¶éå ã§èª¿æŽã§ããŸãïŒã誀差ã¯çŽ1ïŒ ã§ãã ãããããèµ·åæã«ããã»ããµã¯ããã¯åšæ³¢æ°ãçæãããããããã¹ãŠã®ããŒãã³ãŒãã¯12 MHzã®ã¯ããã¯åšæ³¢æ°ã§å®è¡ãããŸãã ãã®ãªãã·ã§ã³ã¯å¯èœãªéãã·ã³ãã«ã§ããïŒæ©èœãããããã«äœãããå¿ èŠã¯ãããŸããïŒãè¿œå ã®å€éšã³ã³ããŒãã³ãã¯å¿ èŠãããŸããã æ®å¿µãªãããããã«ã¯ç¬èªã®åé¡ããããŸããç§ãè¿°ã¹ãããã«ãå ±æ¯åšã¯ããäžæ£ç¢ºã§ããããã«ã50 MHzã§å®å šã«åäœãããšãã12 MHzã§ã³ã¢ãé§åããããšã«ç¹ã«èå³ã¯ãããŸããã
第äºã«ãã¡ã€ã³åšæ³¢æ°ã¯ãã1ã€ã®å éšãžã§ãã¬ãŒã¿ãŒã§èšå®ã§ããŸããããã¯éåžžããŠã©ããããã°åäœã«äœ¿çšããããŠã©ããããã°çºæ¯åšã§ãã ãã®çºæ¯åšã¯ã9.4 kHzã2.3 MHzã®é床ïŒÂ±40ïŒ ã®ç²ŸåºŠïŒã§åäœããŸã-ããã¯ãã¡ã€ã³åšæ³¢æ°ã®æé©ãªãœãªã¥ãŒã·ã§ã³ã§ã¯ãªãããã§ãã äžæ¹ãããã¯ãåšèŸºæ©åšã®äžéšãåäœããããŸãŸãã«ãŒãã«ãã¹ãªãŒãã¢ãŒãã«ããå¿ èŠãããå Žåã«ããŸãã«çŽ æŽãããããšãã«ã®ãŒå¹çã®é«ããœãªã¥ãŒã·ã§ã³ã§ãã
第äžã«ã PLLã®åãŸãã¯åŸã«ã·ã¹ãã çºæ¯åšããåºæ¬åšæ³¢æ°ãååŸã§ããŸãã ããã¯ããªãèšå€§ãªãããã¯ã§ãããããPLLã®è©³çŽ°ã«ã€ããŠã¯æãäžããŸããã èå³ã®ããæ¹ã¯ãã»ã¯ã·ã§ã³ã3.11ã·ã¹ãã PLLæ©èœã®èª¬æããã芧ã«ãªãããšããå§ãããŸãã
â¶ã·ã¹ãã çºæ¯åš
ã·ã¹ãã ãªã·ã¬ãŒã¿ãŒã¯ãããŒããŠã§ã¢ã®å€æŽãªãã§ã¯åäœããªãããã»ããµãŒã®äžéšã§ããããªã·ã¬ãŒã¿ãŒã®äž»ãªæ©èœãæ¬ ããŠããŸã-æ°Žæ¶ïŒãŸãã¯æ°Žæ¶æ¯ååïŒã¯å€éšã«æ¥ç¶ããå¿ èŠããããææ°ã®ããã»ããµãŒã«ã¯XTALIN / XTALOUTãã³ããããŸãã
å ·äœçã«ã¯ãLPC1114ïŒãã ããLPC111xã©ã€ã³ã®ä»ã®ããã»ããµãšåæ§ïŒã¯ã1 MHzã25 MHzã®çºæ¯åšæ³¢æ°ã®æ°Žæ¶ããµããŒãããŠããŸãã æ°Žæ¶èªäœã«å ããŠã2ã€ã®ã³ã³ãã³ãµãå¿ èŠã«ãªããŸããã³ã³ãã³ãµã®å€ã¯ãéžæããæ°Žæ¶ã®ãã©ã¡ãŒã¿ã«ãã£ãŠç°ãªããŸãã ããã§ã ããŒã¿ã·ãŒããåç §ããŸããã»ã¯ã·ã§ã³12.3ïŒXTALå ¥åïŒã«ã¯ãæ¥ç¶å³ãšæšå¥šã³ã³ãã³ãµå®¹éã®è¡šããããŸãã ãã¹ãåè·¯ã§ã¯ãåšæ³¢æ°12 MHzãè² è·å®¹é20 pFã2ã€ã®ã³ã³ãã³ãµ39 pFã®æ°Žæ¶ã䜿çšããããšããŸãããããã®åäœã¢ãŒãã¯ãã以äžèæ ®ãããŸããã
ä¿¡é Œã§ããå€éšã¯ããã¯ãœãŒã¹ãããå Žåã¯ãã·ã¹ãã ãªã·ã¬ãŒã¿ãŒãã¹ãããããŠãXTALINãã³ããã¯ããã¯åšæ³¢æ°ãååŸã§ããŸãã
ã·ã¹ãã çºæ¯åšã¯ãåºæ¬åšæ³¢æ°çºçåšãšããŠçŽæ¥äœ¿çšããããšãã以åã«PLLãä»ããŠæž¡ãããšãã§ããŸãã
â·PLL
é»æ°æ©æ¢°åŠã«å ¥ãããšãªããPLLã¯å ¥åã¯ããã¯åšæ³¢æ°ãæåã«ä¹ç®ããŠããååšããããã€ã¹ã§ãã å ¥åã§ã¯ãPLLã¯IRCãŸãã¯ã·ã¹ãã ãªã·ã¬ãŒã¿ãŒããåšæ³¢æ°ãåä¿¡ã§ããåºåã¯åºæ¬åšæ³¢æ°ã«äœ¿çšãããŸãã
PLLãã©ã¡ãŒã¿ãŒã®èšå®ã¯ãããã»ããµãŒå éšã«ãšã£ãŠæœåšçã«å±éºã§ãããããã£ãŠã NXPãŠãŒãã£ãªã㣠ïŒGoogleãã©ã€ãã§æ£åžžã«å€æããŠåäœããŸãïŒã䜿çšããŠå¿ èŠãªãã©ã¡ãŒã¿ãŒãéžæããå ¥åçºæ¯åšåšæ³¢æ°ãšåä¿¡ãããæçµåšæ³¢æ°ãèšå®ããã ãã§ãå¯èœãªãªãã·ã§ã³ãèšç®ããããšããå§ãããŸãã
ãããã¯ãŒã¯ã«ã¯ãIRCåšæ³¢æ°ãäžããŠPLLåºåã§50 MHzãçæããæ¹æ³ã«é¢ããèå³æ·±ãã¡ã¢ããããŸããããã®çµæããããã°ããã«ã¯ãªã·ãã¹ã³ãŒããå¿ èŠã§ãã
âžã·ã¹ãã åšæ³¢æ°
éåžžãã³ã¢ïŒCortex-M0ã§ãããšããäºå®ïŒã¯ã¡ã€ã³åšæ³¢æ°ã§åäœããŸãããå¿ èŠã«å¿ããŠãã¡ã€ã³åšæ³¢æ°ãåå²ïŒæ倧255ãŸã§ïŒã§ãããããã·ã¹ãã åšæ³¢æ°ã«ãªããŸãã ã³ã¢èªäœã«å ããŠããã©ãã·ã¥ã¡ã¢ãªãRAMãããã³ãã¹ãŠã®åšèŸºæ©åšã¯ãSPIããã³UARTãé€ãããã®åšæ³¢æ°ã§åäœããŸãã ããã§ã®æ倧åšæ³¢æ°ã¯50 MHzã§ãã
SPI SPIãšUARTã¯ã©ãã§ããïŒ
ãããã®ã€ã³ã¿ãŒãã§ã€ã¹ã®ç¹æ§ã«ãããããšãã°UARTã«å°çšã®ååšåšããããç®çã®ãããã¬ãŒããéžæã§ããŸãã
åè·¯ã®ããã€ãã®éèªææ§ã«ãããããããã¡ã€ã³ã§ã¯ãªããã·ã¹ãã åšæ³¢æ°ãååšåšã®å ¥åã«å°éããŸãã
ãããã¬ãŒãã®é€æ°ãèšç®ããã®ã¯ããªãé£ããäœæ¥ãªã®ã§ãããäžåºŠã13.5.15 UARTåæ°ååšã¬ãžã¹ã¿ïŒU0FDR-0x4000 8028ïŒããšããæ瀺ã«éããŸãã èšç®åŒãè¿œå ã®åæ°åŒæ°ã®èª¬æãããã³ç¹å®ã®ãããã¬ãŒãã«å¿ èŠãªãã©ã¡ãŒã¿ãŒãèŠã€ããããã®ãããã¯å³ãšããã€ãã®äŸããããŸãã
SPIã§ã¯ããã¹ãŠãããåçŽã«ãªããŸããããããããã¹äžã®ãã¹ã¿ãŒãåšæ³¢æ°ãèšå®ããæ®ãã®ããã€ã¹ããã®åšæ³¢æ°ã§åäœããããã§ããå£å€ã®åæã¯äžèŠã§ãã ãããã£ãŠãã§ããããšã¯é€æ°ãèšå®ããããšã ãã§ãã éèŠãªãã€ã³ã-ããã»ããµããã¹ã¿ãŒã¢ãŒãã®å Žåãæå°ååšåšã¯2ãã€ãŸã48 MHzã®ã·ã¹ãã åšæ³¢æ°ã§ã¯ãSPIã§ã®ããŒã¿è»¢éé床ã¯24 MHzã«ãªããŸãã
UPD ïŒ valeriykãæ£ããææããããã«ããã®ååšåšã ããåºååšæ³¢æ°ã«åœ±é¿ãäžãããã®ã§ã¯ãããŸããã ããšãã°ãSPIã®å Žåããã£ãªã¢åšæ³¢æ°ã¯æ¬¡ã®åŒã§èšç®ãããŸãïŒ
PCLK / (CPSDVSR * (SCR + 1))
ãããã§PCLKã¯åšèŸºåšæ³¢æ°ã§ãã CPSDVSR-ãããªã¹ããªãã¿ãŒãã SCR-åºåãããããšã®ããªããŒããŒãµã€ã¯ã«ã®æ°ã
lifeåœãå®ãçªç¬
ãŠã©ããããã°ã¯ããã®ç¹ç°æ§ã«ãããå€ç«ããã³ã³ããŒãã³ãã§ãã ãããã£ãŠãäž»èŠãªåšæ³¢æ°ãšããŠãã·ã¹ãã ãIRCããŸãã¯å¥ã®ãªã·ã¬ãŒã¿ãŒã䜿çšã§ããŸãã åæ§ã«ããŠã©ããããã°ã«ã¯å°çšã®é€æ°ããããŸãã
ãŠã©ããããã°ã«å¥ã®ã¯ããã¯ãå¿ èŠãªã®ã¯ãªãã§ããïŒ ãã¡ãããããã°ã©ã ã誀ã£ãŠã¡ã€ã³ãžã§ãã¬ãŒã¿ãå£ããŠããŸã£ãå Žåã¯ããã¡ããã§ãïŒ ãã®åŸã圌女ã¯ãŠã©ããããã°ã¿ã€ããŒã«ãã£ãŠãªã»ãããããå¯èœæ§ããããŸãã
exitçµäºããã«ã¯
æåŸã«ãããã»ããµã¯CLKOUTãã³ïŒGPIO 0.1ã®ä»£æ¿æ©èœã®1ã€ïŒã§ã¯ããã¯åºåä¿¡å·ãçæã§ããŸãã äž»èŠãªåšæ³¢æ°ãšããŠãçºæ¯åšïŒIRCãã·ã¹ãã ãŸãã¯ãŠã©ããããã°ïŒãŸãã¯ã·ã¹ãã åšæ³¢æ°ïŒãªã³ã«ãªã£ãŠããå Žåã¯PLLã®åŸïŒããå©çšå¯èœãªä»»æã®ãã®ã䜿çšã§ããŸãã ããŠããã¡ãããããªãã®é€æ°ã
mbedã«ã€ããŠ
LPC1114ã®ã¯ããã¯çæããã»ã¹ã詳现ã«æ€èšããŸããããLPC1768ã¯ã©ãã§ããïŒ å®éãåããã»ããµã©ã€ã³ã«ã¯ç¬èªã®ç¹å¥ãªã¢ãããŒããããå¯èœæ§ããããŸãïŒãããã£ãŠãç¬èªã®ç¹å¥ãªã¢ãããŒããããå¯èœæ§ãé«ãããããã®ãããã¯ã®æé ã¯éåžžã«æ éã«æ€èšããå¿ èŠããããŸããLPC1768ã«ã¯å éšãªã·ã¬ãŒã¿IRCããããŸããã ïŒã¡ã€ã³ïŒã·ã¹ãã ãªã·ã¬ãŒã¿ãšåããªã·ã¬ãŒã¿mbedã§ã¯ã12 MHzã®æ°Žæ¶ãæ¥ç¶ãããŠããŸãæåŸã«ããªã¢ã«ã¿ã€ã ã¯ããã¯ïŒRTCïŒçºæ¯åšããããŸãããæ°Žæ¶ã¯æ¥ç¶ãããŠããŸããã
ãŸããã¡ã€ã³PLLã«å ããŠãUSBã®åäœåšæ³¢æ°ãçæããããã«äœ¿çšãããè¿œå ã®PLLããããŸãã ãã¹ãŠã®åšèŸºã³ã³ããŒãã³ãã«ã¯ãåäœåšæ³¢æ°ã«å¯ŸããŠç¬ç«ããŠèª¿æŽå¯èœãªååšåšããããŸãã
åšæ³¢æ°å€åã®å®çšçãªãã¥ã¢ã³ã¹
åäœã¯ããã¯åšæ³¢æ°ãå€æŽãããšãããã€ãã®çµæãçããŸãã æãæãããªã®ã¯ãã¿ã€ããŒãå調æŽããå¿ èŠãããããšã§ãã ãŸãããã£ãªã¢åšæ³¢æ°ïŒUARTãUSBïŒãä¿®æ£ããããšãéèŠãªå Žåããããã³ã«ã§åäœããåšèŸºæ©åšã®ååæåãå¿ èŠã§ãã æåŸã«ããã©ãã·ã¥ã¡ã¢ãªã«ã¢ã¯ã»ã¹ããããã®æ段ã®æ°ãéèŠãªåœ¹å²ãæãããŸãã LPC1114ã®ããã©ã«ãå€ã¯3ã¯ããã¯ãµã€ã¯ã«ïŒ50 MHzãŸã§ã®åäœåšæ³¢æ°ãFLASHCFGã¬ãžã¹ã¿ã®ããã¥ã¡ã³ããåç §ïŒã§ãããããã¯ã¿ã¹ã¯ã«ååã§ãã ãã ããLPC1768ã®ããã©ã«ãå€ã¯4ãµã€ã¯ã«ã§ãåäœåšæ³¢æ°ã¯æ倧80 MHzã§ãããããã§ã¯ååã§ã¯ãããŸããã
ãã ããããé«ãåšæ³¢æ°ã§ã®åäœãæçã§ããå¯èœæ§ããããŸãã çµã¿èŸŒã¿ããã»ããµã¯ã»ãšãã©ã®æéãã¹ãªãŒãã¢ãŒãã§äœ¿çšããããããŠã§ã€ã¯ãµã€ã¯ã«ã®åŠçãé«éã«ãªãã»ã©ãæçµçã«æ¶è²»ãããšãã«ã®ãŒãå°ãªããªããŸãã
åãããã«ïŒ
ããã§å¿ èŠãªçè«äžã®è·ç©ãã§ããã®ã§ãç¥èãå®è·µã«ç§»ãæºåãã§ããŸãããLEDã1ç§ã«1åã確å®çã«ç¹æ» ãããŸãã
åã«èŠãããã«ãå€ãã®ã¿ã¹ã¯ã¯åãæ¹æ³ã§å®è¡ãããŸã-ã¬ãžã¹ã¿ã®æžã蟌ã¿ãšèªã¿åãïŒäžè¬ã«ã ãã¹ãŠã®ã¿ã¹ã¯ã¯ãã®ããã«å®è¡ãããŸãïŒã ARMã¯ããã®CMSISãååšãããããç¹å®ã®ããã»ããµã«é¢é£ä»ããããŠããªãã¿ã¹ã¯ãåãCã³ãŒãã§å®è¡ã§ããããšã確èªããŸãããããã¯ãããã»ããµã³ã¢ã®ãã©ã€ãã®ã»ããã§ãã ãã³ããŒã¯éåžžãæ®ãã®åšèŸºæ©åšçšã®ãã©ã€ããŒã§æ¡åŒµããŸãã
CMSISã®é£ããéšåã¯ãçŸåšã®ããŒãžã§ã³ãã©ãã«ããããå®å šã«æ確ã§ãªãå Žåãããããšã§ãã ãã¡ã€ã«ã®åºæ¬ã»ããã¯ã ARMããçŽæ¥ããŠã³ããŒãã§ããŸããå·çæç¹ã§ã¯ãããŒãžã§ã³3.01ãå©çšã§ããŸãã ããããŒãã¡ã€ã«ã«å ããŠãARMã¯DSPäžã®ããŸããŸãªè€éãªèšç®çšã®ã©ã€ãã©ãªãæäŸããŸãïŒããŒããŠã§ã¢ã«ã¯ãŸã ãããŸããïŒã ç¹å®ã®ã¡ãŒã«ãŒã®ãã©ã€ããŒã§ã¯ç¶æ³ãããã«æªåããŸãã ããšãã°ãNXPã®å ŽåãLPC1114ã®CMSISã¯CMSIS 1.30ã«åºã¥ããŠãããLPC1768ã®å Žåã¯2.10ã«åºã¥ããŠããŸãã ããã«ãäžé£ã®åšèŸºãã©ã€ããŒã®ã³ãŒãã«ã¯æãããªãšã©ãŒããããŸãã ãŸããTIãããã®ãã©ã€ããŒã¯Googleã§åŸ¹åºçã«æ€çŽ¢ããå¿ èŠããããŸãã
ãããã2ã€ã®éèŠãªçµè«ãå°ãåºãããšãã§ããŸãã第äžã«ããã©ã€ããŒã³ãŒãã¯ã»ãŒå®å šã«ãªãŒãã³ã§ããããããä¿¡é Œãããæ€èšŒããããšããæ瀺ãšããŒã¿ã·ãŒãã¯ãåšèŸºæ©åšã®æäœã«é¢ããäž»èŠãªæç®ã§ãã 第äºã«ããã©ã€ããŒã«ã¯èªåã§æžãããšãã§ããªãã£ããã®ã¯ã»ãšãã©ãããŸãããã€ãŸããããã¯åªããããããŠå€ãã®å Žåãå®çšçãªåèè³æã§ãã äœããå¥åŠã«èŠããå Žåãäž»ãªããšã¯ãããæ¹å€çã«åãã®ãå¿ããªãããšã§ã-ããã»ããµã®ããã¥ã¢ã«ãåžã£ãŠãã ããã
ããã§ããœãŒã¹ã³ãŒãã®æ§é ãè¥å¹²åäžããŸããã ãã®çµæããã¡ã€ã«æ°ãå€§å¹ ã«å¢å ããŸããããããã€ãã®ç°ãªããã©ãããã©ãŒã ããµããŒãããã®ãã¯ããã«ç°¡åã«ãªããŸããã ä»æ¥ã®äŸã®ãœãŒã¹ã¯ãGitHubã§å ¥æã§ããŸãïŒ farcaller / arm-demos ïŒæ°ããã¢ãŒããã¯ãã£ã®ãã«ãªã¯ãšã¹ãã¯å€§æè¿ã§ãïŒïŒ
ãœãŒã¹ããªãŒã¯ãŸã å®å šã«
boot.s
ããŸãããç¹ã«ãããªããã£ã
boot.s
ãš
memmap.ld
ããŸãã
memmap.ld
ã 次ã®éšåã¯ããªã³ã«ã®åé¡ïŒã¬ããŒãžã³ã¬ã¯ã·ã§ã³ãš.dataããã³.bssã®é©åãªåæåãå«ãïŒã«å®å šã«å°å¿µãããã¹ãŠã®è«äºã®ããåé¡ã®å®äºãæ±ããŸãã ãã¹ãŠã®ã³ãŒãã¯3ã€ã®ã«ããŽãªã«åããããŸãïŒ
app/
ã¯ãã¢ããªã±ãŒã·ã§ã³ãã®ãã¡ã€ã«ã§ã-çŽæ¥åäœãããµã³ãã«ã³ãŒãã
setup()
ããã³
loop()
é¢æ°ã«ãããarduinoã¹ã¿ã€ã«ã§ã¹ã¿ã€ã«ãèšå®ãããŸãã Platform
platform/
ã¯ãããŸããŸãªãã©ãããã©ãŒã ãšãã©ãããã©ãŒã ã«äŸåããæ©èœã®èª¬æãå«ãŸããŸãïŒãã¡ã€ã«ããã¹ãŠã®ãã©ãããã©ãŒã ã«ãªã³ã¯ãããŠãã
platform/common
ãé€ãïŒã æåŸã«ã
cpu/
ã¯ç¹å®ã®ããã»ããµãŒçšã®CMSISã§ãã
ãã®ã³ã³ãã€ã³å šäœãå°ãé¢çœãRakefileã«ãªããŸãã ãã¶ããmakeã§ããŸããããããããŸãããããã¹ãŠã1ã€ã®ãã¡ã€ã«ã«ãã¡ããšãŸãšããããšæã£ãã®ã§ãäŸããã«ãããã«ã¯ããŒãžã§ã³1.9ããå€ããã®ããããå¿ èŠã¯ãããŸããã
æèšä»æã
ã¿ã¹ã¯ãå®è¡ããã«ã¯ïŒæãåºãããŠãã ãããLEDã1ç§ã«1åæ£ç¢ºã«ç¹æ» ãããå¿ èŠããããŸãïŒãäœããã®ã¿ã€ããŒãå¿ èŠã«ãªããŸãã 幞ããªããšã«ãLPCããŒã¹ã®ããã»ããµã«ã¯ããã€ãã®ã¿ã€ããŒãäžåºŠã«ãããŸããæãçµ±äžãããSysTickã䜿çšããŸãã ãã®ã¿ã€ããŒã¯CMSISã«çŽæ¥èšè¿°ãããŠããŸããã€ãŸããä»ã®ããã»ããµãŒã«ããå¯èœæ§ãé«ãã§ãã OSã§ã¿ã¹ã¯ãåãæ¿ãããšãã«æéã®éã枬å®ããããã«äœ¿çšããããšã«ãªã£ãŠããŸãããåçŽãªã¿ã¹ã¯ã«äœ¿çšããããšã劚ãããã®ã¯ãããŸããã
SysTickã¯ãæå®ãããå€ãããŒããŸã§ã«ãŠã³ãããåçŽãªã¿ã€ããŒã§ããªãŒããŒãããŒããããèšå®ããå²ã蟌ã¿ããã«ããŠãåã³ã«ãŠã³ããéå§ããŸãã
platform/common/systick.c
ïŒ
void platform_systick_setup(unsigned int load) { SysTick->CTRL = 0x04; SysTick->LOAD = load < 0xffffff ? load : 0xffffff; SysTick->VAL = 0; SysTick->CTRL = 0x05; }
æ§æããå§ããŸãããã ãããã®ãã°ãããæ§é ã¯CMSISããå ¥æã§ããã¬ãžã¹ã¿ã®å ŽæãèŠããå¿ èŠããªããªãããã£ãŒã«ããžã®ã¢ã¯ã»ã¹ãããæ確ã«å®çŸãããŸãã
ã¿ã€ããŒãåæåããã«ã¯ãå¶åŸ¡ã¬ãžã¹ã¿ã«4ãæžã蟌ã¿ãŸãã ããã«ãããã¿ã€ããŒããªãã«ãªãããªã³ã«ãªã£ãŠããå Žåãå²ã蟌ã¿ããªãã«ãªããSysTickãããã»ããµãŒåšæ³¢æ°ã®äœ¿çšã«åãæ¿ãããŸãïŒããã©ã«ãã¯12 MHzã§ããããšãæãåºããŠãã ããïŒã 次ã«ãSYST_RVRã¬ãžã¹ã¿ã«éå§åºæºç¹ãããŒãããæ倧å€ã16777215ã«å¶éããã¬ãžã¹ã¿ã®çŸåšã®å€ããŒãã«ãªã»ããããŠãã¿ã€ããŒãéå§ããŸãã
次ã«ã1ç§éåŸ æ©ããæ¹æ³ã«ã€ããŠèª¬æããŸãã
void platform_systick_wait() { volatile int i; i = SysTick->CTRL; while((i & 0x00010000) == 0) { i = SysTick->CTRL; } }
SYST_CSRã¬ãžã¹ã¿ããCOUNTFLAGã®å€ãèªã¿åããŸãã COUNTFLAGã¯ãã«ãŠã³ã¿ãŒãæ°ããåã«ç§»åãããš1ã«èšå®ãããèªã¿åãæã«ãŒãã«ãªã»ãããããŸãã ãããã£ãŠãã«ãŠã³ã¿ãŒããªãŒããŒãããŒãããŸã§ãµã€ã¯ã«ã«ãªããŸãã
ãããžã§ã¯ãã®ä»ã®ãã¡ã€ã«ãèŠãŠã¿ãŸãããã
app/systick-blink.c
ïŒ
#include "platform.h" void setup() { platform_led_setup(); #if PLATFORM == MBED platform_systick_setup(4000000); #elif PLATFORM == PROTOBOARD platform_systick_setup(12000000); #else #error Unknown platform #endif } void loop() { platform_led_toggle(1); platform_systick_wait(); platform_led_toggle(0); platform_systick_wait(); }
ããã§ã¯ãã¹ãŠãæ確ã§ãã LEDãšã¿ã€ããŒã®ããã©ã€ããŒããåæåãããµã€ã¯ã«ã§é 延ã䌎ã£ãŠLEDããªã³/ãªãããŸãã ãã©ãããã©ãŒã ã«å¿ããŠãç°ãªãéå§ã¿ã€ããŒå€ã䜿çšããŸãïŒmbedã®IRCãšãããã¿ã€ãããŒãã¯ç°ãªãåšæ³¢æ°ã§åäœããŸãïŒã ããããLEDèªäœã®ã³ãŒãã¯ã©ã®ããã«æ©èœããŸããïŒ
platform/protoboard/led.c
ïŒ
#include "LPC11xx.h" #define LED_PIN (1<<9) void platform_led_setup() { LPC_GPIO1->DIR |= LED_PIN; } void platform_led_toggle(int on) { LPC_GPIO1->MASKED_ACCESS[LED_PIN] = on ? LED_PIN : 0; }
ã芧ã®ãšãããCMSISã䜿çšãããšããã¹ãŠãæ¬åœã«èªã¿ããããªããŸããã å¯äžã®èå³æ·±ãç¹ã¯ãäžè¬çãªGPIOã¬ãžã¹ã¿ã®ä»£ããã«ããã¹ã¯ä»ãã®ã¬ãžã¹ã¿ã䜿çšããŠããããšã§ãã ãã¹ã¯ã䜿çšããŠç¹å®ã®ãã³ã®GPIOããããèšå®ã§ããŸããã€ãŸããé£æ¥ãããã³ã®ç¶æ ãä¿åããå¿ èŠããããšã¯æããã«ãç®çã®å€ãæžã蟌ãããšãã§ããŸãã ããã«ã€ããŠã®è©³çŽ°ïŒããã³åçïŒã«ã€ããŠã¯ãã12.4.1ããŒã¿ã®æžã蟌ã¿/èªã¿åãæäœããåç §ããŠãã ããã
æ¯èŒã®ããã«ãmbedã®ã³ãŒãã以äžã«ç€ºããŸãã
platform/mbed/led.c
ïŒ
#include "LPC17xx.h" #define LED_PIN (1<<18) #define LED_PIN_IN_B2 (1<<2) void platform_led_setup() { LPC_GPIO1->FIODIR |= LED_PIN; } void platform_led_toggle(int on) { LPC_GPIO1->FIOMASK2 |= ~LED_PIN_IN_B2; if (on) { LPC_GPIO1->FIOSET2 = LED_PIN_IN_B2; } else { LPC_GPIO1->FIOCLR2 = LED_PIN_IN_B2; } }
ã芧ã®ãšãããéåžžã«ãã䌌ãŠããŸãã LPC1768ã«ã¯ããã€ã³ã¿ã®ã¢ãã¬ã¹ã«ãã¹ã¯ãçŽæ¥èšå®ããæ©èœã¯ãããŸããããã¬ãžã¹ã¿ãžã®ãã€ãåäœã®ã¢ã¯ã»ã¹ããããã¢ã»ã³ãã©ã®ãªã¹ããå°ãå¹ççã«ãªããŸãã
rake build_protoboard
ãŸãã¯
rake build_mbed
ã䜿çšã
rake build_protoboard
ãããžã§ã¯ãã
rake build_protoboard
ã§ããŸãã ããã€ã¹ãããã«ãã©ãã·ã¥ããããšãã§ã
rake upload_protoboard TTY=/dev/ftdi/tty/device
ãŸãã¯
rake upload_mbed MOUNT=/Volumes/MBED
ã ããã§ãäž¡æ¹ã®ããã€ã¹ã§LEDãåãããã«ç¹æ» ããŸãã
åšæ³¢æ°ãåçããŸããããïŒ
ããã§ã¿ã¹ã¯ã¯è§£æ±ºããããã§ããLEDã¯æ£ããééã§ç¹æ» ããŸãããèåŸã«äœããæ®ã£ãŠããŸãã LPC1114ã®æ倧åäœåšæ³¢æ°ã¯50 MHzã§ãããLPC1768ã«ã¯ããã«100 MHzã®åšæ³¢æ°ãããã3åã®1ã®åã§é§åããããšã¯ã»ãšãã©ãããŸããã
ãã©ãããã©ãŒã ãé©åã«åæåãããšããæ¥ãŸããã
platform/protoboard/init.c
ïŒ
#define CLOCK_MODE_IRC 0 // 12 MHz #define CLOCK_MODE_IRC_WITH_PLL 1 // 48 MHz #define CLOCK_MODE_SYS_WITH_PLL 2 // 48 MHz with external 12MHz crystal #define CLOCK_MODE CLOCK_MODE_IRC
LPC1114ã®ãœãŒã¹ã³ãŒãã«ã¯ãIRCã®æšæº12 MHzãPLLãééããIRCã®48 MHzãããã³PLLãééããã·ã¹ãã ãªã·ã¬ãŒã¿ã®48 MHzã®3ã€ã®ãã³ãã¬ãŒãããããŸãã åŸè ã®ãªãã·ã§ã³ã«ã¯è¿œå ã®ããŒããŠã§ã¢ãµããŒããå¿ èŠã§ãããããã¯éåžžã«é©åãªäœ¿çšã¢ãŒãã§ãããããæ€èšäžã§ãã
void platform_init() { // set up system oscillator and toggle PLL to point at it #if CLOCK_MODE == CLOCK_MODE_SYS_WITH_PLL int i; // power up system oscillator LPC_SYSCON->PDRUNCFG &= ~(1 << 5); // oscillator is not bypassed, runs at 1-20MHz range LPC_SYSCON->SYSOSCCTRL = 0; // allow circutry to settle down for (i = 0; i < 200; ++i) __NOP(); // set PLL clock source to system oscillator LPC_SYSCON->SYSPLLCLKSEL = 1; // wait for PLL clock source to be updated LPC_SYSCON->SYSPLLCLKUEN = 1; LPC_SYSCON->SYSPLLCLKUEN = 0; LPC_SYSCON->SYSPLLCLKUEN = 1; while (!(LPC_SYSCON->SYSPLLCLKUEN & 1)) ; #endif
ã·ã¹ãã ãªã·ã¬ãŒã¿ãŒã§äœæ¥ããå Žåã¯ãæ£ããåæåããããŸãæåã«ãªã³ã«ããå¿ èŠããããŸãã åã«èª¬æããããã«ããã§ã«çæãããã¯ããã¯ä¿¡å·ãXTALINå ¥åã«ååšããå Žåãçºæ¯åšãã¹ãããã§ããŸãã
åæåæååŸãããããªé 延ãçºçããã¯ãã§ãã 次ã«ãPLLãïŒIRCã®ä»£ããã«ïŒã·ã¹ãã çºæ¯åšããåäœããããã«è»¢éããŸããããã«ã¯èå³æ·±ãã¡ã«ããºã ããããŸããæžã蟌ã¿0ãæžã蟌ã¿1ãåŸ æ©-ã¬ãžã¹ã¿ã¯1ãè¿ãå§ããŸãã
// set up PLL if it's used #if CLOCK_MODE == CLOCK_MODE_IRC_WITH_PLL || CLOCK_MODE == CLOCK_MODE_SYS_WITH_PLL // set up PLL dividers LPC_SYSCON->SYSPLLCTRL = 0x23; // M = 3, P = 12MHz // PLLout = 12MHz * (M+1) / P = 48MHz // power up PLL LPC_SYSCON->PDRUNCFG &= ~(1 << 7); // wait until PLL is locked while (!(LPC_SYSCON->SYSPLLSTAT & 1)) ; // switch main clock to be driven from PLL LPC_SYSCON->MAINCLKSEL = 3; // wait for main clock source to be updated LPC_SYSCON->MAINCLKUEN = 1; LPC_SYSCON->MAINCLKUEN = 0; LPC_SYSCON->MAINCLKUEN = 1; while (!(LPC_SYSCON->MAINCLKUEN & 1)) ; #endif
2çªç®ã®éšåã¯PLLãåæåãããã®æ®µéã§IRCãŸãã¯ã·ã¹ãã ãªã·ã¬ãŒã¿ãŒããå ¥åã§ä¿¡å·ãåãåããŸãã æ瀺ã®åŒã«åŸã£ãŠååšåšã調æŽããPLLããªã³ã«ããŠããããã¯ããããŸã§åŸ ã¡ãŸãã ããŒãåŸã®äž»ãªåšæ³¢æ°ã¯IRCããåäœããPLLåºåããåäœããããã«è»¢éãããã®å€æŽããæŽå®ãããããŸã§åŸ æ©ããŸãã
SysTickã®48 MHzã§ã¯ã48000000ãµã€ã¯ã«ãå¿ èŠã§ãããããã¯æ倧å€ãè¶ ããŠããŸãã 1ã€ã®è§£æ±ºçã¯ã
platform_systick_wait_loop
é¢æ°ã«å®è£ ãããŠããããã€ãã®ã¿ã€ããŒãµã€ã¯ã«ãåŸ æ©ããããš
platform_systick_wait_loop
ïŒå¥ã®ãªãã·ã§ã³ã¯32ãããCT32B0ã¿ã€ããŒã䜿çšããããšã§ãïŒã
ç¹°ãè¿ãã«ãªããŸãããLPC1768ã³ãŒãã¯äžè¬çã«äŒŒãŠããŸãã ããã§éèŠãªç¹ã¯ãPLLãžã®åºåã§ã¯ãããã»ããµãžã®å ¥åã§å°ãªããšã275 MHzã§ãªããã°ãªããªããšããããšã§ã-100 MHz以äžã§ãã äžè¬ã«ãä»åããæ éã«ãã§ãã¯ããŸãã ãŸããããã©ã«ãå€ãããäœãé »åºŠã§äœæ¥ããããããã©ãã·ã¥ã¡ã¢ãªãžã®ã¢ã¯ã»ã¹ã«å¿ èŠãªæ段ã®æ°ãå¢ããããšã«æ³šæããããšãéèŠã§ãã
platform/mbed/init.c
ïŒ
// if we go for clock > 80 MHz, we need to set up flash access time LPC_SC->FLASHCFG = (LPC_SC->FLASHCFG & 0xFFF) | 0x4000; // 4 cpu clocks
ãã®äŸã®ã³ãŒãã¯ãç¹å®ã®æ°Žæ¶åšæ³¢æ°ã«é¢é£ä»ããããŠãããããmbedäžã®LPC1768ã«ã®ã¿é¢é£ããŠããŸãã ããã«ãLPC1768ããçŽæ¥ãæäœããå Žåããã®ããŒãããŒããŒã¯IRCããªã³ã«ã㊠PLLããªã³ã«ããŠèµ·åãããããã»ããã¢ããããåã«ã€ãã·ã£ã©ã€ã¶ãŒã§ãªãã«ããå¿ èŠããããŸãã
ãŸãšãããš
ãŸããä»æ¥ã¯CLKOUTãšãããžãã¯ã¢ãã©ã€ã¶ãŒãŸãã¯ãªã·ãã¹ã³ãŒãã§åšæ³¢æ°ãå¶åŸ¡ããæ¹æ³ã«ã€ããŠã話ããããã£ãã®ã§ããããã®æ¹æ³ã§ã¯èšäºã倧ããããŸãã CLKOUTã32ãããã¿ã€ããŒãå²ã蟌ã¿ãããã³ã¹ãªãŒãã¢ãŒã-ãããã¯ãã¹ãŠå°æ¥ã®ãªãªãŒã¹ã«å«ãŸããŸãã
Stellaris LaunchPadãå ¥ã£ãããã¯ã¹ãå ¥æããŸãããã¹ããŒãªãŒãçç Žããã«å¥ã®ã¢ãŒããã¯ãã£ãè¿œå ããæåã®æ¹æ³ãèããŸãããããã«ãããLPC1114ãã¡ã€ã³ã®ã¿ãŒã²ããããã»ããµã«ãªããŸããæåã«ãã¹ãŠã®äŸãå®è¡ããŸãã
ããã«ãããã¯ãããpoã³ããŸãããããããã£ãšæå³ã®ããæç« ãæžãããšæããŸãã
PSãã€ãã®ããã«ãããã¹ããæ ¡æ£ããŠãããpfactumãšãé»æ°æ©æ¢°ã«é¢ãã貎éãªã³ã¡ã³ãã«æè¬ããŸãããŸããPLLã«ã€ããŠèª¬æããŸã:-)ã