ãã®èšäºã§ã¯ãSTM32F4-DISCOVERYããŒãã䜿çšããŠã¢ããã°çœé»ãããªä¿¡å·ããã£ããã£ããæ¹æ³ãšãUSBã䜿çšããŠã³ã³ãã¥ãŒã¿ãŒã«è»¢éããæ©èœã«ã€ããŠèª¬æããŸãã
USBçµç±ã§ã³ã³ãã¥ãŒã¿ãŒã«ç»åã転éãã
STM32F4-DISCOVERYããŒãã䜿çšãããšãããŸããŸãªUSBããã€ã¹ãäœæã§ããŸã-䜿çšãããŠãããã€ã¯ãã³ã³ãããŒã©ãŒã®USBåšèŸºã¢ãžã¥ãŒã«ã«ã¯åªããæ©èœããããŸãã ãããããããã¯ãŒã¯äžã§äœ¿çšããçãããã¶ã€ã³ã®äŸã¯ã»ãšãã©ãããŸãã-ã»ãšãã©ã®å ŽåãUSBã䜿çšããŠHIDïŒããŒããŒããããŠã¹ããžã§ã€ã¹ãã£ãã¯ã®ãšãã¥ã¬ãŒã·ã§ã³ïŒããã³CDCïŒCOMããŒããšãã¥ã¬ãŒã·ã§ã³ïŒã¯ã©ã¹ãå®è£ ããŸãã éåžžãå èµUSBãã¹ãã¯ãUSBãã©ãã·ã¥ãã©ã€ãã®æ¥ç¶ã«äœ¿çšãããŸãã
ãŠã§ãã«ã¡ã©ãªã©ã®çããUSBããã€ã¹ãäœãããã£ãã ããã2ã€ã®æ¹æ³ã§å®è£ ã§ããŸã-ç¬èªã®ã¯ã©ã¹ã®USBããã€ã¹ãšãã®ãã©ã€ããŒãäœæããããã¯ããã«ç°¡åãªUSBãããªããã€ã¹çšã®æšæºUSBã¯ã©ã¹USBãããªããã€ã¹ã¯ã©ã¹ã䜿çšããŸãã ãã®ãããªããã€ã¹ã®ãã©ã€ããŒã¯ãWindows XPã«çµ±åãããŠããŸãã åºæ¬çãªUVCã®èª¬æã¯ã ãã®ããã¥ã¡ã³ãã«ãããŸãïŒæ°ãã1.1ããããŸãããUVCããŒãžã§ã³1.0ã䜿çšããŸããïŒã
ã€ã³ã¿ãŒãããäžã®ãã€ã¯ãã³ã³ãããŒã©ãŒã«UVCãå®è£ ããäŸã¯ã»ãšãã©ãããŸããã ããã€ã¹èšè¿°åã®æ£ããã³ã³ãã€ã«ã¯éåžžã«è€éã§ãïŒèšè¿°åã¯ãã¹ãŠã®æ©èœãèšè¿°ããŸãïŒã èšè¿°åã«ããããªãšã©ãŒããã£ãŠããããã€ã¹ãæ€åºãããããã«èŠãããšããäºå®ããŸãã¯BSODã«ããã€ãªããå¯èœæ§ããããŸãã æ¢åã®ãŠã§ãã«ã¡ã©ããèšè¿°åãã³ããŒã§ããŸããããããã¯äžå¿ èŠã«è€éã«ãªãå¯èœæ§ããããŸã-ã«ã¡ã©ã«ã¯å€ãã®å Žåãã€ã¯ãå«ãŸããŠãããåäžã®ç»åããã£ããã£ã§ããŸãïŒUVCã®çšèªã§ã¯éæ¢ç»åãã£ããã£ïŒããŸããå€æ°ã®ã«ã¡ã©èšå®ãå€æŽã§ããŸãã ããããã¹ãŠãæ··åããããã®ã§ããããžã§ã¯ããã§ããã ãã·ã³ãã«ã«ãããã£ãã®ã§ãã
é·ãæ€çŽ¢ã®åŸãç§ã¯å¶ç¶ãã®ãããªäžåœã®ãããžã§ã¯ãã«ã€ãŸãããã ããã¯STM32F103ã®ãããªã¹ã§ãããã³ã³ãã¥ãŒã¿ãŒã䜿çšããŠãã³ã³ãããŒã©ãŒãUVCããã€ã¹ãšèŠãªãç»åã衚瀺ããŸãã ãã®ãããžã§ã¯ãã¯MJPEGãšã³ã³ãŒããå®è£ ããŠããŸãã ãã®ãããžã§ã¯ãã¯éåžžã«èå³æ·±ããã®ã§ãããããã«ããã³ãŒãã¯éåžžã«çŽãããããã³ã¡ã³ãã¯ã»ãšãã©ãããŸããã ããããèšè¿°åãåãåºããèŠä»¶ã«åãããŠå°ã調æŽããŸããã
èšè¿°åãã³ã³ãã€ã«ãããšãã¯ããšããããéä¿¡ãããã€ã¡ãŒãžã®ãã©ã¡ãŒã¿ãŒãæå®ããå¿ èŠããããŸãã 320x240ãã¯ã»ã«ã®ç»åãµã€ãºãšNV12ç»åãã©ãŒãããã«æ±ºããŸããã UVCæšæºã§ã¯ãNV12ãšYUY2ã®2ã€ã®åœ¢åŒã®éå§çž®ç»åã®ã¿ãé ä¿¡ã§ããŸãã
2çªç®ã®åœ¢åŒã¯ããäžè¬çã§ãããNV12ã¯çœé»ç»åã®ãšã³ã³ãŒãã«ããé©ããŠãããå æã¹ããŒã¹ãå°ãªããªããŸãã ãã®åœ¢åŒã§ã¯ãããŒã¿ã¯YUV 4ïŒ2ïŒ0ã¿ã€ãã«åŸã£ãŠãšã³ã³ãŒããããŸãïŒ4ãã€ãã®è²æ å ±ã¯4ãã¯ã»ã«ã«è©²åœããŸãïŒã æåã«ç»åå šäœã®æããã«é¢ããæ å ±ïŒç§ã®å Žåã¯320 * 240ãã€ãïŒã次ã«è²ã«é¢ããæ å ±ïŒãã€ãUãšVã亀äºã«ç§»åããŸãïŒããããŸãã
åèšã§ãã€ã¡ãŒãžã¯ïŒ320 * 240 * 3/2ïŒãã€ããå æããŸãã ãã®åœ¢åŒã«ã¯æ¬ ç¹ããããŸã-ãã¹ãŠã®ããã°ã©ã ããã®åœ¢åŒã§åäœã§ããããã§ã¯ãããŸããã ãã®åœ¢åŒã®ããªãŒãŠã§ã¢ContaCamã§ã®åäœãä¿èšŒãããŠãããSkypeãæ£åžžã«æ©èœããŸããã
ãã¹ãç»åãã³ã³ãããŒã©ãŒã«ã¢ããããŒãããããã«ããšã³ã³ãŒããããç»åããŒã¿ãå«ã.hãã¡ã€ã«ãçæããç¹å¥ãªã³ã³ããŒã¿ãŒãäœæãããŸããã NV12ã«å ããŠãã³ã³ããŒã¿ãŒã¯YUY2圢åŒã§ç»åããšã³ã³ãŒãã§ããŸãã
éå§çž®ã€ã¡ãŒãžã®å Žåã«èšè¿°åãé©åã«æ§æããããŒã¿ãéä¿¡ããæ¹æ³ã®è©³çŽ°ãªèª¬æã¯ãå¥ã®ææžã ãããªããã€ã¹ã®ãŠãããŒãµã«ã·ãªã¢ã«ãã¹ããã€ã¹ã¯ã©ã¹å®çŸ©ïŒéå§çž®ãã€ããŒã ãã«èšèŒãããŠããŸãã
åºæ¬çãªãããžã§ã¯ããšããŠã USBãã€ã¯ãããžã§ã¯ããåãäžããŸããã ãŸããã¢ã€ãœã¯ããã¹ãšã³ããã€ã³ããä»ããã³ã³ãã¥ãŒã¿ãŒãžã®ããŒã¿è»¢éãå®è£ ããŸããã USBã§ã®äœæ¥ã¯ãã³ã³ãããŒã©ãŒè£œé å ã®ã©ã€ãã©ãªïŒSTSW-STM32046ïŒã䜿çšããŠå®è£ ãããŸãã èšè¿°åãVID / PIDïŒç§ãç解ããããã«ãä»»æã®ãã®ãã€ã³ã¹ããŒã«ã§ããŸãïŒã眮ãæããåŸãã³ã³ãããŒã©ãŒã¯ç»ååŠçããã€ã¹ãšããŠæ€åºãããŸããã 次ã®æ®µéã¯ããããªæ å ±ã¹ããªãŒã ã®ã³ã³ãã¥ãŒã¿ãŒãžã®è»¢éã§ãïŒã¹ã¿ãŒã¿ãŒã®å Žåãã³ã³ãããŒã©ãŒã®ã¡ã¢ãªã«ä¿åããããã¹ãç»åïŒã
äºåã«ãåŠçããå¿ èŠãããããŸããŸãªUSBèŠæ±ïŒèŠæ±ïŒã«èšåãã䟡å€ããããŸãã ã³ã³ãããŒã©ãŒãã³ã³ãã¥ãŒã¿ãŒïŒãã¹ãïŒããç¹å®ã®çš®é¡ã®èŠæ±ã«å¯ŸããèŠæ±ãåä¿¡ãããšãUSBã©ã€ãã©ãªã¯usbd_video_Setupé¢æ°ãåŒã³åºããèŠæ±ãåŠçããå¿ èŠããããŸãã
ãã®æ©èœã®ã»ãšãã©ã¯ããã€ã¯ã³ãŒãããååŸãããŸããããã¯ãæšæºããã€ã¹ãªã¯ãšã¹ãã®åŠçã§ãã ããã§ã¯ãSET_INTERFACEèŠæ±ãåä¿¡ãããšãã«çºçãã代æ¿ã€ã³ã¿ãŒãã§ã€ã¹éã®åãæ¿ãã«æ³šæãæãããšãã§ããŸãã UVCããã€ã¹ã¯ãå°ãªããšã2ã€ã®ä»£æ¿ã€ã³ã¿ãŒãã§ãŒã¹ãæäŸããå¿ èŠããããŸãããã®ãã¡ã®1ã€ïŒãŒã垯åå¹ ã0æªæºã®æ°å€ïŒã¯ãã³ã³ãã¥ãŒã¿ãŒãäžèŠãªãšãã«USBããã€ã¹ãåãæ¿ãããã¹äžã®ããŒã¿ãããŒãå¶éããŸãã ã³ã³ãã¥ãŒã¿ãŒäžã®ããã°ã©ã ãããã€ã¹ããããŒã¿ãåä¿¡ããæºåãã§ãããšãããã€ã¹ã«ãªã¯ãšã¹ããéä¿¡ããŠå¥ã®ä»£æ¿ã€ã³ã¿ãŒãã§ã€ã¹ã«åãæ¿ããŸãããã®åŸãããã€ã¹ã¯ãã¹ãããã®INããŒã¯ã³ãã±ããã®åä¿¡ãéå§ãããã¹ããããŒã¿ã®éä¿¡ãåŸ æ©ããŠããããšãéç¥ããŸãã
å¥ã®ã¿ã€ãã®èŠæ±ããããŸã-ãã®ã¯ã©ã¹ã«åºæã®ã¯ã©ã¹ããã€ã¹èŠæ±-UVCã ãããã¯ãã«ã¡ã©ããã¹ããŒã¿ã¹ã«é¢ããããŒã¿ãååŸãããã®åäœãå¶åŸ¡ããããã«äœ¿çšãããŸãã ããããæãåçŽãªå®è£ ã§ããã«ã¡ã©ã®ãã©ã¡ãŒã¿ãŒãå€æŽã§ããªãå Žåãããã°ã©ã ã¯ãªã¯ãšã¹ããåŠçããå¿ èŠããããŸãïŒGET_CURãGET_DEFãGET_MINãGET_MAXãSET_CURã ãããã¯ãã¹ãŠãã³ã³ãã¥ãŒã¿ãŒããã«ã¡ã©ã®é»æºãå ¥ããåã«éä¿¡ãããŸãã UVCä»æ§ã«åŸã£ãŠãã³ã³ãã¥ãŒã¿ãŒã¯ã«ã¡ã©ã«åäœå¯èœãªã¢ãŒããèŠæ±ããã«ã¡ã©ãåäœããã¢ãŒãã®æ瀺ãéä¿¡ããŸãã ãããŠããã®ãããªãªã¯ãšã¹ãã«ã¯ããããŒããšã³ãããã®2çš®é¡ããããŸãã ç§ã®å Žåããã®ããŒã¿ã¯äžå䜿çšãããŸãããããªã¯ãšã¹ããåŠçãããªãå ŽåïŒéä¿¡ãããããŒã¿ãååŸããªãããŸãã¯å¿çããªãïŒãã³ã³ãã¥ãŒã¿ãŒäžã®ããã°ã©ã ã¯ãããªãŒãºãããã³ã³ãããŒã©ãŒãåèµ·åããå¿ èŠããããŸãã
ãããžã§ã¯ããäœæããéçšã§ãUSBã©ã€ãã©ãªããã¹ããžã®ããŒã¿è»¢éèŠæ±ã誀ã£ãŠåŠçããããšãããããšãããããŸãã-å°éã®ããŒã¿ã転éããåŸãããŒã¿è»¢éãåæ¢ããã³ã³ãã¥ãŒã¿ãŒãåèµ·åããããšã«ãã£ãŠã®ã¿åèµ·åã§ããŸãã ããã¯ããããªæ å ±ïŒ1ãšã³ããã€ã³ããä»ããŠïŒãšå¶åŸ¡æ å ±ïŒ0ãšã³ããã€ã³ããä»ããŠïŒã®äŒéã«é©çšãããŸãã ããã¯ãæžã蟌ã¿ãéå§ããåã«ãç®çã®ãšã³ããã€ã³ãã®FIFOãäºåã«ã¯ãªã¢ããããšã§ä¿®æ£ãããŸãã
ãã¹ãŠã®å¿ èŠãªèŠæ±ã転éãããã³ã³ãã¥ãŒã¿ãŒã代æ¿ã€ã³ã¿ãŒãã§ã€ã¹ãã¡ã€ã³ã¢ãŒãã«åãæ¿ããèŠæ±ãéä¿¡ããåŸããããªããŒã¿ã®éä¿¡ãéå§ã§ããŸãã ã³ã³ãã¥ãŒã¿ãŒã¯ãããªç§ããšã«INããŒã¯ã³ãã±ãããã¹ã«çºè¡ãéå§ããŸãããããåä¿¡ãããšãã³ã³ãããŒã©ãŒã¯usbd_video_DataIné¢æ°ãåŒã³åºããããããã©ã€ãã©ãªããŒã¿è»¢éé¢æ°DCD_EP_TxãåŒã³åºãå¿ èŠããããŸãã
ãããªããŒã¿ã¯ãã±ããã§éä¿¡ãããŸããåãã±ããã®å é ã«ã¯ã2ãã€ãã®é·ãã®ããããŒãå¿ èŠã§ãïŒUVCä»æ§ã§ã¯ãè¿œå æ å ±ãå«ãé·ãããããŒã®äœ¿çšããµããŒããããŠããŸãïŒã ããããŒã®æåã®ãã€ãã¯åžžã«2ã§ã-ããã¯ããããŒã®å šé·ã§ãã 2çªç®ã®ãã€ãã«ããããã¹ãã¯ãã¬ãŒã ã®éå§ãšãã®å€æŽãæ€åºã§ããŸãããã®ãã€ãã®æåã®ãããã¯ãæ°ãããã¬ãŒã ã®æåã®ãã±ããã§äº€æããå¿ èŠããããŸãã ãã®ãã¬ãŒã ã®åŸç¶ã®ãã±ããã§ã¯ããã®ãããã®å€ã¯åããŸãŸã§ãã æ®ãã®ãããã¯ãŒãã®ãŸãŸã«ããŠããããšãã§ããŸãã ããã±ãŒãžã®æ®ãã¯ãããªããŒã¿ã§ãã ããã±ãŒãžå ã®é·ãã¯ä»»æã§ãïŒãã ããç¹å®ã®ãµã€ãºãè¶ ããªãããã«ããŠãã ããïŒã
ãã±ããå ã®ãããªããŒã¿ã®é·ããç¹å¥ã«éžæããŠããã€ãåäœã®ç»åã®ãµã€ãºãäœããªãåå²ããŸãããã€ãŸãããã¹ãŠã®ãã±ããã¯åãé·ãã§ãã
ãããçµæã§ãïŒ
ããã©ãŒãã³ã¹ã¯ã©ãã§ããïŒ
ãã®ã³ã³ãããŒã©ãŒã¯ãUSBãã«ã¹ããŒãæšæºããµããŒãããŠããŸããããã«ãããçè«äžã®é床ã¯12 Mbpsã«ãªããŸãã ãããã£ãŠãä¿¡é Œã§ããæ倧å€ã¯ããã¬ãŒã éä¿¡æéãïŒ320 * 240 * 3/2ïŒ/ïŒ12 * 10 ^ 6/8ïŒ= 76 msã§ããã13 FPSã«ãªããŸãã ãã ããUSBã¯åäºéãããã³ã«ã§ããããã€ã¯ãã³ã³ãããŒã©ãŒã«ã¯å¶éããããŸãã ã³ã³ãããŒã©ã¯ãFIFOã䜿çšããŠUSBçµç±ã§ããŒã¿ãéä¿¡ããŸããããã«ããã®ã³ã³ãããŒã©ã«ã¯1250ãã€ãã®ã¡ã¢ãªãããããã¹ãŠã®ã³ã³ãããŒã«ãã€ã³ãéã§åå²ããå¿ èŠããããŸãã ã¡ã¢ãªå²ãåœãŠã¯ãusb_conf.hããã¡ã€ã«ã«ç€ºããããµã€ãºã¯32ãããã¯ãŒãã§ç€ºãããŸãã
#define RX_FIFO_FS_SIZE 64 #define TX0_FIFO_FS_SIZE 16 #define TX1_FIFO_FS_SIZE 232 #define TX2_FIFO_FS_SIZE 0 #define TX3_FIFO_FS_SIZE 0
FIFOã³ãã³ããã³ã³ãã¥ãŒã¿ãŒããåä¿¡ããã«ã¯ãå°ãªããšã64ã¯ãŒããå²ãåœãŠãå¿ èŠããããŸã; FIFOã®å Žåã0ãšã³ããã€ã³ããä»ããã³ã³ãã¥ãŒã¿ãŒãžã®å¶åŸ¡æ å ±ã®è»¢éã«ã¯ãããã«16ã¯ãŒããå¿ èŠã§ãã ä»ã®ãã¹ãŠã¯ããããªäŒéã®æåã®ãšã³ããã€ã³ãã«å²ãåœãŠãããšãã§ããŸãã åèšã¯ïŒ64 + 16 + 232ïŒ* 4 = 1248ãã€ãã§ãã 232ã¯ãŒãïŒ928ãã€ãïŒã®å¶éãããããããã±ãããµã€ãºïŒVIDEO_PACKET_SIZEïŒã¯ïŒ768 + 2ïŒãã€ãã«èšå®ãããŸããã ãããã£ãŠã1ãã¬ãŒã ã¯ãïŒ320 * 240 * 3/2ïŒ/ïŒ768ïŒ= 150ãã±ããã§æ§æããã150 * 1msã§éä¿¡ããã6.6 FPSã«ãªããŸãã
å®éã®çµæã¯ãèšç®ããããã®ãšäžèŽããŸãã
ããã»ã©å€ãã¯ãããŸããããåããµã€ãºã®éå§çž®ç»åã転éããå Žåããã以äžã¯ååŸã§ããŸããã ãã®ããããã€ã¯ãã³ã³ãããŒã©ãŒã§ç»åãå§çž®ããããšã«ããŸããã
MJPEGãžã®ç§»è¡
UVCæšæºã¯ãããŸããŸãªã¿ã€ãã®å§çž®ããµããŒãããŠããŸãããã®ãã¡ã®1ã€ãMJPEGã§ãã ãã®ã¿ã€ãã®å§çž®ã§ã¯ãåãœãŒã¹ç»åãã¬ãŒã ã¯JPEGæšæºã«åŸã£ãŠå§çž®ãããŸãã çµæã®å§çž®ãã¬ãŒã ã¯ãäžèšã®ããã«ã³ã³ãã¥ãŒã¿ãŒã«éä¿¡ã§ããŸãã MJPEGã®èšè¿°åãšããŒã¿è»¢éæ©èœã«ã€ããŠã¯ãã ãããªããã€ã¹ã®ãŠãããŒãµã«ã·ãªã¢ã«ãã¹ããã€ã¹ã¯ã©ã¹å®çŸ©ïŒMotion-JPEGãã€ããŒã ãã®ããã¥ã¡ã³ãã§èª¬æããŠããŸãã
ã³ã³ãã¥ãŒã¿ãŒã§æºåãããéçã€ã¡ãŒãžã®è»¢éã¯éåžžã«ç°¡åã§ããããšãå€æããŸããã以åã®ããã«ãéåžžã®JPEGãã¡ã€ã«ã.hãã¡ã€ã«ã«å€æãããããžã§ã¯ãã«è¿œå ããŠããããã§è»¢éããŸãã å§çž®ã€ã¡ãŒãžã®ãµã€ãºã¯ä»»æã§ãããããæåŸã®ããŒã¿ãã±ããã®é·ããå¯å€ã§ãããããèšç®ããå¿ èŠããããŸãã
30000ãã€ãã®å§çž®ã€ã¡ãŒãžãµã€ãºã§ã¯ãïŒ30000/768ïŒ=> 40ãã±ããã§æ§æããã40ãã±ãããéä¿¡ãããŸããããã¯25 FPSã«çžåœããŸãã
JPEGã§ã®å§çž®ã«ã¯ã ããã§ååŸãããšã³ã³ãŒããŒã䜿çšããããšã«ããŸãã ã ããã¯ARMã«é©åããŠãããçœé»ç»åçšã«ã®ã¿èšèšãããŠãããç§ã«é©ããŠããŸãããã®ãããçœé»ã«ã¡ã©ããããŒã¿ãååŸããŸãã
ãã®ãšã³ã³ãŒããŒã¯STM32F4ã§ããã«åäœãéå§ããŸããããCortrx-M4ã«ã¯é©å¿ããŸããã§ããã ãã¹ãbmpãã¡ã€ã«ã¯25ããªç§ã§å§çž®ãããããã¯40 FPSã«çžåœããŸãã ã³ã³ãããŒã©ãŒããå§çž®ã€ã¡ãŒãžãèªã¿åãããã«ãSTM32 ST-LINK Utilityããã°ã©ã ã䜿çšããŸããã ãŸããããã°ã©ã ã®ãããã°äžã«ãå§çž®ã€ã¡ãŒãžãé 眮ãããé åã®éå§ã¢ãã¬ã¹ãèŠã€ããŠããããã®ããã°ã©ã ã§æå®ããå¿ èŠããããŸãã èªã¿åããã³ãã¯ãããã«.jpgãšããŠä¿åã§ããŸãã
次ã«ãããã«ãããã¡ãªã³ã°ã®ããã«ãšã³ã³ãŒãã«2ã€ã®åºåé åãæäœããæ©èœãè¿œå ããUSBããŒã¿åºåãããžã§ã¯ããšçµã¿åãããŸããã
CCMã¡ã¢ãªäœ¿çšéæ©èœ
䜿çšãããã³ã³ãããŒã©ãŒã§ã¯ãRAMã¯ããã€ãã®ãããã¯ã«åå²ãããŸãã ãã®1ã€-ïŒ64 Kãã€ãïŒã¯CCMãšåŒã°ããDMAãä»ããŠã¢ã¯ã»ã¹ã§ããŸããã ããã«ãå§çž®ã€ã¡ãŒãžãä¿åããããã®2ã€ã®é
åãé
眮ããããšã«ããŸããã
ãã®ã¡ã¢ãªã䜿çšããã«ã¯ãIARã§äœ¿çšãã.icfãã¡ã€ã«ãç·šéããè¡ãè¿œå ããå¿ èŠããããŸãã
ã³ãŒãå ã®é åã¯ã次ã®ããã«å®£èšããå¿ èŠããããŸãã
ãã®ã¡ã¢ãªã䜿çšããã«ã¯ãIARã§äœ¿çšãã.icfãã¡ã€ã«ãç·šéããè¡ãè¿œå ããå¿ èŠããããŸãã
define symbol __ICFEDIT_region_RAMCCM_start__ = 0x10000000; define symbol __ICFEDIT_region_RAMCCM_end__ = 0x1000FFFF; ....... define region CCMRAM_region = mem:[from __ICFEDIT_region_RAMCCM_start__ to __ICFEDIT_region_RAMCCM_end__]; ....... place in CCMRAM_region {section .ccmram};
ã³ãŒãå ã®é åã¯ã次ã®ããã«å®£èšããå¿ èŠããããŸãã
#pragma location = ".ccmram" uint8_t outbytes0[32000]; #pragma location = ".ccmram" uint8_t outbytes1[32000];
ãã ããçµæã®ãã¶ã€ã³ã¯ContaCamããã°ã©ã ãšãã©ãŠã¶ãŒã§ã®ã¿æ©èœããŸããïŒ ãã¡ãã§ç¢ºèªããŠãã ãã ïŒã éæ¢ç»åã§ã¯ã35 FPSãååŸã§ããŸããã
å§çž®ç»åã®äŸïŒç»åãµã€ãº17 Kãã€ãïŒïŒ
bmpãã¡ã€ã«ã®æ å ±ã¯ãã®ããã«ä¿åããããããã€ã¡ãŒãžã¯äžäžéã«ãªã£ãŠããŸãã
ããããä»ã®ããã°ã©ã ã¯ãŸã£ããæ©èœããªããããã®ãããªã€ã¡ãŒãžãäžããŸããã
ããã¯ãUVCæšæºãMJPEGã䜿çšããçœé»ç»åã®è»¢éããµããŒãããŠããªããšããäºå®ã«ãããã®ã§ãã
JPEGç»åã®èŠä»¶ã¯æ¬¡ã®ãšããã§ãã
â¢ã«ã©ãŒãšã³ã³ãŒãã£ã³ã°-YCbCr
â¢ãã¯ã»ã«ãããã®ãããæ°-ã«ã©ãŒã³ã³ããŒãã³ãããšã«8ã€ïŒãã£ã«ã¿ãªã³ã°/ãµããµã³ããªã³ã°åïŒ
â¢ãµããµã³ããªã³ã°-422
ãããã£ãŠãæ¢åã®ãšã³ã³ãŒããåäœæããŠæ¬äŒŒã«ã©ãŒç»åã圢æããå¿ èŠããããŸãããå®éããã®ãããªç»åã§ã¯èŒåºŠããŒã¿ïŒYïŒã®ã¿ããšã³ã³ãŒããããã«ã©ãŒããŒã¿ïŒCbããã³CrïŒã®ä»£ããã«ãŒããéä¿¡ãããŸãã JPEG圢åŒã®æ§é ãããæ·±ãç¥ãå¿ èŠããããŸããã
çœé»ããæ¬äŒŒã«ã©ãŒãžã®ç§»è¡
以åã®ãšã³ã³ãŒããŒã®ä»çµã¿ïŒ
1. JPEGãã¡ã€ã«ã®ããããŒã圢æãããŸãã
2.å ã®ç»åã®ãããã¯ïŒ8x8ãã¯ã»ã«ïŒåŠçã
2.1åãããã¯ã¯ã¡ã¢ãªããèªã¿åããããã®é¢æ£ã³ãµã€ã³å€æïŒDCTïŒ
2.2çµæã®64åã®å€ã¯éååãããçµæã¯ãããã³ã³ãŒãã䜿çšããŠããã¯ãããŸãã
3.ããŒã¿çµäºããŒã«ãŒãçæãããå§çž®ç»åã®ãµã€ãºãèšç®ãããŸãã
JPEGã®è©³çŽ°ã«ã€ããŠã¯ã ãã¡ããšãã¡ããã芧ãã ãã ã
å§çž®ãããç»åã®è²æ å ±ã¯JPEGããããŒã«ä¿åããããããå€æŽããå¿ èŠããããŸãã è²11ã®èŒåºŠæåéåŒã22ã§ãSOF0ããã³SOSã»ã¯ã·ã§ã³ãå€æŽãããããã®3ã€ã®æåã®äœ¿çšã瀺ãå¿ èŠããããŸããã©ãã§ããéååããŒãã«ã®èå¥åãšããŠ0ãæå®ããŸããã
ããã§ãæ å ±ã®ã³ãŒãã£ã³ã°æ¹æ³ãå€æŽã§ããŸãã è²æ å ±ã¯éåŒããããããã4ã€ã®è²æ å ±ãããã¯ã¯2ã€ã®è²æ å ±ãããã¯ã«å¯Ÿå¿ããå¿ èŠããããŸãã ãããã£ãŠãèŒåºŠæ å ±ã®4ã€ã®ãããã¯ãæåã«é çªã«ã³ãŒãã£ã³ã°ãããŸãããã®åŸãããã«2ã€ã®è²æ å ±ã®ãããã¯ããšã³ã³ãŒãããå¿ èŠããããŸãïŒäžèšã®èšäºã®äŸïŒã
䜿çšãããã©ã€ãã©ãªã§ã¯ãéååãåŠçãããããŒã¿ã®æçµå§çž®ãããã³ã¡ã¢ãªãžã®æžã蟌ã¿ã¯å¥ã®é¢æ°ã«ãã£ãŠå®è¡ããããããè²æ å ±ã®åœ¢æã«ã¯ãDCTä¿æ°ã®é åãç¡å¹ã«ããŠãã®é¢æ°ã2ååŒã³åºãã ãã§ååã§ãã
ãã ããJPEGã³ãŒãã£ã³ã°ã«ã¯éèŠãªæ©èœããããŸãããšã³ã³ãŒããããã®ã¯åãããã¯ã®å é ã®DCä¿æ°ã§ã¯ãªããçŸåšã®DCä¿æ°ãšå¯Ÿå¿ããã³ã³ããŒãã³ãã®åã®ãããã¯ã®DCä¿æ°ã®å·®ã§ã ã ã©ã€ãã©ãªã§ã¯ããã®å·®ç°ã¯éååã®åã«æåã«èšç®ããããããCrããã³Cbãã£ãã«ã®åŠçäžã«å·®ç°ãèšç®ãããªãããã«äžèšã®é¢æ°ãå€æŽããå¿ èŠããããŸãã-ãããã®ã³ã³ããŒãã³ãã§ã¯ãŒããç¶ããŸãã
ãã®çµæã䜿çšãããŠãããã¹ãŠã®ãããªãã£ããã£ããã°ã©ã ã§ç»åãæ£ãã衚瀺ãããããã«ãªããŸããã ãã®ç䌌ã«ã©ãŒã³ãŒãã£ã³ã°ã®æ¬ ç¹ã¯ãé床ãå€å°äœäžããããšã§ãã ãã¹ãã€ã¡ãŒãžã®å§çž®ã«ã¯35ããªç§ãããã28 FPSã«ãªããŸããã
ã¢ããã°ãããªãã£ããã£
ãããªããŒã¿ã蚱容å¯èœãªé床ã§ã³ã³ãã¥ãŒã¿ãŒã«è»¢éããæ¹æ³ãã§ããã®ã§ããããªä¿¡å·ã«åãçµãããšãã§ããŸãã USBã䜿çšããå®éšã®æåããããããã°ããŒãèªäœã䜿çšããŠã¢ããã°ãããªã«ã¡ã©ããã®ãããªä¿¡å·ã®ãã£ããã£ãå®è£ ããã€ããã§ããã
ãã§ã«ãã€ã¯ãã³ã³ãããŒã©ã§èªå®¶è£œã®ãã¬ããäœã£ãã®ã§ãçœé»ã®ãããªä¿¡å·ããã£ããã£ããæè¡ã¯ç§ã«ãšã£ãŠæ°ãããã®ã§ã¯ãããŸããã§ããã ãã¡ãããSTM32F4ã³ã³ãããŒã©ãŒã¯ATxmegaãšã¯å€§ããç°ãªãããããããªãã£ããã£ãžã®ã¢ãããŒããå€æŽããå¿ èŠããããŸããã
PAL圢åŒèªäœã¯ãã§ã«ããŸããŸãªãªãœãŒã¹ã§ç¹°ãè¿ã説æãããŠããã®ã§ãäž»ãªèŠå®ã«çŠç¹ãåœãŠãŸãããããã¯çœé»ããŒãžã§ã³ã®ã¿ã§ãã
ãã®åœ¢åŒã®ãã¬ãŒã åšæ³¢æ°ã¯25 Hzã§ãããã€ã³ã¿ãŒã¬ãŒã¹ã¹ãã£ã³ã䜿çšãããŸããã€ãŸãããã¬ãŒã ãéä¿¡ãããšãã«ãå¶æ°ã©ã€ã³ãšå¥æ°ã©ã€ã³ãæåã«éä¿¡ãããŸãã ãã®ãããªè¡ã®åã»ããã¯ããã£ãŒã«ããšåŒã°ããŸãã ãã®åœ¢åŒã®ãã£ãŒã«ãã«ã¯ã50 HzïŒ20 msïŒã®åšæ³¢æ°ããããŸãã 1ã€ã®ãã£ãŒã«ãã§ã¯ã312.5è¡ãéä¿¡ãããŸãïŒãã®ãã¡288.5è¡ã®ã¿ããããªæ å ±ãå«ã¿ãŸãïŒã ãã¹ãŠã®ã©ã€ã³ã¯ã64ÎŒsã®åšæã§ç¶ãã¯ããã¯ãã«ã¹ã«ãã£ãŠåé¢ãããŸãã ã©ã€ã³èªäœã®ãããªä¿¡å·ã¯52ÎŒsããããŸãã
ãã£ãŒã«ãã¯ãã¬ãŒã ãšã€ã³ã©ã€ãžã³ã°ã¯ããã¯ãã«ã¹ã§åºåãããŸãã ã¯ããã¯ãã«ã¹ãã€ã³ã©ã€ãºããéèŠãªæ©èœã¯ãåšæãè¡åšæã®2åïŒ32ÎŒsïŒã§ãããããã¯ããã¯ãã«ã¹ãšç°¡åã«åºå¥ã§ããããšã§ãã
ãããã£ãŠãã³ã³ãããŒã©ãŒã®ã¡ã¢ãªã«ç»åããã£ããã£ããã«ã¯ãã¯ããã¯ä¿¡å·ãæ€åºãããããããã€ã³ã©ã€ãºãã«ã¹ãæœåºããåã©ã€ã³ã®ãããªéä¿¡ãéå§ããåã«ADCã®å€æãéå§ã§ããããã°ã©ã ãäœæããå¿ èŠããããŸãã
次ã«ããããªä¿¡å·ãããžã¿ã«åããæ¹æ³ã«ã€ããŠè©³ãã説æããŸãã
STM32F4ã³ã³ãããŒã©ãŒã«ã¯3ã€ã®åå¥ã®ADCããããããããã12ãããã®å解èœã§2.4 MSPSã®é床ã§åäœã§ããŸãã ããã容éãæžå°ãããšé床ã¯åäžããŸããã320 * 240ã®è§£å床ãåŸãã«ã¯ååã§ã¯ãããŸããã ãã ããã³ã³ãããŒã©ãŒã䜿çšãããšãè€æ°ã®ADCãçµã¿åãããããšãã§ããŸãããã¹ãŠã®ADCã«ãããã£ããã£ãåæã«æ§æããããšããADCéã®ãã£ããã£é 延ãèšå®ããããšãã§ããŸãããã®çµæãå šäœçãªãã£ããã£é床ãåäžããŸãã
2ã€ã®ADCãåæã«äœ¿çšããå Žåã®ãã£ããã£é床ã¯ã©ã®ãããã§ããïŒã€ã³ã¿ãŒãªãŒããã¥ã¢ã«ã¢ãŒãïŒïŒ
ADCã®ã¯ãããã³ã°ã«ã¯ãAPB2ãã¹ã䜿çšããããã®ã¯ããã¯åšæ³¢æ°ã¯ãã³ã³ãããŒã©ãŒãåæåããããšãã«ã·ã¹ãã åšæ³¢æ°ã®ååïŒ168 MHz / 2ïŒ= 84 MHzã«èšå®ãããŸãã ADCã®å Žåãããã¯å€ããããããADCãã»ããã¢ãããããšãã¯ãååšåšã2ã«èšå®ããå¿ èŠããããŸããçµæã®42 MHzã®åšæ³¢æ°ã¯ãããŒã¿ã·ãŒãã§èš±å®¹ãããæ倧å€ïŒ36 MHzïŒãããé«ãã§ããããã®åšæ³¢æ°ã§ãADCã¯ããŸãæ©èœããŸãã
ããã深床ã8ãããã«èšå®ãããåADCãåå¥ã«åäœããå Žåãæ倧å€æé床ã¯ïŒ42 MHz /ïŒ3 + 8ïŒïŒ= 3.81 MSPSã«ãªããŸãã 6ãµã€ã¯ã«ã®ããŒã¿ãã£ããã£æéã®éã«é 延ãèšå®ããããšã«ããã7 MSPSã®é床ãšã7ãµã€ã¯ã«-6 MSPSãåŸãããšãã§ããŸãã
æåŸã®ãªãã·ã§ã³ãéžæããŸããã ã©ã€ã³å šäœïŒ64ÎŒsïŒã«ã¯384ãã€ãããããªä¿¡å·ã®ããã©ã€ã³ã®ã¢ã¯ãã£ãéšåïŒ52ÎŒsïŒã«ã¯312ãã€ãïŒãã¯ã»ã«ïŒãå¿ èŠã§ãã
ADCã¯ãDMAã䜿çšããŠå€æçµæãã¡ã¢ãªã«éä¿¡ããŸãã 2ã€ã®8ãããADCã䜿çšããå Žåã2çªç®ã®ADCã®å€ææã«ããŒã¿ã16ãããã¯ãŒãã®åœ¢åŒã§ã¡ã¢ãªã«è»¢éãããŸãã ååãšããŠããã¬ãŒã å šäœã®å 容ãã¡ã¢ãªã«ãã£ããã£ããããšãå¯èœã§ããããã«ã¯ãïŒ384 * 240ïŒ= 92.16 KBãå¿ èŠã§ãã ããããç§ã¯å¥ã®æ¹æ³ãåããŸãããããŒã¿ãã£ããã£ã¯ãã³ã³ãããŒã©ãåæãã«ã¹ãæ€åºããåŸã«å§ãŸãã366ãã€ãïŒ183 DMA転éïŒããã£ããã£ããåŸã«åæ¢ããŸãã ãªããã®ãããªæ°ãéžã°ããã®ã-ç§ã¯ããã«äŒããŸãã ãã®çµæããããªããŒã¿ã¯ïŒ366 * 240ïŒ= 87.84 KBã®RAMãå æããŸãã
ã¯ããã¯ä¿¡å·ãæ€åºããæ¹æ³ãæ€èšããŠãã ããã çæ³çã«ã¯ãç¹å¥ãªãããããŸãã¯å°ãªããšãã³ã³ãã¬ãŒã¿ã§æ€åºããæ¹ãè¯ãã®ã§ãããããã¯èšèšãè€éã«ããŸãã æªäœ¿çšã®ADCã¯ãŸã 1ã€ãããããããã䜿çšããŠã¯ããã¯ä¿¡å·ãæ€åºããããšã«ããŸããã åADCã«ã¯ãç¹å¥ãªã¢ãžã¥ãŒã«ãã¢ããã°ãŠã©ããããã°ããå«ãŸããŠããŸãã ããžã¿ã«åãããå€ãæå®ãããå¶éãè¶ ããŠããå Žåãå²ã蟌ã¿ãçæã§ããŸãã ãã ãããã®ã¢ãžã¥ãŒã«ã¯ããžã¿ã«åãããä¿¡å·ã®ãšããžã®å€åã«å¿çããããšã¯ã§ããŸãããå ¥åä¿¡å·ãŸãã¯ã¢ãžã¥ãŒã«èšå®ãå€æŽããããŸã§å²ã蟌ã¿ãçæããŸãã ä¿¡å·ã®åç·ãæ€åºããå¿ èŠããããããäžæããããã³ã«ãã®ã¢ãžã¥ãŒã«ãåæ§æããå¿ èŠããããŸããã ã¢ããã°ãŠã©ããããã°ã®ãããå€ã®èªåæ€åºãããã°ã©ã ã«å®è£ ããªãã£ãããã䜿çšäžã®ã«ã¡ã©ã«å¯ŸããŠæåã§æå®ãããŸãã
ã€ã³ã©ã€ãžã³ã°ãã«ã¹ãæ€åºããããã«ã1 MHzã®åšæ³¢æ°ã§åäœããã³ã³ãããŒã©ãŒã¿ã€ããŒã®1ã€ã䜿çšãããŸãã ã¿ã€ããŒã¯ç¶ç¶çã«å®è¡ãããã¢ããã°ãŠã©ããããã°å²ã蟌ã¿ãã³ãã©ãŒïŒã¯ããã¯ã®ç«ã¡äžãããšããžãæ€åºããããšãïŒã§ãçŸåšã®å€ãèªã¿åãããåã®å€ãšæ¯èŒãããŸãã ãããã£ãŠãæ°Žå¹³åæãã«ã¹ãçåãã«ã¹ãšåºå¥ããããšãå¯èœã§ãã ã€ã³ã©ã€ãžã³ã°ã¯ããã¯ãã«ã¹ãçµäºãããšãã³ã³ãããŒã©ãŒã¯17åã®æ°Žå¹³ã¯ããã¯ãã«ã¹ãã¹ãããããã¯ããã¯ãã«ã¹ã®ç«ã¡äžãããšããžãæ€åºããããšãçŸåšã®ã©ã€ã³ã®ãããªããŒã¿ã®ãã£ããã£ãéå§ããŸãã ãã®ã³ã³ãããŒã©ãŒã®å²ã蟌ã¿ãã³ãã©ãŒãžã®å ¥åã¯å¯å€æéã§çºçããå¯èœæ§ããããADC 3ãæåã®2ã€ãããäœéã§å®è¡ããããããã¯ããã¯ããã³ããšãã£ããã£éå§éã®æéãç°ãªãå Žåããããéãããã©ã€ã³ã ãããããããªããŒã¿ã®ãã£ããã£ãã¯ããã¯ã®ãªãŒãã£ã³ã°ãšããžããå§ãŸããã©ã€ã³ã366ãã€ããããçç±ã§ãããããã£ãŠãã¯ããã¯ã®äžéšããã¬ãŒã ã«èœã¡ãã©ã€ã³ããšã«ããã°ã©ã ã§åé€ã§ããŸãã
波圢ã¯ããããªä¿¡å·ãã©ã®ããã«ãã£ããã£ãããŠãããã瀺ããŸãïŒDMAåäœäžããé»è²ããã£ã³ãã«ã¯1ã«èšå®ãããŸãïŒã
ãã£ããã£ã¯ããããªããŒã¿ã®åºçŸåŸã«ã®ã¿éå§ãããŸãã
240è¡ã®å¶éãèšå®ãããŠããããã1ã€ã®ãã£ãŒã«ãã®ãã¹ãŠã®è¡ããã£ããã£ãããããã§ã¯ãããŸããã
çµæã¯æ¬¡ã®çç»åã§ãïŒST-LinkãŠãŒãã£ãªãã£ã䜿çšããŠååŸïŒïŒ
ã³ã³ãããŒã©ã®ã¡ã¢ãªã«ç»åããã£ããã£ããããåŠçããå¿ èŠããããŸããåã©ã€ã³ã§ãã¯ããã¯ä¿¡å·ã®ãã£ããã£ã«é¢é£ãããªãã»ãããåé€ãããã¯ã»ã«èŒåºŠå€ããé»ã¬ãã«ãæžç®ããŸãã ãã®ã³ãŒããæé©åããããšããªãã£ãã®ã§ãå®äºãããŸã§ã«5ããªç§ããããŸãã
ç»åãåŠçãããåŸãJPEGã§ã®ãšã³ã³ãŒããéå§ã§ããŸããåæã«ãUSBãä»ããŠåã®ç»åã®æ¢ã«ãšã³ã³ãŒããããããŒã¿ã®è»¢éãéå§ãããŸãã
ãããã£ãŠããã¬ãŒã ã¯20ããªç§ãã£ããã£ãããåŠçã«ã¯5ããªç§ããããããŒã¿è»¢éã§ã®ãšã³ã³ãŒãã¯35ããªç§ã§ãããåèš60ããªç§ãã€ãŸã16.6 FPSã®ãã¬ãŒã ã¬ãŒãã«ãªããŸãã ãã®çµæã1ã€ã®ãã¬ãŒã ïŒå®éã«ã¯ãã£ãŒã«ãïŒããã£ããã£ããã2ã€ã®ãã¬ãŒã ãã¹ããããããããšãããããŸããã PALã¹ãã£ã³ã¯ã€ã³ã¿ãŒã¬ãŒã¹ã§ãããããå¶æ°ãŸãã¯å¥æ°ãã£ãŒã«ãã亀äºã«ãã£ããã£ããã1ãã¯ã»ã«ãã€ç»åã«ãžãã¿ãŒãçããããšãããããŸãã ãããåãé€ãã«ã¯ããã¬ãŒã ã®ãã£ããã£éã«è¿œå ã®é 延ãè¿œå ããŸãããã®åŸãå¥ã®ãã£ãŒã«ããã¹ããããããåºåã®ãã¬ãŒã ã¬ãŒããïŒ50/4ïŒ= 12.5 FPSã«äœäžããŸãã
ãããªãœãŒã¹ã«ã€ããŠå°ã
æåã¯ãKPC-190Sãããªç£èŠã«ã¡ã©ãä¿¡å·æºãšããŠäœ¿çšããäºå®ã§ããïŒãã®ã«ã¡ã©ã¯ã»ãŒ15幎åã§ãïŒã ããã¯ãè¯å¥œãªç»åå質ãæäŸãããšããããšã§ã¯ãããŸãã-éåžžã«ãã€ãºãå€ããã³ã³ãã©ã¹ããããŸãé«ããªããæ¯å¹ ãå°ããïŒãªã·ãã°ã©ã ãã1 Vã«è¿ãããšãããããŸãïŒã åºåä¿¡å·ããããã«èª¿æŽããããã«ãã«ã¡ã©ã¯å¯å€æµæåšã®æµæåå²åšãä»ããŠã³ã³ãããŒã©ãŒã«æ¥ç¶ãããŸãã ã«ã¡ã©ãæ¥ç¶ãããŠããããŒãã®å¯äžã®ä¿¡å·åºåã¯PC2ã§ãïŒãã¹ãŠã®ADCãæ¥ç¶ãããŠããŸãïŒã
ãã¶ã€ã³ã®å€èŠ³ïŒ
ãã®ã«ã¡ã©ã¯è¯å¥œãªç»è³ªãæäŸããªãã£ããããCanon A710ã«ã¡ã©ããã®ä¿¡å·ãååŸããããšã«ããŸããã ãã¬ãã«æ¥ç¶ããããã®ã¢ããã°åºåããããã«ã¡ã©ç»é¢ã«è¡šç€ºããããã¹ãŠã®ãã®ã衚瀺ãããŸãã ã«ã¡ã©ã®ä¿¡å·å質ã¯åªããŠããŸããããããªä¿¡å·ã¯ã«ã©ãŒã§ãã ä¿¡å·ããè²æåãé€å»ããããã«ããã®ãã£ã«ã¿ãŒã䜿çšããŸããïŒ
ããã«ãã«ã¡ã©åºåã®ã¯ããã¯ãã«ã¹ã®æ¥µæ§ã¯è² ã§ãããããã³ã³ãããŒã©ãŒã®ADCã§æ€åºããã«ã¯ã調æŽå¯èœãªé»æºã䜿çšããŠä¿¡å·ã«ãã€ã¢ã¹é»å§ãè¿œå ããå¿ èŠããããŸããã ãŸããã¢ããã°ãŠã©ããããã°ã®å¿çãããå€ããããã«å€æŽããå¿ èŠããããŸããã
ã«ã¡ã©ãæ¥ç¶ããããã¶ã€ã³ã®å€èŠ³ïŒ
ã«ã¡ã©ããåãåã£ãç»åã®äŸïŒ
ãããªããã€ã¹ã®æäœïŒ
ãããžã§ã¯ãã®ãœãŒã¹ã³ãŒãïŒ github.com/iliasam/STM32F4_UVC_Camera