snapshot before checking ioc in TrafficLightsPlusPlus
This commit is contained in:
2407
.metadata/.ide.log
2407
.metadata/.ide.log
File diff suppressed because one or more lines are too long
2099
.metadata/.ide.log-2025-09-22.log
Normal file
2099
.metadata/.ide.log-2025-09-22.log
Normal file
File diff suppressed because one or more lines are too long
2035
.metadata/.ide.log-2025-09-29.log
Normal file
2035
.metadata/.ide.log-2025-09-29.log
Normal file
File diff suppressed because one or more lines are too long
310
.metadata/.ide.log-2025-09-30.log
Normal file
310
.metadata/.ide.log-2025-09-30.log
Normal file
@@ -0,0 +1,310 @@
|
|||||||
|
2025-09-30 16:10:40,870 [INFO] Activator:176 -
|
||||||
|
|
||||||
|
|
||||||
|
2025-09-30 16:10:40,873 [INFO] Activator:177 - !SESSION log4j initialized
|
||||||
|
2025-09-30 16:10:46,753 [INFO] LogOutputStream:77 - [STDOUT_REDIRECT]
|
||||||
|
2025-09-30 16:10:48,576 [INFO] ApplicationProperties:184 - Using Application install path: /home/ja/st/stm32cubeide_1.19.0/plugins/com.st.stm32cube.common.mx_6.15.0.202507011659
|
||||||
|
2025-09-30 16:10:48,600 [INFO] DbMcusXml:78 - Set database path to: /home/ja/st/stm32cubeide_1.19.0/plugins/com.st.stm32cube.common.mx_6.15.0.202507011659//db//mcu/
|
||||||
|
2025-09-30 16:10:48,601 [INFO] ApiDb:274 - Set plugin database path to: /home/ja/st/stm32cubeide_1.19.0/plugins/com.st.stm32cube.common.mx_6.15.0.202507011659//db//plugins/boardmanager/
|
||||||
|
2025-09-30 16:10:48,601 [WARN] ApiDb:259 - Overriding images path with different value: => /home/ja/st/stm32cubeide_1.19.0/plugins/com.st.stm32cube.common.mx_6.15.0.202507011659//db//plugins/mcufinder/images/
|
||||||
|
2025-09-30 16:10:48,609 [INFO] ApiDb:250 - Set database path to: /home/ja/.stmcufinder/plugins/mcufinder//mcu/
|
||||||
|
2025-09-30 16:10:48,611 [INFO] DbMcusAds:125 - Set database path to: /home/ja/.stmcufinder/plugins/mcufinder//mcu/
|
||||||
|
2025-09-30 16:10:48,614 [INFO] CrossReferenceDbSqlite:203 - Set database path to: /home/ja/.stmcufinder/plugins/mcufinder//mcu/cs/
|
||||||
|
2025-09-30 16:10:48,753 [INFO] RulesReader:64 - Compatibility file has been processed (317 Rules)
|
||||||
|
2025-09-30 16:10:48,826 [INFO] DbMcusXml:78 - Set database path to: /home/ja/st/stm32cubeide_1.19.0/plugins/com.st.stm32cube.common.mx_6.15.0.202507011659//db//mcu/
|
||||||
|
2025-09-30 16:10:48,826 [INFO] ApiDb:274 - Set plugin database path to: /home/ja/st/stm32cubeide_1.19.0/plugins/com.st.stm32cube.common.mx_6.15.0.202507011659//db//plugins/boardmanager/
|
||||||
|
2025-09-30 16:10:48,826 [INFO] ApiDb:261 - Set plugin images path to: /home/ja/st/stm32cubeide_1.19.0/plugins/com.st.stm32cube.common.mx_6.15.0.202507011659//db//plugins/mcufinder/images/
|
||||||
|
2025-09-30 16:10:48,826 [WARN] DbFile:41 - Overriding database path with different value: /home/ja/.stmcufinder/plugins/mcufinder/ => /home/ja/.stmcufinder/plugins/mcufinder
|
||||||
|
2025-09-30 16:10:48,826 [INFO] ApiDb:250 - Set database path to: /home/ja/.stmcufinder/plugins/mcufinder//mcu/
|
||||||
|
2025-09-30 16:10:48,827 [WARN] DbFile:41 - Overriding database path with different value: /home/ja/.stmcufinder/plugins/mcufinder/ => /home/ja/.stmcufinder/plugins/mcufinder
|
||||||
|
2025-09-30 16:10:48,827 [INFO] DbMcusAds:125 - Set database path to: /home/ja/.stmcufinder/plugins/mcufinder//mcu/
|
||||||
|
2025-09-30 16:10:48,827 [WARN] DbFile:41 - Overriding database path with different value: /home/ja/.stmcufinder/plugins/mcufinder/ => /home/ja/.stmcufinder/plugins/mcufinder
|
||||||
|
2025-09-30 16:10:48,827 [WARN] DbFile:41 - Overriding database path with different value: /home/ja/.stmcufinder/plugins/mcufinder/ => /home/ja/.stmcufinder/plugins/mcufinder
|
||||||
|
2025-09-30 16:10:48,827 [INFO] CrossReferenceDbSqlite:203 - Set database path to: /home/ja/.stmcufinder/plugins/mcufinder//mcu/cs/
|
||||||
|
2025-09-30 16:10:48,905 [INFO] MainPanel:274 - HeapMemory: 268435456
|
||||||
|
2025-09-30 16:10:49,445 [INFO] DbMcusXml:78 - Set database path to: /home/ja/st/stm32cubeide_1.19.0/plugins/com.st.stm32cube.common.mx_6.15.0.202507011659//db//mcu/
|
||||||
|
2025-09-30 16:10:49,445 [INFO] ApiDb:274 - Set plugin database path to: /home/ja/st/stm32cubeide_1.19.0/plugins/com.st.stm32cube.common.mx_6.15.0.202507011659//db//plugins/boardmanager/
|
||||||
|
2025-09-30 16:10:49,445 [INFO] ApiDb:261 - Set plugin images path to: /home/ja/st/stm32cubeide_1.19.0/plugins/com.st.stm32cube.common.mx_6.15.0.202507011659//db//plugins/mcufinder/images/
|
||||||
|
2025-09-30 16:10:49,446 [WARN] DbFile:41 - Overriding database path with different value: /home/ja/.stmcufinder/plugins/mcufinder/ => /home/ja/.stmcufinder/plugins/mcufinder
|
||||||
|
2025-09-30 16:10:49,446 [INFO] ApiDb:250 - Set database path to: /home/ja/.stmcufinder/plugins/mcufinder//mcu/
|
||||||
|
2025-09-30 16:10:49,446 [WARN] DbFile:41 - Overriding database path with different value: /home/ja/.stmcufinder/plugins/mcufinder/ => /home/ja/.stmcufinder/plugins/mcufinder
|
||||||
|
2025-09-30 16:10:49,446 [INFO] DbMcusAds:125 - Set database path to: /home/ja/.stmcufinder/plugins/mcufinder//mcu/
|
||||||
|
2025-09-30 16:10:49,446 [WARN] DbFile:41 - Overriding database path with different value: /home/ja/.stmcufinder/plugins/mcufinder/ => /home/ja/.stmcufinder/plugins/mcufinder
|
||||||
|
2025-09-30 16:10:49,446 [WARN] DbFile:41 - Overriding database path with different value: /home/ja/.stmcufinder/plugins/mcufinder/ => /home/ja/.stmcufinder/plugins/mcufinder
|
||||||
|
2025-09-30 16:10:49,446 [INFO] CrossReferenceDbSqlite:203 - Set database path to: /home/ja/.stmcufinder/plugins/mcufinder//mcu/cs/
|
||||||
|
2025-09-30 16:10:49,466 [INFO] ApplicationProperties:184 - Using Application install path: /home/ja/st/stm32cubeide_1.19.0/plugins/com.st.stm32cube.common.mx_6.15.0.202507011659
|
||||||
|
2025-09-30 16:10:49,467 [INFO] PluginManage:196 - Search for loadable plugins [exclusion list=, ]
|
||||||
|
2025-09-30 16:10:49,468 [INFO] PluginManage:310 - Check plugin analytics
|
||||||
|
2025-09-30 16:10:49,824 [INFO] AnalyticsPlugin:253 - Accepted Software Licenses: STM32CubeMX.6.15.0
|
||||||
|
2025-09-30 16:10:49,825 [INFO] AnalyticsPlugin:255 - Accepted CMSIS Pack Licenses:
|
||||||
|
2025-09-30 16:10:49,825 [INFO] AnalyticsPlugin:257 - Accepted Firmware Licenses: FW.F4.1.28.0
|
||||||
|
2025-09-30 16:10:49,831 [INFO] PluginManage:359 - Loaded plugin analytics (category:tool,tabindex:-1)
|
||||||
|
2025-09-30 16:10:49,833 [INFO] PluginManage:310 - Check plugin cadmodel
|
||||||
|
2025-09-30 16:10:49,840 [INFO] CADModel:105 - Init CAD model plugin
|
||||||
|
2025-09-30 16:10:49,841 [INFO] PluginManage:359 - Loaded plugin cadmodel (category:power,tabindex:5)
|
||||||
|
2025-09-30 16:10:49,841 [INFO] PluginManage:310 - Check plugin clock
|
||||||
|
2025-09-30 16:10:49,853 [INFO] PluginManage:359 - Loaded plugin clock (category:base,tabindex:2)
|
||||||
|
2025-09-30 16:10:49,853 [INFO] PluginManage:310 - Check plugin ddr
|
||||||
|
2025-09-30 16:10:49,857 [INFO] PluginManage:359 - Loaded plugin ddr (category:tool,tabindex:6)
|
||||||
|
2025-09-30 16:10:49,857 [INFO] PluginManage:310 - Check plugin filemanager
|
||||||
|
2025-09-30 16:10:50,044 [INFO] PluginManage:359 - Loaded plugin filemanager (category:base,tabindex:10)
|
||||||
|
2025-09-30 16:10:50,044 [INFO] PluginManage:310 - Check plugin ipmanager
|
||||||
|
2025-09-30 16:10:50,049 [INFO] PluginManage:359 - Loaded plugin ipmanager (category:base,tabindex:5)
|
||||||
|
2025-09-30 16:10:50,049 [INFO] PluginManage:310 - Check plugin lpbam
|
||||||
|
2025-09-30 16:10:50,061 [INFO] PluginManage:359 - Loaded plugin lpbam (category:base,tabindex:0)
|
||||||
|
2025-09-30 16:10:50,061 [INFO] PluginManage:310 - Check plugin memorymap
|
||||||
|
2025-09-30 16:10:50,074 [INFO] PluginManage:359 - Loaded plugin memorymap (category:base,tabindex:4)
|
||||||
|
2025-09-30 16:10:50,074 [INFO] PluginManage:310 - Check plugin pinoutandconfiguration
|
||||||
|
2025-09-30 16:10:50,083 [INFO] PluginManage:359 - Loaded plugin pinoutandconfiguration (category:base,tabindex:1)
|
||||||
|
2025-09-30 16:10:50,083 [INFO] PluginManage:310 - Check plugin pinoutconfig
|
||||||
|
2025-09-30 16:10:50,185 [WARN] SupportedApi:132 - Cannot load RTOS API schema: s4s-elt-must-match.1: The content of 'definitions' must match (annotation?, (simpleType | complexType)?, (unique | key | keyref)*)). A problem was found starting at: attribute.
|
||||||
|
2025-09-30 16:10:50,344 [INFO] PluginManage:359 - Loaded plugin pinoutconfig (category:base,tabindex:0)
|
||||||
|
2025-09-30 16:10:50,344 [INFO] PluginManage:310 - Check plugin power
|
||||||
|
2025-09-30 16:10:50,356 [INFO] PluginManage:359 - Loaded plugin power (category:power,tabindex:4)
|
||||||
|
2025-09-30 16:10:50,356 [INFO] PluginManage:310 - Check plugin projectmanager
|
||||||
|
2025-09-30 16:10:50,375 [INFO] PluginManage:359 - Loaded plugin projectmanager (category:projectmanager,tabindex:4)
|
||||||
|
2025-09-30 16:10:50,375 [INFO] PluginManage:310 - Check plugin rif
|
||||||
|
2025-09-30 16:10:50,386 [INFO] PluginManage:359 - Loaded plugin rif (category:base,tabindex:3)
|
||||||
|
2025-09-30 16:10:50,386 [INFO] PluginManage:310 - Check plugin thirdparty
|
||||||
|
2025-09-30 16:10:50,582 [WARN] IntegrityCheckThread:84 - waiting for thirdparty lock release [integrity check]
|
||||||
|
2025-09-30 16:10:50,582 [INFO] IntegrityCheckThread:86 - entering critical section [integrity check]
|
||||||
|
2025-09-30 16:10:50,582 [INFO] PluginManage:359 - Loaded plugin thirdparty (category:base,tabindex:-1)
|
||||||
|
2025-09-30 16:10:50,583 [INFO] PluginManage:310 - Check plugin tools
|
||||||
|
2025-09-30 16:10:50,583 [INFO] ThirdPartyUpdaterWithRetryManager:70 - Updater plugin not ready yet. [1/15]
|
||||||
|
2025-09-30 16:10:50,586 [INFO] PluginManage:359 - Loaded plugin tools (category:base,tabindex:7)
|
||||||
|
2025-09-30 16:10:50,586 [INFO] PluginManage:310 - Check plugin tutovideos
|
||||||
|
2025-09-30 16:10:50,906 [INFO] PluginManage:359 - Loaded plugin tutovideos (category:base,tabindex:-1)
|
||||||
|
2025-09-30 16:10:50,906 [INFO] PluginManage:310 - Check plugin updater
|
||||||
|
2025-09-30 16:10:50,949 [INFO] PluginManage:359 - Loaded plugin updater (category:base,tabindex:12)
|
||||||
|
2025-09-30 16:10:50,949 [INFO] PluginManage:310 - Check plugin userauth
|
||||||
|
2025-09-30 16:10:50,959 [INFO] UserAuth:118 - Init User Auth plugin
|
||||||
|
2025-09-30 16:10:50,961 [INFO] PluginManage:359 - Loaded plugin userauth (category:base,tabindex:14)
|
||||||
|
2025-09-30 16:10:50,962 [INFO] PluginManage:283 - PluginManage : Loaded plugins [18]
|
||||||
|
2025-09-30 16:10:51,266 [INFO] PinOutPanel:1589 - setPackage(No Configuration,No Configuration)
|
||||||
|
2025-09-30 16:10:51,368 [INFO] CADModel:165 - CPN selected for project level
|
||||||
|
2025-09-30 16:10:51,368 [INFO] CADModel:114 - Register for checkConnection events
|
||||||
|
2025-09-30 16:10:51,387 [INFO] IPUIPlugin:80 - create IPUIPlugin
|
||||||
|
2025-09-30 16:10:51,388 [INFO] PluginManager:220 - loadIPPluginJar : add gtzc
|
||||||
|
2025-09-30 16:10:51,396 [INFO] IPUIPlugin:80 - create IPUIPlugin
|
||||||
|
2025-09-30 16:10:51,397 [INFO] PluginManager:220 - loadIPPluginJar : add usbx
|
||||||
|
2025-09-30 16:10:51,399 [INFO] IPUIPlugin:80 - create IPUIPlugin
|
||||||
|
2025-09-30 16:10:51,399 [INFO] PluginManager:220 - loadIPPluginJar : add fatfs
|
||||||
|
2025-09-30 16:10:51,404 [INFO] IPUIPlugin:80 - create IPUIPlugin
|
||||||
|
2025-09-30 16:10:51,404 [INFO] PluginManager:220 - loadIPPluginJar : add i2c
|
||||||
|
2025-09-30 16:10:51,407 [INFO] IPUIPlugin:80 - create IPUIPlugin
|
||||||
|
2025-09-30 16:10:51,407 [INFO] PluginManager:220 - loadIPPluginJar : add tim
|
||||||
|
2025-09-30 16:10:51,409 [INFO] IPUIPlugin:80 - create IPUIPlugin
|
||||||
|
2025-09-30 16:10:51,409 [INFO] PluginManager:220 - loadIPPluginJar : add quadspi
|
||||||
|
2025-09-30 16:10:51,414 [INFO] IPUIPlugin:80 - create IPUIPlugin
|
||||||
|
2025-09-30 16:10:51,415 [INFO] PluginManager:220 - loadIPPluginJar : add ipddr
|
||||||
|
2025-09-30 16:10:51,418 [INFO] IPUIPlugin:80 - create IPUIPlugin
|
||||||
|
2025-09-30 16:10:51,418 [INFO] PluginManager:220 - loadIPPluginJar : add i2s
|
||||||
|
2025-09-30 16:10:51,424 [INFO] IPUIPlugin:80 - create IPUIPlugin
|
||||||
|
2025-09-30 16:10:51,424 [INFO] PluginManager:220 - loadIPPluginJar : add openamp
|
||||||
|
2025-09-30 16:10:51,429 [INFO] IPUIPlugin:80 - create IPUIPlugin
|
||||||
|
2025-09-30 16:10:51,429 [INFO] PluginManager:220 - loadIPPluginJar : add i3c
|
||||||
|
2025-09-30 16:10:51,431 [INFO] IPUIPlugin:80 - create IPUIPlugin
|
||||||
|
2025-09-30 16:10:51,432 [INFO] PluginManager:220 - loadIPPluginJar : add ucpd
|
||||||
|
2025-09-30 16:10:51,434 [INFO] IPUIPlugin:80 - create IPUIPlugin
|
||||||
|
2025-09-30 16:10:51,434 [INFO] PluginManager:220 - loadIPPluginJar : add cryp
|
||||||
|
2025-09-30 16:10:51,436 [INFO] IPUIPlugin:80 - create IPUIPlugin
|
||||||
|
2025-09-30 16:10:51,436 [INFO] PluginManager:220 - loadIPPluginJar : add comp
|
||||||
|
2025-09-30 16:10:51,440 [INFO] IPUIPlugin:80 - create IPUIPlugin
|
||||||
|
2025-09-30 16:10:51,441 [INFO] PluginManager:220 - loadIPPluginJar : add spi
|
||||||
|
2025-09-30 16:10:51,447 [INFO] IPUIPlugin:80 - create IPUIPlugin
|
||||||
|
2025-09-30 16:10:51,447 [INFO] PluginManager:220 - loadIPPluginJar : add touchsensing
|
||||||
|
2025-09-30 16:10:51,449 [INFO] IPUIPlugin:80 - create IPUIPlugin
|
||||||
|
2025-09-30 16:10:51,450 [INFO] PluginManager:220 - loadIPPluginJar : add can
|
||||||
|
2025-09-30 16:10:51,452 [INFO] IPUIPlugin:80 - create IPUIPlugin
|
||||||
|
2025-09-30 16:10:51,453 [INFO] PluginManager:220 - loadIPPluginJar : add aes
|
||||||
|
2025-09-30 16:10:51,468 [INFO] IPUIPlugin:80 - create IPUIPlugin
|
||||||
|
2025-09-30 16:10:51,468 [INFO] PluginManager:220 - loadIPPluginJar : add adc
|
||||||
|
2025-09-30 16:10:51,475 [INFO] IPUIPlugin:80 - create IPUIPlugin
|
||||||
|
2025-09-30 16:10:51,476 [INFO] PluginManager:220 - loadIPPluginJar : add nvic
|
||||||
|
2025-09-30 16:10:51,482 [INFO] IPUIPlugin:80 - create IPUIPlugin
|
||||||
|
2025-09-30 16:10:51,482 [INFO] PluginManager:220 - loadIPPluginJar : add freertos
|
||||||
|
2025-09-30 16:10:51,493 [INFO] IPUIPlugin:80 - create IPUIPlugin
|
||||||
|
2025-09-30 16:10:51,494 [INFO] PluginManager:220 - loadIPPluginJar : add dma
|
||||||
|
2025-09-30 16:10:51,499 [INFO] IPUIPlugin:80 - create IPUIPlugin
|
||||||
|
2025-09-30 16:10:51,499 [INFO] PluginManager:220 - loadIPPluginJar : add resmgrutility
|
||||||
|
2025-09-30 16:10:51,502 [INFO] IPUIPlugin:80 - create IPUIPlugin
|
||||||
|
2025-09-30 16:10:51,503 [INFO] PluginManager:220 - loadIPPluginJar : add pdm2pcm
|
||||||
|
2025-09-30 16:10:51,507 [INFO] IPUIPlugin:80 - create IPUIPlugin
|
||||||
|
2025-09-30 16:10:51,507 [INFO] PluginManager:220 - loadIPPluginJar : add hash
|
||||||
|
2025-09-30 16:10:51,509 [INFO] IPUIPlugin:80 - create IPUIPlugin
|
||||||
|
2025-09-30 16:10:51,510 [INFO] PluginManager:220 - loadIPPluginJar : add dfsdm
|
||||||
|
2025-09-30 16:10:51,512 [INFO] IPUIPlugin:80 - create IPUIPlugin
|
||||||
|
2025-09-30 16:10:51,513 [INFO] PluginManager:220 - loadIPPluginJar : add radio
|
||||||
|
2025-09-30 16:10:51,522 [INFO] IPUIPlugin:80 - create IPUIPlugin
|
||||||
|
2025-09-30 16:10:51,527 [INFO] PluginManager:220 - loadIPPluginJar : add plateformsettings
|
||||||
|
2025-09-30 16:10:51,533 [INFO] IPUIPlugin:80 - create IPUIPlugin
|
||||||
|
2025-09-30 16:10:51,533 [INFO] PluginManager:220 - loadIPPluginJar : add gic
|
||||||
|
2025-09-30 16:10:51,535 [INFO] IPUIPlugin:80 - create IPUIPlugin
|
||||||
|
2025-09-30 16:10:51,535 [INFO] PluginManager:220 - loadIPPluginJar : add ltdc
|
||||||
|
2025-09-30 16:10:51,538 [INFO] IPUIPlugin:80 - create IPUIPlugin
|
||||||
|
2025-09-30 16:10:51,538 [INFO] PluginManager:220 - loadIPPluginJar : add tracer_emb
|
||||||
|
2025-09-30 16:10:51,542 [INFO] IPUIPlugin:80 - create IPUIPlugin
|
||||||
|
2025-09-30 16:10:51,543 [INFO] PluginManager:220 - loadIPPluginJar : add lorawan
|
||||||
|
2025-09-30 16:10:51,545 [INFO] IPUIPlugin:80 - create IPUIPlugin
|
||||||
|
2025-09-30 16:10:51,545 [INFO] PluginManager:220 - loadIPPluginJar : add tsc
|
||||||
|
2025-09-30 16:10:51,547 [INFO] IPUIPlugin:80 - create IPUIPlugin
|
||||||
|
2025-09-30 16:10:51,547 [INFO] PluginManager:220 - loadIPPluginJar : add ts
|
||||||
|
2025-09-30 16:10:51,549 [INFO] IPUIPlugin:80 - create IPUIPlugin
|
||||||
|
2025-09-30 16:10:51,549 [INFO] PluginManager:220 - loadIPPluginJar : add gfxmmu
|
||||||
|
2025-09-30 16:10:51,552 [INFO] IPUIPlugin:80 - create IPUIPlugin
|
||||||
|
2025-09-30 16:10:51,553 [INFO] PluginManager:220 - loadIPPluginJar : add dma3
|
||||||
|
2025-09-30 16:10:51,559 [INFO] IPUIPlugin:80 - create IPUIPlugin
|
||||||
|
2025-09-30 16:10:51,559 [INFO] PluginManager:220 - loadIPPluginJar : add ddr_ctrl_phy
|
||||||
|
2025-09-30 16:10:51,561 [INFO] IPUIPlugin:80 - create IPUIPlugin
|
||||||
|
2025-09-30 16:10:51,561 [INFO] PluginManager:220 - loadIPPluginJar : add genericplugin
|
||||||
|
2025-09-30 16:10:51,564 [INFO] IPUIPlugin:80 - create IPUIPlugin
|
||||||
|
2025-09-30 16:10:51,564 [INFO] PluginManager:220 - loadIPPluginJar : add opamp
|
||||||
|
2025-09-30 16:10:51,575 [INFO] IPUIPlugin:80 - create IPUIPlugin
|
||||||
|
2025-09-30 16:10:51,575 [INFO] PluginManager:220 - loadIPPluginJar : add stm32_wpan
|
||||||
|
2025-09-30 16:10:51,578 [INFO] IPUIPlugin:80 - create IPUIPlugin
|
||||||
|
2025-09-30 16:10:51,578 [INFO] PluginManager:220 - loadIPPluginJar : add usart
|
||||||
|
2025-09-30 16:10:51,581 [INFO] IPUIPlugin:80 - create IPUIPlugin
|
||||||
|
2025-09-30 16:10:51,581 [INFO] PluginManager:220 - loadIPPluginJar : add sai
|
||||||
|
2025-09-30 16:10:51,594 [INFO] IPUIPlugin:80 - create IPUIPlugin
|
||||||
|
2025-09-30 16:10:51,594 [INFO] PluginManager:220 - loadIPPluginJar : add linkedlist
|
||||||
|
2025-09-30 16:10:51,598 [INFO] IPUIPlugin:80 - create IPUIPlugin
|
||||||
|
2025-09-30 16:10:51,598 [INFO] PluginManager:220 - loadIPPluginJar : add extmemmanager
|
||||||
|
2025-09-30 16:10:51,605 [INFO] IPUIPlugin:80 - create IPUIPlugin
|
||||||
|
2025-09-30 16:10:51,605 [INFO] PluginManager:220 - loadIPPluginJar : add fmc
|
||||||
|
2025-09-30 16:10:51,613 [INFO] IPUIPlugin:80 - create IPUIPlugin
|
||||||
|
2025-09-30 16:10:51,614 [INFO] PluginManager:220 - loadIPPluginJar : add gpio
|
||||||
|
2025-09-30 16:10:51,624 [INFO] IPUIPlugin:80 - create IPUIPlugin
|
||||||
|
2025-09-30 16:10:51,624 [INFO] PluginManager:220 - loadIPPluginJar : add mdma
|
||||||
|
2025-09-30 16:10:51,748 [FATAL] Updater:351 - Updater called before beeing initialized
|
||||||
|
2025-09-30 16:10:51,785 [INFO] RulesReader:64 - Compatibility file has been processed (317 Rules)
|
||||||
|
2025-09-30 16:10:51,801 [INFO] RulesReader:64 - Compatibility file has been processed (317 Rules)
|
||||||
|
2025-09-30 16:10:51,811 [INFO] CADModel:165 - CPN selected for project level
|
||||||
|
2025-09-30 16:10:51,812 [INFO] CADModel:114 - Register for checkConnection events
|
||||||
|
2025-09-30 16:10:51,812 [FATAL] Updater:351 - Updater called before beeing initialized
|
||||||
|
2025-09-30 16:10:51,812 [ERROR] CADModel:125 - Updater not yet initialized, retry later
|
||||||
|
2025-09-30 16:10:52,000 [FATAL] Updater:351 - Updater called before beeing initialized
|
||||||
|
2025-09-30 16:10:52,002 [INFO] CADModel:165 - CPN selected for project level
|
||||||
|
2025-09-30 16:10:52,002 [INFO] CADModel:114 - Register for checkConnection events
|
||||||
|
2025-09-30 16:10:52,003 [FATAL] Updater:351 - Updater called before beeing initialized
|
||||||
|
2025-09-30 16:10:52,003 [ERROR] CADModel:125 - Updater not yet initialized, retry later
|
||||||
|
2025-09-30 16:10:52,008 [FATAL] Updater:351 - Updater called before beeing initialized
|
||||||
|
2025-09-30 16:10:52,188 [FATAL] Updater:351 - Updater called before beeing initialized
|
||||||
|
2025-09-30 16:10:52,197 [INFO] DbMcusAds:53 - JSON generation date=Tue Jul 08 03:14:23 CDT 2025 (1751962463524)
|
||||||
|
2025-09-30 16:10:52,198 [FATAL] Updater:351 - Updater called before beeing initialized
|
||||||
|
2025-09-30 16:10:52,249 [WARN] DetailPanel:346 - Failed to get advertising image, set to default
|
||||||
|
2025-09-30 16:10:52,315 [FATAL] Updater:351 - Updater called before beeing initialized
|
||||||
|
2025-09-30 16:10:52,317 [FATAL] Updater:351 - Updater called before beeing initialized
|
||||||
|
2025-09-30 16:10:52,317 [FATAL] Updater:351 - Updater called before beeing initialized
|
||||||
|
2025-09-30 16:10:52,317 [WARN] DetailPanel:346 - Failed to get advertising image, set to default
|
||||||
|
2025-09-30 16:10:52,319 [FATAL] Updater:351 - Updater called before beeing initialized
|
||||||
|
2025-09-30 16:10:52,356 [ERROR] Updater:1198 - MainUpdater not yet initialized. External WinMGr cannot be set.
|
||||||
|
2025-09-30 16:10:52,359 [INFO] Updater:1134 - Updater Version found : 6.15.0
|
||||||
|
2025-09-30 16:10:52,380 [INFO] ApplicationProperties:184 - Using Application install path: /home/ja/st/stm32cubeide_1.19.0/plugins/com.st.stm32cube.common.mx_6.15.0.202507011659
|
||||||
|
2025-09-30 16:10:53,184 [INFO] MainUpdater:2872 - connection check result : 10
|
||||||
|
2025-09-30 16:10:53,186 [INFO] MainUpdater:289 - Updater Check For Update Now.
|
||||||
|
2025-09-30 16:10:53,187 [INFO] MicroXplorer:498 - Change Database Version : DB.6.0.150
|
||||||
|
2025-09-30 16:10:53,191 [INFO] McuFinderGlobals:63 - Set McuFinder mode to 2 (CubeIDE integrated)
|
||||||
|
2025-09-30 16:10:53,192 [INFO] UserAuth:487 - Internet connection configuration mode: 1
|
||||||
|
2025-09-30 16:10:53,212 [INFO] JxBrowserEngine:152 - Initiate JxBrowser Engine with user profile folder
|
||||||
|
2025-09-30 16:10:53,390 [INFO] CheckServerUpdateThread:120 - End of CheckServer Thread
|
||||||
|
2025-09-30 16:10:53,797 [WARN] PackLoader:240 - Cannot read IP mode file for STMicroelectronics.FP-SNS-MOTENVWB1.1.4.0
|
||||||
|
2025-09-30 16:10:53,812 [WARN] PackLoader:240 - Cannot read IP mode file for STMicroelectronics.FP-ATR-ASTRA1.2.0.2
|
||||||
|
2025-09-30 16:10:53,822 [WARN] PackLoader:240 - Cannot read IP mode file for STMicroelectronics.X-CUBE-SMBUS.2.1.0
|
||||||
|
2025-09-30 16:10:53,832 [WARN] PackLoader:240 - Cannot read IP mode file for STMicroelectronics.X-CUBE-ST60.1.0.0
|
||||||
|
2025-09-30 16:10:53,896 [WARN] PackLoader:240 - Cannot read IP mode file for STMicroelectronics.X-CUBE-AZRTOS-F7.1.1.0
|
||||||
|
2025-09-30 16:10:53,953 [WARN] PackLoader:240 - Cannot read IP mode file for WES.I-CUBE-Cesium.1.4.0
|
||||||
|
2025-09-30 16:10:54,073 [WARN] PackLoader:240 - Cannot read IP mode file for Infineon.AIROC-Wi-Fi-Bluetooth-STM32.1.7.1
|
||||||
|
2025-09-30 16:10:54,149 [WARN] PackLoader:240 - Cannot read IP mode file for STMicroelectronics.X-CUBE-AZRTOS-H7.3.4.0
|
||||||
|
2025-09-30 16:10:54,185 [WARN] PackLoader:240 - Cannot read IP mode file for STMicroelectronics.X-CUBE-DISPLAY.3.0.0
|
||||||
|
2025-09-30 16:10:54,226 [WARN] PackLoader:240 - Cannot read IP mode file for STMicroelectronics.X-CUBE-NFC10.1.0.0
|
||||||
|
2025-09-30 16:10:54,246 [WARN] PackLoader:240 - Cannot read IP mode file for emotas.I-CUBE-CANOPEN.1.3.0
|
||||||
|
2025-09-30 16:10:54,262 [WARN] PackLoader:240 - Cannot read IP mode file for STMicroelectronics.FP-SNS-STBOX1.2.1.0
|
||||||
|
2025-09-30 16:10:54,282 [WARN] PackLoader:240 - Cannot read IP mode file for STMicroelectronics.FP-SNS-SMARTAG2.1.2.0
|
||||||
|
2025-09-30 16:10:54,294 [WARN] PackLoader:240 - Cannot read IP mode file for STMicroelectronics.FP-SNS-FLIGHT1.5.1.0
|
||||||
|
2025-09-30 16:10:54,325 [INFO] LogOutputStream:77 - [STDOUT_REDIRECT] 1 : Invalid condition id : UX_CORESTACK_Condition cause : null
|
||||||
|
2025-09-30 16:10:54,326 [INFO] LogOutputStream:77 - [STDOUT_REDIRECT] 1 : Invalid condition id : UX_CORESTACK_Condition cause : null
|
||||||
|
2025-09-30 16:10:54,327 [INFO] LogOutputStream:77 - [STDOUT_REDIRECT] 1 : Invalid condition id : UX_CORESTACK_Condition cause : null
|
||||||
|
2025-09-30 16:10:54,327 [INFO] LogOutputStream:77 - [STDOUT_REDIRECT] 1 : Invalid condition id : UX_CORESTACK_Condition cause : null
|
||||||
|
2025-09-30 16:10:54,327 [INFO] LogOutputStream:77 - [STDOUT_REDIRECT] 1 : Invalid condition id : UX_CORESTACK_Condition cause : null
|
||||||
|
2025-09-30 16:10:54,340 [WARN] PackLoader:240 - Cannot read IP mode file for STMicroelectronics.X-CUBE-AZRTOS-WL.2.0.0
|
||||||
|
2025-09-30 16:10:54,346 [WARN] PackLoader:240 - Cannot read IP mode file for STMicroelectronics.FP-SNS-MOTENV1.5.0.0
|
||||||
|
2025-09-30 16:10:54,359 [WARN] PackLoader:240 - Cannot read IP mode file for STMicroelectronics.X-CUBE-BLE2.3.3.0
|
||||||
|
2025-09-30 16:10:54,370 [WARN] PackLoader:240 - Cannot read IP mode file for STMicroelectronics.X-CUBE-NFC9.1.0.0
|
||||||
|
2025-09-30 16:10:54,380 [WARN] PackLoader:240 - Cannot read IP mode file for wolfSSL.I-CUBE-wolfSSL.5.8.2
|
||||||
|
2025-09-30 16:10:54,389 [WARN] PackLoader:240 - Cannot read IP mode file for STMicroelectronics.X-CUBE-BLE1.7.1.0
|
||||||
|
2025-09-30 16:10:54,396 [WARN] PackLoader:240 - Cannot read IP mode file for wolfSSL.I-CUBE-wolfMQTT.1.19.2
|
||||||
|
2025-09-30 16:10:54,408 [WARN] PackLoader:240 - Cannot read IP mode file for STMicroelectronics.X-CUBE-EEPRMA1.5.2.0
|
||||||
|
2025-09-30 16:10:54,452 [WARN] PackLoader:240 - Cannot read IP mode file for STMicroelectronics.X-CUBE-AZRTOS-G0.1.1.0
|
||||||
|
2025-09-30 16:10:54,479 [WARN] PackLoader:240 - Cannot read IP mode file for STMicroelectronics.X-CUBE-SAFEA1.1.2.2
|
||||||
|
2025-09-30 16:10:54,499 [WARN] PackLoader:240 - Cannot read IP mode file for STMicroelectronics.X-CUBE-NFC4.3.0.0
|
||||||
|
2025-09-30 16:10:54,528 [INFO] WebApp:169 - Instantiating new browser for Auth
|
||||||
|
2025-09-30 16:10:54,540 [WARN] PackLoader:240 - Cannot read IP mode file for EmbeddedOffice.I-CUBE-FS-RTOS.1.0.1
|
||||||
|
2025-09-30 16:10:54,551 [WARN] PackLoader:240 - Cannot read IP mode file for STMicroelectronics.X-CUBE-WB05N.2.0.0
|
||||||
|
2025-09-30 16:10:54,559 [WARN] PackLoader:240 - Cannot read IP mode file for wolfSSL.I-CUBE-wolfTPM.3.8.0
|
||||||
|
2025-09-30 16:10:54,574 [WARN] PackLoader:240 - Cannot read IP mode file for STMicroelectronics.X-CUBE-TCPP.4.2.0
|
||||||
|
2025-09-30 16:10:54,622 [WARN] PackLoader:240 - Cannot read IP mode file for RealThread.X-CUBE-RT-Thread_Nano.4.1.1
|
||||||
|
2025-09-30 16:10:54,630 [WARN] PackLoader:240 - Cannot read IP mode file for STMicroelectronics.FP-ATR-SIGFOX1.3.2.0
|
||||||
|
2025-09-30 16:10:54,638 [WARN] PackLoader:240 - Cannot read IP mode file for ITTIA_DB.I-CUBE-ITTIADB.8.9.0
|
||||||
|
2025-09-30 16:10:54,647 [WARN] PackLoader:240 - Cannot read IP mode file for STMicroelectronics.X-CUBE-ST67W61.1.0.0
|
||||||
|
2025-09-30 16:10:54,653 [WARN] PackLoader:240 - Cannot read IP mode file for STMicroelectronics.X-CUBE-AI.10.2.0
|
||||||
|
2025-09-30 16:10:54,707 [WARN] PackLoader:240 - Cannot read IP mode file for SEGGER.I-CUBE-embOS.1.3.1
|
||||||
|
2025-09-30 16:10:54,806 [WARN] PackLoader:240 - Cannot read IP mode file for STMicroelectronics.X-CUBE-ALGOBUILD.1.4.0
|
||||||
|
2025-09-30 16:10:54,912 [WARN] PackLoader:240 - Cannot read IP mode file for STMicroelectronics.X-CUBE-MEMS1.11.3.0
|
||||||
|
2025-09-30 16:10:55,413 [WARN] PackLoader:240 - Cannot read IP mode file for STMicroelectronics.X-CUBE-PM33A1.1.0.0
|
||||||
|
2025-09-30 16:10:55,442 [WARN] PackLoader:240 - Cannot read IP mode file for STMicroelectronics.X-CUBE-AZRTOS-F4.1.1.0
|
||||||
|
2025-09-30 16:10:55,449 [WARN] PackLoader:240 - Cannot read IP mode file for Avnet-IotConnect.X-CUBE-IoTC-DA16k-PMOD.1.0.0
|
||||||
|
2025-09-30 16:10:55,454 [WARN] PackLoader:240 - Cannot read IP mode file for STMicroelectronics.X-CUBE-ISPU.2.1.0
|
||||||
|
2025-09-30 16:10:55,464 [WARN] PackLoader:240 - Cannot read IP mode file for STMicroelectronics.X-CUBE-NFC12.1.0.0
|
||||||
|
2025-09-30 16:10:55,523 [WARN] PackLoader:240 - Cannot read IP mode file for STMicroelectronics.X-CUBE-AZRTOS-L5.2.0.0
|
||||||
|
2025-09-30 16:10:55,539 [WARN] PackLoader:240 - Cannot read IP mode file for STMicroelectronics.X-CUBE-NFC6.3.1.0
|
||||||
|
2025-09-30 16:10:55,550 [WARN] PackLoader:240 - Cannot read IP mode file for STMicroelectronics.X-CUBE-FREERTOS.1.3.1
|
||||||
|
2025-09-30 16:10:55,556 [WARN] PackLoader:240 - Cannot read IP mode file for STMicroelectronics.X-CUBE-TOUCHGFX.4.26.0
|
||||||
|
2025-09-30 16:10:55,562 [WARN] PackLoader:240 - Cannot read IP mode file for STMicroelectronics.FP-SNS-STAIOTCFT.1.0.0
|
||||||
|
2025-09-30 16:10:55,569 [WARN] PackLoader:240 - Cannot read IP mode file for STMicroelectronics.X-CUBE-DPower.1.3.0
|
||||||
|
2025-09-30 16:10:55,608 [WARN] ConditionMgr:438 - getConditionDescription Invalid condition id : LAN8742 Phy interface Condition cause : null
|
||||||
|
2025-09-30 16:10:55,610 [WARN] PackLoader:240 - Cannot read IP mode file for STMicroelectronics.X-CUBE-AZRTOS-L4.2.0.0
|
||||||
|
2025-09-30 16:10:55,613 [WARN] ConditionMgr:1044 - genDependencies : Invalid condition id : LAN8742 Phy interface Condition cause : null
|
||||||
|
2025-09-30 16:10:55,613 [WARN] ConditionMgr:1044 - genDependencies : Invalid condition id : LAN8742 Phy interface Condition cause : null
|
||||||
|
2025-09-30 16:10:55,615 [WARN] ConditionMgr:1044 - genDependencies : Invalid condition id : LAN8742 Phy interface Condition cause : null
|
||||||
|
2025-09-30 16:10:55,628 [WARN] PackLoader:240 - Cannot read IP mode file for STMicroelectronics.X-CUBE-SFXS2LP1.4.0.0
|
||||||
|
2025-09-30 16:10:55,663 [WARN] PackLoader:240 - Cannot read IP mode file for STMicroelectronics.X-CUBE-BLEMGR.4.1.0
|
||||||
|
2025-09-30 16:10:55,692 [WARN] ConditionMgr:438 - getConditionDescription Invalid condition id : UX DEVICE CLASS RTOS Condition cause : null
|
||||||
|
2025-09-30 16:10:55,692 [WARN] ConditionMgr:438 - getConditionDescription Invalid condition id : UX DEVICE CLASS RTOS Condition cause : null
|
||||||
|
2025-09-30 16:10:55,695 [WARN] PackLoader:240 - Cannot read IP mode file for STMicroelectronics.X-CUBE-AZRTOS-WB.2.0.0
|
||||||
|
2025-09-30 16:10:55,696 [WARN] ConditionMgr:1044 - genDependencies : Invalid condition id : UX DEVICE CLASS RTOS Condition cause : null
|
||||||
|
2025-09-30 16:10:55,696 [WARN] ConditionMgr:1044 - genDependencies : Invalid condition id : UX DEVICE CLASS RTOS Condition cause : null
|
||||||
|
2025-09-30 16:10:55,696 [WARN] ConditionMgr:1044 - genDependencies : Invalid condition id : UX DEVICE CLASS RTOS Condition cause : null
|
||||||
|
2025-09-30 16:10:55,697 [WARN] ConditionMgr:1044 - genDependencies : Invalid condition id : UX DEVICE CLASS RTOS Condition cause : null
|
||||||
|
2025-09-30 16:10:55,697 [WARN] ConditionMgr:1044 - genDependencies : Invalid condition id : UX DEVICE CLASS RTOS Condition cause : null
|
||||||
|
2025-09-30 16:10:55,713 [WARN] PackLoader:240 - Cannot read IP mode file for STMicroelectronics.X-CUBE-GNSS1.7.0.1
|
||||||
|
2025-09-30 16:10:55,719 [WARN] PackLoader:240 - Cannot read IP mode file for STMicroelectronics.X-CUBE-TOUCHGFX.4.25.0
|
||||||
|
2025-09-30 16:10:55,724 [WARN] ConditionMgr:438 - getConditionDescription Invalid condition id : Cortex-A Device cause : null
|
||||||
|
2025-09-30 16:10:55,742 [WARN] ConditionMgr:1044 - genDependencies : Invalid condition id : Cortex-A Device cause : null
|
||||||
|
2025-09-30 16:10:55,742 [WARN] ConditionMgr:1044 - genDependencies : Invalid condition id : Cortex-A Device cause : null
|
||||||
|
2025-09-30 16:10:55,742 [WARN] ConditionMgr:1044 - genDependencies : Invalid condition id : Cortex-A Device cause : null
|
||||||
|
2025-09-30 16:10:55,758 [WARN] PackLoader:240 - Cannot read IP mode file for STMicroelectronics.X-CUBE-SUBG2.5.0.0
|
||||||
|
2025-09-30 16:10:55,802 [WARN] PackLoader:240 - Cannot read IP mode file for STMicroelectronics.X-CUBE-AZRTOS-H7RS.1.1.0
|
||||||
|
2025-09-30 16:10:55,810 [WARN] PackLoader:240 - Cannot read IP mode file for Cesanta.I-CUBE-Mongoose.7.13.0
|
||||||
|
2025-09-30 16:10:55,843 [WARN] PackLoader:240 - Cannot read IP mode file for STMicroelectronics.X-CUBE-AZRTOS-G4.2.0.0
|
||||||
|
2025-09-30 16:10:55,848 [WARN] PackLoader:240 - Cannot read IP mode file for wolfSSL.I-CUBE-wolfSSH.1.4.20
|
||||||
|
2025-09-30 16:10:55,857 [WARN] PackLoader:240 - Cannot read IP mode file for STMicroelectronics.X-CUBE-NFC7.2.0.0
|
||||||
|
2025-09-30 16:10:55,876 [WARN] PackLoader:240 - Cannot read IP mode file for STMicroelectronics.X-CUBE-IPS.3.1.0
|
||||||
|
2025-09-30 16:10:55,887 [WARN] PackLoader:240 - Cannot read IP mode file for STMicroelectronics.X-CUBE-ALS.1.0.2
|
||||||
|
2025-09-30 16:10:55,894 [WARN] PackLoader:240 - Cannot read IP mode file for STMicroelectronics.X-CUBE-STSE01.1.0.0
|
||||||
|
2025-09-30 16:10:55,901 [WARN] PackLoader:240 - Cannot read IP mode file for portGmbH.I-Cube-SoM-uGOAL.1.1.0
|
||||||
|
2025-09-30 16:10:55,916 [WARN] PackLoader:240 - Cannot read IP mode file for STMicroelectronics.X-CUBE-TOF1.3.4.3
|
||||||
|
2025-09-30 16:10:55,934 [INFO] ThirdParty:978 - Integrity check success = true
|
||||||
|
2025-09-30 16:10:55,934 [INFO] IntegrityCheckThread:100 - exiting critical section [integrity check]
|
||||||
|
2025-09-30 16:10:55,935 [INFO] IntegrityCheckThread:103 - End integrity checks thread
|
||||||
|
2025-09-30 16:10:56,192 [INFO] WebApp:463 - Apply proxy settings
|
||||||
|
2025-09-30 16:10:56,193 [INFO] WebApp:548 - Chromium requires no authentication
|
||||||
|
2025-09-30 16:10:56,204 [INFO] WebApp:491 - Direct internet connection detected
|
||||||
|
2025-09-30 16:10:56,229 [INFO] WebApp:900 - Register for checkConnection events
|
||||||
|
2025-09-30 16:10:56,229 [INFO] WebApp:463 - Apply proxy settings
|
||||||
|
2025-09-30 16:10:56,229 [INFO] WebApp:548 - Chromium requires no authentication
|
||||||
|
2025-09-30 16:10:56,230 [INFO] WebApp:491 - Direct internet connection detected
|
||||||
|
2025-09-30 16:10:56,407 [INFO] WebApp:225 - Starting web application
|
||||||
|
2025-09-30 16:10:56,407 [INFO] WebApp:593 - Web application path used /home/ja/st/stm32cubeide_1.19.0/plugins/com.st.stm32cube.common.mx_6.15.0.202507011659/db/plugins/mcufinder/reactClient1/index.html
|
||||||
|
2025-09-30 16:10:56,542 [INFO] UserAuth:487 - Internet connection configuration mode: 1
|
||||||
|
2025-09-30 16:10:57,055 [INFO] WebApp:191 - Connection restablished
|
||||||
|
2025-09-30 16:23:40,163 [ERROR] LogOutputStream:75 - [STDERR_REDIRECT]
|
||||||
570
.metadata/.ide.log-2025-10-01.log
Normal file
570
.metadata/.ide.log-2025-10-01.log
Normal file
File diff suppressed because one or more lines are too long
322
.metadata/.ide.log-2025-10-06.log
Normal file
322
.metadata/.ide.log-2025-10-06.log
Normal file
@@ -0,0 +1,322 @@
|
|||||||
|
2025-10-06 14:00:19,647 [INFO] Activator:176 -
|
||||||
|
|
||||||
|
|
||||||
|
2025-10-06 14:00:19,650 [INFO] Activator:177 - !SESSION log4j initialized
|
||||||
|
2025-10-06 14:00:25,791 [INFO] LogOutputStream:77 - [STDOUT_REDIRECT]
|
||||||
|
2025-10-06 14:00:27,947 [INFO] ApplicationProperties:184 - Using Application install path: /home/ja/st/stm32cubeide_1.19.0/plugins/com.st.stm32cube.common.mx_6.15.0.202507011659
|
||||||
|
2025-10-06 14:00:27,963 [INFO] DbMcusXml:78 - Set database path to: /home/ja/st/stm32cubeide_1.19.0/plugins/com.st.stm32cube.common.mx_6.15.0.202507011659//db//mcu/
|
||||||
|
2025-10-06 14:00:27,963 [INFO] ApiDb:274 - Set plugin database path to: /home/ja/st/stm32cubeide_1.19.0/plugins/com.st.stm32cube.common.mx_6.15.0.202507011659//db//plugins/boardmanager/
|
||||||
|
2025-10-06 14:00:27,963 [WARN] ApiDb:259 - Overriding images path with different value: => /home/ja/st/stm32cubeide_1.19.0/plugins/com.st.stm32cube.common.mx_6.15.0.202507011659//db//plugins/mcufinder/images/
|
||||||
|
2025-10-06 14:00:27,969 [INFO] ApiDb:250 - Set database path to: /home/ja/.stmcufinder/plugins/mcufinder//mcu/
|
||||||
|
2025-10-06 14:00:27,970 [INFO] DbMcusAds:125 - Set database path to: /home/ja/.stmcufinder/plugins/mcufinder//mcu/
|
||||||
|
2025-10-06 14:00:27,972 [INFO] CrossReferenceDbSqlite:203 - Set database path to: /home/ja/.stmcufinder/plugins/mcufinder//mcu/cs/
|
||||||
|
2025-10-06 14:00:28,079 [INFO] RulesReader:64 - Compatibility file has been processed (317 Rules)
|
||||||
|
2025-10-06 14:00:28,133 [INFO] DbMcusXml:78 - Set database path to: /home/ja/st/stm32cubeide_1.19.0/plugins/com.st.stm32cube.common.mx_6.15.0.202507011659//db//mcu/
|
||||||
|
2025-10-06 14:00:28,133 [INFO] ApiDb:274 - Set plugin database path to: /home/ja/st/stm32cubeide_1.19.0/plugins/com.st.stm32cube.common.mx_6.15.0.202507011659//db//plugins/boardmanager/
|
||||||
|
2025-10-06 14:00:28,133 [INFO] ApiDb:261 - Set plugin images path to: /home/ja/st/stm32cubeide_1.19.0/plugins/com.st.stm32cube.common.mx_6.15.0.202507011659//db//plugins/mcufinder/images/
|
||||||
|
2025-10-06 14:00:28,133 [WARN] DbFile:41 - Overriding database path with different value: /home/ja/.stmcufinder/plugins/mcufinder/ => /home/ja/.stmcufinder/plugins/mcufinder
|
||||||
|
2025-10-06 14:00:28,134 [INFO] ApiDb:250 - Set database path to: /home/ja/.stmcufinder/plugins/mcufinder//mcu/
|
||||||
|
2025-10-06 14:00:28,134 [WARN] DbFile:41 - Overriding database path with different value: /home/ja/.stmcufinder/plugins/mcufinder/ => /home/ja/.stmcufinder/plugins/mcufinder
|
||||||
|
2025-10-06 14:00:28,134 [INFO] DbMcusAds:125 - Set database path to: /home/ja/.stmcufinder/plugins/mcufinder//mcu/
|
||||||
|
2025-10-06 14:00:28,134 [WARN] DbFile:41 - Overriding database path with different value: /home/ja/.stmcufinder/plugins/mcufinder/ => /home/ja/.stmcufinder/plugins/mcufinder
|
||||||
|
2025-10-06 14:00:28,134 [WARN] DbFile:41 - Overriding database path with different value: /home/ja/.stmcufinder/plugins/mcufinder/ => /home/ja/.stmcufinder/plugins/mcufinder
|
||||||
|
2025-10-06 14:00:28,134 [INFO] CrossReferenceDbSqlite:203 - Set database path to: /home/ja/.stmcufinder/plugins/mcufinder//mcu/cs/
|
||||||
|
2025-10-06 14:00:28,196 [INFO] MainPanel:274 - HeapMemory: 268435456
|
||||||
|
2025-10-06 14:00:28,647 [INFO] DbMcusXml:78 - Set database path to: /home/ja/st/stm32cubeide_1.19.0/plugins/com.st.stm32cube.common.mx_6.15.0.202507011659//db//mcu/
|
||||||
|
2025-10-06 14:00:28,647 [INFO] ApiDb:274 - Set plugin database path to: /home/ja/st/stm32cubeide_1.19.0/plugins/com.st.stm32cube.common.mx_6.15.0.202507011659//db//plugins/boardmanager/
|
||||||
|
2025-10-06 14:00:28,648 [INFO] ApiDb:261 - Set plugin images path to: /home/ja/st/stm32cubeide_1.19.0/plugins/com.st.stm32cube.common.mx_6.15.0.202507011659//db//plugins/mcufinder/images/
|
||||||
|
2025-10-06 14:00:28,648 [WARN] DbFile:41 - Overriding database path with different value: /home/ja/.stmcufinder/plugins/mcufinder/ => /home/ja/.stmcufinder/plugins/mcufinder
|
||||||
|
2025-10-06 14:00:28,648 [INFO] ApiDb:250 - Set database path to: /home/ja/.stmcufinder/plugins/mcufinder//mcu/
|
||||||
|
2025-10-06 14:00:28,648 [WARN] DbFile:41 - Overriding database path with different value: /home/ja/.stmcufinder/plugins/mcufinder/ => /home/ja/.stmcufinder/plugins/mcufinder
|
||||||
|
2025-10-06 14:00:28,648 [INFO] DbMcusAds:125 - Set database path to: /home/ja/.stmcufinder/plugins/mcufinder//mcu/
|
||||||
|
2025-10-06 14:00:28,648 [WARN] DbFile:41 - Overriding database path with different value: /home/ja/.stmcufinder/plugins/mcufinder/ => /home/ja/.stmcufinder/plugins/mcufinder
|
||||||
|
2025-10-06 14:00:28,648 [WARN] DbFile:41 - Overriding database path with different value: /home/ja/.stmcufinder/plugins/mcufinder/ => /home/ja/.stmcufinder/plugins/mcufinder
|
||||||
|
2025-10-06 14:00:28,648 [INFO] CrossReferenceDbSqlite:203 - Set database path to: /home/ja/.stmcufinder/plugins/mcufinder//mcu/cs/
|
||||||
|
2025-10-06 14:00:28,661 [INFO] ApplicationProperties:184 - Using Application install path: /home/ja/st/stm32cubeide_1.19.0/plugins/com.st.stm32cube.common.mx_6.15.0.202507011659
|
||||||
|
2025-10-06 14:00:28,662 [INFO] PluginManage:196 - Search for loadable plugins [exclusion list=, ]
|
||||||
|
2025-10-06 14:00:28,664 [INFO] PluginManage:310 - Check plugin analytics
|
||||||
|
2025-10-06 14:00:28,987 [INFO] AnalyticsPlugin:253 - Accepted Software Licenses: STM32CubeMX.6.15.0
|
||||||
|
2025-10-06 14:00:28,987 [INFO] AnalyticsPlugin:255 - Accepted CMSIS Pack Licenses:
|
||||||
|
2025-10-06 14:00:28,987 [INFO] AnalyticsPlugin:257 - Accepted Firmware Licenses: FW.F4.1.28.0
|
||||||
|
2025-10-06 14:00:28,989 [INFO] PluginManage:359 - Loaded plugin analytics (category:tool,tabindex:-1)
|
||||||
|
2025-10-06 14:00:28,989 [INFO] PluginManage:310 - Check plugin cadmodel
|
||||||
|
2025-10-06 14:00:28,993 [INFO] CADModel:105 - Init CAD model plugin
|
||||||
|
2025-10-06 14:00:28,993 [INFO] PluginManage:359 - Loaded plugin cadmodel (category:power,tabindex:5)
|
||||||
|
2025-10-06 14:00:28,993 [INFO] PluginManage:310 - Check plugin clock
|
||||||
|
2025-10-06 14:00:29,000 [INFO] PluginManage:359 - Loaded plugin clock (category:base,tabindex:2)
|
||||||
|
2025-10-06 14:00:29,001 [INFO] PluginManage:310 - Check plugin ddr
|
||||||
|
2025-10-06 14:00:29,002 [INFO] PluginManage:359 - Loaded plugin ddr (category:tool,tabindex:6)
|
||||||
|
2025-10-06 14:00:29,002 [INFO] PluginManage:310 - Check plugin filemanager
|
||||||
|
2025-10-06 14:00:29,128 [INFO] PluginManage:359 - Loaded plugin filemanager (category:base,tabindex:10)
|
||||||
|
2025-10-06 14:00:29,128 [INFO] PluginManage:310 - Check plugin ipmanager
|
||||||
|
2025-10-06 14:00:29,132 [INFO] PluginManage:359 - Loaded plugin ipmanager (category:base,tabindex:5)
|
||||||
|
2025-10-06 14:00:29,133 [INFO] PluginManage:310 - Check plugin lpbam
|
||||||
|
2025-10-06 14:00:29,141 [INFO] PluginManage:359 - Loaded plugin lpbam (category:base,tabindex:0)
|
||||||
|
2025-10-06 14:00:29,141 [INFO] PluginManage:310 - Check plugin memorymap
|
||||||
|
2025-10-06 14:00:29,151 [INFO] PluginManage:359 - Loaded plugin memorymap (category:base,tabindex:4)
|
||||||
|
2025-10-06 14:00:29,151 [INFO] PluginManage:310 - Check plugin pinoutandconfiguration
|
||||||
|
2025-10-06 14:00:29,158 [INFO] PluginManage:359 - Loaded plugin pinoutandconfiguration (category:base,tabindex:1)
|
||||||
|
2025-10-06 14:00:29,158 [INFO] PluginManage:310 - Check plugin pinoutconfig
|
||||||
|
2025-10-06 14:00:29,233 [WARN] SupportedApi:132 - Cannot load RTOS API schema: s4s-elt-must-match.1: The content of 'definitions' must match (annotation?, (simpleType | complexType)?, (unique | key | keyref)*)). A problem was found starting at: attribute.
|
||||||
|
2025-10-06 14:00:29,343 [INFO] PluginManage:359 - Loaded plugin pinoutconfig (category:base,tabindex:0)
|
||||||
|
2025-10-06 14:00:29,344 [INFO] PluginManage:310 - Check plugin power
|
||||||
|
2025-10-06 14:00:29,350 [INFO] PluginManage:359 - Loaded plugin power (category:power,tabindex:4)
|
||||||
|
2025-10-06 14:00:29,351 [INFO] PluginManage:310 - Check plugin projectmanager
|
||||||
|
2025-10-06 14:00:29,366 [INFO] PluginManage:359 - Loaded plugin projectmanager (category:projectmanager,tabindex:4)
|
||||||
|
2025-10-06 14:00:29,366 [INFO] PluginManage:310 - Check plugin rif
|
||||||
|
2025-10-06 14:00:29,375 [INFO] PluginManage:359 - Loaded plugin rif (category:base,tabindex:3)
|
||||||
|
2025-10-06 14:00:29,375 [INFO] PluginManage:310 - Check plugin thirdparty
|
||||||
|
2025-10-06 14:00:29,492 [INFO] PluginManage:359 - Loaded plugin thirdparty (category:base,tabindex:-1)
|
||||||
|
2025-10-06 14:00:29,492 [WARN] IntegrityCheckThread:84 - waiting for thirdparty lock release [integrity check]
|
||||||
|
2025-10-06 14:00:29,492 [INFO] PluginManage:310 - Check plugin tools
|
||||||
|
2025-10-06 14:00:29,492 [INFO] IntegrityCheckThread:86 - entering critical section [integrity check]
|
||||||
|
2025-10-06 14:00:29,493 [INFO] ThirdPartyUpdaterWithRetryManager:70 - Updater plugin not ready yet. [1/15]
|
||||||
|
2025-10-06 14:00:29,494 [INFO] PluginManage:359 - Loaded plugin tools (category:base,tabindex:7)
|
||||||
|
2025-10-06 14:00:29,494 [INFO] PluginManage:310 - Check plugin tutovideos
|
||||||
|
2025-10-06 14:00:29,671 [INFO] PluginManage:359 - Loaded plugin tutovideos (category:base,tabindex:-1)
|
||||||
|
2025-10-06 14:00:29,671 [INFO] PluginManage:310 - Check plugin updater
|
||||||
|
2025-10-06 14:00:29,690 [INFO] PluginManage:359 - Loaded plugin updater (category:base,tabindex:12)
|
||||||
|
2025-10-06 14:00:29,690 [INFO] PluginManage:310 - Check plugin userauth
|
||||||
|
2025-10-06 14:00:29,694 [INFO] UserAuth:118 - Init User Auth plugin
|
||||||
|
2025-10-06 14:00:29,694 [INFO] PluginManage:359 - Loaded plugin userauth (category:base,tabindex:14)
|
||||||
|
2025-10-06 14:00:29,695 [INFO] PluginManage:283 - PluginManage : Loaded plugins [18]
|
||||||
|
2025-10-06 14:00:29,847 [INFO] PinOutPanel:1589 - setPackage(No Configuration,No Configuration)
|
||||||
|
2025-10-06 14:00:29,903 [INFO] CADModel:165 - CPN selected for project level
|
||||||
|
2025-10-06 14:00:29,903 [INFO] CADModel:114 - Register for checkConnection events
|
||||||
|
2025-10-06 14:00:29,912 [INFO] IPUIPlugin:80 - create IPUIPlugin
|
||||||
|
2025-10-06 14:00:29,912 [INFO] PluginManager:220 - loadIPPluginJar : add gtzc
|
||||||
|
2025-10-06 14:00:29,916 [INFO] IPUIPlugin:80 - create IPUIPlugin
|
||||||
|
2025-10-06 14:00:29,916 [INFO] PluginManager:220 - loadIPPluginJar : add usbx
|
||||||
|
2025-10-06 14:00:29,917 [INFO] IPUIPlugin:80 - create IPUIPlugin
|
||||||
|
2025-10-06 14:00:29,918 [INFO] PluginManager:220 - loadIPPluginJar : add fatfs
|
||||||
|
2025-10-06 14:00:29,919 [INFO] IPUIPlugin:80 - create IPUIPlugin
|
||||||
|
2025-10-06 14:00:29,919 [INFO] PluginManager:220 - loadIPPluginJar : add i2c
|
||||||
|
2025-10-06 14:00:29,921 [INFO] IPUIPlugin:80 - create IPUIPlugin
|
||||||
|
2025-10-06 14:00:29,921 [INFO] PluginManager:220 - loadIPPluginJar : add tim
|
||||||
|
2025-10-06 14:00:29,922 [INFO] IPUIPlugin:80 - create IPUIPlugin
|
||||||
|
2025-10-06 14:00:29,922 [INFO] PluginManager:220 - loadIPPluginJar : add quadspi
|
||||||
|
2025-10-06 14:00:29,925 [INFO] IPUIPlugin:80 - create IPUIPlugin
|
||||||
|
2025-10-06 14:00:29,925 [INFO] PluginManager:220 - loadIPPluginJar : add ipddr
|
||||||
|
2025-10-06 14:00:29,927 [INFO] IPUIPlugin:80 - create IPUIPlugin
|
||||||
|
2025-10-06 14:00:29,927 [INFO] PluginManager:220 - loadIPPluginJar : add i2s
|
||||||
|
2025-10-06 14:00:29,929 [INFO] IPUIPlugin:80 - create IPUIPlugin
|
||||||
|
2025-10-06 14:00:29,929 [INFO] PluginManager:220 - loadIPPluginJar : add openamp
|
||||||
|
2025-10-06 14:00:29,931 [INFO] IPUIPlugin:80 - create IPUIPlugin
|
||||||
|
2025-10-06 14:00:29,931 [INFO] PluginManager:220 - loadIPPluginJar : add i3c
|
||||||
|
2025-10-06 14:00:29,933 [INFO] IPUIPlugin:80 - create IPUIPlugin
|
||||||
|
2025-10-06 14:00:29,933 [INFO] PluginManager:220 - loadIPPluginJar : add ucpd
|
||||||
|
2025-10-06 14:00:29,935 [INFO] IPUIPlugin:80 - create IPUIPlugin
|
||||||
|
2025-10-06 14:00:29,935 [INFO] PluginManager:220 - loadIPPluginJar : add cryp
|
||||||
|
2025-10-06 14:00:29,936 [INFO] IPUIPlugin:80 - create IPUIPlugin
|
||||||
|
2025-10-06 14:00:29,936 [INFO] PluginManager:220 - loadIPPluginJar : add comp
|
||||||
|
2025-10-06 14:00:29,937 [INFO] IPUIPlugin:80 - create IPUIPlugin
|
||||||
|
2025-10-06 14:00:29,937 [INFO] PluginManager:220 - loadIPPluginJar : add spi
|
||||||
|
2025-10-06 14:00:29,940 [INFO] IPUIPlugin:80 - create IPUIPlugin
|
||||||
|
2025-10-06 14:00:29,940 [INFO] PluginManager:220 - loadIPPluginJar : add touchsensing
|
||||||
|
2025-10-06 14:00:29,941 [INFO] IPUIPlugin:80 - create IPUIPlugin
|
||||||
|
2025-10-06 14:00:29,941 [INFO] PluginManager:220 - loadIPPluginJar : add can
|
||||||
|
2025-10-06 14:00:29,943 [INFO] IPUIPlugin:80 - create IPUIPlugin
|
||||||
|
2025-10-06 14:00:29,943 [INFO] PluginManager:220 - loadIPPluginJar : add aes
|
||||||
|
2025-10-06 14:00:29,949 [INFO] IPUIPlugin:80 - create IPUIPlugin
|
||||||
|
2025-10-06 14:00:29,949 [INFO] PluginManager:220 - loadIPPluginJar : add adc
|
||||||
|
2025-10-06 14:00:29,952 [INFO] IPUIPlugin:80 - create IPUIPlugin
|
||||||
|
2025-10-06 14:00:29,952 [INFO] PluginManager:220 - loadIPPluginJar : add nvic
|
||||||
|
2025-10-06 14:00:29,957 [INFO] IPUIPlugin:80 - create IPUIPlugin
|
||||||
|
2025-10-06 14:00:29,957 [INFO] PluginManager:220 - loadIPPluginJar : add freertos
|
||||||
|
2025-10-06 14:00:29,961 [INFO] IPUIPlugin:80 - create IPUIPlugin
|
||||||
|
2025-10-06 14:00:29,962 [INFO] PluginManager:220 - loadIPPluginJar : add dma
|
||||||
|
2025-10-06 14:00:29,964 [INFO] IPUIPlugin:80 - create IPUIPlugin
|
||||||
|
2025-10-06 14:00:29,964 [INFO] PluginManager:220 - loadIPPluginJar : add resmgrutility
|
||||||
|
2025-10-06 14:00:29,966 [INFO] IPUIPlugin:80 - create IPUIPlugin
|
||||||
|
2025-10-06 14:00:29,967 [INFO] PluginManager:220 - loadIPPluginJar : add pdm2pcm
|
||||||
|
2025-10-06 14:00:29,968 [INFO] IPUIPlugin:80 - create IPUIPlugin
|
||||||
|
2025-10-06 14:00:29,968 [INFO] PluginManager:220 - loadIPPluginJar : add hash
|
||||||
|
2025-10-06 14:00:29,970 [INFO] IPUIPlugin:80 - create IPUIPlugin
|
||||||
|
2025-10-06 14:00:29,970 [INFO] PluginManager:220 - loadIPPluginJar : add dfsdm
|
||||||
|
2025-10-06 14:00:29,971 [INFO] IPUIPlugin:80 - create IPUIPlugin
|
||||||
|
2025-10-06 14:00:29,971 [INFO] PluginManager:220 - loadIPPluginJar : add radio
|
||||||
|
2025-10-06 14:00:29,976 [INFO] IPUIPlugin:80 - create IPUIPlugin
|
||||||
|
2025-10-06 14:00:29,978 [INFO] PluginManager:220 - loadIPPluginJar : add plateformsettings
|
||||||
|
2025-10-06 14:00:29,983 [INFO] IPUIPlugin:80 - create IPUIPlugin
|
||||||
|
2025-10-06 14:00:29,983 [INFO] PluginManager:220 - loadIPPluginJar : add gic
|
||||||
|
2025-10-06 14:00:29,984 [INFO] IPUIPlugin:80 - create IPUIPlugin
|
||||||
|
2025-10-06 14:00:29,984 [INFO] PluginManager:220 - loadIPPluginJar : add ltdc
|
||||||
|
2025-10-06 14:00:29,985 [INFO] IPUIPlugin:80 - create IPUIPlugin
|
||||||
|
2025-10-06 14:00:29,985 [INFO] PluginManager:220 - loadIPPluginJar : add tracer_emb
|
||||||
|
2025-10-06 14:00:29,987 [INFO] IPUIPlugin:80 - create IPUIPlugin
|
||||||
|
2025-10-06 14:00:29,987 [INFO] PluginManager:220 - loadIPPluginJar : add lorawan
|
||||||
|
2025-10-06 14:00:29,988 [INFO] IPUIPlugin:80 - create IPUIPlugin
|
||||||
|
2025-10-06 14:00:29,988 [INFO] PluginManager:220 - loadIPPluginJar : add tsc
|
||||||
|
2025-10-06 14:00:29,989 [INFO] IPUIPlugin:80 - create IPUIPlugin
|
||||||
|
2025-10-06 14:00:29,989 [INFO] PluginManager:220 - loadIPPluginJar : add ts
|
||||||
|
2025-10-06 14:00:29,991 [INFO] IPUIPlugin:80 - create IPUIPlugin
|
||||||
|
2025-10-06 14:00:29,991 [INFO] PluginManager:220 - loadIPPluginJar : add gfxmmu
|
||||||
|
2025-10-06 14:00:29,992 [INFO] IPUIPlugin:80 - create IPUIPlugin
|
||||||
|
2025-10-06 14:00:29,992 [INFO] PluginManager:220 - loadIPPluginJar : add dma3
|
||||||
|
2025-10-06 14:00:29,995 [INFO] IPUIPlugin:80 - create IPUIPlugin
|
||||||
|
2025-10-06 14:00:29,995 [INFO] PluginManager:220 - loadIPPluginJar : add ddr_ctrl_phy
|
||||||
|
2025-10-06 14:00:29,996 [INFO] IPUIPlugin:80 - create IPUIPlugin
|
||||||
|
2025-10-06 14:00:29,996 [INFO] PluginManager:220 - loadIPPluginJar : add genericplugin
|
||||||
|
2025-10-06 14:00:29,998 [INFO] IPUIPlugin:80 - create IPUIPlugin
|
||||||
|
2025-10-06 14:00:29,998 [INFO] PluginManager:220 - loadIPPluginJar : add opamp
|
||||||
|
2025-10-06 14:00:30,002 [INFO] IPUIPlugin:80 - create IPUIPlugin
|
||||||
|
2025-10-06 14:00:30,002 [INFO] PluginManager:220 - loadIPPluginJar : add stm32_wpan
|
||||||
|
2025-10-06 14:00:30,004 [INFO] IPUIPlugin:80 - create IPUIPlugin
|
||||||
|
2025-10-06 14:00:30,004 [INFO] PluginManager:220 - loadIPPluginJar : add usart
|
||||||
|
2025-10-06 14:00:30,006 [INFO] IPUIPlugin:80 - create IPUIPlugin
|
||||||
|
2025-10-06 14:00:30,006 [INFO] PluginManager:220 - loadIPPluginJar : add sai
|
||||||
|
2025-10-06 14:00:30,012 [INFO] IPUIPlugin:80 - create IPUIPlugin
|
||||||
|
2025-10-06 14:00:30,012 [INFO] PluginManager:220 - loadIPPluginJar : add linkedlist
|
||||||
|
2025-10-06 14:00:30,014 [INFO] IPUIPlugin:80 - create IPUIPlugin
|
||||||
|
2025-10-06 14:00:30,014 [INFO] PluginManager:220 - loadIPPluginJar : add extmemmanager
|
||||||
|
2025-10-06 14:00:30,017 [INFO] IPUIPlugin:80 - create IPUIPlugin
|
||||||
|
2025-10-06 14:00:30,017 [INFO] PluginManager:220 - loadIPPluginJar : add fmc
|
||||||
|
2025-10-06 14:00:30,020 [INFO] IPUIPlugin:80 - create IPUIPlugin
|
||||||
|
2025-10-06 14:00:30,020 [INFO] PluginManager:220 - loadIPPluginJar : add gpio
|
||||||
|
2025-10-06 14:00:30,025 [INFO] IPUIPlugin:80 - create IPUIPlugin
|
||||||
|
2025-10-06 14:00:30,025 [INFO] PluginManager:220 - loadIPPluginJar : add mdma
|
||||||
|
2025-10-06 14:00:30,120 [FATAL] Updater:351 - Updater called before beeing initialized
|
||||||
|
2025-10-06 14:00:30,162 [INFO] RulesReader:64 - Compatibility file has been processed (317 Rules)
|
||||||
|
2025-10-06 14:00:30,173 [INFO] RulesReader:64 - Compatibility file has been processed (317 Rules)
|
||||||
|
2025-10-06 14:00:30,178 [INFO] CADModel:165 - CPN selected for project level
|
||||||
|
2025-10-06 14:00:30,178 [INFO] CADModel:114 - Register for checkConnection events
|
||||||
|
2025-10-06 14:00:30,178 [FATAL] Updater:351 - Updater called before beeing initialized
|
||||||
|
2025-10-06 14:00:30,179 [ERROR] CADModel:125 - Updater not yet initialized, retry later
|
||||||
|
2025-10-06 14:00:30,311 [FATAL] Updater:351 - Updater called before beeing initialized
|
||||||
|
2025-10-06 14:00:30,312 [INFO] CADModel:165 - CPN selected for project level
|
||||||
|
2025-10-06 14:00:30,312 [INFO] CADModel:114 - Register for checkConnection events
|
||||||
|
2025-10-06 14:00:30,312 [FATAL] Updater:351 - Updater called before beeing initialized
|
||||||
|
2025-10-06 14:00:30,312 [ERROR] CADModel:125 - Updater not yet initialized, retry later
|
||||||
|
2025-10-06 14:00:30,315 [FATAL] Updater:351 - Updater called before beeing initialized
|
||||||
|
2025-10-06 14:00:30,377 [FATAL] Updater:351 - Updater called before beeing initialized
|
||||||
|
2025-10-06 14:00:30,381 [INFO] DbMcusAds:53 - JSON generation date=Tue Jul 08 03:14:23 CDT 2025 (1751962463524)
|
||||||
|
2025-10-06 14:00:30,381 [FATAL] Updater:351 - Updater called before beeing initialized
|
||||||
|
2025-10-06 14:00:30,410 [WARN] DetailPanel:346 - Failed to get advertising image, set to default
|
||||||
|
2025-10-06 14:00:30,468 [FATAL] Updater:351 - Updater called before beeing initialized
|
||||||
|
2025-10-06 14:00:30,470 [FATAL] Updater:351 - Updater called before beeing initialized
|
||||||
|
2025-10-06 14:00:30,470 [FATAL] Updater:351 - Updater called before beeing initialized
|
||||||
|
2025-10-06 14:00:30,470 [WARN] DetailPanel:346 - Failed to get advertising image, set to default
|
||||||
|
2025-10-06 14:00:30,470 [FATAL] Updater:351 - Updater called before beeing initialized
|
||||||
|
2025-10-06 14:00:30,495 [ERROR] Updater:1198 - MainUpdater not yet initialized. External WinMGr cannot be set.
|
||||||
|
2025-10-06 14:00:30,497 [INFO] Updater:1134 - Updater Version found : 6.15.0
|
||||||
|
2025-10-06 14:00:30,513 [INFO] ApplicationProperties:184 - Using Application install path: /home/ja/st/stm32cubeide_1.19.0/plugins/com.st.stm32cube.common.mx_6.15.0.202507011659
|
||||||
|
2025-10-06 14:00:31,573 [INFO] MainUpdater:2872 - connection check result : 10
|
||||||
|
2025-10-06 14:00:31,573 [INFO] MainUpdater:3604 - Updater definition file requires update
|
||||||
|
2025-10-06 14:00:31,575 [INFO] MainUpdater:289 - Updater Check For Update Now.
|
||||||
|
2025-10-06 14:00:31,575 [INFO] MicroXplorer:498 - Change Database Version : DB.6.0.150
|
||||||
|
2025-10-06 14:00:31,586 [INFO] McuFinderGlobals:63 - Set McuFinder mode to 2 (CubeIDE integrated)
|
||||||
|
2025-10-06 14:00:31,587 [INFO] UserAuth:487 - Internet connection configuration mode: 1
|
||||||
|
2025-10-06 14:00:31,605 [INFO] JxBrowserEngine:152 - Initiate JxBrowser Engine with user profile folder
|
||||||
|
2025-10-06 14:00:31,892 [INFO] ServerAccessManage:452 - Complete download http(s) 200
|
||||||
|
2025-10-06 14:00:31,894 [INFO] ServerAccessManage:509 - Download File updaters.zip
|
||||||
|
2025-10-06 14:00:32,217 [INFO] WebApp:169 - Instantiating new browser for Auth
|
||||||
|
2025-10-06 14:00:32,493 [WARN] MainUpdater:1193 - Updater busy. Cannot search thirdparties
|
||||||
|
2025-10-06 14:00:32,493 [INFO] ThirdPartyUpdaterWithRetryManager:96 - Updater plugin is busy. [1/15]
|
||||||
|
2025-10-06 14:00:32,531 [INFO] FileExtend:248 - Unzip File : updaters.zip
|
||||||
|
2025-10-06 14:00:32,531 [INFO] FileExtend:263 - Standard Zip Deflate
|
||||||
|
2025-10-06 14:00:32,884 [INFO] ServerAccessManage:452 - Complete download http(s) 200
|
||||||
|
2025-10-06 14:00:32,884 [INFO] ServerAccessManage:509 - Download File PacksControlFlags.xml
|
||||||
|
2025-10-06 14:00:32,910 [INFO] WebApp:463 - Apply proxy settings
|
||||||
|
2025-10-06 14:00:32,910 [INFO] WebApp:548 - Chromium requires no authentication
|
||||||
|
2025-10-06 14:00:32,919 [INFO] WebApp:491 - Direct internet connection detected
|
||||||
|
2025-10-06 14:00:32,943 [INFO] WebApp:900 - Register for checkConnection events
|
||||||
|
2025-10-06 14:00:32,943 [INFO] WebApp:463 - Apply proxy settings
|
||||||
|
2025-10-06 14:00:32,943 [INFO] WebApp:548 - Chromium requires no authentication
|
||||||
|
2025-10-06 14:00:32,944 [INFO] WebApp:491 - Direct internet connection detected
|
||||||
|
2025-10-06 14:00:33,078 [INFO] WebApp:225 - Starting web application
|
||||||
|
2025-10-06 14:00:33,078 [INFO] WebApp:593 - Web application path used /home/ja/st/stm32cubeide_1.19.0/plugins/com.st.stm32cube.common.mx_6.15.0.202507011659/db/plugins/mcufinder/reactClient1/index.html
|
||||||
|
2025-10-06 14:00:33,148 [INFO] ServerAccessManage:452 - Complete download http(s) 200
|
||||||
|
2025-10-06 14:00:33,148 [INFO] ServerAccessManage:509 - Download File cubemx.pidx
|
||||||
|
2025-10-06 14:00:33,166 [INFO] UserAuth:487 - Internet connection configuration mode: 1
|
||||||
|
2025-10-06 14:00:33,260 [INFO] LoadServerUpdatesThread:375 - End of LoadServerUpdate Thread
|
||||||
|
2025-10-06 14:00:33,416 [INFO] CheckServerUpdateThread:120 - End of CheckServer Thread
|
||||||
|
2025-10-06 14:00:33,845 [INFO] WebApp:191 - Connection restablished
|
||||||
|
2025-10-06 14:00:35,640 [WARN] PackLoader:240 - Cannot read IP mode file for STMicroelectronics.FP-SNS-MOTENVWB1.1.4.0
|
||||||
|
2025-10-06 14:00:35,648 [WARN] PackLoader:240 - Cannot read IP mode file for STMicroelectronics.FP-ATR-ASTRA1.2.0.2
|
||||||
|
2025-10-06 14:00:35,657 [WARN] PackLoader:240 - Cannot read IP mode file for STMicroelectronics.X-CUBE-SMBUS.2.1.0
|
||||||
|
2025-10-06 14:00:35,662 [WARN] PackLoader:240 - Cannot read IP mode file for STMicroelectronics.X-CUBE-ST60.1.0.0
|
||||||
|
2025-10-06 14:00:35,705 [WARN] PackLoader:240 - Cannot read IP mode file for STMicroelectronics.X-CUBE-AZRTOS-F7.1.1.0
|
||||||
|
2025-10-06 14:00:35,723 [WARN] PackLoader:240 - Cannot read IP mode file for WES.I-CUBE-Cesium.1.4.0
|
||||||
|
2025-10-06 14:00:35,763 [WARN] PackLoader:240 - Cannot read IP mode file for Infineon.AIROC-Wi-Fi-Bluetooth-STM32.1.7.1
|
||||||
|
2025-10-06 14:00:35,808 [WARN] PackLoader:240 - Cannot read IP mode file for STMicroelectronics.X-CUBE-AZRTOS-H7.3.4.0
|
||||||
|
2025-10-06 14:00:35,823 [WARN] PackLoader:240 - Cannot read IP mode file for STMicroelectronics.X-CUBE-DISPLAY.3.0.0
|
||||||
|
2025-10-06 14:00:35,839 [WARN] PackLoader:240 - Cannot read IP mode file for STMicroelectronics.X-CUBE-NFC10.1.0.0
|
||||||
|
2025-10-06 14:00:35,846 [WARN] PackLoader:240 - Cannot read IP mode file for emotas.I-CUBE-CANOPEN.1.3.0
|
||||||
|
2025-10-06 14:00:35,856 [WARN] PackLoader:240 - Cannot read IP mode file for STMicroelectronics.FP-SNS-STBOX1.2.1.0
|
||||||
|
2025-10-06 14:00:35,864 [WARN] PackLoader:240 - Cannot read IP mode file for STMicroelectronics.FP-SNS-SMARTAG2.1.2.0
|
||||||
|
2025-10-06 14:00:35,869 [WARN] PackLoader:240 - Cannot read IP mode file for STMicroelectronics.FP-SNS-FLIGHT1.5.1.0
|
||||||
|
2025-10-06 14:00:35,881 [INFO] LogOutputStream:77 - [STDOUT_REDIRECT] 1 : Invalid condition id : UX_CORESTACK_Condition cause : null
|
||||||
|
2025-10-06 14:00:35,881 [INFO] LogOutputStream:77 - [STDOUT_REDIRECT] 1 : Invalid condition id : UX_CORESTACK_Condition cause : null
|
||||||
|
2025-10-06 14:00:35,882 [INFO] LogOutputStream:77 - [STDOUT_REDIRECT] 1 : Invalid condition id : UX_CORESTACK_Condition cause : null
|
||||||
|
2025-10-06 14:00:35,882 [INFO] LogOutputStream:77 - [STDOUT_REDIRECT] 1 : Invalid condition id : UX_CORESTACK_Condition cause : null
|
||||||
|
2025-10-06 14:00:35,882 [INFO] LogOutputStream:77 - [STDOUT_REDIRECT] 1 : Invalid condition id : UX_CORESTACK_Condition cause : null
|
||||||
|
2025-10-06 14:00:35,888 [WARN] PackLoader:240 - Cannot read IP mode file for STMicroelectronics.X-CUBE-AZRTOS-WL.2.0.0
|
||||||
|
2025-10-06 14:00:35,894 [WARN] PackLoader:240 - Cannot read IP mode file for STMicroelectronics.FP-SNS-MOTENV1.5.0.0
|
||||||
|
2025-10-06 14:00:35,902 [WARN] PackLoader:240 - Cannot read IP mode file for STMicroelectronics.X-CUBE-BLE2.3.3.0
|
||||||
|
2025-10-06 14:00:35,910 [WARN] PackLoader:240 - Cannot read IP mode file for STMicroelectronics.X-CUBE-NFC9.1.0.0
|
||||||
|
2025-10-06 14:00:35,917 [WARN] PackLoader:240 - Cannot read IP mode file for wolfSSL.I-CUBE-wolfSSL.5.8.2
|
||||||
|
2025-10-06 14:00:35,922 [WARN] PackLoader:240 - Cannot read IP mode file for STMicroelectronics.X-CUBE-BLE1.7.1.0
|
||||||
|
2025-10-06 14:00:35,926 [WARN] PackLoader:240 - Cannot read IP mode file for wolfSSL.I-CUBE-wolfMQTT.1.19.2
|
||||||
|
2025-10-06 14:00:35,932 [WARN] PackLoader:240 - Cannot read IP mode file for STMicroelectronics.X-CUBE-EEPRMA1.5.2.0
|
||||||
|
2025-10-06 14:00:35,956 [WARN] PackLoader:240 - Cannot read IP mode file for STMicroelectronics.X-CUBE-AZRTOS-G0.1.1.0
|
||||||
|
2025-10-06 14:00:35,966 [WARN] PackLoader:240 - Cannot read IP mode file for STMicroelectronics.X-CUBE-SAFEA1.1.2.2
|
||||||
|
2025-10-06 14:00:35,972 [WARN] PackLoader:240 - Cannot read IP mode file for STMicroelectronics.X-CUBE-NFC4.3.0.0
|
||||||
|
2025-10-06 14:00:35,983 [WARN] PackLoader:240 - Cannot read IP mode file for EmbeddedOffice.I-CUBE-FS-RTOS.1.0.1
|
||||||
|
2025-10-06 14:00:35,990 [WARN] PackLoader:240 - Cannot read IP mode file for STMicroelectronics.X-CUBE-WB05N.2.0.0
|
||||||
|
2025-10-06 14:00:35,994 [WARN] PackLoader:240 - Cannot read IP mode file for wolfSSL.I-CUBE-wolfTPM.3.8.0
|
||||||
|
2025-10-06 14:00:36,000 [WARN] PackLoader:240 - Cannot read IP mode file for STMicroelectronics.X-CUBE-TCPP.4.2.0
|
||||||
|
2025-10-06 14:00:36,006 [WARN] PackLoader:240 - Cannot read IP mode file for RealThread.X-CUBE-RT-Thread_Nano.4.1.1
|
||||||
|
2025-10-06 14:00:36,010 [WARN] PackLoader:240 - Cannot read IP mode file for STMicroelectronics.FP-ATR-SIGFOX1.3.2.0
|
||||||
|
2025-10-06 14:00:36,015 [WARN] PackLoader:240 - Cannot read IP mode file for ITTIA_DB.I-CUBE-ITTIADB.8.9.0
|
||||||
|
2025-10-06 14:00:36,021 [WARN] PackLoader:240 - Cannot read IP mode file for STMicroelectronics.X-CUBE-ST67W61.1.0.0
|
||||||
|
2025-10-06 14:00:36,025 [WARN] PackLoader:240 - Cannot read IP mode file for STMicroelectronics.X-CUBE-AI.10.2.0
|
||||||
|
2025-10-06 14:00:36,062 [WARN] PackLoader:240 - Cannot read IP mode file for SEGGER.I-CUBE-embOS.1.3.1
|
||||||
|
2025-10-06 14:00:36,123 [WARN] PackLoader:240 - Cannot read IP mode file for STMicroelectronics.X-CUBE-ALGOBUILD.1.4.0
|
||||||
|
2025-10-06 14:00:36,191 [WARN] PackLoader:240 - Cannot read IP mode file for STMicroelectronics.X-CUBE-MEMS1.11.3.0
|
||||||
|
2025-10-06 14:00:36,322 [WARN] PackLoader:240 - Cannot read IP mode file for STMicroelectronics.X-CUBE-PM33A1.1.0.0
|
||||||
|
2025-10-06 14:00:36,334 [WARN] PackLoader:240 - Cannot read IP mode file for STMicroelectronics.X-CUBE-AZRTOS-F4.1.1.0
|
||||||
|
2025-10-06 14:00:36,338 [WARN] PackLoader:240 - Cannot read IP mode file for Avnet-IotConnect.X-CUBE-IoTC-DA16k-PMOD.1.0.0
|
||||||
|
2025-10-06 14:00:36,341 [WARN] PackLoader:240 - Cannot read IP mode file for STMicroelectronics.X-CUBE-ISPU.2.1.0
|
||||||
|
2025-10-06 14:00:36,348 [WARN] PackLoader:240 - Cannot read IP mode file for STMicroelectronics.X-CUBE-NFC12.1.0.0
|
||||||
|
2025-10-06 14:00:36,367 [WARN] PackLoader:240 - Cannot read IP mode file for STMicroelectronics.X-CUBE-AZRTOS-L5.2.0.0
|
||||||
|
2025-10-06 14:00:36,378 [WARN] PackLoader:240 - Cannot read IP mode file for STMicroelectronics.X-CUBE-NFC6.3.1.0
|
||||||
|
2025-10-06 14:00:36,385 [WARN] PackLoader:240 - Cannot read IP mode file for STMicroelectronics.X-CUBE-FREERTOS.1.3.1
|
||||||
|
2025-10-06 14:00:36,389 [WARN] PackLoader:240 - Cannot read IP mode file for STMicroelectronics.X-CUBE-TOUCHGFX.4.26.0
|
||||||
|
2025-10-06 14:00:36,394 [WARN] PackLoader:240 - Cannot read IP mode file for STMicroelectronics.FP-SNS-STAIOTCFT.1.0.0
|
||||||
|
2025-10-06 14:00:36,398 [WARN] PackLoader:240 - Cannot read IP mode file for STMicroelectronics.X-CUBE-DPower.1.3.0
|
||||||
|
2025-10-06 14:00:36,418 [WARN] ConditionMgr:438 - getConditionDescription Invalid condition id : LAN8742 Phy interface Condition cause : null
|
||||||
|
2025-10-06 14:00:36,419 [WARN] PackLoader:240 - Cannot read IP mode file for STMicroelectronics.X-CUBE-AZRTOS-L4.2.0.0
|
||||||
|
2025-10-06 14:00:36,421 [WARN] ConditionMgr:1044 - genDependencies : Invalid condition id : LAN8742 Phy interface Condition cause : null
|
||||||
|
2025-10-06 14:00:36,421 [WARN] ConditionMgr:1044 - genDependencies : Invalid condition id : LAN8742 Phy interface Condition cause : null
|
||||||
|
2025-10-06 14:00:36,422 [WARN] ConditionMgr:1044 - genDependencies : Invalid condition id : LAN8742 Phy interface Condition cause : null
|
||||||
|
2025-10-06 14:00:36,429 [WARN] PackLoader:240 - Cannot read IP mode file for STMicroelectronics.X-CUBE-SFXS2LP1.4.0.0
|
||||||
|
2025-10-06 14:00:36,441 [WARN] PackLoader:240 - Cannot read IP mode file for STMicroelectronics.X-CUBE-BLEMGR.4.1.0
|
||||||
|
2025-10-06 14:00:36,457 [WARN] ConditionMgr:438 - getConditionDescription Invalid condition id : UX DEVICE CLASS RTOS Condition cause : null
|
||||||
|
2025-10-06 14:00:36,458 [WARN] ConditionMgr:438 - getConditionDescription Invalid condition id : UX DEVICE CLASS RTOS Condition cause : null
|
||||||
|
2025-10-06 14:00:36,460 [WARN] PackLoader:240 - Cannot read IP mode file for STMicroelectronics.X-CUBE-AZRTOS-WB.2.0.0
|
||||||
|
2025-10-06 14:00:36,461 [WARN] ConditionMgr:1044 - genDependencies : Invalid condition id : UX DEVICE CLASS RTOS Condition cause : null
|
||||||
|
2025-10-06 14:00:36,461 [WARN] ConditionMgr:1044 - genDependencies : Invalid condition id : UX DEVICE CLASS RTOS Condition cause : null
|
||||||
|
2025-10-06 14:00:36,462 [WARN] ConditionMgr:1044 - genDependencies : Invalid condition id : UX DEVICE CLASS RTOS Condition cause : null
|
||||||
|
2025-10-06 14:00:36,462 [WARN] ConditionMgr:1044 - genDependencies : Invalid condition id : UX DEVICE CLASS RTOS Condition cause : null
|
||||||
|
2025-10-06 14:00:36,462 [WARN] ConditionMgr:1044 - genDependencies : Invalid condition id : UX DEVICE CLASS RTOS Condition cause : null
|
||||||
|
2025-10-06 14:00:36,467 [WARN] PackLoader:240 - Cannot read IP mode file for STMicroelectronics.X-CUBE-GNSS1.7.0.1
|
||||||
|
2025-10-06 14:00:36,471 [WARN] PackLoader:240 - Cannot read IP mode file for STMicroelectronics.X-CUBE-TOUCHGFX.4.25.0
|
||||||
|
2025-10-06 14:00:36,473 [WARN] ConditionMgr:438 - getConditionDescription Invalid condition id : Cortex-A Device cause : null
|
||||||
|
2025-10-06 14:00:36,482 [WARN] ConditionMgr:1044 - genDependencies : Invalid condition id : Cortex-A Device cause : null
|
||||||
|
2025-10-06 14:00:36,482 [WARN] ConditionMgr:1044 - genDependencies : Invalid condition id : Cortex-A Device cause : null
|
||||||
|
2025-10-06 14:00:36,482 [WARN] ConditionMgr:1044 - genDependencies : Invalid condition id : Cortex-A Device cause : null
|
||||||
|
2025-10-06 14:00:36,493 [WARN] PackLoader:240 - Cannot read IP mode file for STMicroelectronics.X-CUBE-SUBG2.5.0.0
|
||||||
|
2025-10-06 14:00:36,519 [WARN] PackLoader:240 - Cannot read IP mode file for STMicroelectronics.X-CUBE-AZRTOS-H7RS.1.1.0
|
||||||
|
2025-10-06 14:00:36,524 [WARN] PackLoader:240 - Cannot read IP mode file for Cesanta.I-CUBE-Mongoose.7.13.0
|
||||||
|
2025-10-06 14:00:36,537 [WARN] PackLoader:240 - Cannot read IP mode file for STMicroelectronics.X-CUBE-AZRTOS-G4.2.0.0
|
||||||
|
2025-10-06 14:00:36,541 [WARN] PackLoader:240 - Cannot read IP mode file for wolfSSL.I-CUBE-wolfSSH.1.4.20
|
||||||
|
2025-10-06 14:00:36,544 [WARN] PackLoader:240 - Cannot read IP mode file for STMicroelectronics.X-CUBE-NFC7.2.0.0
|
||||||
|
2025-10-06 14:00:36,558 [WARN] PackLoader:240 - Cannot read IP mode file for STMicroelectronics.X-CUBE-IPS.3.1.0
|
||||||
|
2025-10-06 14:00:36,580 [WARN] PackLoader:240 - Cannot read IP mode file for STMicroelectronics.X-CUBE-ALS.1.0.2
|
||||||
|
2025-10-06 14:00:36,584 [WARN] PackLoader:240 - Cannot read IP mode file for STMicroelectronics.X-CUBE-STSE01.1.0.0
|
||||||
|
2025-10-06 14:00:36,588 [WARN] PackLoader:240 - Cannot read IP mode file for portGmbH.I-Cube-SoM-uGOAL.1.1.0
|
||||||
|
2025-10-06 14:00:36,595 [WARN] PackLoader:240 - Cannot read IP mode file for STMicroelectronics.X-CUBE-TOF1.3.4.3
|
||||||
|
2025-10-06 14:00:36,602 [INFO] ThirdParty:978 - Integrity check success = true
|
||||||
|
2025-10-06 14:00:36,603 [INFO] IntegrityCheckThread:100 - exiting critical section [integrity check]
|
||||||
|
2025-10-06 14:00:36,603 [INFO] IntegrityCheckThread:103 - End integrity checks thread
|
||||||
|
2025-10-06 16:14:50,904 [ERROR] LogOutputStream:75 - [STDERR_REDIRECT]
|
||||||
361
.metadata/.log
361
.metadata/.log
@@ -529,3 +529,364 @@ Command-line arguments: -os linux -ws gtk -arch x86_64
|
|||||||
|
|
||||||
!ENTRY org.eclipse.cdt.core 1 0 2025-09-22 14:30:06.505
|
!ENTRY org.eclipse.cdt.core 1 0 2025-09-22 14:30:06.505
|
||||||
!MESSAGE Indexed 'TrafficLightsPlusPlus' (58 sources, 125 headers) in 4.39 sec: 12,712 declarations; 87,377 references; 0 unresolved inclusions; 1 syntax errors; 2 unresolved names (0.002%)
|
!MESSAGE Indexed 'TrafficLightsPlusPlus' (58 sources, 125 headers) in 4.39 sec: 12,712 declarations; 87,377 references; 0 unresolved inclusions; 1 syntax errors; 2 unresolved names (0.002%)
|
||||||
|
!SESSION 2025-09-29 14:05:26.003 -----------------------------------------------
|
||||||
|
eclipse.buildId=Version 1.19.0
|
||||||
|
java.version=21.0.3
|
||||||
|
java.vendor=Eclipse Adoptium
|
||||||
|
BootLoader constants: OS=linux, ARCH=x86_64, WS=gtk, NL=en_US
|
||||||
|
Command-line arguments: -os linux -ws gtk -arch x86_64
|
||||||
|
|
||||||
|
!ENTRY com.st.stm32cube.ide.mcu.informationcenter 4 4 2025-09-29 14:05:33.441
|
||||||
|
!MESSAGE CubeMX plugin appears to be active, Log4j initialization might be too late.
|
||||||
|
|
||||||
|
!ENTRY com.st.stm32cube.ide.mcu.informationcenter 1 1 2025-09-29 14:05:33.442
|
||||||
|
!MESSAGE Log4j2 initialized with config file /home/ja/st/Home/.metadata/.log4j2.xml
|
||||||
|
|
||||||
|
!ENTRY com.st.stm32cube.ide.mcu.ide 1 1 2025-09-29 14:05:40.190
|
||||||
|
!MESSAGE Started RMI Server, listening on port 41337
|
||||||
|
!SESSION 2025-09-29 14:20:57.093 -----------------------------------------------
|
||||||
|
eclipse.buildId=Version 1.19.0
|
||||||
|
java.version=21.0.3
|
||||||
|
java.vendor=Eclipse Adoptium
|
||||||
|
BootLoader constants: OS=linux, ARCH=x86_64, WS=gtk, NL=en_US
|
||||||
|
Command-line arguments: -os linux -ws gtk -arch x86_64
|
||||||
|
|
||||||
|
!ENTRY com.st.stm32cube.ide.mcu.informationcenter 4 4 2025-09-29 14:21:08.082
|
||||||
|
!MESSAGE CubeMX plugin appears to be active, Log4j initialization might be too late.
|
||||||
|
|
||||||
|
!ENTRY com.st.stm32cube.ide.mcu.informationcenter 1 1 2025-09-29 14:21:08.083
|
||||||
|
!MESSAGE Log4j2 initialized with config file /home/ja/st/Home/.metadata/.log4j2.xml
|
||||||
|
|
||||||
|
!ENTRY com.st.stm32cube.ide.mcu.ide 1 1 2025-09-29 14:21:15.394
|
||||||
|
!MESSAGE Started RMI Server, listening on port 41337
|
||||||
|
|
||||||
|
!ENTRY org.eclipse.cdt.core 4 0 2025-09-29 17:50:26.302
|
||||||
|
!MESSAGE Error: Cannot run program "bear -- make": Unknown reason
|
||||||
|
!STACK 0
|
||||||
|
java.io.IOException: Cannot run program "bear -- make": Unknown reason
|
||||||
|
at org.eclipse.cdt.utils.spawner.Spawner.exec(Spawner.java:450)
|
||||||
|
at org.eclipse.cdt.utils.spawner.Spawner.<init>(Spawner.java:147)
|
||||||
|
at org.eclipse.cdt.utils.spawner.Spawner.<init>(Spawner.java:134)
|
||||||
|
at org.eclipse.cdt.utils.spawner.ProcessFactory$Builder.start(ProcessFactory.java:273)
|
||||||
|
at org.eclipse.cdt.utils.spawner.ProcessFactory.exec(ProcessFactory.java:366)
|
||||||
|
at org.eclipse.cdt.core.CommandLauncher.execute(CommandLauncher.java:189)
|
||||||
|
at org.eclipse.cdt.core.CommandLauncherManager$CommandLauncherWrapper.execute(CommandLauncherManager.java:146)
|
||||||
|
at org.eclipse.cdt.internal.core.BuildRunnerHelper.build(BuildRunnerHelper.java:274)
|
||||||
|
at org.eclipse.cdt.managedbuilder.core.ExternalBuildRunner.invokeExternalBuild(ExternalBuildRunner.java:140)
|
||||||
|
at org.eclipse.cdt.managedbuilder.core.ExternalBuildRunner.invokeBuild(ExternalBuildRunner.java:73)
|
||||||
|
at com.st.stm32cube.ide.mcu.toolchain.armnone.setup.BuildRunner.invokeBuild(BuildRunner.java:81)
|
||||||
|
at org.eclipse.cdt.managedbuilder.internal.core.CommonBuilder.build(CommonBuilder.java:783)
|
||||||
|
at org.eclipse.cdt.managedbuilder.internal.core.CommonBuilder.build(CommonBuilder.java:530)
|
||||||
|
at org.eclipse.cdt.managedbuilder.internal.core.CommonBuilder.build(CommonBuilder.java:471)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:1077)
|
||||||
|
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:47)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:296)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:352)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:441)
|
||||||
|
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:47)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:444)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:555)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:503)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:585)
|
||||||
|
at org.eclipse.core.internal.resources.Workspace.buildInternal(Workspace.java:595)
|
||||||
|
at org.eclipse.core.internal.resources.Workspace.build(Workspace.java:491)
|
||||||
|
at org.eclipse.ui.actions.BuildAction$1.runInWorkspace(BuildAction.java:288)
|
||||||
|
at org.eclipse.core.internal.resources.InternalWorkspaceJob.run(InternalWorkspaceJob.java:43)
|
||||||
|
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)
|
||||||
|
!SESSION 2025-09-29 17:53:33.055 -----------------------------------------------
|
||||||
|
eclipse.buildId=Version 1.19.0
|
||||||
|
java.version=21.0.3
|
||||||
|
java.vendor=Eclipse Adoptium
|
||||||
|
BootLoader constants: OS=linux, ARCH=x86_64, WS=gtk, NL=en_US
|
||||||
|
Command-line arguments: -os linux -ws gtk -arch x86_64
|
||||||
|
|
||||||
|
!ENTRY com.st.stm32cube.ide.mcu.informationcenter 4 4 2025-09-29 17:53:41.312
|
||||||
|
!MESSAGE CubeMX plugin appears to be active, Log4j initialization might be too late.
|
||||||
|
|
||||||
|
!ENTRY com.st.stm32cube.ide.mcu.informationcenter 1 1 2025-09-29 17:53:41.313
|
||||||
|
!MESSAGE Log4j2 initialized with config file /home/ja/st/Home/.metadata/.log4j2.xml
|
||||||
|
|
||||||
|
!ENTRY com.st.stm32cube.ide.mcu.ide 1 1 2025-09-29 17:53:50.780
|
||||||
|
!MESSAGE Started RMI Server, listening on port 41337
|
||||||
|
!SESSION 2025-09-29 19:26:27.227 -----------------------------------------------
|
||||||
|
eclipse.buildId=Version 1.19.0
|
||||||
|
java.version=21.0.3
|
||||||
|
java.vendor=Eclipse Adoptium
|
||||||
|
BootLoader constants: OS=linux, ARCH=x86_64, WS=gtk, NL=en_US
|
||||||
|
Command-line arguments: -os linux -ws gtk -arch x86_64
|
||||||
|
|
||||||
|
!ENTRY com.st.stm32cube.ide.mcu.informationcenter 4 4 2025-09-29 19:26:34.184
|
||||||
|
!MESSAGE CubeMX plugin appears to be active, Log4j initialization might be too late.
|
||||||
|
|
||||||
|
!ENTRY com.st.stm32cube.ide.mcu.informationcenter 1 1 2025-09-29 19:26:34.185
|
||||||
|
!MESSAGE Log4j2 initialized with config file /home/ja/st/Home/.metadata/.log4j2.xml
|
||||||
|
|
||||||
|
!ENTRY com.st.stm32cube.ide.mcu.ide 1 1 2025-09-29 19:26:41.574
|
||||||
|
!MESSAGE Started RMI Server, listening on port 41337
|
||||||
|
!SESSION 2025-09-30 16:10:32.335 -----------------------------------------------
|
||||||
|
eclipse.buildId=Version 1.19.0
|
||||||
|
java.version=21.0.3
|
||||||
|
java.vendor=Eclipse Adoptium
|
||||||
|
BootLoader constants: OS=linux, ARCH=x86_64, WS=gtk, NL=en_US
|
||||||
|
Command-line arguments: -os linux -ws gtk -arch x86_64
|
||||||
|
|
||||||
|
!ENTRY com.st.stm32cube.ide.mcu.informationcenter 4 4 2025-09-30 16:10:40.407
|
||||||
|
!MESSAGE CubeMX plugin appears to be active, Log4j initialization might be too late.
|
||||||
|
|
||||||
|
!ENTRY com.st.stm32cube.ide.mcu.informationcenter 1 1 2025-09-30 16:10:40.408
|
||||||
|
!MESSAGE Log4j2 initialized with config file /home/ja/st/Home/.metadata/.log4j2.xml
|
||||||
|
|
||||||
|
!ENTRY com.st.stm32cube.ide.mcu.ide 1 1 2025-09-30 16:10:48.370
|
||||||
|
!MESSAGE Started RMI Server, listening on port 41337
|
||||||
|
!SESSION 2025-10-01 14:12:17.472 -----------------------------------------------
|
||||||
|
eclipse.buildId=Version 1.19.0
|
||||||
|
java.version=21.0.3
|
||||||
|
java.vendor=Eclipse Adoptium
|
||||||
|
BootLoader constants: OS=linux, ARCH=x86_64, WS=gtk, NL=en_US
|
||||||
|
Command-line arguments: -os linux -ws gtk -arch x86_64
|
||||||
|
|
||||||
|
!ENTRY com.st.stm32cube.ide.mcu.informationcenter 4 4 2025-10-01 14:12:28.447
|
||||||
|
!MESSAGE CubeMX plugin appears to be active, Log4j initialization might be too late.
|
||||||
|
|
||||||
|
!ENTRY com.st.stm32cube.ide.mcu.informationcenter 1 1 2025-10-01 14:12:28.448
|
||||||
|
!MESSAGE Log4j2 initialized with config file /home/ja/st/Home/.metadata/.log4j2.xml
|
||||||
|
|
||||||
|
!ENTRY com.st.stm32cube.ide.mcu.ide 1 1 2025-10-01 14:12:56.294
|
||||||
|
!MESSAGE Started RMI Server, listening on port 41337
|
||||||
|
!SESSION 2025-10-06 14:00:12.368 -----------------------------------------------
|
||||||
|
eclipse.buildId=Version 1.19.0
|
||||||
|
java.version=21.0.3
|
||||||
|
java.vendor=Eclipse Adoptium
|
||||||
|
BootLoader constants: OS=linux, ARCH=x86_64, WS=gtk, NL=en_US
|
||||||
|
Command-line arguments: -os linux -ws gtk -arch x86_64
|
||||||
|
|
||||||
|
!ENTRY org.eclipse.core.resources 2 10035 2025-10-06 14:00:16.176
|
||||||
|
!MESSAGE The workspace exited with unsaved changes in the previous session; refreshing workspace to recover changes.
|
||||||
|
|
||||||
|
!ENTRY com.st.stm32cube.ide.mcu.informationcenter 4 4 2025-10-06 14:00:19.104
|
||||||
|
!MESSAGE CubeMX plugin appears to be active, Log4j initialization might be too late.
|
||||||
|
|
||||||
|
!ENTRY com.st.stm32cube.ide.mcu.informationcenter 1 1 2025-10-06 14:00:19.104
|
||||||
|
!MESSAGE Log4j2 initialized with config file /home/ja/st/Home/.metadata/.log4j2.xml
|
||||||
|
|
||||||
|
!ENTRY com.st.stm32cube.ide.mcu.ide 1 1 2025-10-06 14:00:27.811
|
||||||
|
!MESSAGE Started RMI Server, listening on port 41337
|
||||||
|
|
||||||
|
!ENTRY org.eclipse.cdt.core 4 0 2025-10-06 14:22:03.962
|
||||||
|
!MESSAGE Error: Cannot run program "bear -- make": Unknown reason
|
||||||
|
!STACK 0
|
||||||
|
java.io.IOException: Cannot run program "bear -- make": Unknown reason
|
||||||
|
at org.eclipse.cdt.utils.spawner.Spawner.exec(Spawner.java:450)
|
||||||
|
at org.eclipse.cdt.utils.spawner.Spawner.<init>(Spawner.java:147)
|
||||||
|
at org.eclipse.cdt.utils.spawner.Spawner.<init>(Spawner.java:134)
|
||||||
|
at org.eclipse.cdt.utils.spawner.ProcessFactory$Builder.start(ProcessFactory.java:273)
|
||||||
|
at org.eclipse.cdt.utils.spawner.ProcessFactory.exec(ProcessFactory.java:366)
|
||||||
|
at org.eclipse.cdt.core.CommandLauncher.execute(CommandLauncher.java:189)
|
||||||
|
at org.eclipse.cdt.core.CommandLauncherManager$CommandLauncherWrapper.execute(CommandLauncherManager.java:146)
|
||||||
|
at org.eclipse.cdt.internal.core.BuildRunnerHelper.build(BuildRunnerHelper.java:274)
|
||||||
|
at org.eclipse.cdt.managedbuilder.core.ExternalBuildRunner.invokeExternalBuild(ExternalBuildRunner.java:140)
|
||||||
|
at org.eclipse.cdt.managedbuilder.core.ExternalBuildRunner.invokeBuild(ExternalBuildRunner.java:73)
|
||||||
|
at com.st.stm32cube.ide.mcu.toolchain.armnone.setup.BuildRunner.invokeBuild(BuildRunner.java:81)
|
||||||
|
at org.eclipse.cdt.managedbuilder.internal.core.CommonBuilder.build(CommonBuilder.java:783)
|
||||||
|
at org.eclipse.cdt.managedbuilder.internal.core.CommonBuilder.build(CommonBuilder.java:530)
|
||||||
|
at org.eclipse.cdt.managedbuilder.internal.core.CommonBuilder.build(CommonBuilder.java:471)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:1077)
|
||||||
|
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:47)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:296)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:352)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:441)
|
||||||
|
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:47)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:444)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:555)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:503)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:585)
|
||||||
|
at org.eclipse.core.internal.resources.Workspace.buildInternal(Workspace.java:595)
|
||||||
|
at org.eclipse.core.internal.resources.Workspace.build(Workspace.java:491)
|
||||||
|
at org.eclipse.ui.actions.BuildAction$1.runInWorkspace(BuildAction.java:288)
|
||||||
|
at org.eclipse.core.internal.resources.InternalWorkspaceJob.run(InternalWorkspaceJob.java:43)
|
||||||
|
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)
|
||||||
|
|
||||||
|
!ENTRY org.eclipse.cdt.core 4 0 2025-10-06 14:32:48.179
|
||||||
|
!MESSAGE Error: Cannot run program "bear --": Unknown reason
|
||||||
|
!STACK 0
|
||||||
|
java.io.IOException: Cannot run program "bear --": Unknown reason
|
||||||
|
at org.eclipse.cdt.utils.spawner.Spawner.exec(Spawner.java:450)
|
||||||
|
at org.eclipse.cdt.utils.spawner.Spawner.<init>(Spawner.java:147)
|
||||||
|
at org.eclipse.cdt.utils.spawner.Spawner.<init>(Spawner.java:134)
|
||||||
|
at org.eclipse.cdt.utils.spawner.ProcessFactory$Builder.start(ProcessFactory.java:273)
|
||||||
|
at org.eclipse.cdt.utils.spawner.ProcessFactory.exec(ProcessFactory.java:366)
|
||||||
|
at org.eclipse.cdt.core.CommandLauncher.execute(CommandLauncher.java:189)
|
||||||
|
at org.eclipse.cdt.core.CommandLauncherManager$CommandLauncherWrapper.execute(CommandLauncherManager.java:146)
|
||||||
|
at org.eclipse.cdt.internal.core.BuildRunnerHelper.build(BuildRunnerHelper.java:274)
|
||||||
|
at org.eclipse.cdt.managedbuilder.core.ExternalBuildRunner.invokeExternalBuild(ExternalBuildRunner.java:140)
|
||||||
|
at org.eclipse.cdt.managedbuilder.core.ExternalBuildRunner.invokeBuild(ExternalBuildRunner.java:73)
|
||||||
|
at com.st.stm32cube.ide.mcu.toolchain.armnone.setup.BuildRunner.invokeBuild(BuildRunner.java:81)
|
||||||
|
at org.eclipse.cdt.managedbuilder.internal.core.CommonBuilder.build(CommonBuilder.java:783)
|
||||||
|
at org.eclipse.cdt.managedbuilder.internal.core.CommonBuilder.build(CommonBuilder.java:530)
|
||||||
|
at org.eclipse.cdt.managedbuilder.internal.core.CommonBuilder.build(CommonBuilder.java:471)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:1077)
|
||||||
|
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:47)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:296)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:352)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:441)
|
||||||
|
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:47)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:444)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:555)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:503)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:585)
|
||||||
|
at org.eclipse.core.internal.resources.Workspace.buildInternal(Workspace.java:595)
|
||||||
|
at org.eclipse.core.internal.resources.Workspace.build(Workspace.java:491)
|
||||||
|
at org.eclipse.ui.actions.BuildAction$1.runInWorkspace(BuildAction.java:288)
|
||||||
|
at org.eclipse.core.internal.resources.InternalWorkspaceJob.run(InternalWorkspaceJob.java:43)
|
||||||
|
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)
|
||||||
|
|
||||||
|
!ENTRY org.eclipse.cdt.core 4 0 2025-10-06 14:34:03.172
|
||||||
|
!MESSAGE Error: Cannot run program "bear -- make": Unknown reason
|
||||||
|
!STACK 0
|
||||||
|
java.io.IOException: Cannot run program "bear -- make": Unknown reason
|
||||||
|
at org.eclipse.cdt.utils.spawner.Spawner.exec(Spawner.java:450)
|
||||||
|
at org.eclipse.cdt.utils.spawner.Spawner.<init>(Spawner.java:147)
|
||||||
|
at org.eclipse.cdt.utils.spawner.Spawner.<init>(Spawner.java:134)
|
||||||
|
at org.eclipse.cdt.utils.spawner.ProcessFactory$Builder.start(ProcessFactory.java:273)
|
||||||
|
at org.eclipse.cdt.utils.spawner.ProcessFactory.exec(ProcessFactory.java:366)
|
||||||
|
at org.eclipse.cdt.core.CommandLauncher.execute(CommandLauncher.java:189)
|
||||||
|
at org.eclipse.cdt.core.CommandLauncherManager$CommandLauncherWrapper.execute(CommandLauncherManager.java:146)
|
||||||
|
at org.eclipse.cdt.internal.core.BuildRunnerHelper.build(BuildRunnerHelper.java:274)
|
||||||
|
at org.eclipse.cdt.managedbuilder.core.ExternalBuildRunner.invokeExternalBuild(ExternalBuildRunner.java:140)
|
||||||
|
at org.eclipse.cdt.managedbuilder.core.ExternalBuildRunner.invokeBuild(ExternalBuildRunner.java:73)
|
||||||
|
at com.st.stm32cube.ide.mcu.toolchain.armnone.setup.BuildRunner.invokeBuild(BuildRunner.java:81)
|
||||||
|
at org.eclipse.cdt.managedbuilder.internal.core.CommonBuilder.build(CommonBuilder.java:783)
|
||||||
|
at org.eclipse.cdt.managedbuilder.internal.core.CommonBuilder.build(CommonBuilder.java:530)
|
||||||
|
at org.eclipse.cdt.managedbuilder.internal.core.CommonBuilder.build(CommonBuilder.java:471)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:1077)
|
||||||
|
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:47)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:296)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:352)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:441)
|
||||||
|
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:47)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:444)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:555)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:503)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:585)
|
||||||
|
at org.eclipse.core.internal.resources.Workspace.buildInternal(Workspace.java:595)
|
||||||
|
at org.eclipse.core.internal.resources.Workspace.build(Workspace.java:491)
|
||||||
|
at org.eclipse.ui.actions.BuildAction$1.runInWorkspace(BuildAction.java:288)
|
||||||
|
at org.eclipse.core.internal.resources.InternalWorkspaceJob.run(InternalWorkspaceJob.java:43)
|
||||||
|
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)
|
||||||
|
|
||||||
|
!ENTRY org.eclipse.cdt.core 4 0 2025-10-06 14:35:29.559
|
||||||
|
!MESSAGE Error: Cannot run program "bear make": Unknown reason
|
||||||
|
!STACK 0
|
||||||
|
java.io.IOException: Cannot run program "bear make": Unknown reason
|
||||||
|
at org.eclipse.cdt.utils.spawner.Spawner.exec(Spawner.java:450)
|
||||||
|
at org.eclipse.cdt.utils.spawner.Spawner.<init>(Spawner.java:147)
|
||||||
|
at org.eclipse.cdt.utils.spawner.Spawner.<init>(Spawner.java:134)
|
||||||
|
at org.eclipse.cdt.utils.spawner.ProcessFactory$Builder.start(ProcessFactory.java:273)
|
||||||
|
at org.eclipse.cdt.utils.spawner.ProcessFactory.exec(ProcessFactory.java:366)
|
||||||
|
at org.eclipse.cdt.core.CommandLauncher.execute(CommandLauncher.java:189)
|
||||||
|
at org.eclipse.cdt.core.CommandLauncherManager$CommandLauncherWrapper.execute(CommandLauncherManager.java:146)
|
||||||
|
at org.eclipse.cdt.internal.core.BuildRunnerHelper.build(BuildRunnerHelper.java:274)
|
||||||
|
at org.eclipse.cdt.managedbuilder.core.ExternalBuildRunner.invokeExternalBuild(ExternalBuildRunner.java:140)
|
||||||
|
at org.eclipse.cdt.managedbuilder.core.ExternalBuildRunner.invokeBuild(ExternalBuildRunner.java:73)
|
||||||
|
at com.st.stm32cube.ide.mcu.toolchain.armnone.setup.BuildRunner.invokeBuild(BuildRunner.java:81)
|
||||||
|
at org.eclipse.cdt.managedbuilder.internal.core.CommonBuilder.build(CommonBuilder.java:783)
|
||||||
|
at org.eclipse.cdt.managedbuilder.internal.core.CommonBuilder.build(CommonBuilder.java:530)
|
||||||
|
at org.eclipse.cdt.managedbuilder.internal.core.CommonBuilder.build(CommonBuilder.java:471)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:1077)
|
||||||
|
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:47)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:296)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:352)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:441)
|
||||||
|
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:47)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:444)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:555)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:503)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:585)
|
||||||
|
at org.eclipse.core.internal.resources.Workspace.buildInternal(Workspace.java:595)
|
||||||
|
at org.eclipse.core.internal.resources.Workspace.build(Workspace.java:491)
|
||||||
|
at org.eclipse.ui.actions.BuildAction$1.runInWorkspace(BuildAction.java:288)
|
||||||
|
at org.eclipse.core.internal.resources.InternalWorkspaceJob.run(InternalWorkspaceJob.java:43)
|
||||||
|
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)
|
||||||
|
|
||||||
|
!ENTRY org.eclipse.cdt.core 4 0 2025-10-06 14:41:30.597
|
||||||
|
!MESSAGE Error: Cannot run program "/usr/bin/bear -- make": Unknown reason
|
||||||
|
!STACK 0
|
||||||
|
java.io.IOException: Cannot run program "/usr/bin/bear -- make": Unknown reason
|
||||||
|
at org.eclipse.cdt.utils.spawner.Spawner.exec(Spawner.java:450)
|
||||||
|
at org.eclipse.cdt.utils.spawner.Spawner.<init>(Spawner.java:147)
|
||||||
|
at org.eclipse.cdt.utils.spawner.Spawner.<init>(Spawner.java:134)
|
||||||
|
at org.eclipse.cdt.utils.spawner.ProcessFactory$Builder.start(ProcessFactory.java:273)
|
||||||
|
at org.eclipse.cdt.utils.spawner.ProcessFactory.exec(ProcessFactory.java:366)
|
||||||
|
at org.eclipse.cdt.core.CommandLauncher.execute(CommandLauncher.java:189)
|
||||||
|
at org.eclipse.cdt.core.CommandLauncherManager$CommandLauncherWrapper.execute(CommandLauncherManager.java:146)
|
||||||
|
at org.eclipse.cdt.internal.core.BuildRunnerHelper.build(BuildRunnerHelper.java:274)
|
||||||
|
at org.eclipse.cdt.managedbuilder.core.ExternalBuildRunner.invokeExternalBuild(ExternalBuildRunner.java:140)
|
||||||
|
at org.eclipse.cdt.managedbuilder.core.ExternalBuildRunner.invokeBuild(ExternalBuildRunner.java:73)
|
||||||
|
at com.st.stm32cube.ide.mcu.toolchain.armnone.setup.BuildRunner.invokeBuild(BuildRunner.java:81)
|
||||||
|
at org.eclipse.cdt.managedbuilder.internal.core.CommonBuilder.build(CommonBuilder.java:783)
|
||||||
|
at org.eclipse.cdt.managedbuilder.internal.core.CommonBuilder.build(CommonBuilder.java:530)
|
||||||
|
at org.eclipse.cdt.managedbuilder.internal.core.CommonBuilder.build(CommonBuilder.java:471)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:1077)
|
||||||
|
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:47)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:296)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:352)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:441)
|
||||||
|
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:47)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:444)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:555)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:503)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:585)
|
||||||
|
at org.eclipse.core.internal.resources.Workspace.buildInternal(Workspace.java:595)
|
||||||
|
at org.eclipse.core.internal.resources.Workspace.build(Workspace.java:491)
|
||||||
|
at org.eclipse.ui.actions.BuildAction$1.runInWorkspace(BuildAction.java:288)
|
||||||
|
at org.eclipse.core.internal.resources.InternalWorkspaceJob.run(InternalWorkspaceJob.java:43)
|
||||||
|
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)
|
||||||
|
|
||||||
|
!ENTRY org.eclipse.cdt.core 4 0 2025-10-06 14:42:46.335
|
||||||
|
!MESSAGE Error: Cannot run program "bear -- make -j8 all": Unknown reason
|
||||||
|
!STACK 0
|
||||||
|
java.io.IOException: Cannot run program "bear -- make -j8 all": Unknown reason
|
||||||
|
at org.eclipse.cdt.utils.spawner.Spawner.exec(Spawner.java:450)
|
||||||
|
at org.eclipse.cdt.utils.spawner.Spawner.<init>(Spawner.java:147)
|
||||||
|
at org.eclipse.cdt.utils.spawner.Spawner.<init>(Spawner.java:134)
|
||||||
|
at org.eclipse.cdt.utils.spawner.ProcessFactory$Builder.start(ProcessFactory.java:273)
|
||||||
|
at org.eclipse.cdt.utils.spawner.ProcessFactory.exec(ProcessFactory.java:366)
|
||||||
|
at org.eclipse.cdt.core.CommandLauncher.execute(CommandLauncher.java:189)
|
||||||
|
at org.eclipse.cdt.core.CommandLauncherManager$CommandLauncherWrapper.execute(CommandLauncherManager.java:146)
|
||||||
|
at org.eclipse.cdt.internal.core.BuildRunnerHelper.build(BuildRunnerHelper.java:274)
|
||||||
|
at org.eclipse.cdt.managedbuilder.core.ExternalBuildRunner.invokeExternalBuild(ExternalBuildRunner.java:140)
|
||||||
|
at org.eclipse.cdt.managedbuilder.core.ExternalBuildRunner.invokeBuild(ExternalBuildRunner.java:73)
|
||||||
|
at com.st.stm32cube.ide.mcu.toolchain.armnone.setup.BuildRunner.invokeBuild(BuildRunner.java:81)
|
||||||
|
at org.eclipse.cdt.managedbuilder.internal.core.CommonBuilder.build(CommonBuilder.java:783)
|
||||||
|
at org.eclipse.cdt.managedbuilder.internal.core.CommonBuilder.build(CommonBuilder.java:530)
|
||||||
|
at org.eclipse.cdt.managedbuilder.internal.core.CommonBuilder.build(CommonBuilder.java:471)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:1077)
|
||||||
|
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:47)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:296)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:352)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:441)
|
||||||
|
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:47)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:444)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:555)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:503)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:585)
|
||||||
|
at org.eclipse.core.internal.resources.Workspace.buildInternal(Workspace.java:595)
|
||||||
|
at org.eclipse.core.internal.resources.Workspace.build(Workspace.java:491)
|
||||||
|
at org.eclipse.ui.actions.BuildAction$1.runInWorkspace(BuildAction.java:288)
|
||||||
|
at org.eclipse.core.internal.resources.InternalWorkspaceJob.run(InternalWorkspaceJob.java:43)
|
||||||
|
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)
|
||||||
|
!SESSION 2025-10-13 14:21:35.248 -----------------------------------------------
|
||||||
|
eclipse.buildId=Version 1.19.0
|
||||||
|
java.version=21.0.3
|
||||||
|
java.vendor=Eclipse Adoptium
|
||||||
|
BootLoader constants: OS=linux, ARCH=x86_64, WS=gtk, NL=en_US
|
||||||
|
Command-line arguments: -os linux -ws gtk -arch x86_64
|
||||||
|
|
||||||
|
!ENTRY com.st.stm32cube.ide.mcu.informationcenter 4 4 2025-10-13 14:21:52.837
|
||||||
|
!MESSAGE CubeMX plugin appears to be active, Log4j initialization might be too late.
|
||||||
|
|
||||||
|
!ENTRY com.st.stm32cube.ide.mcu.informationcenter 1 1 2025-10-13 14:21:52.838
|
||||||
|
!MESSAGE Log4j2 initialized with config file /home/ja/st/Home/.metadata/.log4j2.xml
|
||||||
|
|
||||||
|
!ENTRY com.st.stm32cube.ide.mcu.ide 1 1 2025-10-13 14:21:59.450
|
||||||
|
!MESSAGE Started RMI Server, listening on port 41337
|
||||||
|
|||||||
@@ -17,3 +17,10 @@
|
|||||||
*** SESSION Sep 20, 2025 22:34:37.42 -------------------------------------------
|
*** SESSION Sep 20, 2025 22:34:37.42 -------------------------------------------
|
||||||
*** SESSION Sep 22, 2025 14:12:24.952 ------------------------------------------
|
*** SESSION Sep 22, 2025 14:12:24.952 ------------------------------------------
|
||||||
*** SESSION Sep 22, 2025 14:25:48.576 ------------------------------------------
|
*** SESSION Sep 22, 2025 14:25:48.576 ------------------------------------------
|
||||||
|
*** SESSION Sep 29, 2025 14:05:32.147 ------------------------------------------
|
||||||
|
*** SESSION Sep 29, 2025 14:21:06.486 ------------------------------------------
|
||||||
|
*** SESSION Sep 29, 2025 17:53:39.168 ------------------------------------------
|
||||||
|
*** SESSION Sep 29, 2025 19:26:32.917 ------------------------------------------
|
||||||
|
*** SESSION Sep 30, 2025 16:10:38.815 ------------------------------------------
|
||||||
|
*** SESSION Oct 06, 2025 14:00:17.912 ------------------------------------------
|
||||||
|
*** SESSION Oct 13, 2025 14:21:51.496 ------------------------------------------
|
||||||
|
|||||||
Binary file not shown.
@@ -1,18 +1,10 @@
|
|||||||
01:20:42 **** Incremental Build of configuration Debug for project TrafficLightsPlus ****
|
17:50:44 **** Incremental Build of configuration Debug for project TrafficLightsPlus ****
|
||||||
make -j8 all
|
make -j8 all
|
||||||
arm-none-eabi-gcc "../Core/Src/breadboard.c" -mcpu=cortex-m4 -std=gnu11 -g3 -DDEBUG -DUSE_HAL_DRIVER -DSTM32F429xx -c -I../Core/Inc -I../USB_HOST/App -I../USB_HOST/Target -I../Drivers/STM32F4xx_HAL_Driver/Inc -I../Drivers/STM32F4xx_HAL_Driver/Inc/Legacy -I../Middlewares/Third_Party/FreeRTOS/Source/include -I../Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS -I../Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F -I../Middlewares/ST/STM32_USB_Host_Library/Core/Inc -I../Middlewares/ST/STM32_USB_Host_Library/Class/CDC/Inc -I../Drivers/CMSIS/Device/ST/STM32F4xx/Include -I../Drivers/CMSIS/Include -O0 -ffunction-sections -fdata-sections -Wall -fstack-usage -fcyclomatic-complexity -MMD -MP -MF"Core/Src/breadboard.d" -MT"Core/Src/breadboard.o" --specs=nano.specs -mfpu=fpv4-sp-d16 -mfloat-abi=hard -mthumb -o "Core/Src/breadboard.o"
|
|
||||||
arm-none-eabi-gcc "../Core/Src/main.c" -mcpu=cortex-m4 -std=gnu11 -g3 -DDEBUG -DUSE_HAL_DRIVER -DSTM32F429xx -c -I../Core/Inc -I../USB_HOST/App -I../USB_HOST/Target -I../Drivers/STM32F4xx_HAL_Driver/Inc -I../Drivers/STM32F4xx_HAL_Driver/Inc/Legacy -I../Middlewares/Third_Party/FreeRTOS/Source/include -I../Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS -I../Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F -I../Middlewares/ST/STM32_USB_Host_Library/Core/Inc -I../Middlewares/ST/STM32_USB_Host_Library/Class/CDC/Inc -I../Drivers/CMSIS/Device/ST/STM32F4xx/Include -I../Drivers/CMSIS/Include -O0 -ffunction-sections -fdata-sections -Wall -fstack-usage -fcyclomatic-complexity -MMD -MP -MF"Core/Src/main.d" -MT"Core/Src/main.o" --specs=nano.specs -mfpu=fpv4-sp-d16 -mfloat-abi=hard -mthumb -o "Core/Src/main.o"
|
|
||||||
arm-none-eabi-gcc -o "TrafficLightsPlus.elf" @"objects.list" -mcpu=cortex-m4 -T"/home/ja/st/Home/TrafficLightsPlus/STM32F429ZITX_FLASH.ld" --specs=nosys.specs -Wl,-Map="TrafficLightsPlus.map" -Wl,--gc-sections -static --specs=nano.specs -mfpu=fpv4-sp-d16 -mfloat-abi=hard -mthumb -Wl,--start-group -lc -lm -Wl,--end-group
|
|
||||||
Finished building target: TrafficLightsPlus.elf
|
|
||||||
|
|
||||||
arm-none-eabi-size TrafficLightsPlus.elf
|
arm-none-eabi-size TrafficLightsPlus.elf
|
||||||
arm-none-eabi-objdump -h -S TrafficLightsPlus.elf > "TrafficLightsPlus.list"
|
|
||||||
text data bss dec hex filename
|
text data bss dec hex filename
|
||||||
32656 16 3496 36168 8d48 TrafficLightsPlus.elf
|
32656 16 3496 36168 8d48 TrafficLightsPlus.elf
|
||||||
Finished building: default.size.stdout
|
Finished building: default.size.stdout
|
||||||
|
|
||||||
Finished building: TrafficLightsPlus.list
|
|
||||||
|
|
||||||
|
|
||||||
01:20:42 Build Finished. 0 errors, 0 warnings. (took 593ms)
|
17:50:44 Build Finished. 0 errors, 0 warnings. (took 132ms)
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
14:52:33 **** Incremental Build of configuration Debug for project TrafficLightsPlusPlus ****
|
||||||
|
make -j8 all
|
||||||
|
arm-none-eabi-g++ -o "TrafficLightsPlusPlus.elf" @"objects.list" -mcpu=cortex-m4 -T"/home/ja/st/Home/TrafficLightsPlusPlus/STM32F429ZITX_FLASH.ld" --specs=nosys.specs -Wl,-Map="TrafficLightsPlusPlus.map" -Wl,--gc-sections -static --specs=nano.specs -mfpu=fpv4-sp-d16 -mfloat-abi=hard -mthumb -Wl,--start-group -lc -lm -lstdc++ -lsupc++ -Wl,--end-group
|
||||||
|
/home/ja/st/stm32cubeide_1.19.0/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.13.3.rel1.linux64_1.0.0.202410170706/tools/bin/../lib/gcc/arm-none-eabi/13.3.1/../../../../arm-none-eabi/bin/ld: ./Core/Src/stm32f4xx_it.o: in function `DMA2D_IRQHandler':
|
||||||
|
/home/ja/st/Home/TrafficLightsPlusPlus/Debug/../Core/Src/stm32f4xx_it.c:203:(.text.DMA2D_IRQHandler+0x10): undefined reference to `hdma2d'
|
||||||
|
collect2: error: ld returned 1 exit status
|
||||||
|
make: *** [makefile:92: TrafficLightsPlusPlus.elf] Error 1
|
||||||
|
"make -j8 all" terminated with exit code 2. Build might be incomplete.
|
||||||
|
|
||||||
|
14:52:33 Build Failed. 2 errors, 0 warnings. (took 171ms)
|
||||||
|
|
||||||
@@ -1,15 +1,8 @@
|
|||||||
01:20:42 **** Incremental Build of configuration Debug for project TrafficLightsPlus ****
|
14:52:33 **** Incremental Build of configuration Debug for project TrafficLightsPlusPlus ****
|
||||||
make -j8 all
|
make -j8 all
|
||||||
arm-none-eabi-gcc "../Core/Src/breadboard.c" -mcpu=cortex-m4 -std=gnu11 -g3 -DDEBUG -DUSE_HAL_DRIVER -DSTM32F429xx -c -I../Core/Inc -I../USB_HOST/App -I../USB_HOST/Target -I../Drivers/STM32F4xx_HAL_Driver/Inc -I../Drivers/STM32F4xx_HAL_Driver/Inc/Legacy -I../Middlewares/Third_Party/FreeRTOS/Source/include -I../Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS -I../Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F -I../Middlewares/ST/STM32_USB_Host_Library/Core/Inc -I../Middlewares/ST/STM32_USB_Host_Library/Class/CDC/Inc -I../Drivers/CMSIS/Device/ST/STM32F4xx/Include -I../Drivers/CMSIS/Include -O0 -ffunction-sections -fdata-sections -Wall -fstack-usage -fcyclomatic-complexity -MMD -MP -MF"Core/Src/breadboard.d" -MT"Core/Src/breadboard.o" --specs=nano.specs -mfpu=fpv4-sp-d16 -mfloat-abi=hard -mthumb -o "Core/Src/breadboard.o"
|
arm-none-eabi-g++ -o "TrafficLightsPlusPlus.elf" @"objects.list" -mcpu=cortex-m4 -T"/home/ja/st/Home/TrafficLightsPlusPlus/STM32F429ZITX_FLASH.ld" --specs=nosys.specs -Wl,-Map="TrafficLightsPlusPlus.map" -Wl,--gc-sections -static --specs=nano.specs -mfpu=fpv4-sp-d16 -mfloat-abi=hard -mthumb -Wl,--start-group -lc -lm -lstdc++ -lsupc++ -Wl,--end-group
|
||||||
arm-none-eabi-gcc "../Core/Src/main.c" -mcpu=cortex-m4 -std=gnu11 -g3 -DDEBUG -DUSE_HAL_DRIVER -DSTM32F429xx -c -I../Core/Inc -I../USB_HOST/App -I../USB_HOST/Target -I../Drivers/STM32F4xx_HAL_Driver/Inc -I../Drivers/STM32F4xx_HAL_Driver/Inc/Legacy -I../Middlewares/Third_Party/FreeRTOS/Source/include -I../Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS -I../Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F -I../Middlewares/ST/STM32_USB_Host_Library/Core/Inc -I../Middlewares/ST/STM32_USB_Host_Library/Class/CDC/Inc -I../Drivers/CMSIS/Device/ST/STM32F4xx/Include -I../Drivers/CMSIS/Include -O0 -ffunction-sections -fdata-sections -Wall -fstack-usage -fcyclomatic-complexity -MMD -MP -MF"Core/Src/main.d" -MT"Core/Src/main.o" --specs=nano.specs -mfpu=fpv4-sp-d16 -mfloat-abi=hard -mthumb -o "Core/Src/main.o"
|
/home/ja/st/stm32cubeide_1.19.0/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.13.3.rel1.linux64_1.0.0.202410170706/tools/bin/../lib/gcc/arm-none-eabi/13.3.1/../../../../arm-none-eabi/bin/ld: ./Core/Src/stm32f4xx_it.o: in function `DMA2D_IRQHandler':
|
||||||
arm-none-eabi-gcc -o "TrafficLightsPlus.elf" @"objects.list" -mcpu=cortex-m4 -T"/home/ja/st/Home/TrafficLightsPlus/STM32F429ZITX_FLASH.ld" --specs=nosys.specs -Wl,-Map="TrafficLightsPlus.map" -Wl,--gc-sections -static --specs=nano.specs -mfpu=fpv4-sp-d16 -mfloat-abi=hard -mthumb -Wl,--start-group -lc -lm -Wl,--end-group
|
/home/ja/st/Home/TrafficLightsPlusPlus/Debug/../Core/Src/stm32f4xx_it.c:203:(.text.DMA2D_IRQHandler+0x10): undefined reference to `hdma2d'
|
||||||
Finished building target: TrafficLightsPlus.elf
|
collect2: error: ld returned 1 exit status
|
||||||
|
make: *** [makefile:92: TrafficLightsPlusPlus.elf] Error 1
|
||||||
arm-none-eabi-size TrafficLightsPlus.elf
|
"make -j8 all" terminated with exit code 2. Build might be incomplete.
|
||||||
arm-none-eabi-objdump -h -S TrafficLightsPlus.elf > "TrafficLightsPlus.list"
|
|
||||||
text data bss dec hex filename
|
|
||||||
32656 16 3496 36168 8d48 TrafficLightsPlus.elf
|
|
||||||
Finished building: default.size.stdout
|
|
||||||
|
|
||||||
Finished building: TrafficLightsPlus.list
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,95 +0,0 @@
|
|||||||
/*
|
|
||||||
* breadboard.c
|
|
||||||
*
|
|
||||||
* Created on: Sep 17, 2025
|
|
||||||
* Author: ja
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* #define RedLight_Pin GPIO_PIN_2
|
|
||||||
* #define RedLight_GPIO_Port GPIOE
|
|
||||||
*
|
|
||||||
* #define YellowLight_Pin GPIO_PIN_3
|
|
||||||
* #define YellowLight_GPIO_Port GPIOE
|
|
||||||
*
|
|
||||||
* #define GreenLight_Pin GPIO_PIN_4
|
|
||||||
* #define GreenLight_GPIO_Port GPIOE
|
|
||||||
*
|
|
||||||
* RedLight: PE2
|
|
||||||
* YellowLight: PE3
|
|
||||||
* GreenLight: PE4
|
|
||||||
* WalkLight: PE5
|
|
||||||
*
|
|
||||||
* Done: Traffic Light
|
|
||||||
* TODO: async? Walk Signal, Light Dimmer
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "main.h"
|
|
||||||
#include "breadboard.h"
|
|
||||||
|
|
||||||
#define R_Pin RedLight_Pin
|
|
||||||
#define Y_Pin YellowLight_Pin
|
|
||||||
#define G_Pin GreenLight_Pin
|
|
||||||
#define W_Pin WalkLight_Pin
|
|
||||||
|
|
||||||
#define R_Prt RedLight_GPIO_Port
|
|
||||||
#define Y_Prt YellowLight_GPIO_Port
|
|
||||||
#define G_Prt GreenLight_GPIO_Port
|
|
||||||
#define W_Prt WalkLight_GPIO_Port
|
|
||||||
|
|
||||||
uint32_t trafftick_last;
|
|
||||||
uint32_t walktick_last;
|
|
||||||
|
|
||||||
uint8_t trafflight_i = 0;
|
|
||||||
|
|
||||||
void
|
|
||||||
starttick(void)
|
|
||||||
{
|
|
||||||
trafftick_last = HAL_GetTick();
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
trafflight(int traffSPD)
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
HAL_GPIO_TogglePin(R_Prt, R_Pin);
|
|
||||||
HAL_Delay(traffSPD);
|
|
||||||
HAL_GPIO_TogglePin(R_Prt, R_Pin);
|
|
||||||
|
|
||||||
HAL_GPIO_TogglePin(Y_Prt, Y_Pin);
|
|
||||||
HAL_Delay(traffSPD);
|
|
||||||
HAL_GPIO_TogglePin(Y_Prt, Y_Pin);
|
|
||||||
|
|
||||||
HAL_GPIO_TogglePin(G_Prt, G_Pin);
|
|
||||||
HAL_Delay(traffSPD);
|
|
||||||
HAL_GPIO_TogglePin(G_Prt, G_Pin);
|
|
||||||
*/
|
|
||||||
|
|
||||||
uint32_t trafftick_curr = HAL_GetTick();
|
|
||||||
|
|
||||||
if ((trafftick_curr - trafftick_last) >= traffSPD) {
|
|
||||||
HAL_GPIO_WritePin(R_Prt, R_Pin, GPIO_PIN_RESET);
|
|
||||||
HAL_GPIO_WritePin(Y_Prt, Y_Pin, GPIO_PIN_RESET);
|
|
||||||
HAL_GPIO_WritePin(G_Prt, G_Pin, GPIO_PIN_RESET);
|
|
||||||
|
|
||||||
switch (trafflight_i) {
|
|
||||||
case 0:
|
|
||||||
HAL_GPIO_WritePin(R_Prt, R_Pin, GPIO_PIN_SET);
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
HAL_GPIO_WritePin(Y_Prt, Y_Pin, GPIO_PIN_SET);
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
HAL_GPIO_WritePin(G_Prt, G_Pin);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
trafflight_i = (trafflight_i + 1) % 3;
|
|
||||||
trafftick_last = trafftick_curr;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((trafftick_curr - walktick_last) >= walkSPD) {
|
|
||||||
HAL_GPIO_TogglePin(W_Prt, W_Pin);
|
|
||||||
walktick_last = trafftick_curr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,310 @@
|
|||||||
|
/* USER CODE BEGIN Header */
|
||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
* @file : main.c
|
||||||
|
* @brief : Main program body
|
||||||
|
******************************************************************************
|
||||||
|
* @attention
|
||||||
|
*
|
||||||
|
* Copyright (c) 2025 STMicroelectronics.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This software is licensed under terms that can be found in the LICENSE file
|
||||||
|
* in the root directory of this software component.
|
||||||
|
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||||
|
*
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
extern "C" {
|
||||||
|
/* USER CODE END Header */
|
||||||
|
/* Includes ------------------------------------------------------------------*/
|
||||||
|
#include "main.h"
|
||||||
|
|
||||||
|
/* Private function prototypes -----------------------------------------------*/
|
||||||
|
void SystemClock_Config(void);
|
||||||
|
static void MX_GPIO_Init(void);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Private user code ---------------------------------------------------------*/
|
||||||
|
/* USER CODE BEGIN 0 */
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
enum class TrafficState { GREEN, YELLOW, RED };
|
||||||
|
void SetTrafficLights(TrafficState s);
|
||||||
|
|
||||||
|
TrafficState currentState = TrafficState::GREEN;
|
||||||
|
uint32_t stateStartTime = 0; //HAL_GetTick() at the start of this state
|
||||||
|
bool buttonPressedThisCycle = false;
|
||||||
|
bool pedestrianNextCycle = false;
|
||||||
|
bool pedestrianThisCycle = false;
|
||||||
|
|
||||||
|
const uint32_t DURATION_GREEN = 5000;
|
||||||
|
const uint32_t DURATION_YELLOW = 3000;
|
||||||
|
const uint32_t DURATION_RED_NOPED = 5000;
|
||||||
|
const uint32_t DURATION_RED_PED = 7000;
|
||||||
|
|
||||||
|
/* USER CODE END 0 */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief The application entry point.
|
||||||
|
* @retval int
|
||||||
|
*/
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
HAL_Init();
|
||||||
|
|
||||||
|
/* USER CODE BEGIN Init */
|
||||||
|
|
||||||
|
/* USER CODE END Init */
|
||||||
|
|
||||||
|
/* Configure the system clock */
|
||||||
|
SystemClock_Config();
|
||||||
|
MX_GPIO_Init();
|
||||||
|
|
||||||
|
stateStartTime = HAL_GetTick();
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
/* USER CODE END WHILE */
|
||||||
|
uint32_t now = HAL_GetTick();
|
||||||
|
uint32_t elapsed = now - stateStartTime;
|
||||||
|
|
||||||
|
switch(currentState)
|
||||||
|
{
|
||||||
|
case TrafficState::GREEN:
|
||||||
|
if (buttonPressedThisCycle)
|
||||||
|
pedestrianThisCycle = true;
|
||||||
|
|
||||||
|
/*
|
||||||
|
if (buttonPressedThisCycle)
|
||||||
|
{
|
||||||
|
currentState = TrafficState::YELLOW;
|
||||||
|
stateStartTime = now;
|
||||||
|
buttonPressedThisCycle = false;
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pedestrianNextCycle = false;
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
else if (elapsed >= DURATION_GREEN)
|
||||||
|
{
|
||||||
|
currentState = TrafficState::YELLOW;
|
||||||
|
stateStartTime = now;
|
||||||
|
buttonPressedThisCycle = false;
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case TrafficState::YELLOW:
|
||||||
|
if (buttonPressedThisCycle || pedstrianNextCycle)
|
||||||
|
pedestrianThisCycle = true;
|
||||||
|
|
||||||
|
if (elapsed >= DURATION_YELLOW)
|
||||||
|
{
|
||||||
|
currentState = TrafficState::RED;
|
||||||
|
stateStartTime = now;
|
||||||
|
buttonPressedThisCycle = false; //TODO add pressed pedestrian button in yellow
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
// If Ped Button was pressed during GREEN or YELLOW, we need to enable WHITE this cycle
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case TrafficState::RED:
|
||||||
|
if (pedestrianNextCycle)
|
||||||
|
{
|
||||||
|
HAL_GPIO_WritePin(GPIOD,White_Pin,GPIO_PIN_SET); // turn on Pedestrian LED
|
||||||
|
if (elapsed >= DURATION_RED_PED)
|
||||||
|
{
|
||||||
|
HAL_GPIO_WritePin(GPIOD,White_Pin,GPIO_PIN_RESET);
|
||||||
|
pedestrianNextCycle = false;
|
||||||
|
currentState = TrafficState::GREEN;
|
||||||
|
stateStartTime = now;
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
HAL_GPIO_WritePin(GPIOD,White_Pin,GPIO_PIN_RESET);
|
||||||
|
if(elapsed >= DURATION_RED_PED)
|
||||||
|
{
|
||||||
|
currentState = TrafficState::GREEN;
|
||||||
|
stateStartTime = now;
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/* USER CODE BEGIN 3 */
|
||||||
|
}
|
||||||
|
/* USER CODE END 3 */
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief System Clock Configuration
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void SystemClock_Config(void)
|
||||||
|
{
|
||||||
|
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
|
||||||
|
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
|
||||||
|
|
||||||
|
/** Configure the main internal regulator output voltage
|
||||||
|
*/
|
||||||
|
__HAL_RCC_PWR_CLK_ENABLE();
|
||||||
|
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE3);
|
||||||
|
|
||||||
|
/** Initializes the RCC Oscillators according to the specified parameters
|
||||||
|
* in the RCC_OscInitTypeDef structure.
|
||||||
|
*/
|
||||||
|
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
|
||||||
|
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
|
||||||
|
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
|
||||||
|
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
||||||
|
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
|
||||||
|
RCC_OscInitStruct.PLL.PLLM = 8;
|
||||||
|
RCC_OscInitStruct.PLL.PLLN = 50;
|
||||||
|
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4;
|
||||||
|
RCC_OscInitStruct.PLL.PLLQ = 7;
|
||||||
|
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Initializes the CPU, AHB and APB buses clocks
|
||||||
|
*/
|
||||||
|
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|
||||||
|
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
|
||||||
|
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
|
||||||
|
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
|
||||||
|
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV8;
|
||||||
|
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV4;
|
||||||
|
|
||||||
|
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief GPIO Initialization Function
|
||||||
|
* @param None
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
static void MX_GPIO_Init(void)
|
||||||
|
{
|
||||||
|
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||||
|
/* USER CODE BEGIN MX_GPIO_Init_1 */
|
||||||
|
|
||||||
|
/* USER CODE END MX_GPIO_Init_1 */
|
||||||
|
|
||||||
|
/* GPIO Ports Clock Enable */
|
||||||
|
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||||
|
__HAL_RCC_GPIOD_CLK_ENABLE();
|
||||||
|
|
||||||
|
/*Configure GPIO pin Output Level */
|
||||||
|
HAL_GPIO_WritePin(GPIOD, White_Pin|Red_Pin|Yellow_Pin|Green_Pin, GPIO_PIN_RESET);
|
||||||
|
|
||||||
|
/*Configure GPIO pin : PedButton_Pin */
|
||||||
|
GPIO_InitStruct.Pin = PedButton_Pin;
|
||||||
|
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
|
||||||
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
|
HAL_GPIO_Init(PedButton_GPIO_Port, &GPIO_InitStruct);
|
||||||
|
|
||||||
|
/*Configure GPIO pins : White_Pin Red_Pin Yellow_Pin Green_Pin */
|
||||||
|
GPIO_InitStruct.Pin = White_Pin|Red_Pin|Yellow_Pin|Green_Pin;
|
||||||
|
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||||
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||||
|
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
|
||||||
|
|
||||||
|
/* EXTI interrupt init*/
|
||||||
|
HAL_NVIC_SetPriority(EXTI15_10_IRQn, 15, 0);
|
||||||
|
HAL_NVIC_EnableIRQ(EXTI15_10_IRQn);
|
||||||
|
|
||||||
|
/* USER CODE BEGIN MX_GPIO_Init_2 */
|
||||||
|
|
||||||
|
/* USER CODE END MX_GPIO_Init_2 */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* USER CODE BEGIN 4 */
|
||||||
|
void HAL_GPIO_EXTI_CallBack()
|
||||||
|
{
|
||||||
|
static uint32_t lastInterruptTime = 0;
|
||||||
|
uint32_t now = HAL_GetTick();
|
||||||
|
if(now - lastInterruptTime < 100)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
lastInterruptTime = now;
|
||||||
|
|
||||||
|
if (PedButton_Pin)
|
||||||
|
{
|
||||||
|
buttonPressedThisCycle = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void HAL_GPIO_EXTI_IRQHandler()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/* USER CODE END 4 */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function is executed in case of error occurrence.
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void Error_Handler(void)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN Error_Handler_Debug */
|
||||||
|
/* User can add his own implementation to report the HAL error return state */
|
||||||
|
__disable_irq();
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
/* USER CODE END Error_Handler_Debug */
|
||||||
|
}
|
||||||
|
#ifdef USE_FULL_ASSERT
|
||||||
|
/**
|
||||||
|
* @brief Reports the name of the source file and the source line number
|
||||||
|
* where the assert_param error has occurred.
|
||||||
|
* @param file: pointer to the source file name
|
||||||
|
* @param line: assert_param error line source number
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void assert_failed(uint8_t *file, uint32_t line)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN 6 */
|
||||||
|
/* User can add his own implementation to report the file name and line number,
|
||||||
|
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
|
||||||
|
/* USER CODE END 6 */
|
||||||
|
}
|
||||||
|
#endif /* USE_FULL_ASSERT */
|
||||||
|
|
||||||
|
void SetTrafficLights(TrafficState s)
|
||||||
|
{
|
||||||
|
// reset all
|
||||||
|
HAL_GPIO_WritePin(GPIOD, Green_Pin, GPIO_PIN_RESET);
|
||||||
|
HAL_GPIO_WritePin(GPIOD, Yellow_Pin, GPIO_PIN_RESET);
|
||||||
|
HAL_GPIO_WritePin(GPIOD, Red_Pin, GPIO_PIN_SET);
|
||||||
|
|
||||||
|
switch (s)
|
||||||
|
{
|
||||||
|
case TrafficState::GREEN :
|
||||||
|
HAL_GPIO_WritePin(GPIOD, Green_Pin, GPIO_PIN_SET);
|
||||||
|
break;
|
||||||
|
case TrafficState::YELLOW :
|
||||||
|
HAL_GPIO_WritePin(GPIOD, Yellow_Pin, GPIO_PIN_SET);
|
||||||
|
break;
|
||||||
|
case TrafficState::RED:
|
||||||
|
HAL_GPIO_WritePin(GPIOD, Red_Pin, GPIO_PIN_SET);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,95 +0,0 @@
|
|||||||
/*
|
|
||||||
* breadboard.c
|
|
||||||
*
|
|
||||||
* Created on: Sep 17, 2025
|
|
||||||
* Author: ja
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* #define RedLight_Pin GPIO_PIN_2
|
|
||||||
* #define RedLight_GPIO_Port GPIOE
|
|
||||||
*
|
|
||||||
* #define YellowLight_Pin GPIO_PIN_3
|
|
||||||
* #define YellowLight_GPIO_Port GPIOE
|
|
||||||
*
|
|
||||||
* #define GreenLight_Pin GPIO_PIN_4
|
|
||||||
* #define GreenLight_GPIO_Port GPIOE
|
|
||||||
*
|
|
||||||
* RedLight: PE2
|
|
||||||
* YellowLight: PE3
|
|
||||||
* GreenLight: PE4
|
|
||||||
* WalkLight: PE5
|
|
||||||
*
|
|
||||||
* Done: Traffic Light
|
|
||||||
* TODO: async? Walk Signal, Light Dimmer
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "main.h"
|
|
||||||
#include "breadboard.h"
|
|
||||||
|
|
||||||
#define R_Pin RedLight_Pin
|
|
||||||
#define Y_Pin YellowLight_Pin
|
|
||||||
#define G_Pin GreenLight_Pin
|
|
||||||
#define W_Pin WalkLight_Pin
|
|
||||||
|
|
||||||
#define R_Prt RedLight_GPIO_Port
|
|
||||||
#define Y_Prt YellowLight_GPIO_Port
|
|
||||||
#define G_Prt GreenLight_GPIO_Port
|
|
||||||
#define W_Prt WalkLight_GPIO_Port
|
|
||||||
|
|
||||||
uint32_t trafftick_last;
|
|
||||||
uint32_t walktick_last;
|
|
||||||
|
|
||||||
uint8_t trafflight_i = 0;
|
|
||||||
|
|
||||||
void
|
|
||||||
starttick(void)
|
|
||||||
{
|
|
||||||
trafftick_last = HAL_GetTick();
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
trafflight(int traffSPD)
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
HAL_GPIO_TogglePin(R_Prt, R_Pin);
|
|
||||||
HAL_Delay(traffSPD);
|
|
||||||
HAL_GPIO_TogglePin(R_Prt, R_Pin);
|
|
||||||
|
|
||||||
HAL_GPIO_TogglePin(Y_Prt, Y_Pin);
|
|
||||||
HAL_Delay(traffSPD);
|
|
||||||
HAL_GPIO_TogglePin(Y_Prt, Y_Pin);
|
|
||||||
|
|
||||||
HAL_GPIO_TogglePin(G_Prt, G_Pin);
|
|
||||||
HAL_Delay(traffSPD);
|
|
||||||
HAL_GPIO_TogglePin(G_Prt, G_Pin);
|
|
||||||
*/
|
|
||||||
|
|
||||||
uint32_t trafftick_curr = HAL_GetTick();
|
|
||||||
|
|
||||||
if ((trafftick_curr - trafftick_last) >= traffSPD) {
|
|
||||||
HAL_GPIO_WritePin(R_Prt, R_Pin, GPIO_PIN_RESET);
|
|
||||||
HAL_GPIO_WritePin(Y_Prt, Y_Pin, GPIO_PIN_RESET);
|
|
||||||
HAL_GPIO_WritePin(G_Prt, G_Pin, GPIO_PIN_RESET);
|
|
||||||
|
|
||||||
switch (trafflight_i) {
|
|
||||||
case 0:
|
|
||||||
HAL_GPIO_WritePin(R_Prt, R_Pin, GPIO_PIN_SET);
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
HAL_GPIO_WritePin(Y_Prt, Y_Pin);
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
HAL_GPIO_WritePin(G_Prt, G_Pin);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
trafflight_i = (trafflight_i + 1) % 3;
|
|
||||||
trafftick_last = trafftick_curr;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((trafftick_curr - walktick_last) >= walkSPD) {
|
|
||||||
HAL_GPIO_TogglePin(W_Prt, W_Pin);
|
|
||||||
walktick_last = trafftick_curr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,311 @@
|
|||||||
|
/* USER CODE BEGIN Header */
|
||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
* @file : main.c
|
||||||
|
* @brief : Main program body
|
||||||
|
******************************************************************************
|
||||||
|
* @attention
|
||||||
|
*
|
||||||
|
* Copyright (c) 2025 STMicroelectronics.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This software is licensed under terms that can be found in the LICENSE file
|
||||||
|
* in the root directory of this software component.
|
||||||
|
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||||
|
*
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
// Feeling sneaky.
|
||||||
|
extern "C" {
|
||||||
|
/* USER CODE END Header */
|
||||||
|
/* Includes ------------------------------------------------------------------*/
|
||||||
|
#include "main.h"
|
||||||
|
|
||||||
|
/* Private function prototypes -----------------------------------------------*/
|
||||||
|
void SystemClock_Config(void);
|
||||||
|
static void MX_GPIO_Init(void);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Private user code ---------------------------------------------------------*/
|
||||||
|
/* USER CODE BEGIN 0 */
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
enum class TrafficState { GREEN, YELLOW, RED };
|
||||||
|
void SetTrafficLights(TrafficState s);
|
||||||
|
|
||||||
|
TrafficState currentState = TrafficState::GREEN;
|
||||||
|
uint32_t stateStartTime = 0; //HAL_GetTick() at the start of this state
|
||||||
|
bool buttonPressedThisCycle = false;
|
||||||
|
bool pedestrianNextCycle = false;
|
||||||
|
bool pedestrianThisCycle = false;
|
||||||
|
|
||||||
|
const uint32_t DURATION_GREEN = 5000;
|
||||||
|
const uint32_t DURATION_YELLOW = 3000;
|
||||||
|
const uint32_t DURATION_RED_NOPED = 5000;
|
||||||
|
const uint32_t DURATION_RED_PED = 7000;
|
||||||
|
|
||||||
|
/* USER CODE END 0 */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief The application entry point.
|
||||||
|
* @retval int
|
||||||
|
*/
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
HAL_Init();
|
||||||
|
|
||||||
|
/* USER CODE BEGIN Init */
|
||||||
|
|
||||||
|
/* USER CODE END Init */
|
||||||
|
|
||||||
|
/* Configure the system clock */
|
||||||
|
SystemClock_Config();
|
||||||
|
MX_GPIO_Init();
|
||||||
|
|
||||||
|
stateStartTime = HAL_GetTick();
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
/* USER CODE END WHILE */
|
||||||
|
uint32_t now = HAL_GetTick();
|
||||||
|
uint32_t elapsed = now - stateStartTime;
|
||||||
|
|
||||||
|
switch(currentState)
|
||||||
|
{
|
||||||
|
case TrafficState::GREEN:
|
||||||
|
if (buttonPressedThisCycle)
|
||||||
|
pedestrianThisCycle = true;
|
||||||
|
|
||||||
|
/*
|
||||||
|
if (buttonPressedThisCycle)
|
||||||
|
{
|
||||||
|
currentState = TrafficState::YELLOW;
|
||||||
|
stateStartTime = now;
|
||||||
|
buttonPressedThisCycle = false;
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pedestrianNextCycle = false;
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
else if (elapsed >= DURATION_GREEN)
|
||||||
|
{
|
||||||
|
currentState = TrafficState::YELLOW;
|
||||||
|
stateStartTime = now;
|
||||||
|
buttonPressedThisCycle = false;
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case TrafficState::YELLOW:
|
||||||
|
if (buttonPressedThisCycle || pedstrianNextCycle)
|
||||||
|
pedestrianThisCycle = true;
|
||||||
|
|
||||||
|
if (elapsed >= DURATION_YELLOW)
|
||||||
|
{
|
||||||
|
currentState = TrafficState::RED;
|
||||||
|
stateStartTime = now;
|
||||||
|
buttonPressedThisCycle = false; //TODO add pressed pedestrian button in yellow
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
// If Ped Button was pressed during GREEN or YELLOW, we need to enable WHITE this cycle
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case TrafficState::RED:
|
||||||
|
if (pedestrianNextCycle)
|
||||||
|
{
|
||||||
|
HAL_GPIO_WritePin(GPIOD,White_Pin,GPIO_PIN_SET); // turn on Pedestrian LED
|
||||||
|
if (elapsed >= DURATION_RED_PED)
|
||||||
|
{
|
||||||
|
HAL_GPIO_WritePin(GPIOD,White_Pin,GPIO_PIN_RESET);
|
||||||
|
pedestrianNextCycle = false;
|
||||||
|
currentState = TrafficState::GREEN;
|
||||||
|
stateStartTime = now;
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
HAL_GPIO_WritePin(GPIOD,White_Pin,GPIO_PIN_RESET);
|
||||||
|
if(elapsed >= DURATION_RED_PED)
|
||||||
|
{
|
||||||
|
currentState = TrafficState::GREEN;
|
||||||
|
stateStartTime = now;
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/* USER CODE BEGIN 3 */
|
||||||
|
}
|
||||||
|
/* USER CODE END 3 */
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief System Clock Configuration
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void SystemClock_Config(void)
|
||||||
|
{
|
||||||
|
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
|
||||||
|
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
|
||||||
|
|
||||||
|
/** Configure the main internal regulator output voltage
|
||||||
|
*/
|
||||||
|
__HAL_RCC_PWR_CLK_ENABLE();
|
||||||
|
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE3);
|
||||||
|
|
||||||
|
/** Initializes the RCC Oscillators according to the specified parameters
|
||||||
|
* in the RCC_OscInitTypeDef structure.
|
||||||
|
*/
|
||||||
|
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
|
||||||
|
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
|
||||||
|
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
|
||||||
|
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
||||||
|
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
|
||||||
|
RCC_OscInitStruct.PLL.PLLM = 8;
|
||||||
|
RCC_OscInitStruct.PLL.PLLN = 50;
|
||||||
|
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4;
|
||||||
|
RCC_OscInitStruct.PLL.PLLQ = 7;
|
||||||
|
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Initializes the CPU, AHB and APB buses clocks
|
||||||
|
*/
|
||||||
|
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|
||||||
|
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
|
||||||
|
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
|
||||||
|
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
|
||||||
|
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV8;
|
||||||
|
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV4;
|
||||||
|
|
||||||
|
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief GPIO Initialization Function
|
||||||
|
* @param None
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
static void MX_GPIO_Init(void)
|
||||||
|
{
|
||||||
|
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||||
|
/* USER CODE BEGIN MX_GPIO_Init_1 */
|
||||||
|
|
||||||
|
/* USER CODE END MX_GPIO_Init_1 */
|
||||||
|
|
||||||
|
/* GPIO Ports Clock Enable */
|
||||||
|
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||||
|
__HAL_RCC_GPIOD_CLK_ENABLE();
|
||||||
|
|
||||||
|
/*Configure GPIO pin Output Level */
|
||||||
|
HAL_GPIO_WritePin(GPIOD, White_Pin|Red_Pin|Yellow_Pin|Green_Pin, GPIO_PIN_RESET);
|
||||||
|
|
||||||
|
/*Configure GPIO pin : PedButton_Pin */
|
||||||
|
GPIO_InitStruct.Pin = PedButton_Pin;
|
||||||
|
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
|
||||||
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
|
HAL_GPIO_Init(PedButton_GPIO_Port, &GPIO_InitStruct);
|
||||||
|
|
||||||
|
/*Configure GPIO pins : White_Pin Red_Pin Yellow_Pin Green_Pin */
|
||||||
|
GPIO_InitStruct.Pin = White_Pin|Red_Pin|Yellow_Pin|Green_Pin;
|
||||||
|
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||||
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||||
|
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
|
||||||
|
|
||||||
|
/* EXTI interrupt init*/
|
||||||
|
HAL_NVIC_SetPriority(EXTI15_10_IRQn, 15, 0);
|
||||||
|
HAL_NVIC_EnableIRQ(EXTI15_10_IRQn);
|
||||||
|
|
||||||
|
/* USER CODE BEGIN MX_GPIO_Init_2 */
|
||||||
|
|
||||||
|
/* USER CODE END MX_GPIO_Init_2 */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* USER CODE BEGIN 4 */
|
||||||
|
void HAL_GPIO_EXTI_CallBack()
|
||||||
|
{
|
||||||
|
static uint32_t lastInterruptTime = 0;
|
||||||
|
uint32_t now = HAL_GetTick();
|
||||||
|
if(now - lastInterruptTime < 100)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
lastInterruptTime = now;
|
||||||
|
|
||||||
|
if (PedButton_Pin)
|
||||||
|
{
|
||||||
|
buttonPressedThisCycle = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void HAL_GPIO_EXTI_IRQHandler()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/* USER CODE END 4 */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function is executed in case of error occurrence.
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void Error_Handler(void)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN Error_Handler_Debug */
|
||||||
|
/* User can add his own implementation to report the HAL error return state */
|
||||||
|
__disable_irq();
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
/* USER CODE END Error_Handler_Debug */
|
||||||
|
}
|
||||||
|
#ifdef USE_FULL_ASSERT
|
||||||
|
/**
|
||||||
|
* @brief Reports the name of the source file and the source line number
|
||||||
|
* where the assert_param error has occurred.
|
||||||
|
* @param file: pointer to the source file name
|
||||||
|
* @param line: assert_param error line source number
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void assert_failed(uint8_t *file, uint32_t line)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN 6 */
|
||||||
|
/* User can add his own implementation to report the file name and line number,
|
||||||
|
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
|
||||||
|
/* USER CODE END 6 */
|
||||||
|
}
|
||||||
|
#endif /* USE_FULL_ASSERT */
|
||||||
|
|
||||||
|
void SetTrafficLights(TrafficState s)
|
||||||
|
{
|
||||||
|
// reset all
|
||||||
|
HAL_GPIO_WritePin(GPIOD, Green_Pin, GPIO_PIN_RESET);
|
||||||
|
HAL_GPIO_WritePin(GPIOD, Yellow_Pin, GPIO_PIN_RESET);
|
||||||
|
HAL_GPIO_WritePin(GPIOD, Red_Pin, GPIO_PIN_SET);
|
||||||
|
|
||||||
|
switch (s)
|
||||||
|
{
|
||||||
|
case TrafficState::GREEN :
|
||||||
|
HAL_GPIO_WritePin(GPIOD, Green_Pin, GPIO_PIN_SET);
|
||||||
|
break;
|
||||||
|
case TrafficState::YELLOW :
|
||||||
|
HAL_GPIO_WritePin(GPIOD, Yellow_Pin, GPIO_PIN_SET);
|
||||||
|
break;
|
||||||
|
case TrafficState::RED:
|
||||||
|
HAL_GPIO_WritePin(GPIOD, Red_Pin, GPIO_PIN_SET);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
/*
|
|
||||||
* breadboard.h
|
|
||||||
*
|
|
||||||
* Created on: Sep 20, 2025
|
|
||||||
* Author: ja
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef INC_BREADBOARD_H_
|
|
||||||
#define INC_BREADBOARD_H_
|
|
||||||
|
|
||||||
void trafflight(int);
|
|
||||||
|
|
||||||
#endif /* INC_BREADBOARD_H_ */
|
|
||||||
@@ -1,95 +0,0 @@
|
|||||||
/*
|
|
||||||
* breadboard.c
|
|
||||||
*
|
|
||||||
* Created on: Sep 17, 2025
|
|
||||||
* Author: ja
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* #define RedLight_Pin GPIO_PIN_2
|
|
||||||
* #define RedLight_GPIO_Port GPIOE
|
|
||||||
*
|
|
||||||
* #define YellowLight_Pin GPIO_PIN_3
|
|
||||||
* #define YellowLight_GPIO_Port GPIOE
|
|
||||||
*
|
|
||||||
* #define GreenLight_Pin GPIO_PIN_4
|
|
||||||
* #define GreenLight_GPIO_Port GPIOE
|
|
||||||
*
|
|
||||||
* RedLight: PE2
|
|
||||||
* YellowLight: PE3
|
|
||||||
* GreenLight: PE4
|
|
||||||
* WalkLight: PE5
|
|
||||||
*
|
|
||||||
* Done: Traffic Light
|
|
||||||
* TODO: async? Walk Signal, Light Dimmer
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "main.h"
|
|
||||||
#include "breadboard.h"
|
|
||||||
|
|
||||||
#define R_Pin RedLight_Pin
|
|
||||||
#define Y_Pin YellowLight_Pin
|
|
||||||
#define G_Pin GreenLight_Pin
|
|
||||||
#define W_Pin WalkLight_Pin
|
|
||||||
|
|
||||||
#define R_Prt RedLight_GPIO_Port
|
|
||||||
#define Y_Prt YellowLight_GPIO_Port
|
|
||||||
#define G_Prt GreenLight_GPIO_Port
|
|
||||||
#define W_Prt WalkLight_GPIO_Port
|
|
||||||
|
|
||||||
uint32_t trafftick_last;
|
|
||||||
uint32_t walktick_last;
|
|
||||||
|
|
||||||
uint8_t trafflight_i = 0;
|
|
||||||
|
|
||||||
void
|
|
||||||
starttick(void)
|
|
||||||
{
|
|
||||||
trafftick_last = HAL_GetTick();
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
trafflight(int traffSPD)
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
HAL_GPIO_TogglePin(R_Prt, R_Pin);
|
|
||||||
HAL_Delay(traffSPD);
|
|
||||||
HAL_GPIO_TogglePin(R_Prt, R_Pin);
|
|
||||||
|
|
||||||
HAL_GPIO_TogglePin(Y_Prt, Y_Pin);
|
|
||||||
HAL_Delay(traffSPD);
|
|
||||||
HAL_GPIO_TogglePin(Y_Prt, Y_Pin);
|
|
||||||
|
|
||||||
HAL_GPIO_TogglePin(G_Prt, G_Pin);
|
|
||||||
HAL_Delay(traffSPD);
|
|
||||||
HAL_GPIO_TogglePin(G_Prt, G_Pin);
|
|
||||||
*/
|
|
||||||
|
|
||||||
uint32_t trafftick_curr = HAL_GetTick();
|
|
||||||
|
|
||||||
if ((trafftick_curr - trafftick_last) >= traffSPD) {
|
|
||||||
HAL_GPIO_WritePin(R_Prt, R_Pin, GPIO_PIN_RESET);
|
|
||||||
HAL_GPIO_WritePin(Y_Prt, Y_Pin, GPIO_PIN_RESET);
|
|
||||||
HAL_GPIO_WritePin(G_Prt, G_Pin, GPIO_PIN_RESET);
|
|
||||||
|
|
||||||
switch (trafflight_i) {
|
|
||||||
case 0:
|
|
||||||
HAL_GPIO_WritePin(R_Prt, R_Pin, GPIO_PIN_SET);
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
HAL_GPIO_WritePin(Y_Prt, Y_Pin, GPIO_PIN_SET);
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
HAL_GPIO_WritePin(G_Prt, G_Pin, GPIO_PIN_SET);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
trafflight_i = (trafflight_i + 1) % 3;
|
|
||||||
trafftick_last = trafftick_curr;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((trafftick_curr - walktick_last) >= walkSPD) {
|
|
||||||
HAL_GPIO_TogglePin(W_Prt, W_Pin);
|
|
||||||
walktick_last = trafftick_curr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
635E684B79701B039C64EA45C3F84D30=76D5CABA7E36F5DD0D38ED323FA426B4
|
|
||||||
eclipse.preferences.version=1
|
|
||||||
@@ -1,85 +0,0 @@
|
|||||||
/*
|
|
||||||
* breadboard.c
|
|
||||||
*
|
|
||||||
* Created on: Sep 17, 2025
|
|
||||||
* Author: ja
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* #define RedLight_Pin GPIO_PIN_2
|
|
||||||
* #define RedLight_GPIO_Port GPIOE
|
|
||||||
*
|
|
||||||
* #define YellowLight_Pin GPIO_PIN_3
|
|
||||||
* #define YellowLight_GPIO_Port GPIOE
|
|
||||||
*
|
|
||||||
* #define GreenLight_Pin GPIO_PIN_4
|
|
||||||
* #define GreenLight_GPIO_Port GPIOE
|
|
||||||
*
|
|
||||||
* RedLight: PE2
|
|
||||||
* YellowLight: PE3
|
|
||||||
* GreenLight: PE4
|
|
||||||
* WalkLight: PE5
|
|
||||||
*
|
|
||||||
* Done: Traffic Light
|
|
||||||
* TODO: async? Walk Signal, Light Dimmer
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "main.h"
|
|
||||||
#include "breadboard.h"
|
|
||||||
|
|
||||||
#define R_Pin RedLight_Pin
|
|
||||||
#define Y_Pin YellowLight_Pin
|
|
||||||
#define G_Pin GreenLight_Pin
|
|
||||||
#define W_Pin WalkLight_Pin
|
|
||||||
|
|
||||||
#define R_Prt RedLight_GPIO_Port
|
|
||||||
#define Y_Prt YellowLight_GPIO_Port
|
|
||||||
#define G_Prt GreenLight_GPIO_Port
|
|
||||||
#define W_Prt WalkLight_GPIO_Port
|
|
||||||
|
|
||||||
uint32_t trafftick_last;
|
|
||||||
|
|
||||||
uint8_t trafflight_i = 0;
|
|
||||||
|
|
||||||
void
|
|
||||||
starttick(void)
|
|
||||||
{
|
|
||||||
trafftick_last = HAL_GetTick();
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
trafflight(int traffSPD)
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
HAL_GPIO_TogglePin(R_Prt, R_Pin);
|
|
||||||
HAL_Delay(traffSPD);
|
|
||||||
HAL_GPIO_TogglePin(R_Prt, R_Pin);
|
|
||||||
|
|
||||||
HAL_GPIO_TogglePin(Y_Prt, Y_Pin);
|
|
||||||
HAL_Delay(traffSPD);
|
|
||||||
HAL_GPIO_TogglePin(Y_Prt, Y_Pin);
|
|
||||||
|
|
||||||
HAL_GPIO_TogglePin(G_Prt, G_Pin);
|
|
||||||
HAL_Delay(traffSPD);
|
|
||||||
HAL_GPIO_TogglePin(G_Prt, G_Pin);
|
|
||||||
*/
|
|
||||||
|
|
||||||
uint32_t trafftick_curr = HAL_GetTick();
|
|
||||||
|
|
||||||
if ((trafftick_curr - trafftick_last) >= traffSPD) {
|
|
||||||
HAL_GPIO_WritePin(
|
|
||||||
R_Prt, R_Pin |
|
|
||||||
Y_Prt, Y_Pin |
|
|
||||||
G_Prt, G_Pin,
|
|
||||||
GPIO_PIN_RESET
|
|
||||||
);
|
|
||||||
|
|
||||||
switch (trafflight_i) {
|
|
||||||
case 0:
|
|
||||||
HAL_GPIO_WritePin(R_Prt, R_Pin);
|
|
||||||
break;
|
|
||||||
case 0:
|
|
||||||
HAL_GPIO_WritePin(Y_Prt, Y_Pin);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,731 +0,0 @@
|
|||||||
/* USER CODE BEGIN Header */
|
|
||||||
/**
|
|
||||||
******************************************************************************
|
|
||||||
* @file : main.c
|
|
||||||
* @brief : Main program body
|
|
||||||
******************************************************************************
|
|
||||||
* @attention
|
|
||||||
*
|
|
||||||
* Copyright (c) 2025 STMicroelectronics.
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* This software is licensed under terms that can be found in the LICENSE file
|
|
||||||
* in the root directory of this software component.
|
|
||||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
|
||||||
*
|
|
||||||
******************************************************************************
|
|
||||||
*/
|
|
||||||
/* USER CODE END Header */
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
|
||||||
#include "main.h"
|
|
||||||
#include "cmsis_os.h"
|
|
||||||
#include "usb_host.h"
|
|
||||||
|
|
||||||
/* Private includes ----------------------------------------------------------*/
|
|
||||||
/* USER CODE BEGIN Includes */
|
|
||||||
#include "breadboard.h"
|
|
||||||
|
|
||||||
/* USER CODE END Includes */
|
|
||||||
|
|
||||||
/* Private typedef -----------------------------------------------------------*/
|
|
||||||
/* USER CODE BEGIN PTD */
|
|
||||||
|
|
||||||
/* USER CODE END PTD */
|
|
||||||
|
|
||||||
/* Private define ------------------------------------------------------------*/
|
|
||||||
/* USER CODE BEGIN PD */
|
|
||||||
|
|
||||||
/* USER CODE END PD */
|
|
||||||
|
|
||||||
/* Private macro -------------------------------------------------------------*/
|
|
||||||
/* USER CODE BEGIN PM */
|
|
||||||
|
|
||||||
/* USER CODE END PM */
|
|
||||||
|
|
||||||
/* Private variables ---------------------------------------------------------*/
|
|
||||||
CRC_HandleTypeDef hcrc;
|
|
||||||
|
|
||||||
DMA2D_HandleTypeDef hdma2d;
|
|
||||||
|
|
||||||
I2C_HandleTypeDef hi2c3;
|
|
||||||
|
|
||||||
LTDC_HandleTypeDef hltdc;
|
|
||||||
|
|
||||||
SPI_HandleTypeDef hspi5;
|
|
||||||
|
|
||||||
TIM_HandleTypeDef htim1;
|
|
||||||
|
|
||||||
UART_HandleTypeDef huart1;
|
|
||||||
|
|
||||||
SDRAM_HandleTypeDef hsdram1;
|
|
||||||
|
|
||||||
osThreadId defaultTaskHandle;
|
|
||||||
/* USER CODE BEGIN PV */
|
|
||||||
|
|
||||||
/* USER CODE END PV */
|
|
||||||
|
|
||||||
/* Private function prototypes -----------------------------------------------*/
|
|
||||||
void SystemClock_Config(void);
|
|
||||||
static void MX_GPIO_Init(void);
|
|
||||||
static void MX_CRC_Init(void);
|
|
||||||
static void MX_DMA2D_Init(void);
|
|
||||||
static void MX_FMC_Init(void);
|
|
||||||
static void MX_I2C3_Init(void);
|
|
||||||
static void MX_LTDC_Init(void);
|
|
||||||
static void MX_SPI5_Init(void);
|
|
||||||
static void MX_TIM1_Init(void);
|
|
||||||
static void MX_USART1_UART_Init(void);
|
|
||||||
void StartDefaultTask(void const * argument);
|
|
||||||
|
|
||||||
/* USER CODE BEGIN PFP */
|
|
||||||
|
|
||||||
/* USER CODE END PFP */
|
|
||||||
|
|
||||||
/* Private user code ---------------------------------------------------------*/
|
|
||||||
/* USER CODE BEGIN 0 */
|
|
||||||
|
|
||||||
/* USER CODE END 0 */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief The application entry point.
|
|
||||||
* @retval int
|
|
||||||
*/
|
|
||||||
int main(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* USER CODE BEGIN 1 */
|
|
||||||
|
|
||||||
/* USER CODE END 1 */
|
|
||||||
|
|
||||||
/* MCU Configuration--------------------------------------------------------*/
|
|
||||||
|
|
||||||
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
|
|
||||||
HAL_Init();
|
|
||||||
|
|
||||||
/* USER CODE BEGIN Init */
|
|
||||||
|
|
||||||
/* USER CODE END Init */
|
|
||||||
|
|
||||||
/* Configure the system clock */
|
|
||||||
SystemClock_Config();
|
|
||||||
|
|
||||||
/* USER CODE BEGIN SysInit */
|
|
||||||
|
|
||||||
/* USER CODE END SysInit */
|
|
||||||
|
|
||||||
/* Initialize all configured peripherals */
|
|
||||||
MX_GPIO_Init();
|
|
||||||
MX_CRC_Init();
|
|
||||||
MX_DMA2D_Init();
|
|
||||||
MX_FMC_Init();
|
|
||||||
MX_I2C3_Init();
|
|
||||||
MX_LTDC_Init();
|
|
||||||
MX_SPI5_Init();
|
|
||||||
MX_TIM1_Init();
|
|
||||||
MX_USART1_UART_Init();
|
|
||||||
/* USER CODE BEGIN 2 */
|
|
||||||
|
|
||||||
/* USER CODE END 2 */
|
|
||||||
|
|
||||||
/* USER CODE BEGIN RTOS_MUTEX */
|
|
||||||
/* add mutexes, ... */
|
|
||||||
/* USER CODE END RTOS_MUTEX */
|
|
||||||
|
|
||||||
/* USER CODE BEGIN RTOS_SEMAPHORES */
|
|
||||||
/* add semaphores, ... */
|
|
||||||
/* USER CODE END RTOS_SEMAPHORES */
|
|
||||||
|
|
||||||
/* USER CODE BEGIN RTOS_TIMERS */
|
|
||||||
/* start timers, add new ones, ... */
|
|
||||||
/* USER CODE END RTOS_TIMERS */
|
|
||||||
|
|
||||||
/* USER CODE BEGIN RTOS_QUEUES */
|
|
||||||
/* add queues, ... */
|
|
||||||
/* USER CODE END RTOS_QUEUES */
|
|
||||||
|
|
||||||
/* Create the thread(s) */
|
|
||||||
/* definition and creation of defaultTask */
|
|
||||||
//osThreadDef(defaultTask, StartDefaultTask, osPriorityNormal, 0, 4096);
|
|
||||||
//defaultTaskHandle = osThreadCreate(osThread(defaultTask), NULL);
|
|
||||||
|
|
||||||
/* USER CODE BEGIN RTOS_THREADS */
|
|
||||||
/* add threads, ... */
|
|
||||||
/* USER CODE END RTOS_THREADS */
|
|
||||||
|
|
||||||
/* Start scheduler */
|
|
||||||
//osKernelStart();
|
|
||||||
|
|
||||||
/* We should never get here as control is now taken by the scheduler */
|
|
||||||
|
|
||||||
/* Infinite loop */
|
|
||||||
/* USER CODE BEGIN WHILE */
|
|
||||||
while (1)
|
|
||||||
{
|
|
||||||
trafflight(333);
|
|
||||||
walksig(1000);
|
|
||||||
/* USER CODE END WHILE */
|
|
||||||
|
|
||||||
/* USER CODE BEGIN 3 */
|
|
||||||
}
|
|
||||||
/* USER CODE END 3 */
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief System Clock Configuration
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
void SystemClock_Config(void)
|
|
||||||
{
|
|
||||||
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
|
|
||||||
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
|
|
||||||
|
|
||||||
/** Configure the main internal regulator output voltage
|
|
||||||
*/
|
|
||||||
__HAL_RCC_PWR_CLK_ENABLE();
|
|
||||||
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE3);
|
|
||||||
|
|
||||||
/** Initializes the RCC Oscillators according to the specified parameters
|
|
||||||
* in the RCC_OscInitTypeDef structure.
|
|
||||||
*/
|
|
||||||
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
|
|
||||||
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
|
|
||||||
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
|
||||||
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
|
|
||||||
RCC_OscInitStruct.PLL.PLLM = 4;
|
|
||||||
RCC_OscInitStruct.PLL.PLLN = 72;
|
|
||||||
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
|
|
||||||
RCC_OscInitStruct.PLL.PLLQ = 3;
|
|
||||||
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Initializes the CPU, AHB and APB buses clocks
|
|
||||||
*/
|
|
||||||
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|
|
||||||
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
|
|
||||||
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
|
|
||||||
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
|
|
||||||
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
|
|
||||||
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
|
|
||||||
|
|
||||||
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief CRC Initialization Function
|
|
||||||
* @param None
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
static void MX_CRC_Init(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* USER CODE BEGIN CRC_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE END CRC_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE BEGIN CRC_Init 1 */
|
|
||||||
|
|
||||||
/* USER CODE END CRC_Init 1 */
|
|
||||||
hcrc.Instance = CRC;
|
|
||||||
if (HAL_CRC_Init(&hcrc) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
/* USER CODE BEGIN CRC_Init 2 */
|
|
||||||
|
|
||||||
/* USER CODE END CRC_Init 2 */
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief DMA2D Initialization Function
|
|
||||||
* @param None
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
static void MX_DMA2D_Init(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* USER CODE BEGIN DMA2D_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE END DMA2D_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE BEGIN DMA2D_Init 1 */
|
|
||||||
|
|
||||||
/* USER CODE END DMA2D_Init 1 */
|
|
||||||
hdma2d.Instance = DMA2D;
|
|
||||||
hdma2d.Init.Mode = DMA2D_M2M;
|
|
||||||
hdma2d.Init.ColorMode = DMA2D_OUTPUT_ARGB8888;
|
|
||||||
hdma2d.Init.OutputOffset = 0;
|
|
||||||
hdma2d.LayerCfg[1].InputOffset = 0;
|
|
||||||
hdma2d.LayerCfg[1].InputColorMode = DMA2D_INPUT_ARGB8888;
|
|
||||||
hdma2d.LayerCfg[1].AlphaMode = DMA2D_NO_MODIF_ALPHA;
|
|
||||||
hdma2d.LayerCfg[1].InputAlpha = 0;
|
|
||||||
if (HAL_DMA2D_Init(&hdma2d) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
if (HAL_DMA2D_ConfigLayer(&hdma2d, 1) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
/* USER CODE BEGIN DMA2D_Init 2 */
|
|
||||||
|
|
||||||
/* USER CODE END DMA2D_Init 2 */
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief I2C3 Initialization Function
|
|
||||||
* @param None
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
static void MX_I2C3_Init(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* USER CODE BEGIN I2C3_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE END I2C3_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE BEGIN I2C3_Init 1 */
|
|
||||||
|
|
||||||
/* USER CODE END I2C3_Init 1 */
|
|
||||||
hi2c3.Instance = I2C3;
|
|
||||||
hi2c3.Init.ClockSpeed = 100000;
|
|
||||||
hi2c3.Init.DutyCycle = I2C_DUTYCYCLE_2;
|
|
||||||
hi2c3.Init.OwnAddress1 = 0;
|
|
||||||
hi2c3.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
|
|
||||||
hi2c3.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
|
|
||||||
hi2c3.Init.OwnAddress2 = 0;
|
|
||||||
hi2c3.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
|
|
||||||
hi2c3.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
|
|
||||||
if (HAL_I2C_Init(&hi2c3) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Configure Analogue filter
|
|
||||||
*/
|
|
||||||
if (HAL_I2CEx_ConfigAnalogFilter(&hi2c3, I2C_ANALOGFILTER_ENABLE) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Configure Digital filter
|
|
||||||
*/
|
|
||||||
if (HAL_I2CEx_ConfigDigitalFilter(&hi2c3, 0) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
/* USER CODE BEGIN I2C3_Init 2 */
|
|
||||||
|
|
||||||
/* USER CODE END I2C3_Init 2 */
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief LTDC Initialization Function
|
|
||||||
* @param None
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
static void MX_LTDC_Init(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* USER CODE BEGIN LTDC_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE END LTDC_Init 0 */
|
|
||||||
|
|
||||||
LTDC_LayerCfgTypeDef pLayerCfg = {0};
|
|
||||||
|
|
||||||
/* USER CODE BEGIN LTDC_Init 1 */
|
|
||||||
|
|
||||||
/* USER CODE END LTDC_Init 1 */
|
|
||||||
hltdc.Instance = LTDC;
|
|
||||||
hltdc.Init.HSPolarity = LTDC_HSPOLARITY_AL;
|
|
||||||
hltdc.Init.VSPolarity = LTDC_VSPOLARITY_AL;
|
|
||||||
hltdc.Init.DEPolarity = LTDC_DEPOLARITY_AL;
|
|
||||||
hltdc.Init.PCPolarity = LTDC_PCPOLARITY_IPC;
|
|
||||||
hltdc.Init.HorizontalSync = 9;
|
|
||||||
hltdc.Init.VerticalSync = 1;
|
|
||||||
hltdc.Init.AccumulatedHBP = 29;
|
|
||||||
hltdc.Init.AccumulatedVBP = 3;
|
|
||||||
hltdc.Init.AccumulatedActiveW = 269;
|
|
||||||
hltdc.Init.AccumulatedActiveH = 323;
|
|
||||||
hltdc.Init.TotalWidth = 279;
|
|
||||||
hltdc.Init.TotalHeigh = 327;
|
|
||||||
hltdc.Init.Backcolor.Blue = 0;
|
|
||||||
hltdc.Init.Backcolor.Green = 0;
|
|
||||||
hltdc.Init.Backcolor.Red = 0;
|
|
||||||
if (HAL_LTDC_Init(&hltdc) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
pLayerCfg.WindowX0 = 0;
|
|
||||||
pLayerCfg.WindowX1 = 240;
|
|
||||||
pLayerCfg.WindowY0 = 0;
|
|
||||||
pLayerCfg.WindowY1 = 320;
|
|
||||||
pLayerCfg.PixelFormat = LTDC_PIXEL_FORMAT_RGB565;
|
|
||||||
pLayerCfg.Alpha = 255;
|
|
||||||
pLayerCfg.Alpha0 = 0;
|
|
||||||
pLayerCfg.BlendingFactor1 = LTDC_BLENDING_FACTOR1_PAxCA;
|
|
||||||
pLayerCfg.BlendingFactor2 = LTDC_BLENDING_FACTOR2_PAxCA;
|
|
||||||
pLayerCfg.FBStartAdress = 0xD0000000;
|
|
||||||
pLayerCfg.ImageWidth = 240;
|
|
||||||
pLayerCfg.ImageHeight = 320;
|
|
||||||
pLayerCfg.Backcolor.Blue = 0;
|
|
||||||
pLayerCfg.Backcolor.Green = 0;
|
|
||||||
pLayerCfg.Backcolor.Red = 0;
|
|
||||||
if (HAL_LTDC_ConfigLayer(&hltdc, &pLayerCfg, 0) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
/* USER CODE BEGIN LTDC_Init 2 */
|
|
||||||
|
|
||||||
/* USER CODE END LTDC_Init 2 */
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief SPI5 Initialization Function
|
|
||||||
* @param None
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
static void MX_SPI5_Init(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* USER CODE BEGIN SPI5_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE END SPI5_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE BEGIN SPI5_Init 1 */
|
|
||||||
|
|
||||||
/* USER CODE END SPI5_Init 1 */
|
|
||||||
/* SPI5 parameter configuration*/
|
|
||||||
hspi5.Instance = SPI5;
|
|
||||||
hspi5.Init.Mode = SPI_MODE_MASTER;
|
|
||||||
hspi5.Init.Direction = SPI_DIRECTION_2LINES;
|
|
||||||
hspi5.Init.DataSize = SPI_DATASIZE_8BIT;
|
|
||||||
hspi5.Init.CLKPolarity = SPI_POLARITY_LOW;
|
|
||||||
hspi5.Init.CLKPhase = SPI_PHASE_1EDGE;
|
|
||||||
hspi5.Init.NSS = SPI_NSS_SOFT;
|
|
||||||
hspi5.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_16;
|
|
||||||
hspi5.Init.FirstBit = SPI_FIRSTBIT_MSB;
|
|
||||||
hspi5.Init.TIMode = SPI_TIMODE_DISABLE;
|
|
||||||
hspi5.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
|
|
||||||
hspi5.Init.CRCPolynomial = 10;
|
|
||||||
if (HAL_SPI_Init(&hspi5) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
/* USER CODE BEGIN SPI5_Init 2 */
|
|
||||||
|
|
||||||
/* USER CODE END SPI5_Init 2 */
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief TIM1 Initialization Function
|
|
||||||
* @param None
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
static void MX_TIM1_Init(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* USER CODE BEGIN TIM1_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE END TIM1_Init 0 */
|
|
||||||
|
|
||||||
TIM_ClockConfigTypeDef sClockSourceConfig = {0};
|
|
||||||
TIM_MasterConfigTypeDef sMasterConfig = {0};
|
|
||||||
|
|
||||||
/* USER CODE BEGIN TIM1_Init 1 */
|
|
||||||
|
|
||||||
/* USER CODE END TIM1_Init 1 */
|
|
||||||
htim1.Instance = TIM1;
|
|
||||||
htim1.Init.Prescaler = 0;
|
|
||||||
htim1.Init.CounterMode = TIM_COUNTERMODE_UP;
|
|
||||||
htim1.Init.Period = 65535;
|
|
||||||
htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
|
||||||
htim1.Init.RepetitionCounter = 0;
|
|
||||||
htim1.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
|
|
||||||
if (HAL_TIM_Base_Init(&htim1) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
|
|
||||||
if (HAL_TIM_ConfigClockSource(&htim1, &sClockSourceConfig) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
|
|
||||||
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
|
|
||||||
if (HAL_TIMEx_MasterConfigSynchronization(&htim1, &sMasterConfig) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
/* USER CODE BEGIN TIM1_Init 2 */
|
|
||||||
|
|
||||||
/* USER CODE END TIM1_Init 2 */
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief USART1 Initialization Function
|
|
||||||
* @param None
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
static void MX_USART1_UART_Init(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* USER CODE BEGIN USART1_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE END USART1_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE BEGIN USART1_Init 1 */
|
|
||||||
|
|
||||||
/* USER CODE END USART1_Init 1 */
|
|
||||||
huart1.Instance = USART1;
|
|
||||||
huart1.Init.BaudRate = 115200;
|
|
||||||
huart1.Init.WordLength = UART_WORDLENGTH_8B;
|
|
||||||
huart1.Init.StopBits = UART_STOPBITS_1;
|
|
||||||
huart1.Init.Parity = UART_PARITY_NONE;
|
|
||||||
huart1.Init.Mode = UART_MODE_TX_RX;
|
|
||||||
huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
|
|
||||||
huart1.Init.OverSampling = UART_OVERSAMPLING_16;
|
|
||||||
if (HAL_UART_Init(&huart1) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
/* USER CODE BEGIN USART1_Init 2 */
|
|
||||||
|
|
||||||
/* USER CODE END USART1_Init 2 */
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/* FMC initialization function */
|
|
||||||
static void MX_FMC_Init(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* USER CODE BEGIN FMC_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE END FMC_Init 0 */
|
|
||||||
|
|
||||||
FMC_SDRAM_TimingTypeDef SdramTiming = {0};
|
|
||||||
|
|
||||||
/* USER CODE BEGIN FMC_Init 1 */
|
|
||||||
|
|
||||||
/* USER CODE END FMC_Init 1 */
|
|
||||||
|
|
||||||
/** Perform the SDRAM1 memory initialization sequence
|
|
||||||
*/
|
|
||||||
hsdram1.Instance = FMC_SDRAM_DEVICE;
|
|
||||||
/* hsdram1.Init */
|
|
||||||
hsdram1.Init.SDBank = FMC_SDRAM_BANK2;
|
|
||||||
hsdram1.Init.ColumnBitsNumber = FMC_SDRAM_COLUMN_BITS_NUM_8;
|
|
||||||
hsdram1.Init.RowBitsNumber = FMC_SDRAM_ROW_BITS_NUM_12;
|
|
||||||
hsdram1.Init.MemoryDataWidth = FMC_SDRAM_MEM_BUS_WIDTH_16;
|
|
||||||
hsdram1.Init.InternalBankNumber = FMC_SDRAM_INTERN_BANKS_NUM_4;
|
|
||||||
hsdram1.Init.CASLatency = FMC_SDRAM_CAS_LATENCY_3;
|
|
||||||
hsdram1.Init.WriteProtection = FMC_SDRAM_WRITE_PROTECTION_DISABLE;
|
|
||||||
hsdram1.Init.SDClockPeriod = FMC_SDRAM_CLOCK_PERIOD_2;
|
|
||||||
hsdram1.Init.ReadBurst = FMC_SDRAM_RBURST_DISABLE;
|
|
||||||
hsdram1.Init.ReadPipeDelay = FMC_SDRAM_RPIPE_DELAY_1;
|
|
||||||
/* SdramTiming */
|
|
||||||
SdramTiming.LoadToActiveDelay = 2;
|
|
||||||
SdramTiming.ExitSelfRefreshDelay = 7;
|
|
||||||
SdramTiming.SelfRefreshTime = 4;
|
|
||||||
SdramTiming.RowCycleDelay = 7;
|
|
||||||
SdramTiming.WriteRecoveryTime = 3;
|
|
||||||
SdramTiming.RPDelay = 2;
|
|
||||||
SdramTiming.RCDDelay = 2;
|
|
||||||
|
|
||||||
if (HAL_SDRAM_Init(&hsdram1, &SdramTiming) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler( );
|
|
||||||
}
|
|
||||||
|
|
||||||
/* USER CODE BEGIN FMC_Init 2 */
|
|
||||||
|
|
||||||
/* USER CODE END FMC_Init 2 */
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief GPIO Initialization Function
|
|
||||||
* @param None
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
static void MX_GPIO_Init(void)
|
|
||||||
{
|
|
||||||
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
|
||||||
/* USER CODE BEGIN MX_GPIO_Init_1 */
|
|
||||||
|
|
||||||
/* USER CODE END MX_GPIO_Init_1 */
|
|
||||||
|
|
||||||
/* GPIO Ports Clock Enable */
|
|
||||||
__HAL_RCC_GPIOE_CLK_ENABLE();
|
|
||||||
__HAL_RCC_GPIOC_CLK_ENABLE();
|
|
||||||
__HAL_RCC_GPIOF_CLK_ENABLE();
|
|
||||||
__HAL_RCC_GPIOH_CLK_ENABLE();
|
|
||||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
|
||||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
|
||||||
__HAL_RCC_GPIOG_CLK_ENABLE();
|
|
||||||
__HAL_RCC_GPIOD_CLK_ENABLE();
|
|
||||||
|
|
||||||
/*Configure GPIO pin Output Level */
|
|
||||||
HAL_GPIO_WritePin(GPIOE, RedLight_Pin|YellowLight_Pin|GreenLight_Pin|WalkLight_Pin, GPIO_PIN_RESET);
|
|
||||||
|
|
||||||
/*Configure GPIO pin Output Level */
|
|
||||||
HAL_GPIO_WritePin(GPIOC, NCS_MEMS_SPI_Pin|CSX_Pin|OTG_FS_PSO_Pin, GPIO_PIN_RESET);
|
|
||||||
|
|
||||||
/*Configure GPIO pin Output Level */
|
|
||||||
HAL_GPIO_WritePin(ACP_RST_GPIO_Port, ACP_RST_Pin, GPIO_PIN_RESET);
|
|
||||||
|
|
||||||
/*Configure GPIO pin Output Level */
|
|
||||||
HAL_GPIO_WritePin(GPIOD, RDX_Pin|WRX_DCX_Pin, GPIO_PIN_RESET);
|
|
||||||
|
|
||||||
/*Configure GPIO pin Output Level */
|
|
||||||
HAL_GPIO_WritePin(GPIOG, LD3_Pin|LD4_Pin, GPIO_PIN_RESET);
|
|
||||||
|
|
||||||
/*Configure GPIO pins : RedLight_Pin YellowLight_Pin GreenLight_Pin WalkLight_Pin */
|
|
||||||
GPIO_InitStruct.Pin = RedLight_Pin|YellowLight_Pin|GreenLight_Pin|WalkLight_Pin;
|
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
||||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
|
||||||
HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
|
|
||||||
|
|
||||||
/*Configure GPIO pins : NCS_MEMS_SPI_Pin CSX_Pin OTG_FS_PSO_Pin */
|
|
||||||
GPIO_InitStruct.Pin = NCS_MEMS_SPI_Pin|CSX_Pin|OTG_FS_PSO_Pin;
|
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
||||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
|
||||||
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
|
|
||||||
|
|
||||||
/*Configure GPIO pins : B1_Pin MEMS_INT1_Pin MEMS_INT2_Pin TP_INT1_Pin */
|
|
||||||
GPIO_InitStruct.Pin = B1_Pin|MEMS_INT1_Pin|MEMS_INT2_Pin|TP_INT1_Pin;
|
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_EVT_RISING;
|
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
||||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
|
||||||
|
|
||||||
/*Configure GPIO pin : ACP_RST_Pin */
|
|
||||||
GPIO_InitStruct.Pin = ACP_RST_Pin;
|
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
||||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
|
||||||
HAL_GPIO_Init(ACP_RST_GPIO_Port, &GPIO_InitStruct);
|
|
||||||
|
|
||||||
/*Configure GPIO pin : OTG_FS_OC_Pin */
|
|
||||||
GPIO_InitStruct.Pin = OTG_FS_OC_Pin;
|
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_EVT_RISING;
|
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
||||||
HAL_GPIO_Init(OTG_FS_OC_GPIO_Port, &GPIO_InitStruct);
|
|
||||||
|
|
||||||
/*Configure GPIO pin : BOOT1_Pin */
|
|
||||||
GPIO_InitStruct.Pin = BOOT1_Pin;
|
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
||||||
HAL_GPIO_Init(BOOT1_GPIO_Port, &GPIO_InitStruct);
|
|
||||||
|
|
||||||
/*Configure GPIO pin : TE_Pin */
|
|
||||||
GPIO_InitStruct.Pin = TE_Pin;
|
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
||||||
HAL_GPIO_Init(TE_GPIO_Port, &GPIO_InitStruct);
|
|
||||||
|
|
||||||
/*Configure GPIO pins : RDX_Pin WRX_DCX_Pin */
|
|
||||||
GPIO_InitStruct.Pin = RDX_Pin|WRX_DCX_Pin;
|
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
||||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
|
||||||
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
|
|
||||||
|
|
||||||
/*Configure GPIO pins : LD3_Pin LD4_Pin */
|
|
||||||
GPIO_InitStruct.Pin = LD3_Pin|LD4_Pin;
|
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
||||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
|
||||||
HAL_GPIO_Init(GPIOG, &GPIO_InitStruct);
|
|
||||||
|
|
||||||
/* USER CODE BEGIN MX_GPIO_Init_2 */
|
|
||||||
|
|
||||||
/* USER CODE END MX_GPIO_Init_2 */
|
|
||||||
}
|
|
||||||
|
|
||||||
/* USER CODE BEGIN 4 */
|
|
||||||
|
|
||||||
/* USER CODE END 4 */
|
|
||||||
|
|
||||||
/* USER CODE BEGIN Header_StartDefaultTask */
|
|
||||||
/**
|
|
||||||
* @brief Function implementing the defaultTask thread.
|
|
||||||
* @param argument: Not used
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
/* USER CODE END Header_StartDefaultTask */
|
|
||||||
void StartDefaultTask(void const * argument)
|
|
||||||
{
|
|
||||||
/* init code for USB_HOST */
|
|
||||||
MX_USB_HOST_Init();
|
|
||||||
/* USER CODE BEGIN 5 */
|
|
||||||
/* Infinite loop */
|
|
||||||
for(;;)
|
|
||||||
{
|
|
||||||
osDelay(1);
|
|
||||||
}
|
|
||||||
/* USER CODE END 5 */
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Period elapsed callback in non blocking mode
|
|
||||||
* @note This function is called when TIM6 interrupt took place, inside
|
|
||||||
* HAL_TIM_IRQHandler(). It makes a direct call to HAL_IncTick() to increment
|
|
||||||
* a global variable "uwTick" used as application time base.
|
|
||||||
* @param htim : TIM handle
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
|
|
||||||
{
|
|
||||||
/* USER CODE BEGIN Callback 0 */
|
|
||||||
|
|
||||||
/* USER CODE END Callback 0 */
|
|
||||||
if (htim->Instance == TIM6)
|
|
||||||
{
|
|
||||||
HAL_IncTick();
|
|
||||||
}
|
|
||||||
/* USER CODE BEGIN Callback 1 */
|
|
||||||
|
|
||||||
/* USER CODE END Callback 1 */
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief This function is executed in case of error occurrence.
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
void Error_Handler(void)
|
|
||||||
{
|
|
||||||
/* USER CODE BEGIN Error_Handler_Debug */
|
|
||||||
/* User can add his own implementation to report the HAL error return state */
|
|
||||||
__disable_irq();
|
|
||||||
while (1)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
/* USER CODE END Error_Handler_Debug */
|
|
||||||
}
|
|
||||||
#ifdef USE_FULL_ASSERT
|
|
||||||
/**
|
|
||||||
* @brief Reports the name of the source file and the source line number
|
|
||||||
* where the assert_param error has occurred.
|
|
||||||
* @param file: pointer to the source file name
|
|
||||||
* @param line: assert_param error line source number
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
void assert_failed(uint8_t *file, uint32_t line)
|
|
||||||
{
|
|
||||||
/* USER CODE BEGIN 6 */
|
|
||||||
/* User can add his own implementation to report the file name and line number,
|
|
||||||
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
|
|
||||||
/* USER CODE END 6 */
|
|
||||||
}
|
|
||||||
#endif /* USE_FULL_ASSERT */
|
|
||||||
@@ -0,0 +1,536 @@
|
|||||||
|
/* USER CODE BEGIN Header */
|
||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
* @file : main.c
|
||||||
|
* @brief : Main program body
|
||||||
|
******************************************************************************
|
||||||
|
* @attention
|
||||||
|
*
|
||||||
|
* Copyright (c) 2025 STMicroelectronics.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This software is licensed under terms that can be found in the LICENSE file
|
||||||
|
* in the root directory of this software component.
|
||||||
|
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||||
|
*
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
/* USER CODE END Header */
|
||||||
|
/* Includes ------------------------------------------------------------------*/
|
||||||
|
#include "main.h"
|
||||||
|
#include "cmsis_os.h"
|
||||||
|
|
||||||
|
/* Private includes ----------------------------------------------------------*/
|
||||||
|
/* USER CODE BEGIN Includes */
|
||||||
|
#include "breadboard.h"
|
||||||
|
#include <stdbool.h>
|
||||||
|
/* USER CODE END Includes */
|
||||||
|
|
||||||
|
/* Private typedef -----------------------------------------------------------*/
|
||||||
|
/* USER CODE BEGIN PTD */
|
||||||
|
|
||||||
|
/* USER CODE END PTD */
|
||||||
|
|
||||||
|
/* Private define ------------------------------------------------------------*/
|
||||||
|
/* USER CODE BEGIN PD */
|
||||||
|
|
||||||
|
/* USER CODE END PD */
|
||||||
|
|
||||||
|
/* Private macro -------------------------------------------------------------*/
|
||||||
|
/* USER CODE BEGIN PM */
|
||||||
|
|
||||||
|
/* USER CODE END PM */
|
||||||
|
|
||||||
|
/* Private variables ---------------------------------------------------------*/
|
||||||
|
CRC_HandleTypeDef hcrc;
|
||||||
|
|
||||||
|
DMA2D_HandleTypeDef hdma2d;
|
||||||
|
|
||||||
|
TIM_HandleTypeDef htim1;
|
||||||
|
|
||||||
|
osThreadId defaultTaskHandle;
|
||||||
|
/* USER CODE BEGIN PV */
|
||||||
|
|
||||||
|
/* USER CODE END PV */
|
||||||
|
|
||||||
|
/* Private function prototypes -----------------------------------------------*/
|
||||||
|
void SystemClock_Config(void);
|
||||||
|
static void MX_GPIO_Init(void);
|
||||||
|
static void MX_CRC_Init(void);
|
||||||
|
static void MX_DMA2D_Init(void);
|
||||||
|
static void MX_TIM1_Init(void);
|
||||||
|
void StartDefaultTask(void const * argument);
|
||||||
|
|
||||||
|
void SetTrafficLights(TrafficSate s);
|
||||||
|
|
||||||
|
/* USER CODE BEGIN PFP */
|
||||||
|
|
||||||
|
/* USER CODE END PFP */
|
||||||
|
|
||||||
|
/* Private user code ---------------------------------------------------------*/
|
||||||
|
|
||||||
|
/* USER CODE BEGIN 0 */
|
||||||
|
|
||||||
|
enum class TrafficState {
|
||||||
|
GREEN,
|
||||||
|
YELLOW,
|
||||||
|
RED
|
||||||
|
};
|
||||||
|
|
||||||
|
TrafficState currentState = TrafficState::GREEN;
|
||||||
|
uint32_t stateStartTime = 0; // HAL_GetTick() at the start of this state
|
||||||
|
bool buttonPressed = false;
|
||||||
|
bool pedestrianNextCycle = false;
|
||||||
|
|
||||||
|
const uint32_t DURATION_GREEN = 5000;
|
||||||
|
const uint32_t DURATION_YELLOW = 3000;
|
||||||
|
const uint32_t DURATION_RED = 5000;
|
||||||
|
const uint32_t DURATION_RED_PED = 7000;
|
||||||
|
|
||||||
|
/* USER CODE END 0 */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief The application entry point.
|
||||||
|
* @retval int
|
||||||
|
*/
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* USER CODE BEGIN 1 */
|
||||||
|
|
||||||
|
/* USER CODE END 1 */
|
||||||
|
|
||||||
|
/* MCU Configuration--------------------------------------------------------*/
|
||||||
|
|
||||||
|
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
|
||||||
|
HAL_Init();
|
||||||
|
|
||||||
|
/* USER CODE BEGIN Init */
|
||||||
|
|
||||||
|
/* USER CODE END Init */
|
||||||
|
|
||||||
|
/* Configure the system clock */
|
||||||
|
SystemClock_Config();
|
||||||
|
|
||||||
|
/* USER CODE BEGIN SysInit */
|
||||||
|
|
||||||
|
stateStartTime = HAL_GetTick();
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
|
||||||
|
/* USER CODE END SysInit */
|
||||||
|
|
||||||
|
/* Initialize all configured peripherals */
|
||||||
|
MX_GPIO_Init();
|
||||||
|
MX_CRC_Init();
|
||||||
|
MX_DMA2D_Init();
|
||||||
|
MX_TIM1_Init();
|
||||||
|
/* USER CODE BEGIN 2 */
|
||||||
|
|
||||||
|
/* USER CODE END 2 */
|
||||||
|
|
||||||
|
/* USER CODE BEGIN RTOS_MUTEX */
|
||||||
|
/* add mutexes, ... */
|
||||||
|
/* USER CODE END RTOS_MUTEX */
|
||||||
|
|
||||||
|
/* USER CODE BEGIN RTOS_SEMAPHORES */
|
||||||
|
/* add semaphores, ... */
|
||||||
|
/* USER CODE END RTOS_SEMAPHORES */
|
||||||
|
|
||||||
|
/* USER CODE BEGIN RTOS_TIMERS */
|
||||||
|
/* start timers, add new ones, ... */
|
||||||
|
/* USER CODE END RTOS_TIMERS */
|
||||||
|
|
||||||
|
/* USER CODE BEGIN RTOS_QUEUES */
|
||||||
|
/* add queues, ... */
|
||||||
|
/* USER CODE END RTOS_QUEUES */
|
||||||
|
|
||||||
|
/* Create the thread(s) */
|
||||||
|
/* definition and creation of defaultTask */
|
||||||
|
//osThreadDef(defaultTask, StartDefaultTask, osPriorityNormal, 0, 4096);
|
||||||
|
//defaultTaskHandle = osThreadCreate(osThread(defaultTask), NULL);
|
||||||
|
|
||||||
|
/* USER CODE BEGIN RTOS_THREADS */
|
||||||
|
/* add threads, ... */
|
||||||
|
/* USER CODE END RTOS_THREADS */
|
||||||
|
|
||||||
|
/* Start scheduler */
|
||||||
|
osKernelStart();
|
||||||
|
|
||||||
|
/* We should never get here as control is now taken by the scheduler */
|
||||||
|
|
||||||
|
/* Infinite loop */
|
||||||
|
/* USER CODE BEGIN WHILE */
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
uint32_t now = HAL_GetTick();
|
||||||
|
uint32_t elapsed = now - stateStartTime;
|
||||||
|
|
||||||
|
/*
|
||||||
|
switch(currentState)
|
||||||
|
{
|
||||||
|
case TrafficState::GREEN:
|
||||||
|
if (elapsed >= DURATION_GREEN) {
|
||||||
|
currentState = TrafficState::YELLOW;
|
||||||
|
stateStartTime = now;
|
||||||
|
buttonPressed = false; // reset the button-flag for the new cycle
|
||||||
|
} else if (buttonPressed) {
|
||||||
|
//idk
|
||||||
|
buttonPressed = true;
|
||||||
|
currentState = TrafficState::YELLOW;
|
||||||
|
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case TrafficState::YELLOW:
|
||||||
|
break;
|
||||||
|
case TrafficState::RED:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
switch(currentState)
|
||||||
|
{
|
||||||
|
case TrafficState::GREEN:
|
||||||
|
if (butonPressedThisCycle)
|
||||||
|
{
|
||||||
|
currentState = TrafficState::YELLOW;
|
||||||
|
stateStartTime = now;
|
||||||
|
buttonPressedThisCycle = false;
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
} else if (elapsed >= DURATION_GREEN)
|
||||||
|
{
|
||||||
|
buttonPressedThisCycle = true;
|
||||||
|
currentState = TrafficState::YELLOW;
|
||||||
|
stateStartTime = now;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case TrafficState::YELLOW:
|
||||||
|
if (elapsed >= DURATION_YELLOW)
|
||||||
|
{
|
||||||
|
currentState = TrafficState::RED;
|
||||||
|
stateStartTime = now;
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
// if ped button was pressed during GREEN or YELLOW,
|
||||||
|
// we need to enable WHITE ...
|
||||||
|
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case TrafficState::RED:
|
||||||
|
if (pedestrianNextCycle)
|
||||||
|
{
|
||||||
|
HAL_GPIO_WritePin(White_GPIO_Port, White_Pin, GPIO_PIN_SET);
|
||||||
|
if (elapsed >= DURATION_RED_PED)
|
||||||
|
{
|
||||||
|
HAL_GPIO_WritePin(White_GPIO_Port, White_Pin, GPIO_PIN_RESET);
|
||||||
|
pedestrianNextCycle = false;
|
||||||
|
currentState = TrafficState::GREEN;
|
||||||
|
stateStartTime = now;
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
HAL_GPIO_WritePin(White_GPIO_Port, White_Pin, GPIO_Pin_RESET);
|
||||||
|
if (elapased >= DURATION_RED_PED)
|
||||||
|
{
|
||||||
|
currentStateTime = now;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/* USER CODE END WHILE */
|
||||||
|
|
||||||
|
/* USER CODE BEGIN 3 */
|
||||||
|
}
|
||||||
|
/* USER CODE END 3 */
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief System Clock Configuration
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void SystemClock_Config(void)
|
||||||
|
{
|
||||||
|
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
|
||||||
|
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
|
||||||
|
|
||||||
|
/** Configure the main internal regulator output voltage
|
||||||
|
*/
|
||||||
|
__HAL_RCC_PWR_CLK_ENABLE();
|
||||||
|
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE3);
|
||||||
|
|
||||||
|
/** Initializes the RCC Oscillators according to the specified parameters
|
||||||
|
* in the RCC_OscInitTypeDef structure.
|
||||||
|
*/
|
||||||
|
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
|
||||||
|
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
|
||||||
|
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
|
||||||
|
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
||||||
|
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
|
||||||
|
RCC_OscInitStruct.PLL.PLLM = 8;
|
||||||
|
RCC_OscInitStruct.PLL.PLLN = 72;
|
||||||
|
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
|
||||||
|
RCC_OscInitStruct.PLL.PLLQ = 3;
|
||||||
|
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Initializes the CPU, AHB and APB buses clocks
|
||||||
|
*/
|
||||||
|
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|
||||||
|
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
|
||||||
|
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
|
||||||
|
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
|
||||||
|
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
|
||||||
|
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
|
||||||
|
|
||||||
|
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief CRC Initialization Function
|
||||||
|
* @param None
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
static void MX_CRC_Init(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* USER CODE BEGIN CRC_Init 0 */
|
||||||
|
|
||||||
|
/* USER CODE END CRC_Init 0 */
|
||||||
|
|
||||||
|
/* USER CODE BEGIN CRC_Init 1 */
|
||||||
|
|
||||||
|
/* USER CODE END CRC_Init 1 */
|
||||||
|
hcrc.Instance = CRC;
|
||||||
|
if (HAL_CRC_Init(&hcrc) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
/* USER CODE BEGIN CRC_Init 2 */
|
||||||
|
|
||||||
|
/* USER CODE END CRC_Init 2 */
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief DMA2D Initialization Function
|
||||||
|
* @param None
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
static void MX_DMA2D_Init(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* USER CODE BEGIN DMA2D_Init 0 */
|
||||||
|
|
||||||
|
/* USER CODE END DMA2D_Init 0 */
|
||||||
|
|
||||||
|
/* USER CODE BEGIN DMA2D_Init 1 */
|
||||||
|
|
||||||
|
/* USER CODE END DMA2D_Init 1 */
|
||||||
|
hdma2d.Instance = DMA2D;
|
||||||
|
hdma2d.Init.Mode = DMA2D_M2M;
|
||||||
|
hdma2d.Init.ColorMode = DMA2D_OUTPUT_ARGB8888;
|
||||||
|
hdma2d.Init.OutputOffset = 0;
|
||||||
|
hdma2d.LayerCfg[1].InputOffset = 0;
|
||||||
|
hdma2d.LayerCfg[1].InputColorMode = DMA2D_INPUT_ARGB8888;
|
||||||
|
hdma2d.LayerCfg[1].AlphaMode = DMA2D_NO_MODIF_ALPHA;
|
||||||
|
hdma2d.LayerCfg[1].InputAlpha = 0;
|
||||||
|
if (HAL_DMA2D_Init(&hdma2d) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
if (HAL_DMA2D_ConfigLayer(&hdma2d, 1) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
/* USER CODE BEGIN DMA2D_Init 2 */
|
||||||
|
|
||||||
|
/* USER CODE END DMA2D_Init 2 */
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief TIM1 Initialization Function
|
||||||
|
* @param None
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
static void MX_TIM1_Init(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* USER CODE BEGIN TIM1_Init 0 */
|
||||||
|
|
||||||
|
/* USER CODE END TIM1_Init 0 */
|
||||||
|
|
||||||
|
TIM_ClockConfigTypeDef sClockSourceConfig = {0};
|
||||||
|
TIM_MasterConfigTypeDef sMasterConfig = {0};
|
||||||
|
|
||||||
|
/* USER CODE BEGIN TIM1_Init 1 */
|
||||||
|
|
||||||
|
/* USER CODE END TIM1_Init 1 */
|
||||||
|
htim1.Instance = TIM1;
|
||||||
|
htim1.Init.Prescaler = 0;
|
||||||
|
htim1.Init.CounterMode = TIM_COUNTERMODE_UP;
|
||||||
|
htim1.Init.Period = 65535;
|
||||||
|
htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
||||||
|
htim1.Init.RepetitionCounter = 0;
|
||||||
|
htim1.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
|
||||||
|
if (HAL_TIM_Base_Init(&htim1) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
|
||||||
|
if (HAL_TIM_ConfigClockSource(&htim1, &sClockSourceConfig) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
|
||||||
|
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
|
||||||
|
if (HAL_TIMEx_MasterConfigSynchronization(&htim1, &sMasterConfig) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
/* USER CODE BEGIN TIM1_Init 2 */
|
||||||
|
|
||||||
|
/* USER CODE END TIM1_Init 2 */
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief GPIO Initialization Function
|
||||||
|
* @param None
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
static void MX_GPIO_Init(void)
|
||||||
|
{
|
||||||
|
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||||
|
/* USER CODE BEGIN MX_GPIO_Init_1 */
|
||||||
|
|
||||||
|
/* USER CODE END MX_GPIO_Init_1 */
|
||||||
|
|
||||||
|
/* GPIO Ports Clock Enable */
|
||||||
|
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||||
|
__HAL_RCC_GPIOD_CLK_ENABLE();
|
||||||
|
|
||||||
|
/*Configure GPIO pin Output Level */
|
||||||
|
HAL_GPIO_WritePin(GPIOD, White_Pin|Red_Pin|Yellow_Pin|Green_Pin, GPIO_PIN_RESET);
|
||||||
|
|
||||||
|
/*Configure GPIO pin : PedButton_Pin */
|
||||||
|
GPIO_InitStruct.Pin = PedButton_Pin;
|
||||||
|
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
|
||||||
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
|
HAL_GPIO_Init(PedButton_GPIO_Port, &GPIO_InitStruct);
|
||||||
|
|
||||||
|
/*Configure GPIO pins : White_Pin Red_Pin Yellow_Pin Green_Pin */
|
||||||
|
GPIO_InitStruct.Pin = White_Pin|Red_Pin|Yellow_Pin|Green_Pin;
|
||||||
|
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||||
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||||
|
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
|
||||||
|
|
||||||
|
/* EXTI interrupt init*/
|
||||||
|
HAL_NVIC_SetPriority(EXTI15_10_IRQn, 15, 0);
|
||||||
|
HAL_NVIC_EnableIRQ(EXTI15_10_IRQn);
|
||||||
|
|
||||||
|
/* USER CODE BEGIN MX_GPIO_Init_2 */
|
||||||
|
|
||||||
|
/* USER CODE END MX_GPIO_Init_2 */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* USER CODE BEGIN 4 */
|
||||||
|
|
||||||
|
void HAL_GPIO_EXTI_CallBack(uint16_t GPIO_Pin)
|
||||||
|
{
|
||||||
|
static uint32_t lastInterruptTime = 0;
|
||||||
|
uint32_t now = HAL_GetTick();
|
||||||
|
if (now - lastInterruptTime < 100) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
lastInterruptTime = now;
|
||||||
|
|
||||||
|
bool buttonPressedThisCycle = false; // temporary, get rid of this
|
||||||
|
|
||||||
|
if (buttonPressed) { // buttonPressedHere?
|
||||||
|
buttonPressedThisCycle = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* USER CODE END 4 */
|
||||||
|
|
||||||
|
/* USER CODE BEGIN Header_StartDefaultTask */
|
||||||
|
/**
|
||||||
|
* @brief Function implementing the defaultTask thread.
|
||||||
|
* @param argument: Not used
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
/* USER CODE END Header_StartDefaultTask */
|
||||||
|
void StartDefaultTask(void const * argument)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN 5 */
|
||||||
|
/* Infinite loop */
|
||||||
|
for(;;)
|
||||||
|
{
|
||||||
|
osDelay(1);
|
||||||
|
}
|
||||||
|
/* USER CODE END 5 */
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Period elapsed callback in non blocking mode
|
||||||
|
* @note This function is called when TIM6 interrupt took place, inside
|
||||||
|
* HAL_TIM_IRQHandler(). It makes a direct call to HAL_IncTick() to increment
|
||||||
|
* a global variable "uwTick" used as application time base.
|
||||||
|
* @param htim : TIM handle
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN Callback 0 */
|
||||||
|
|
||||||
|
/* USER CODE END Callback 0 */
|
||||||
|
if (htim->Instance == TIM6)
|
||||||
|
{
|
||||||
|
HAL_IncTick();
|
||||||
|
}
|
||||||
|
/* USER CODE BEGIN Callback 1 */
|
||||||
|
|
||||||
|
/* USER CODE END Callback 1 */
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function is executed in case of error occurrence.
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void Error_Handler(void)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN Error_Handler_Debug */
|
||||||
|
/* User can add his own implementation to report the HAL error return state */
|
||||||
|
__disable_irq();
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
/* USER CODE END Error_Handler_Debug */
|
||||||
|
}
|
||||||
|
#ifdef USE_FULL_ASSERT
|
||||||
|
/**
|
||||||
|
* @brief Reports the name of the source file and the source line number
|
||||||
|
* where the assert_param error has occurred.
|
||||||
|
* @param file: pointer to the source file name
|
||||||
|
* @param line: assert_param error line source number
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void assert_failed(uint8_t *file, uint32_t line)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN 6 */
|
||||||
|
/* User can add his own implementation to report the file name and line number,
|
||||||
|
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
|
||||||
|
/* USER CODE END 6 */
|
||||||
|
}
|
||||||
|
#endif /* USE_FULL_ASSERT */
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
/*
|
|
||||||
* breadboard.cpp
|
|
||||||
*
|
|
||||||
* Created on: Sep 22, 2025
|
|
||||||
* Author: ja
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "breadboad.hpp"
|
|
||||||
|
|
||||||
@@ -0,0 +1,313 @@
|
|||||||
|
/* USER CODE BEGIN Header */
|
||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
* @file : main.c
|
||||||
|
* @brief : Main program body
|
||||||
|
******************************************************************************
|
||||||
|
* @attention
|
||||||
|
*
|
||||||
|
* Copyright (c) 2025 STMicroelectronics.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This software is licensed under terms that can be found in the LICENSE file
|
||||||
|
* in the root directory of this software component.
|
||||||
|
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||||
|
*
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
// Feeling sneaky.
|
||||||
|
extern "C" {
|
||||||
|
/* USER CODE END Header */
|
||||||
|
/* Includes ------------------------------------------------------------------*/
|
||||||
|
#include "main.h"
|
||||||
|
|
||||||
|
/* Private function prototypes -----------------------------------------------*/
|
||||||
|
void SystemClock_Config(void);
|
||||||
|
static void MX_GPIO_Init(void);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Private user code ---------------------------------------------------------*/
|
||||||
|
/* USER CODE BEGIN 0 */
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
enum class TrafficState { GREEN, YELLOW, RED };
|
||||||
|
void SetTrafficLights(TrafficState s);
|
||||||
|
|
||||||
|
TrafficState currentState = TrafficState::GREEN;
|
||||||
|
uint32_t stateStartTime = 0; //HAL_GetTick() at the start of this state
|
||||||
|
bool buttonPressedThisCycle = false;
|
||||||
|
bool pedestrianNextCycle = false;
|
||||||
|
bool pedestrianThisCycle = false;
|
||||||
|
|
||||||
|
const uint32_t DURATION_GREEN = 5000;
|
||||||
|
const uint32_t DURATION_YELLOW = 3000;
|
||||||
|
const uint32_t DURATION_RED_NOPED = 5000;
|
||||||
|
const uint32_t DURATION_RED_PED = 7000;
|
||||||
|
|
||||||
|
/* USER CODE END 0 */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief The application entry point.
|
||||||
|
* @retval int
|
||||||
|
*/
|
||||||
|
|
||||||
|
void SetTrafficLights(TrafficState s)
|
||||||
|
{
|
||||||
|
// reset all
|
||||||
|
HAL_GPIO_WritePin(GPIOD, Green_Pin, GPIO_PIN_RESET);
|
||||||
|
HAL_GPIO_WritePin(GPIOD, Yellow_Pin, GPIO_PIN_RESET);
|
||||||
|
HAL_GPIO_WritePin(GPIOD, Red_Pin, GPIO_PIN_SET);
|
||||||
|
|
||||||
|
switch (s)
|
||||||
|
{
|
||||||
|
case TrafficState::GREEN :
|
||||||
|
HAL_GPIO_WritePin(GPIOD, Green_Pin, GPIO_PIN_SET);
|
||||||
|
break;
|
||||||
|
case TrafficState::YELLOW :
|
||||||
|
HAL_GPIO_WritePin(GPIOD, Yellow_Pin, GPIO_PIN_SET);
|
||||||
|
break;
|
||||||
|
case TrafficState::RED:
|
||||||
|
HAL_GPIO_WritePin(GPIOD, Red_Pin, GPIO_PIN_SET);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
HAL_Init();
|
||||||
|
|
||||||
|
/* USER CODE BEGIN Init */
|
||||||
|
|
||||||
|
/* USER CODE END Init */
|
||||||
|
|
||||||
|
/* Configure the system clock */
|
||||||
|
SystemClock_Config();
|
||||||
|
MX_GPIO_Init();
|
||||||
|
|
||||||
|
stateStartTime = HAL_GetTick();
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
/* USER CODE END WHILE */
|
||||||
|
uint32_t now = HAL_GetTick();
|
||||||
|
uint32_t elapsed = now - stateStartTime;
|
||||||
|
|
||||||
|
switch(currentState)
|
||||||
|
{
|
||||||
|
case TrafficState::GREEN:
|
||||||
|
if (buttonPressedThisCycle)
|
||||||
|
pedestrianThisCycle = true;
|
||||||
|
|
||||||
|
/*
|
||||||
|
if (buttonPressedThisCycle)
|
||||||
|
{
|
||||||
|
currentState = TrafficState::YELLOW;
|
||||||
|
stateStartTime = now;
|
||||||
|
buttonPressedThisCycle = false;
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pedestrianNextCycle = false;
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
else if (elapsed >= DURATION_GREEN)
|
||||||
|
{
|
||||||
|
currentState = TrafficState::YELLOW;
|
||||||
|
stateStartTime = now;
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case TrafficState::YELLOW:
|
||||||
|
if (buttonPressedThisCycle || pedestrianNextCycle)
|
||||||
|
pedestrianThisCycle = true;
|
||||||
|
|
||||||
|
if (elapsed >= DURATION_YELLOW)
|
||||||
|
{
|
||||||
|
currentState = TrafficState::RED;
|
||||||
|
stateStartTime = now;
|
||||||
|
buttonPressedThisCycle = false; //TODO add pressed pedestrian button in yellow
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
// If Ped Button was pressed during GREEN or YELLOW, we need to enable WHITE this cycle
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case TrafficState::RED:
|
||||||
|
if (pedestrianNextCycle)
|
||||||
|
{
|
||||||
|
HAL_GPIO_WritePin(GPIOD,White_Pin,GPIO_PIN_SET); // turn on Pedestrian LED
|
||||||
|
if (elapsed >= DURATION_RED_PED)
|
||||||
|
{
|
||||||
|
HAL_GPIO_WritePin(GPIOD,White_Pin,GPIO_PIN_RESET);
|
||||||
|
pedestrianNextCycle = false;
|
||||||
|
currentState = TrafficState::GREEN;
|
||||||
|
stateStartTime = now;
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
HAL_GPIO_WritePin(GPIOD,White_Pin,GPIO_PIN_RESET);
|
||||||
|
if(elapsed >= DURATION_RED_PED)
|
||||||
|
{
|
||||||
|
currentState = TrafficState::GREEN;
|
||||||
|
stateStartTime = now;
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/* USER CODE BEGIN 3 */
|
||||||
|
}
|
||||||
|
/* USER CODE END 3 */
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief System Clock Configuration
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void SystemClock_Config(void)
|
||||||
|
{
|
||||||
|
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
|
||||||
|
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
|
||||||
|
|
||||||
|
/** Configure the main internal regulator output voltage
|
||||||
|
*/
|
||||||
|
__HAL_RCC_PWR_CLK_ENABLE();
|
||||||
|
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE3);
|
||||||
|
|
||||||
|
/** Initializes the RCC Oscillators according to the specified parameters
|
||||||
|
* in the RCC_OscInitTypeDef structure.
|
||||||
|
*/
|
||||||
|
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
|
||||||
|
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
|
||||||
|
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
|
||||||
|
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
||||||
|
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
|
||||||
|
RCC_OscInitStruct.PLL.PLLM = 8;
|
||||||
|
RCC_OscInitStruct.PLL.PLLN = 50;
|
||||||
|
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4;
|
||||||
|
RCC_OscInitStruct.PLL.PLLQ = 7;
|
||||||
|
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Initializes the CPU, AHB and APB buses clocks
|
||||||
|
*/
|
||||||
|
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|
||||||
|
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
|
||||||
|
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
|
||||||
|
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
|
||||||
|
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV8;
|
||||||
|
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV4;
|
||||||
|
|
||||||
|
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief GPIO Initialization Function
|
||||||
|
* @param None
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
static void MX_GPIO_Init(void)
|
||||||
|
{
|
||||||
|
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||||
|
/* USER CODE BEGIN MX_GPIO_Init_1 */
|
||||||
|
|
||||||
|
/* USER CODE END MX_GPIO_Init_1 */
|
||||||
|
|
||||||
|
/* GPIO Ports Clock Enable */
|
||||||
|
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||||
|
__HAL_RCC_GPIOD_CLK_ENABLE();
|
||||||
|
|
||||||
|
/*Configure GPIO pin Output Level */
|
||||||
|
HAL_GPIO_WritePin(GPIOD, White_Pin|Red_Pin|Yellow_Pin|Green_Pin, GPIO_PIN_RESET);
|
||||||
|
|
||||||
|
/*Configure GPIO pin : PedButton_Pin */
|
||||||
|
GPIO_InitStruct.Pin = PedButton_Pin;
|
||||||
|
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
|
||||||
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
|
HAL_GPIO_Init(PedButton_GPIO_Port, &GPIO_InitStruct);
|
||||||
|
|
||||||
|
/*Configure GPIO pins : White_Pin Red_Pin Yellow_Pin Green_Pin */
|
||||||
|
GPIO_InitStruct.Pin = White_Pin|Red_Pin|Yellow_Pin|Green_Pin;
|
||||||
|
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||||
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||||
|
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
|
||||||
|
|
||||||
|
/* EXTI interrupt init*/
|
||||||
|
HAL_NVIC_SetPriority(EXTI15_10_IRQn, 15, 0);
|
||||||
|
HAL_NVIC_EnableIRQ(EXTI15_10_IRQn);
|
||||||
|
|
||||||
|
/* USER CODE BEGIN MX_GPIO_Init_2 */
|
||||||
|
|
||||||
|
/* USER CODE END MX_GPIO_Init_2 */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* USER CODE BEGIN 4 */
|
||||||
|
void HAL_GPIO_EXTI_CallBack()
|
||||||
|
{
|
||||||
|
static uint32_t lastInterruptTime = 0;
|
||||||
|
uint32_t now = HAL_GetTick();
|
||||||
|
if(now - lastInterruptTime < 100)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
lastInterruptTime = now;
|
||||||
|
|
||||||
|
if (PedButton_Pin)
|
||||||
|
{
|
||||||
|
buttonPressedThisCycle = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void HAL_GPIO_EXTI_IRQHandler()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/* USER CODE END 4 */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function is executed in case of error occurrence.
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void Error_Handler(void)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN Error_Handler_Debug */
|
||||||
|
/* User can add his own implementation to report the HAL error return state */
|
||||||
|
__disable_irq();
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
/* USER CODE END Error_Handler_Debug */
|
||||||
|
}
|
||||||
|
#ifdef USE_FULL_ASSERT
|
||||||
|
/**
|
||||||
|
* @brief Reports the name of the source file and the source line number
|
||||||
|
* where the assert_param error has occurred.
|
||||||
|
* @param file: pointer to the source file name
|
||||||
|
* @param line: assert_param error line source number
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void assert_failed(uint8_t *file, uint32_t line)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN 6 */
|
||||||
|
/* User can add his own implementation to report the file name and line number,
|
||||||
|
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
|
||||||
|
/* USER CODE END 6 */
|
||||||
|
}
|
||||||
|
#endif /* USE_FULL_ASSERT */
|
||||||
|
|
||||||
@@ -0,0 +1,324 @@
|
|||||||
|
/* USER CODE BEGIN Header */
|
||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
* @file : main.c
|
||||||
|
* @brief : Main program body
|
||||||
|
******************************************************************************
|
||||||
|
* @attention
|
||||||
|
*
|
||||||
|
* Copyright (c) 2025 STMicroelectronics.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This software is licensed under terms that can be found in the LICENSE file
|
||||||
|
* in the root directory of this software component.
|
||||||
|
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||||
|
*
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
// Feeling sneaky.
|
||||||
|
extern "C" {
|
||||||
|
/* USER CODE END Header */
|
||||||
|
/* Includes ------------------------------------------------------------------*/
|
||||||
|
#include "main.h"
|
||||||
|
|
||||||
|
/* Private function prototypes -----------------------------------------------*/
|
||||||
|
void SystemClock_Config(void);
|
||||||
|
static void MX_GPIO_Init(void);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Private user code ---------------------------------------------------------*/
|
||||||
|
/* USER CODE BEGIN 0 */
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
enum class TrafficState { GREEN, YELLOW, RED };
|
||||||
|
void SetTrafficLights(TrafficState s);
|
||||||
|
|
||||||
|
TrafficState currentState = TrafficState::GREEN;
|
||||||
|
uint32_t stateStartTime = 0; //HAL_GetTick() at the start of this state
|
||||||
|
bool buttonPressedThisCycle = false;
|
||||||
|
bool pedestrianNextCycle = false;
|
||||||
|
bool pedestrianThisCycle = false;
|
||||||
|
|
||||||
|
const uint32_t DURATION_GREEN = 5000;
|
||||||
|
const uint32_t DURATION_YELLOW = 3000;
|
||||||
|
const uint32_t DURATION_RED_NOPED = 5000;
|
||||||
|
const uint32_t DURATION_RED_PED = 7000;
|
||||||
|
|
||||||
|
/* USER CODE END 0 */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief The application entry point.
|
||||||
|
* @retval int
|
||||||
|
*/
|
||||||
|
|
||||||
|
void SetTrafficLights(TrafficState s)
|
||||||
|
{
|
||||||
|
// reset all
|
||||||
|
HAL_GPIO_WritePin(GPIOD, Green_Pin, GPIO_PIN_RESET);
|
||||||
|
HAL_GPIO_WritePin(GPIOD, Yellow_Pin, GPIO_PIN_RESET);
|
||||||
|
HAL_GPIO_WritePin(GPIOD, Red_Pin, GPIO_PIN_SET);
|
||||||
|
|
||||||
|
switch (s)
|
||||||
|
{
|
||||||
|
case TrafficState::GREEN :
|
||||||
|
HAL_GPIO_WritePin(GPIOD, Green_Pin, GPIO_PIN_SET);
|
||||||
|
break;
|
||||||
|
case TrafficState::YELLOW :
|
||||||
|
HAL_GPIO_WritePin(GPIOD, Yellow_Pin, GPIO_PIN_SET);
|
||||||
|
break;
|
||||||
|
case TrafficState::RED:
|
||||||
|
HAL_GPIO_WritePin(GPIOD, Red_Pin, GPIO_PIN_SET);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
HAL_Init();
|
||||||
|
|
||||||
|
/* USER CODE BEGIN Init */
|
||||||
|
|
||||||
|
/* USER CODE END Init */
|
||||||
|
|
||||||
|
/* Configure the system clock */
|
||||||
|
SystemClock_Config();
|
||||||
|
MX_GPIO_Init();
|
||||||
|
|
||||||
|
stateStartTime = HAL_GetTick();
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
/* USER CODE END WHILE */
|
||||||
|
uint32_t now = HAL_GetTick();
|
||||||
|
uint32_t elapsed = now - stateStartTime;
|
||||||
|
|
||||||
|
switch(currentState)
|
||||||
|
{
|
||||||
|
case TrafficState::GREEN:
|
||||||
|
if (buttonPressedThisCycle)
|
||||||
|
pedestrianThisCycle = true;
|
||||||
|
|
||||||
|
/*
|
||||||
|
if (buttonPressedThisCycle)
|
||||||
|
{
|
||||||
|
currentState = TrafficState::YELLOW;
|
||||||
|
stateStartTime = now;
|
||||||
|
buttonPressedThisCycle = false;
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pedestrianNextCycle = false;
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
else if (elapsed >= DURATION_GREEN)
|
||||||
|
{
|
||||||
|
currentState = TrafficState::YELLOW;
|
||||||
|
stateStartTime = now;
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case TrafficState::YELLOW:
|
||||||
|
if (buttonPressedThisCycle || pedestrianNextCycle)
|
||||||
|
pedestrianThisCycle = true;
|
||||||
|
|
||||||
|
if (elapsed >= DURATION_YELLOW)
|
||||||
|
{
|
||||||
|
currentState = TrafficState::RED;
|
||||||
|
stateStartTime = now;
|
||||||
|
buttonPressedThisCycle = false; //TODO add pressed pedestrian button in yellow
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
// If Ped Button was pressed during GREEN or YELLOW, we need to enable WHITE this cycle
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case TrafficState::RED:
|
||||||
|
/*
|
||||||
|
if (pedestrianNextCycle)
|
||||||
|
{
|
||||||
|
HAL_GPIO_WritePin(GPIOD,White_Pin,GPIO_PIN_SET); // turn on Pedestrian LED
|
||||||
|
if (elapsed >= DURATION_RED_PED)
|
||||||
|
{
|
||||||
|
HAL_GPIO_WritePin(GPIOD,White_Pin,GPIO_PIN_RESET);
|
||||||
|
pedestrianNextCycle = false;
|
||||||
|
currentState = TrafficState::GREEN;
|
||||||
|
stateStartTime = now;
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
HAL_GPIO_WritePin(GPIOD,White_Pin,GPIO_PIN_RESET);
|
||||||
|
if(elapsed >= DURATION_RED_PED)
|
||||||
|
{
|
||||||
|
currentState = TrafficState::GREEN;
|
||||||
|
stateStartTime = now;
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (buttonPressedThisCycle)
|
||||||
|
pedestrianNextCycle = true;
|
||||||
|
|
||||||
|
if (pedestrianThisCycle) {
|
||||||
|
HAL_GPIO_WritePin(White_GPIO_Port, White_Pin, GPIO_PIN_RESET);
|
||||||
|
pedestrianThisCycle = false;
|
||||||
|
pedestrianNextcycle = false;
|
||||||
|
currentState = TrafficState::GREEN;
|
||||||
|
stateStartTime = now;
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
buttonPressedThisCycle = false;
|
||||||
|
} else {
|
||||||
|
HAL_GPIO_WritePin(White_GPIO_Port, White_Pin, GPIO_PIN_RESET);
|
||||||
|
if (elapsed >= DURATION_RED_NOPED)
|
||||||
|
{
|
||||||
|
currentState = TrafficState::GREEN;
|
||||||
|
stateStartTime = now;
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
buttonPressedThisCycle = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/* USER CODE BEGIN 3 */
|
||||||
|
}
|
||||||
|
/* USER CODE END 3 */
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief System Clock Configuration
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
|
||||||
|
void SystemClock_Config(void)
|
||||||
|
{
|
||||||
|
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
|
||||||
|
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
|
||||||
|
|
||||||
|
/** Configure the main internal regulator output voltage
|
||||||
|
*/
|
||||||
|
__HAL_RCC_PWR_CLK_ENABLE();
|
||||||
|
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE3);
|
||||||
|
|
||||||
|
/** Initializes the RCC Oscillators according to the specified parameters
|
||||||
|
* in the RCC_OscInitTypeDef structure.
|
||||||
|
*/
|
||||||
|
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
|
||||||
|
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
|
||||||
|
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
|
||||||
|
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
||||||
|
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
|
||||||
|
RCC_OscInitStruct.PLL.PLLM = 8;
|
||||||
|
RCC_OscInitStruct.PLL.PLLN = 50;
|
||||||
|
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4;
|
||||||
|
RCC_OscInitStruct.PLL.PLLQ = 7;
|
||||||
|
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Initializes the CPU, AHB and APB buses clocks
|
||||||
|
*/
|
||||||
|
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|
||||||
|
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
|
||||||
|
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
|
||||||
|
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
|
||||||
|
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV8;
|
||||||
|
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV4;
|
||||||
|
|
||||||
|
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief GPIO Initialization Function
|
||||||
|
* @param None
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
static void MX_GPIO_Init(void)
|
||||||
|
{
|
||||||
|
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||||
|
/* USER CODE BEGIN MX_GPIO_Init_1 */
|
||||||
|
|
||||||
|
/* USER CODE END MX_GPIO_Init_1 */
|
||||||
|
|
||||||
|
/* GPIO Ports Clock Enable */
|
||||||
|
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||||
|
__HAL_RCC_GPIOD_CLK_ENABLE();
|
||||||
|
|
||||||
|
/*Configure GPIO pin Output Level */
|
||||||
|
HAL_GPIO_WritePin(GPIOD, White_Pin|Red_Pin|Yellow_Pin|Green_Pin, GPIO_PIN_RESET);
|
||||||
|
|
||||||
|
/*Configure GPIO pin : PedButton_Pin */
|
||||||
|
GPIO_InitStruct.Pin = PedButton_Pin;
|
||||||
|
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
|
||||||
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
|
HAL_GPIO_Init(PedButton_GPIO_Port, &GPIO_InitStruct);
|
||||||
|
|
||||||
|
/*Configure GPIO pins : White_Pin Red_Pin Yellow_Pin Green_Pin */
|
||||||
|
GPIO_InitStruct.Pin = White_Pin|Red_Pin|Yellow_Pin|Green_Pin;
|
||||||
|
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||||
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||||
|
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
|
||||||
|
|
||||||
|
/* EXTI interrupt init*/
|
||||||
|
HAL_NVIC_SetPriority(EXTI15_10_IRQn, 15, 0);
|
||||||
|
HAL_NVIC_EnableIRQ(EXTI15_10_IRQn);
|
||||||
|
|
||||||
|
/* USER CODE BEGIN MX_GPIO_Init_2 */
|
||||||
|
|
||||||
|
/* USER CODE END MX_GPIO_Init_2 */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* USER CODE BEGIN 4 */
|
||||||
|
void HAL_GPIO_EXTI_CallBack()
|
||||||
|
{
|
||||||
|
static uint32_t lastInterruptTime = 0;
|
||||||
|
uint32_t now = HAL_GetTick();
|
||||||
|
}
|
||||||
|
|
||||||
|
void HAL_GPIO_EXTI_IRQHandler()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/* USER CODE END 4 */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function is executed in case of error occurrence.
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void Error_Handler(void)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN Error_Handler_Debug */
|
||||||
|
/* User can add his own implementation to report the HAL error return state */
|
||||||
|
__disable_irq();
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
/* USER CODE END Error_Handler_Debug */
|
||||||
|
}
|
||||||
|
#ifdef USE_FULL_ASSERT
|
||||||
|
/**
|
||||||
|
* @brief Reports the name of the source file and the source line number
|
||||||
|
* where the assert_param error has occurred.
|
||||||
|
* @param file: pointer to the source file name
|
||||||
|
* @param line: assert_param error line source number
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void assert_failed(uint8_t *file, uint32_t line)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN 6 */
|
||||||
|
/* User can add his own implementation to report the file name and line number,
|
||||||
|
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
|
||||||
|
/* USER CODE END 6 */
|
||||||
|
}
|
||||||
|
#endif /* USE_FULL_ASSERT */
|
||||||
|
|
||||||
@@ -1,98 +0,0 @@
|
|||||||
/*
|
|
||||||
* breadboard.c
|
|
||||||
*
|
|
||||||
* Created on: Sep 17, 2025
|
|
||||||
* Author: ja
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* #define RedLight_Pin GPIO_PIN_2
|
|
||||||
* #define RedLight_GPIO_Port GPIOE
|
|
||||||
*
|
|
||||||
* #define YellowLight_Pin GPIO_PIN_3
|
|
||||||
* #define YellowLight_GPIO_Port GPIOE
|
|
||||||
*
|
|
||||||
* #define GreenLight_Pin GPIO_PIN_4
|
|
||||||
* #define GreenLight_GPIO_Port GPIOE
|
|
||||||
*
|
|
||||||
* RedLight: PE2
|
|
||||||
* YellowLight: PE3
|
|
||||||
* GreenLight: PE4
|
|
||||||
* WalkLight: PE5
|
|
||||||
*
|
|
||||||
* Done: Traffic Light
|
|
||||||
* TODO: async? Walk Signal, Light Dimmer
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "main.h"
|
|
||||||
#include "breadboard.h"
|
|
||||||
|
|
||||||
#define R_Pin RedLight_Pin
|
|
||||||
#define Y_Pin YellowLight_Pin
|
|
||||||
#define G_Pin GreenLight_Pin
|
|
||||||
#define W_Pin WalkLight_Pin
|
|
||||||
|
|
||||||
#define R_Prt RedLight_GPIO_Port
|
|
||||||
#define Y_Prt YellowLight_GPIO_Port
|
|
||||||
#define G_Prt GreenLight_GPIO_Port
|
|
||||||
#define W_Prt WalkLight_GPIO_Port
|
|
||||||
|
|
||||||
uint32_t trafftick_last;
|
|
||||||
uint32_t walktick_last;
|
|
||||||
|
|
||||||
uint8_t trafflight_i = 0;
|
|
||||||
|
|
||||||
void
|
|
||||||
starttick(void)
|
|
||||||
{
|
|
||||||
trafftick_last = HAL_GetTick();
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
trafflight(int traffSPD)
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
HAL_GPIO_TogglePin(R_Prt, R_Pin);
|
|
||||||
HAL_Delay(traffSPD);
|
|
||||||
HAL_GPIO_TogglePin(R_Prt, R_Pin);
|
|
||||||
|
|
||||||
HAL_GPIO_TogglePin(Y_Prt, Y_Pin);
|
|
||||||
HAL_Delay(traffSPD);
|
|
||||||
HAL_GPIO_TogglePin(Y_Prt, Y_Pin);
|
|
||||||
|
|
||||||
HAL_GPIO_TogglePin(G_Prt, G_Pin);
|
|
||||||
HAL_Delay(traffSPD);
|
|
||||||
HAL_GPIO_TogglePin(G_Prt, G_Pin);
|
|
||||||
*/
|
|
||||||
|
|
||||||
uint32_t trafftick_curr = HAL_GetTick();
|
|
||||||
|
|
||||||
if ((trafftick_curr - trafftick_last) >= traffSPD) {
|
|
||||||
HAL_GPIO_WritePin(
|
|
||||||
R_Prt, R_Pin |
|
|
||||||
Y_Prt, Y_Pin |
|
|
||||||
G_Prt, G_Pin,
|
|
||||||
GPIO_PIN_RESET
|
|
||||||
);
|
|
||||||
|
|
||||||
switch (trafflight_i) {
|
|
||||||
case 0:
|
|
||||||
HAL_GPIO_WritePin(R_Prt, R_Pin);
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
HAL_GPIO_WritePin(Y_Prt, Y_Pin);
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
HAL_GPIO_WritePin(G_Prt, G_Pin);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
trafflight_i = (trafflight_i + 1) % 3;
|
|
||||||
trafftick_last = trafftick_curr;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((trafftick_curr - walktick_last) >= walkSPD) {
|
|
||||||
HAL_GPIO_TogglePin(W_Prt, W_Pin);
|
|
||||||
walktick_last = trafftick_curr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,314 @@
|
|||||||
|
/* USER CODE BEGIN Header */
|
||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
* @file : main.c
|
||||||
|
* @brief : Main program body
|
||||||
|
******************************************************************************
|
||||||
|
* @attention
|
||||||
|
*
|
||||||
|
* Copyright (c) 2025 STMicroelectronics.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This software is licensed under terms that can be found in the LICENSE file
|
||||||
|
* in the root directory of this software component.
|
||||||
|
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||||
|
*
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
// Feeling sneaky.
|
||||||
|
extern "C" {
|
||||||
|
/* USER CODE END Header */
|
||||||
|
/* Includes ------------------------------------------------------------------*/
|
||||||
|
#include "main.h"
|
||||||
|
|
||||||
|
/* Private function prototypes -----------------------------------------------*/
|
||||||
|
void SystemClock_Config(void);
|
||||||
|
static void MX_GPIO_Init(void);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Private user code ---------------------------------------------------------*/
|
||||||
|
/* USER CODE BEGIN 0 */
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
enum class TrafficState { GREEN, YELLOW, RED };
|
||||||
|
void SetTrafficLights(TrafficState s);
|
||||||
|
|
||||||
|
TrafficState currentState = TrafficState::GREEN;
|
||||||
|
uint32_t stateStartTime = 0; //HAL_GetTick() at the start of this state
|
||||||
|
bool buttonPressedThisCycle = false;
|
||||||
|
bool pedestrianNextCycle = false;
|
||||||
|
bool pedestrianThisCycle = false;
|
||||||
|
|
||||||
|
const uint32_t DURATION_GREEN = 5000;
|
||||||
|
const uint32_t DURATION_YELLOW = 3000;
|
||||||
|
const uint32_t DURATION_RED_NOPED = 5000;
|
||||||
|
const uint32_t DURATION_RED_PED = 7000;
|
||||||
|
|
||||||
|
/* USER CODE END 0 */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief The application entry point.
|
||||||
|
* @retval int
|
||||||
|
*/
|
||||||
|
|
||||||
|
void SetTrafficLights(TrafficState s)
|
||||||
|
{
|
||||||
|
// reset all
|
||||||
|
HAL_GPIO_WritePin(GPIOD, Green_Pin, GPIO_PIN_RESET);
|
||||||
|
HAL_GPIO_WritePin(GPIOD, Yellow_Pin, GPIO_PIN_RESET);
|
||||||
|
HAL_GPIO_WritePin(GPIOD, Red_Pin, GPIO_PIN_SET);
|
||||||
|
|
||||||
|
switch (s)
|
||||||
|
{
|
||||||
|
case TrafficState::GREEN :
|
||||||
|
HAL_GPIO_WritePin(GPIOD, Green_Pin, GPIO_PIN_SET);
|
||||||
|
break;
|
||||||
|
case TrafficState::YELLOW :
|
||||||
|
HAL_GPIO_WritePin(GPIOD, Yellow_Pin, GPIO_PIN_SET);
|
||||||
|
break;
|
||||||
|
case TrafficState::RED:
|
||||||
|
HAL_GPIO_WritePin(GPIOD, Red_Pin, GPIO_PIN_SET);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
HAL_Init();
|
||||||
|
|
||||||
|
/* USER CODE BEGIN Init */
|
||||||
|
|
||||||
|
/* USER CODE END Init */
|
||||||
|
|
||||||
|
/* Configure the system clock */
|
||||||
|
SystemClock_Config();
|
||||||
|
MX_GPIO_Init();
|
||||||
|
|
||||||
|
stateStartTime = HAL_GetTick();
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
/* USER CODE END WHILE */
|
||||||
|
uint32_t now = HAL_GetTick();
|
||||||
|
uint32_t elapsed = now - stateStartTime;
|
||||||
|
|
||||||
|
switch(currentState)
|
||||||
|
{
|
||||||
|
case TrafficState::GREEN:
|
||||||
|
if (buttonPressedThisCycle)
|
||||||
|
pedestrianThisCycle = true;
|
||||||
|
|
||||||
|
/*
|
||||||
|
if (buttonPressedThisCycle)
|
||||||
|
{
|
||||||
|
currentState = TrafficState::YELLOW;
|
||||||
|
stateStartTime = now;
|
||||||
|
buttonPressedThisCycle = false;
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pedestrianNextCycle = false;
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
else if (elapsed >= DURATION_GREEN)
|
||||||
|
{
|
||||||
|
currentState = TrafficState::YELLOW;
|
||||||
|
stateStartTime = now;
|
||||||
|
buttonPressedThisCycle = false;
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case TrafficState::YELLOW:
|
||||||
|
if (buttonPressedThisCycle || pedestrianNextCycle)
|
||||||
|
pedestrianThisCycle = true;
|
||||||
|
|
||||||
|
if (elapsed >= DURATION_YELLOW)
|
||||||
|
{
|
||||||
|
currentState = TrafficState::RED;
|
||||||
|
stateStartTime = now;
|
||||||
|
buttonPressedThisCycle = false; //TODO add pressed pedestrian button in yellow
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
// If Ped Button was pressed during GREEN or YELLOW, we need to enable WHITE this cycle
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case TrafficState::RED:
|
||||||
|
if (pedestrianNextCycle)
|
||||||
|
{
|
||||||
|
HAL_GPIO_WritePin(GPIOD,White_Pin,GPIO_PIN_SET); // turn on Pedestrian LED
|
||||||
|
if (elapsed >= DURATION_RED_PED)
|
||||||
|
{
|
||||||
|
HAL_GPIO_WritePin(GPIOD,White_Pin,GPIO_PIN_RESET);
|
||||||
|
pedestrianNextCycle = false;
|
||||||
|
currentState = TrafficState::GREEN;
|
||||||
|
stateStartTime = now;
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
HAL_GPIO_WritePin(GPIOD,White_Pin,GPIO_PIN_RESET);
|
||||||
|
if(elapsed >= DURATION_RED_PED)
|
||||||
|
{
|
||||||
|
currentState = TrafficState::GREEN;
|
||||||
|
stateStartTime = now;
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/* USER CODE BEGIN 3 */
|
||||||
|
}
|
||||||
|
/* USER CODE END 3 */
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief System Clock Configuration
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void SystemClock_Config(void)
|
||||||
|
{
|
||||||
|
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
|
||||||
|
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
|
||||||
|
|
||||||
|
/** Configure the main internal regulator output voltage
|
||||||
|
*/
|
||||||
|
__HAL_RCC_PWR_CLK_ENABLE();
|
||||||
|
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE3);
|
||||||
|
|
||||||
|
/** Initializes the RCC Oscillators according to the specified parameters
|
||||||
|
* in the RCC_OscInitTypeDef structure.
|
||||||
|
*/
|
||||||
|
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
|
||||||
|
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
|
||||||
|
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
|
||||||
|
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
||||||
|
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
|
||||||
|
RCC_OscInitStruct.PLL.PLLM = 8;
|
||||||
|
RCC_OscInitStruct.PLL.PLLN = 50;
|
||||||
|
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4;
|
||||||
|
RCC_OscInitStruct.PLL.PLLQ = 7;
|
||||||
|
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Initializes the CPU, AHB and APB buses clocks
|
||||||
|
*/
|
||||||
|
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|
||||||
|
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
|
||||||
|
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
|
||||||
|
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
|
||||||
|
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV8;
|
||||||
|
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV4;
|
||||||
|
|
||||||
|
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief GPIO Initialization Function
|
||||||
|
* @param None
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
static void MX_GPIO_Init(void)
|
||||||
|
{
|
||||||
|
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||||
|
/* USER CODE BEGIN MX_GPIO_Init_1 */
|
||||||
|
|
||||||
|
/* USER CODE END MX_GPIO_Init_1 */
|
||||||
|
|
||||||
|
/* GPIO Ports Clock Enable */
|
||||||
|
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||||
|
__HAL_RCC_GPIOD_CLK_ENABLE();
|
||||||
|
|
||||||
|
/*Configure GPIO pin Output Level */
|
||||||
|
HAL_GPIO_WritePin(GPIOD, White_Pin|Red_Pin|Yellow_Pin|Green_Pin, GPIO_PIN_RESET);
|
||||||
|
|
||||||
|
/*Configure GPIO pin : PedButton_Pin */
|
||||||
|
GPIO_InitStruct.Pin = PedButton_Pin;
|
||||||
|
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
|
||||||
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
|
HAL_GPIO_Init(PedButton_GPIO_Port, &GPIO_InitStruct);
|
||||||
|
|
||||||
|
/*Configure GPIO pins : White_Pin Red_Pin Yellow_Pin Green_Pin */
|
||||||
|
GPIO_InitStruct.Pin = White_Pin|Red_Pin|Yellow_Pin|Green_Pin;
|
||||||
|
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||||
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||||
|
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
|
||||||
|
|
||||||
|
/* EXTI interrupt init*/
|
||||||
|
HAL_NVIC_SetPriority(EXTI15_10_IRQn, 15, 0);
|
||||||
|
HAL_NVIC_EnableIRQ(EXTI15_10_IRQn);
|
||||||
|
|
||||||
|
/* USER CODE BEGIN MX_GPIO_Init_2 */
|
||||||
|
|
||||||
|
/* USER CODE END MX_GPIO_Init_2 */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* USER CODE BEGIN 4 */
|
||||||
|
void HAL_GPIO_EXTI_CallBack()
|
||||||
|
{
|
||||||
|
static uint32_t lastInterruptTime = 0;
|
||||||
|
uint32_t now = HAL_GetTick();
|
||||||
|
if(now - lastInterruptTime < 100)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
lastInterruptTime = now;
|
||||||
|
|
||||||
|
if (PedButton_Pin)
|
||||||
|
{
|
||||||
|
buttonPressedThisCycle = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void HAL_GPIO_EXTI_IRQHandler()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/* USER CODE END 4 */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function is executed in case of error occurrence.
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void Error_Handler(void)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN Error_Handler_Debug */
|
||||||
|
/* User can add his own implementation to report the HAL error return state */
|
||||||
|
__disable_irq();
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
/* USER CODE END Error_Handler_Debug */
|
||||||
|
}
|
||||||
|
#ifdef USE_FULL_ASSERT
|
||||||
|
/**
|
||||||
|
* @brief Reports the name of the source file and the source line number
|
||||||
|
* where the assert_param error has occurred.
|
||||||
|
* @param file: pointer to the source file name
|
||||||
|
* @param line: assert_param error line source number
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void assert_failed(uint8_t *file, uint32_t line)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN 6 */
|
||||||
|
/* User can add his own implementation to report the file name and line number,
|
||||||
|
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
|
||||||
|
/* USER CODE END 6 */
|
||||||
|
}
|
||||||
|
#endif /* USE_FULL_ASSERT */
|
||||||
|
|
||||||
@@ -0,0 +1,516 @@
|
|||||||
|
/* USER CODE BEGIN Header */
|
||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
* @file : main.c
|
||||||
|
* @brief : Main program body
|
||||||
|
******************************************************************************
|
||||||
|
* @attention
|
||||||
|
*
|
||||||
|
* Copyright (c) 2025 STMicroelectronics.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This software is licensed under terms that can be found in the LICENSE file
|
||||||
|
* in the root directory of this software component.
|
||||||
|
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||||
|
*
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
/* USER CODE END Header */
|
||||||
|
/* Includes ------------------------------------------------------------------*/
|
||||||
|
#include "main.h"
|
||||||
|
#include "cmsis_os.h"
|
||||||
|
|
||||||
|
/* Private includes ----------------------------------------------------------*/
|
||||||
|
/* USER CODE BEGIN Includes */
|
||||||
|
#include "breadboard.h"
|
||||||
|
#include <stdbool.h>
|
||||||
|
/* USER CODE END Includes */
|
||||||
|
|
||||||
|
/* Private typedef -----------------------------------------------------------*/
|
||||||
|
/* USER CODE BEGIN PTD */
|
||||||
|
|
||||||
|
/* USER CODE END PTD */
|
||||||
|
|
||||||
|
/* Private define ------------------------------------------------------------*/
|
||||||
|
/* USER CODE BEGIN PD */
|
||||||
|
|
||||||
|
/* USER CODE END PD */
|
||||||
|
|
||||||
|
/* Private macro -------------------------------------------------------------*/
|
||||||
|
/* USER CODE BEGIN PM */
|
||||||
|
|
||||||
|
/* USER CODE END PM */
|
||||||
|
|
||||||
|
/* Private variables ---------------------------------------------------------*/
|
||||||
|
CRC_HandleTypeDef hcrc;
|
||||||
|
|
||||||
|
DMA2D_HandleTypeDef hdma2d;
|
||||||
|
|
||||||
|
TIM_HandleTypeDef htim1;
|
||||||
|
|
||||||
|
osThreadId defaultTaskHandle;
|
||||||
|
/* USER CODE BEGIN PV */
|
||||||
|
|
||||||
|
/* USER CODE END PV */
|
||||||
|
|
||||||
|
/* Private function prototypes -----------------------------------------------*/
|
||||||
|
void SystemClock_Config(void);
|
||||||
|
static void MX_GPIO_Init(void);
|
||||||
|
static void MX_CRC_Init(void);
|
||||||
|
static void MX_DMA2D_Init(void);
|
||||||
|
static void MX_TIM1_Init(void);
|
||||||
|
void StartDefaultTask(void const * argument);
|
||||||
|
|
||||||
|
void SetTrafficLights(TrafficSate s);
|
||||||
|
|
||||||
|
/* USER CODE BEGIN PFP */
|
||||||
|
|
||||||
|
/* USER CODE END PFP */
|
||||||
|
|
||||||
|
/* Private user code ---------------------------------------------------------*/
|
||||||
|
|
||||||
|
/* USER CODE BEGIN 0 */
|
||||||
|
|
||||||
|
enum class TrafficState {
|
||||||
|
GREEN,
|
||||||
|
YELLOW,
|
||||||
|
RED
|
||||||
|
};
|
||||||
|
|
||||||
|
TrafficState currentState = TrafficState::GREEN;
|
||||||
|
uint32_t stateStartTime = 0; // HAL_GetTick() at the start of this state
|
||||||
|
bool buttonPressed = false;
|
||||||
|
bool pedestrianNextCycle = false;
|
||||||
|
|
||||||
|
const uint32_t DURATION_GREEN = 5000;
|
||||||
|
const uint32_t DURATION_YELLOW = 3000;
|
||||||
|
const uint32_t DURATION_RED = 5000;
|
||||||
|
const uint32_t DURATION_RED_PED = 7000;
|
||||||
|
|
||||||
|
/* USER CODE END 0 */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief The application entry point.
|
||||||
|
* @retval int
|
||||||
|
*/
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* USER CODE BEGIN 1 */
|
||||||
|
|
||||||
|
/* USER CODE END 1 */
|
||||||
|
|
||||||
|
/* MCU Configuration--------------------------------------------------------*/
|
||||||
|
|
||||||
|
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
|
||||||
|
HAL_Init();
|
||||||
|
|
||||||
|
/* USER CODE BEGIN Init */
|
||||||
|
|
||||||
|
/* USER CODE END Init */
|
||||||
|
|
||||||
|
/* Configure the system clock */
|
||||||
|
SystemClock_Config();
|
||||||
|
|
||||||
|
/* USER CODE BEGIN SysInit */
|
||||||
|
|
||||||
|
stateStartTime = HAL_GetTick();
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
|
||||||
|
/* USER CODE END SysInit */
|
||||||
|
|
||||||
|
/* Initialize all configured peripherals */
|
||||||
|
MX_GPIO_Init();
|
||||||
|
MX_CRC_Init();
|
||||||
|
MX_DMA2D_Init();
|
||||||
|
MX_TIM1_Init();
|
||||||
|
/* USER CODE BEGIN 2 */
|
||||||
|
|
||||||
|
/* USER CODE END 2 */
|
||||||
|
|
||||||
|
/* USER CODE BEGIN RTOS_MUTEX */
|
||||||
|
/* add mutexes, ... */
|
||||||
|
/* USER CODE END RTOS_MUTEX */
|
||||||
|
|
||||||
|
/* USER CODE BEGIN RTOS_SEMAPHORES */
|
||||||
|
/* add semaphores, ... */
|
||||||
|
/* USER CODE END RTOS_SEMAPHORES */
|
||||||
|
|
||||||
|
/* USER CODE BEGIN RTOS_TIMERS */
|
||||||
|
/* start timers, add new ones, ... */
|
||||||
|
/* USER CODE END RTOS_TIMERS */
|
||||||
|
|
||||||
|
/* USER CODE BEGIN RTOS_QUEUES */
|
||||||
|
/* add queues, ... */
|
||||||
|
/* USER CODE END RTOS_QUEUES */
|
||||||
|
|
||||||
|
/* Create the thread(s) */
|
||||||
|
/* definition and creation of defaultTask */
|
||||||
|
//osThreadDef(defaultTask, StartDefaultTask, osPriorityNormal, 0, 4096);
|
||||||
|
//defaultTaskHandle = osThreadCreate(osThread(defaultTask), NULL);
|
||||||
|
|
||||||
|
/* USER CODE BEGIN RTOS_THREADS */
|
||||||
|
/* add threads, ... */
|
||||||
|
/* USER CODE END RTOS_THREADS */
|
||||||
|
|
||||||
|
/* Start scheduler */
|
||||||
|
osKernelStart();
|
||||||
|
|
||||||
|
/* We should never get here as control is now taken by the scheduler */
|
||||||
|
|
||||||
|
/* Infinite loop */
|
||||||
|
/* USER CODE BEGIN WHILE */
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
uint32_t now = HAL_GetTick();
|
||||||
|
uint32_t elapsed = now - stateStartTime;
|
||||||
|
|
||||||
|
/*
|
||||||
|
switch(currentState)
|
||||||
|
{
|
||||||
|
case TrafficState::GREEN:
|
||||||
|
if (elapsed >= DURATION_GREEN) {
|
||||||
|
currentState = TrafficState::YELLOW;
|
||||||
|
stateStartTime = now;
|
||||||
|
buttonPressed = false; // reset the button-flag for the new cycle
|
||||||
|
} else if (buttonPressed) {
|
||||||
|
//idk
|
||||||
|
buttonPressed = true;
|
||||||
|
currentState = TrafficState::YELLOW;
|
||||||
|
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case TrafficState::YELLOW:
|
||||||
|
break;
|
||||||
|
case TrafficState::RED:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
switch(currentState)
|
||||||
|
{
|
||||||
|
case TrafficState::GREEN:
|
||||||
|
if (butonPressedThisCycle)
|
||||||
|
{
|
||||||
|
currentState = TrafficState::YELLOW;
|
||||||
|
stateStartTime = now;
|
||||||
|
buttonPressedThisCycle = false;
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
} else if (elapsed >= DURATION_GREEN)
|
||||||
|
{
|
||||||
|
buttonPressedThisCycle = true;
|
||||||
|
currentState = TrafficState::YELLOW;
|
||||||
|
stateStartTime = now;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case TrafficState::YELLOW:
|
||||||
|
if (elapsed >= DURATION_YELLOW)
|
||||||
|
{
|
||||||
|
currentState = TrafficState::RED;
|
||||||
|
stateStartTime = now;
|
||||||
|
// if ped button was pressed during GREEN or YELLOW,
|
||||||
|
// we need to enable WHITE
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case TrafficState::RED:
|
||||||
|
//
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/* USER CODE END WHILE */
|
||||||
|
|
||||||
|
/* USER CODE BEGIN 3 */
|
||||||
|
}
|
||||||
|
/* USER CODE END 3 */
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief System Clock Configuration
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void SystemClock_Config(void)
|
||||||
|
{
|
||||||
|
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
|
||||||
|
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
|
||||||
|
|
||||||
|
/** Configure the main internal regulator output voltage
|
||||||
|
*/
|
||||||
|
__HAL_RCC_PWR_CLK_ENABLE();
|
||||||
|
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE3);
|
||||||
|
|
||||||
|
/** Initializes the RCC Oscillators according to the specified parameters
|
||||||
|
* in the RCC_OscInitTypeDef structure.
|
||||||
|
*/
|
||||||
|
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
|
||||||
|
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
|
||||||
|
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
|
||||||
|
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
||||||
|
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
|
||||||
|
RCC_OscInitStruct.PLL.PLLM = 8;
|
||||||
|
RCC_OscInitStruct.PLL.PLLN = 72;
|
||||||
|
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
|
||||||
|
RCC_OscInitStruct.PLL.PLLQ = 3;
|
||||||
|
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Initializes the CPU, AHB and APB buses clocks
|
||||||
|
*/
|
||||||
|
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|
||||||
|
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
|
||||||
|
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
|
||||||
|
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
|
||||||
|
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
|
||||||
|
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
|
||||||
|
|
||||||
|
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief CRC Initialization Function
|
||||||
|
* @param None
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
static void MX_CRC_Init(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* USER CODE BEGIN CRC_Init 0 */
|
||||||
|
|
||||||
|
/* USER CODE END CRC_Init 0 */
|
||||||
|
|
||||||
|
/* USER CODE BEGIN CRC_Init 1 */
|
||||||
|
|
||||||
|
/* USER CODE END CRC_Init 1 */
|
||||||
|
hcrc.Instance = CRC;
|
||||||
|
if (HAL_CRC_Init(&hcrc) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
/* USER CODE BEGIN CRC_Init 2 */
|
||||||
|
|
||||||
|
/* USER CODE END CRC_Init 2 */
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief DMA2D Initialization Function
|
||||||
|
* @param None
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
static void MX_DMA2D_Init(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* USER CODE BEGIN DMA2D_Init 0 */
|
||||||
|
|
||||||
|
/* USER CODE END DMA2D_Init 0 */
|
||||||
|
|
||||||
|
/* USER CODE BEGIN DMA2D_Init 1 */
|
||||||
|
|
||||||
|
/* USER CODE END DMA2D_Init 1 */
|
||||||
|
hdma2d.Instance = DMA2D;
|
||||||
|
hdma2d.Init.Mode = DMA2D_M2M;
|
||||||
|
hdma2d.Init.ColorMode = DMA2D_OUTPUT_ARGB8888;
|
||||||
|
hdma2d.Init.OutputOffset = 0;
|
||||||
|
hdma2d.LayerCfg[1].InputOffset = 0;
|
||||||
|
hdma2d.LayerCfg[1].InputColorMode = DMA2D_INPUT_ARGB8888;
|
||||||
|
hdma2d.LayerCfg[1].AlphaMode = DMA2D_NO_MODIF_ALPHA;
|
||||||
|
hdma2d.LayerCfg[1].InputAlpha = 0;
|
||||||
|
if (HAL_DMA2D_Init(&hdma2d) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
if (HAL_DMA2D_ConfigLayer(&hdma2d, 1) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
/* USER CODE BEGIN DMA2D_Init 2 */
|
||||||
|
|
||||||
|
/* USER CODE END DMA2D_Init 2 */
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief TIM1 Initialization Function
|
||||||
|
* @param None
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
static void MX_TIM1_Init(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* USER CODE BEGIN TIM1_Init 0 */
|
||||||
|
|
||||||
|
/* USER CODE END TIM1_Init 0 */
|
||||||
|
|
||||||
|
TIM_ClockConfigTypeDef sClockSourceConfig = {0};
|
||||||
|
TIM_MasterConfigTypeDef sMasterConfig = {0};
|
||||||
|
|
||||||
|
/* USER CODE BEGIN TIM1_Init 1 */
|
||||||
|
|
||||||
|
/* USER CODE END TIM1_Init 1 */
|
||||||
|
htim1.Instance = TIM1;
|
||||||
|
htim1.Init.Prescaler = 0;
|
||||||
|
htim1.Init.CounterMode = TIM_COUNTERMODE_UP;
|
||||||
|
htim1.Init.Period = 65535;
|
||||||
|
htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
||||||
|
htim1.Init.RepetitionCounter = 0;
|
||||||
|
htim1.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
|
||||||
|
if (HAL_TIM_Base_Init(&htim1) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
|
||||||
|
if (HAL_TIM_ConfigClockSource(&htim1, &sClockSourceConfig) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
|
||||||
|
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
|
||||||
|
if (HAL_TIMEx_MasterConfigSynchronization(&htim1, &sMasterConfig) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
/* USER CODE BEGIN TIM1_Init 2 */
|
||||||
|
|
||||||
|
/* USER CODE END TIM1_Init 2 */
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief GPIO Initialization Function
|
||||||
|
* @param None
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
static void MX_GPIO_Init(void)
|
||||||
|
{
|
||||||
|
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||||
|
/* USER CODE BEGIN MX_GPIO_Init_1 */
|
||||||
|
|
||||||
|
/* USER CODE END MX_GPIO_Init_1 */
|
||||||
|
|
||||||
|
/* GPIO Ports Clock Enable */
|
||||||
|
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||||
|
__HAL_RCC_GPIOD_CLK_ENABLE();
|
||||||
|
|
||||||
|
/*Configure GPIO pin Output Level */
|
||||||
|
HAL_GPIO_WritePin(GPIOD, White_Pin|Red_Pin|Yellow_Pin|Green_Pin, GPIO_PIN_RESET);
|
||||||
|
|
||||||
|
/*Configure GPIO pin : PedButton_Pin */
|
||||||
|
GPIO_InitStruct.Pin = PedButton_Pin;
|
||||||
|
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
|
||||||
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
|
HAL_GPIO_Init(PedButton_GPIO_Port, &GPIO_InitStruct);
|
||||||
|
|
||||||
|
/*Configure GPIO pins : White_Pin Red_Pin Yellow_Pin Green_Pin */
|
||||||
|
GPIO_InitStruct.Pin = White_Pin|Red_Pin|Yellow_Pin|Green_Pin;
|
||||||
|
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||||
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||||
|
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
|
||||||
|
|
||||||
|
/* EXTI interrupt init*/
|
||||||
|
HAL_NVIC_SetPriority(EXTI15_10_IRQn, 15, 0);
|
||||||
|
HAL_NVIC_EnableIRQ(EXTI15_10_IRQn);
|
||||||
|
|
||||||
|
/* USER CODE BEGIN MX_GPIO_Init_2 */
|
||||||
|
|
||||||
|
/* USER CODE END MX_GPIO_Init_2 */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* USER CODE BEGIN 4 */
|
||||||
|
|
||||||
|
void HAL_GPIO_EXTI_CallBack(uint16_t GPIO_Pin)
|
||||||
|
{
|
||||||
|
static uint32_t lastInterruptTime = 0;
|
||||||
|
uint32_t now = HAL_GetTick();
|
||||||
|
if (now - lastInterruptTime < 100) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
lastInterruptTime = now;
|
||||||
|
|
||||||
|
bool buttonPressedThisCycle = false; // temporary, get rid of this
|
||||||
|
|
||||||
|
if (buttonPressed) { // buttonPressedHere?
|
||||||
|
buttonPressedThisCycle = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* USER CODE END 4 */
|
||||||
|
|
||||||
|
/* USER CODE BEGIN Header_StartDefaultTask */
|
||||||
|
/**
|
||||||
|
* @brief Function implementing the defaultTask thread.
|
||||||
|
* @param argument: Not used
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
/* USER CODE END Header_StartDefaultTask */
|
||||||
|
void StartDefaultTask(void const * argument)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN 5 */
|
||||||
|
/* Infinite loop */
|
||||||
|
for(;;)
|
||||||
|
{
|
||||||
|
osDelay(1);
|
||||||
|
}
|
||||||
|
/* USER CODE END 5 */
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Period elapsed callback in non blocking mode
|
||||||
|
* @note This function is called when TIM6 interrupt took place, inside
|
||||||
|
* HAL_TIM_IRQHandler(). It makes a direct call to HAL_IncTick() to increment
|
||||||
|
* a global variable "uwTick" used as application time base.
|
||||||
|
* @param htim : TIM handle
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN Callback 0 */
|
||||||
|
|
||||||
|
/* USER CODE END Callback 0 */
|
||||||
|
if (htim->Instance == TIM6)
|
||||||
|
{
|
||||||
|
HAL_IncTick();
|
||||||
|
}
|
||||||
|
/* USER CODE BEGIN Callback 1 */
|
||||||
|
|
||||||
|
/* USER CODE END Callback 1 */
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function is executed in case of error occurrence.
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void Error_Handler(void)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN Error_Handler_Debug */
|
||||||
|
/* User can add his own implementation to report the HAL error return state */
|
||||||
|
__disable_irq();
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
/* USER CODE END Error_Handler_Debug */
|
||||||
|
}
|
||||||
|
#ifdef USE_FULL_ASSERT
|
||||||
|
/**
|
||||||
|
* @brief Reports the name of the source file and the source line number
|
||||||
|
* where the assert_param error has occurred.
|
||||||
|
* @param file: pointer to the source file name
|
||||||
|
* @param line: assert_param error line source number
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void assert_failed(uint8_t *file, uint32_t line)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN 6 */
|
||||||
|
/* User can add his own implementation to report the file name and line number,
|
||||||
|
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
|
||||||
|
/* USER CODE END 6 */
|
||||||
|
}
|
||||||
|
#endif /* USE_FULL_ASSERT */
|
||||||
@@ -1,88 +0,0 @@
|
|||||||
/*
|
|
||||||
* breadboard.c
|
|
||||||
*
|
|
||||||
* Created on: Sep 17, 2025
|
|
||||||
* Author: ja
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* #define RedLight_Pin GPIO_PIN_2
|
|
||||||
* #define RedLight_GPIO_Port GPIOE
|
|
||||||
*
|
|
||||||
* #define YellowLight_Pin GPIO_PIN_3
|
|
||||||
* #define YellowLight_GPIO_Port GPIOE
|
|
||||||
*
|
|
||||||
* #define GreenLight_Pin GPIO_PIN_4
|
|
||||||
* #define GreenLight_GPIO_Port GPIOE
|
|
||||||
*
|
|
||||||
* RedLight: PE2
|
|
||||||
* YellowLight: PE3
|
|
||||||
* GreenLight: PE4
|
|
||||||
* WalkLight: PE5
|
|
||||||
*
|
|
||||||
* Done: Traffic Light
|
|
||||||
* TODO: Light Dimmer
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "main.h"
|
|
||||||
#include "breadboard.h"
|
|
||||||
|
|
||||||
#define R_Pin RedLight_Pin
|
|
||||||
#define Y_Pin YellowLight_Pin
|
|
||||||
#define G_Pin GreenLight_Pin
|
|
||||||
#define W_Pin WalkLight_Pin
|
|
||||||
|
|
||||||
#define R_Prt RedLight_GPIO_Port
|
|
||||||
#define Y_Prt YellowLight_GPIO_Port
|
|
||||||
#define G_Prt GreenLight_GPIO_Port
|
|
||||||
#define W_Prt WalkLight_GPIO_Port
|
|
||||||
|
|
||||||
uint32_t trafftick_last;
|
|
||||||
uint32_t walktick_last;
|
|
||||||
|
|
||||||
uint8_t trafflight_index = 0;
|
|
||||||
|
|
||||||
void
|
|
||||||
starttick(void)
|
|
||||||
{
|
|
||||||
trafftick_last = HAL_GetTick();
|
|
||||||
walktick_last = HAL_GetTick();
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
trafflight(int traffSPD, int walkSPD)
|
|
||||||
{
|
|
||||||
uint32_t trafftick_curr = HAL_GetTick();
|
|
||||||
|
|
||||||
if ((trafftick_curr - trafftick_last) >= traffSPD) {
|
|
||||||
HAL_GPIO_WritePin(R_Prt, R_Pin, GPIO_PIN_RESET);
|
|
||||||
HAL_GPIO_WritePin(Y_Prt, Y_Pin, GPIO_PIN_RESET);
|
|
||||||
HAL_GPIO_WritePin(G_Prt, G_Pin, GPIO_PIN_RESET);
|
|
||||||
|
|
||||||
switch (trafflight_index) {
|
|
||||||
case 0:
|
|
||||||
HAL_GPIO_WritePin(R_Prt, R_Pin, GPIO_PIN_SET);
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
HAL_GPIO_WritePin(Y_Prt, Y_Pin, GPIO_PIN_SET);
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
HAL_GPIO_WritePin(G_Prt, G_Pin, GPIO_PIN_SET);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 0:
|
|
||||||
HAL_GPIO_WritePin(G_Prt, G_Pin, GPIO_PIN_SET);
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
HAL_GPIO_WritePin(Y_Prt, Y_Pin, GPIO_PIN_SET);
|
|
||||||
}
|
|
||||||
|
|
||||||
trafflight_index = (trafflight_index + 1) % 3;
|
|
||||||
trafftick_last = trafftick_curr;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((trafftick_curr - walktick_last) >= walkSPD) {
|
|
||||||
HAL_GPIO_TogglePin(W_Prt, W_Pin);
|
|
||||||
walktick_last = trafftick_curr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
/*
|
|
||||||
* breadboard.cpp
|
|
||||||
*
|
|
||||||
* Created on: Sep 22, 2025
|
|
||||||
* Author: ja
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,87 +0,0 @@
|
|||||||
/*
|
|
||||||
* breadboard.c
|
|
||||||
*
|
|
||||||
* Created on: Sep 17, 2025
|
|
||||||
* Author: ja
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* #define RedLight_Pin GPIO_PIN_2
|
|
||||||
* #define RedLight_GPIO_Port GPIOE
|
|
||||||
*
|
|
||||||
* #define YellowLight_Pin GPIO_PIN_3
|
|
||||||
* #define YellowLight_GPIO_Port GPIOE
|
|
||||||
*
|
|
||||||
* #define GreenLight_Pin GPIO_PIN_4
|
|
||||||
* #define GreenLight_GPIO_Port GPIOE
|
|
||||||
*
|
|
||||||
* RedLight: PE2
|
|
||||||
* YellowLight: PE3
|
|
||||||
* GreenLight: PE4
|
|
||||||
* WalkLight: PE5
|
|
||||||
*
|
|
||||||
* Done: Traffic Light
|
|
||||||
* TODO: async? Walk Signal, Light Dimmer
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "main.h"
|
|
||||||
#include "breadboard.h"
|
|
||||||
|
|
||||||
#define R_Pin RedLight_Pin
|
|
||||||
#define Y_Pin YellowLight_Pin
|
|
||||||
#define G_Pin GreenLight_Pin
|
|
||||||
#define W_Pin WalkLight_Pin
|
|
||||||
|
|
||||||
#define R_Prt RedLight_GPIO_Port
|
|
||||||
#define Y_Prt YellowLight_GPIO_Port
|
|
||||||
#define G_Prt GreenLight_GPIO_Port
|
|
||||||
#define W_Prt WalkLight_GPIO_Port
|
|
||||||
|
|
||||||
uint32_t redlight_last;
|
|
||||||
uint32_t ylwlight_last;
|
|
||||||
uint32_t grnlight_last;
|
|
||||||
|
|
||||||
void
|
|
||||||
starttick(void)
|
|
||||||
{
|
|
||||||
redlight_last = HAL_GetTick();
|
|
||||||
ylwlight_last = HAL_GetTick();
|
|
||||||
grnlight_last = HAL_GetTick();
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
trafflight(int traffSPD)
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
HAL_GPIO_TogglePin(R_Prt, R_Pin);
|
|
||||||
HAL_Delay(traffSPD);
|
|
||||||
HAL_GPIO_TogglePin(R_Prt, R_Pin);
|
|
||||||
|
|
||||||
HAL_GPIO_TogglePin(Y_Prt, Y_Pin);
|
|
||||||
HAL_Delay(traffSPD);
|
|
||||||
HAL_GPIO_TogglePin(Y_Prt, Y_Pin);
|
|
||||||
|
|
||||||
HAL_GPIO_TogglePin(G_Prt, G_Pin);
|
|
||||||
HAL_Delay(traffSPD);
|
|
||||||
HAL_GPIO_TogglePin(G_Prt, G_Pin);
|
|
||||||
*/
|
|
||||||
|
|
||||||
uint32_t trafftick_curr = HAL_GetTick();
|
|
||||||
int ldelay2 = traffSPD * 2;
|
|
||||||
int ldelay3 = traffSPD * 3;
|
|
||||||
|
|
||||||
if ((trafftick_curr - redlight_last) >= traffSPD) {
|
|
||||||
redlight_last = trafftick_curr;
|
|
||||||
HAL_GPIO_TogglePin(R_Prt, R_Pin);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((trafftick_curr - ylwlight_last) >= ldelay2) {
|
|
||||||
ylwlight_last = trafftick_curr;
|
|
||||||
HAL_GPIO_TogglePin(Y_Prt, Y_Pin);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((trafftick_curr - grnlight_last) >= ldelay3) {
|
|
||||||
grnlight_last = trafftick_curr;
|
|
||||||
HAL_GPIO_TogglePin(G_Prt, G_Pin);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
/*
|
|
||||||
* breadboard.c
|
|
||||||
*
|
|
||||||
* Created on: Sep 12, 2025
|
|
||||||
* Author: ja
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stdbool.h>
|
|
||||||
#include "main.h"
|
|
||||||
|
|
||||||
void
|
|
||||||
breadboard(int DELAY_MS)
|
|
||||||
{
|
|
||||||
bool Purple = (HAL_GPIO_ReadPin(BTN_PRPL_GPIO_Port, BTN_PRPL_Pin) == GPIO_PIN_SET); // PD5
|
|
||||||
bool Grey = (HAL_GPIO_ReadPin(BTN_GREY_GPIO_Port, BTN_GREY_Pin) == GPIO_PIN_SET); // PD7
|
|
||||||
|
|
||||||
if (Purple && Grey) { // inverted for ease of debug, assignment calls for (Purple && Grey)
|
|
||||||
HAL_GPIO_WritePin(LED_EXT_GPIO_Port, LED_EXT_Pin, GPIO_PIN_SET); // PB4
|
|
||||||
} else {
|
|
||||||
HAL_GPIO_WritePin(LED_EXT_GPIO_Port, LED_EXT_Pin, GPIO_PIN_RESET); // PB4
|
|
||||||
}
|
|
||||||
|
|
||||||
HAL_Delay(DELAY_MS); // milliseconds of delay after execution
|
|
||||||
|
|
||||||
/*
|
|
||||||
// Always flash:
|
|
||||||
HAL_GPIO_WritePin(GPIOB, LED_EXT_Pin, GPIO_PIN_SET); // PB4 ON
|
|
||||||
HAL_Delay(DELAY_MS);
|
|
||||||
HAL_GPIO_WritePin(GPIOB, LED_EXT_Pin, GPIO_PIN_RESET); // PB4 OFF
|
|
||||||
HAL_Delay(DELAY_MS);
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
@@ -1,95 +0,0 @@
|
|||||||
/*
|
|
||||||
* breadboard.c
|
|
||||||
*
|
|
||||||
* Created on: Sep 17, 2025
|
|
||||||
* Author: ja
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* #define RedLight_Pin GPIO_PIN_2
|
|
||||||
* #define RedLight_GPIO_Port GPIOE
|
|
||||||
*
|
|
||||||
* #define YellowLight_Pin GPIO_PIN_3
|
|
||||||
* #define YellowLight_GPIO_Port GPIOE
|
|
||||||
*
|
|
||||||
* #define GreenLight_Pin GPIO_PIN_4
|
|
||||||
* #define GreenLight_GPIO_Port GPIOE
|
|
||||||
*
|
|
||||||
* RedLight: PE2
|
|
||||||
* YellowLight: PE3
|
|
||||||
* GreenLight: PE4
|
|
||||||
* WalkLight: PE5
|
|
||||||
*
|
|
||||||
* Done: Traffic Light
|
|
||||||
* TODO: async? Walk Signal, Light Dimmer
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "main.h"
|
|
||||||
#include "breadboard.h"
|
|
||||||
|
|
||||||
#define R_Pin RedLight_Pin
|
|
||||||
#define Y_Pin YellowLight_Pin
|
|
||||||
#define G_Pin GreenLight_Pin
|
|
||||||
#define W_Pin WalkLight_Pin
|
|
||||||
|
|
||||||
#define R_Prt RedLight_GPIO_Port
|
|
||||||
#define Y_Prt YellowLight_GPIO_Port
|
|
||||||
#define G_Prt GreenLight_GPIO_Port
|
|
||||||
#define W_Prt WalkLight_GPIO_Port
|
|
||||||
|
|
||||||
uint32_t trafftick_last;
|
|
||||||
uint32_t walktick_last;
|
|
||||||
|
|
||||||
uint8_t trafflight_i = 0;
|
|
||||||
|
|
||||||
void
|
|
||||||
starttick(void)
|
|
||||||
{
|
|
||||||
trafftick_last = HAL_GetTick();
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
trafflight(int traffSPD, int walkSPD)
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
HAL_GPIO_TogglePin(R_Prt, R_Pin);
|
|
||||||
HAL_Delay(traffSPD);
|
|
||||||
HAL_GPIO_TogglePin(R_Prt, R_Pin);
|
|
||||||
|
|
||||||
HAL_GPIO_TogglePin(Y_Prt, Y_Pin);
|
|
||||||
HAL_Delay(traffSPD);
|
|
||||||
HAL_GPIO_TogglePin(Y_Prt, Y_Pin);
|
|
||||||
|
|
||||||
HAL_GPIO_TogglePin(G_Prt, G_Pin);
|
|
||||||
HAL_Delay(traffSPD);
|
|
||||||
HAL_GPIO_TogglePin(G_Prt, G_Pin);
|
|
||||||
*/
|
|
||||||
|
|
||||||
uint32_t trafftick_curr = HAL_GetTick();
|
|
||||||
|
|
||||||
if ((trafftick_curr - trafftick_last) >= traffSPD) {
|
|
||||||
HAL_GPIO_WritePin(R_Prt, R_Pin, GPIO_PIN_RESET);
|
|
||||||
HAL_GPIO_WritePin(Y_Prt, Y_Pin, GPIO_PIN_RESET);
|
|
||||||
HAL_GPIO_WritePin(G_Prt, G_Pin, GPIO_PIN_RESET);
|
|
||||||
|
|
||||||
switch (trafflight_i) {
|
|
||||||
case 0:
|
|
||||||
HAL_GPIO_WritePin(R_Prt, R_Pin, GPIO_PIN_SET);
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
HAL_GPIO_WritePin(Y_Prt, Y_Pin, GPIO_PIN_SET);
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
HAL_GPIO_WritePin(G_Prt, G_Pin, GPIO_PIN_SET);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
trafflight_i = (trafflight_i + 1) % 3;
|
|
||||||
trafftick_last = trafftick_curr;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((trafftick_curr - walktick_last) >= walkSPD) {
|
|
||||||
HAL_GPIO_TogglePin(W_Prt, W_Pin);
|
|
||||||
walktick_last = trafftick_curr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
635E684B79701B039C64EA45C3F84D30=76D5CABA7E36F5DD0D38ED323FA426B4
|
|
||||||
DC22A860405A8BF2F2C095E5B6529F12=BB3BD6F58A87E81DE6E549B37335B23A
|
|
||||||
eclipse.preferences.version=1
|
|
||||||
@@ -1,731 +0,0 @@
|
|||||||
/* USER CODE BEGIN Header */
|
|
||||||
/**
|
|
||||||
******************************************************************************
|
|
||||||
* @file : main.c
|
|
||||||
* @brief : Main program body
|
|
||||||
******************************************************************************
|
|
||||||
* @attention
|
|
||||||
*
|
|
||||||
* Copyright (c) 2025 STMicroelectronics.
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* This software is licensed under terms that can be found in the LICENSE file
|
|
||||||
* in the root directory of this software component.
|
|
||||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
|
||||||
*
|
|
||||||
******************************************************************************
|
|
||||||
*/
|
|
||||||
/* USER CODE END Header */
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
|
||||||
#include "main.h"
|
|
||||||
#include "cmsis_os.h"
|
|
||||||
#include "usb_host.h"
|
|
||||||
|
|
||||||
/* Private includes ----------------------------------------------------------*/
|
|
||||||
/* USER CODE BEGIN Includes */
|
|
||||||
#include "breadboard.h"
|
|
||||||
|
|
||||||
/* USER CODE END Includes */
|
|
||||||
|
|
||||||
/* Private typedef -----------------------------------------------------------*/
|
|
||||||
/* USER CODE BEGIN PTD */
|
|
||||||
|
|
||||||
/* USER CODE END PTD */
|
|
||||||
|
|
||||||
/* Private define ------------------------------------------------------------*/
|
|
||||||
/* USER CODE BEGIN PD */
|
|
||||||
|
|
||||||
/* USER CODE END PD */
|
|
||||||
|
|
||||||
/* Private macro -------------------------------------------------------------*/
|
|
||||||
/* USER CODE BEGIN PM */
|
|
||||||
|
|
||||||
/* USER CODE END PM */
|
|
||||||
|
|
||||||
/* Private variables ---------------------------------------------------------*/
|
|
||||||
CRC_HandleTypeDef hcrc;
|
|
||||||
|
|
||||||
DMA2D_HandleTypeDef hdma2d;
|
|
||||||
|
|
||||||
I2C_HandleTypeDef hi2c3;
|
|
||||||
|
|
||||||
LTDC_HandleTypeDef hltdc;
|
|
||||||
|
|
||||||
SPI_HandleTypeDef hspi5;
|
|
||||||
|
|
||||||
TIM_HandleTypeDef htim1;
|
|
||||||
|
|
||||||
UART_HandleTypeDef huart1;
|
|
||||||
|
|
||||||
SDRAM_HandleTypeDef hsdram1;
|
|
||||||
|
|
||||||
osThreadId defaultTaskHandle;
|
|
||||||
/* USER CODE BEGIN PV */
|
|
||||||
|
|
||||||
/* USER CODE END PV */
|
|
||||||
|
|
||||||
/* Private function prototypes -----------------------------------------------*/
|
|
||||||
void SystemClock_Config(void);
|
|
||||||
static void MX_GPIO_Init(void);
|
|
||||||
static void MX_CRC_Init(void);
|
|
||||||
static void MX_DMA2D_Init(void);
|
|
||||||
static void MX_FMC_Init(void);
|
|
||||||
static void MX_I2C3_Init(void);
|
|
||||||
static void MX_LTDC_Init(void);
|
|
||||||
static void MX_SPI5_Init(void);
|
|
||||||
static void MX_TIM1_Init(void);
|
|
||||||
static void MX_USART1_UART_Init(void);
|
|
||||||
void StartDefaultTask(void const * argument);
|
|
||||||
|
|
||||||
/* USER CODE BEGIN PFP */
|
|
||||||
|
|
||||||
/* USER CODE END PFP */
|
|
||||||
|
|
||||||
/* Private user code ---------------------------------------------------------*/
|
|
||||||
/* USER CODE BEGIN 0 */
|
|
||||||
|
|
||||||
/* USER CODE END 0 */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief The application entry point.
|
|
||||||
* @retval int
|
|
||||||
*/
|
|
||||||
int main(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* USER CODE BEGIN 1 */
|
|
||||||
|
|
||||||
/* USER CODE END 1 */
|
|
||||||
|
|
||||||
/* MCU Configuration--------------------------------------------------------*/
|
|
||||||
|
|
||||||
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
|
|
||||||
HAL_Init();
|
|
||||||
|
|
||||||
/* USER CODE BEGIN Init */
|
|
||||||
|
|
||||||
/* USER CODE END Init */
|
|
||||||
|
|
||||||
/* Configure the system clock */
|
|
||||||
SystemClock_Config();
|
|
||||||
|
|
||||||
/* USER CODE BEGIN SysInit */
|
|
||||||
|
|
||||||
/* USER CODE END SysInit */
|
|
||||||
|
|
||||||
/* Initialize all configured peripherals */
|
|
||||||
MX_GPIO_Init();
|
|
||||||
MX_CRC_Init();
|
|
||||||
MX_DMA2D_Init();
|
|
||||||
MX_FMC_Init();
|
|
||||||
MX_I2C3_Init();
|
|
||||||
MX_LTDC_Init();
|
|
||||||
MX_SPI5_Init();
|
|
||||||
MX_TIM1_Init();
|
|
||||||
MX_USART1_UART_Init();
|
|
||||||
/* USER CODE BEGIN 2 */
|
|
||||||
|
|
||||||
/* USER CODE END 2 */
|
|
||||||
|
|
||||||
/* USER CODE BEGIN RTOS_MUTEX */
|
|
||||||
/* add mutexes, ... */
|
|
||||||
/* USER CODE END RTOS_MUTEX */
|
|
||||||
|
|
||||||
/* USER CODE BEGIN RTOS_SEMAPHORES */
|
|
||||||
/* add semaphores, ... */
|
|
||||||
/* USER CODE END RTOS_SEMAPHORES */
|
|
||||||
|
|
||||||
/* USER CODE BEGIN RTOS_TIMERS */
|
|
||||||
/* start timers, add new ones, ... */
|
|
||||||
/* USER CODE END RTOS_TIMERS */
|
|
||||||
|
|
||||||
/* USER CODE BEGIN RTOS_QUEUES */
|
|
||||||
/* add queues, ... */
|
|
||||||
/* USER CODE END RTOS_QUEUES */
|
|
||||||
|
|
||||||
/* Create the thread(s) */
|
|
||||||
/* definition and creation of defaultTask */
|
|
||||||
//osThreadDef(defaultTask, StartDefaultTask, osPriorityNormal, 0, 4096);
|
|
||||||
//defaultTaskHandle = osThreadCreate(osThread(defaultTask), NULL);
|
|
||||||
|
|
||||||
/* USER CODE BEGIN RTOS_THREADS */
|
|
||||||
/* add threads, ... */
|
|
||||||
/* USER CODE END RTOS_THREADS */
|
|
||||||
|
|
||||||
/* Start scheduler */
|
|
||||||
//osKernelStart();
|
|
||||||
|
|
||||||
/* We should never get here as control is now taken by the scheduler */
|
|
||||||
|
|
||||||
/* Infinite loop */
|
|
||||||
/* USER CODE BEGIN WHILE */
|
|
||||||
while (1)
|
|
||||||
{
|
|
||||||
trafflight(333);
|
|
||||||
walksig(1000)
|
|
||||||
/* USER CODE END WHILE */
|
|
||||||
|
|
||||||
/* USER CODE BEGIN 3 */
|
|
||||||
}
|
|
||||||
/* USER CODE END 3 */
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief System Clock Configuration
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
void SystemClock_Config(void)
|
|
||||||
{
|
|
||||||
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
|
|
||||||
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
|
|
||||||
|
|
||||||
/** Configure the main internal regulator output voltage
|
|
||||||
*/
|
|
||||||
__HAL_RCC_PWR_CLK_ENABLE();
|
|
||||||
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE3);
|
|
||||||
|
|
||||||
/** Initializes the RCC Oscillators according to the specified parameters
|
|
||||||
* in the RCC_OscInitTypeDef structure.
|
|
||||||
*/
|
|
||||||
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
|
|
||||||
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
|
|
||||||
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
|
||||||
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
|
|
||||||
RCC_OscInitStruct.PLL.PLLM = 4;
|
|
||||||
RCC_OscInitStruct.PLL.PLLN = 72;
|
|
||||||
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
|
|
||||||
RCC_OscInitStruct.PLL.PLLQ = 3;
|
|
||||||
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Initializes the CPU, AHB and APB buses clocks
|
|
||||||
*/
|
|
||||||
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|
|
||||||
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
|
|
||||||
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
|
|
||||||
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
|
|
||||||
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
|
|
||||||
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
|
|
||||||
|
|
||||||
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief CRC Initialization Function
|
|
||||||
* @param None
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
static void MX_CRC_Init(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* USER CODE BEGIN CRC_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE END CRC_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE BEGIN CRC_Init 1 */
|
|
||||||
|
|
||||||
/* USER CODE END CRC_Init 1 */
|
|
||||||
hcrc.Instance = CRC;
|
|
||||||
if (HAL_CRC_Init(&hcrc) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
/* USER CODE BEGIN CRC_Init 2 */
|
|
||||||
|
|
||||||
/* USER CODE END CRC_Init 2 */
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief DMA2D Initialization Function
|
|
||||||
* @param None
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
static void MX_DMA2D_Init(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* USER CODE BEGIN DMA2D_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE END DMA2D_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE BEGIN DMA2D_Init 1 */
|
|
||||||
|
|
||||||
/* USER CODE END DMA2D_Init 1 */
|
|
||||||
hdma2d.Instance = DMA2D;
|
|
||||||
hdma2d.Init.Mode = DMA2D_M2M;
|
|
||||||
hdma2d.Init.ColorMode = DMA2D_OUTPUT_ARGB8888;
|
|
||||||
hdma2d.Init.OutputOffset = 0;
|
|
||||||
hdma2d.LayerCfg[1].InputOffset = 0;
|
|
||||||
hdma2d.LayerCfg[1].InputColorMode = DMA2D_INPUT_ARGB8888;
|
|
||||||
hdma2d.LayerCfg[1].AlphaMode = DMA2D_NO_MODIF_ALPHA;
|
|
||||||
hdma2d.LayerCfg[1].InputAlpha = 0;
|
|
||||||
if (HAL_DMA2D_Init(&hdma2d) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
if (HAL_DMA2D_ConfigLayer(&hdma2d, 1) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
/* USER CODE BEGIN DMA2D_Init 2 */
|
|
||||||
|
|
||||||
/* USER CODE END DMA2D_Init 2 */
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief I2C3 Initialization Function
|
|
||||||
* @param None
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
static void MX_I2C3_Init(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* USER CODE BEGIN I2C3_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE END I2C3_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE BEGIN I2C3_Init 1 */
|
|
||||||
|
|
||||||
/* USER CODE END I2C3_Init 1 */
|
|
||||||
hi2c3.Instance = I2C3;
|
|
||||||
hi2c3.Init.ClockSpeed = 100000;
|
|
||||||
hi2c3.Init.DutyCycle = I2C_DUTYCYCLE_2;
|
|
||||||
hi2c3.Init.OwnAddress1 = 0;
|
|
||||||
hi2c3.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
|
|
||||||
hi2c3.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
|
|
||||||
hi2c3.Init.OwnAddress2 = 0;
|
|
||||||
hi2c3.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
|
|
||||||
hi2c3.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
|
|
||||||
if (HAL_I2C_Init(&hi2c3) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Configure Analogue filter
|
|
||||||
*/
|
|
||||||
if (HAL_I2CEx_ConfigAnalogFilter(&hi2c3, I2C_ANALOGFILTER_ENABLE) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Configure Digital filter
|
|
||||||
*/
|
|
||||||
if (HAL_I2CEx_ConfigDigitalFilter(&hi2c3, 0) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
/* USER CODE BEGIN I2C3_Init 2 */
|
|
||||||
|
|
||||||
/* USER CODE END I2C3_Init 2 */
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief LTDC Initialization Function
|
|
||||||
* @param None
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
static void MX_LTDC_Init(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* USER CODE BEGIN LTDC_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE END LTDC_Init 0 */
|
|
||||||
|
|
||||||
LTDC_LayerCfgTypeDef pLayerCfg = {0};
|
|
||||||
|
|
||||||
/* USER CODE BEGIN LTDC_Init 1 */
|
|
||||||
|
|
||||||
/* USER CODE END LTDC_Init 1 */
|
|
||||||
hltdc.Instance = LTDC;
|
|
||||||
hltdc.Init.HSPolarity = LTDC_HSPOLARITY_AL;
|
|
||||||
hltdc.Init.VSPolarity = LTDC_VSPOLARITY_AL;
|
|
||||||
hltdc.Init.DEPolarity = LTDC_DEPOLARITY_AL;
|
|
||||||
hltdc.Init.PCPolarity = LTDC_PCPOLARITY_IPC;
|
|
||||||
hltdc.Init.HorizontalSync = 9;
|
|
||||||
hltdc.Init.VerticalSync = 1;
|
|
||||||
hltdc.Init.AccumulatedHBP = 29;
|
|
||||||
hltdc.Init.AccumulatedVBP = 3;
|
|
||||||
hltdc.Init.AccumulatedActiveW = 269;
|
|
||||||
hltdc.Init.AccumulatedActiveH = 323;
|
|
||||||
hltdc.Init.TotalWidth = 279;
|
|
||||||
hltdc.Init.TotalHeigh = 327;
|
|
||||||
hltdc.Init.Backcolor.Blue = 0;
|
|
||||||
hltdc.Init.Backcolor.Green = 0;
|
|
||||||
hltdc.Init.Backcolor.Red = 0;
|
|
||||||
if (HAL_LTDC_Init(&hltdc) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
pLayerCfg.WindowX0 = 0;
|
|
||||||
pLayerCfg.WindowX1 = 240;
|
|
||||||
pLayerCfg.WindowY0 = 0;
|
|
||||||
pLayerCfg.WindowY1 = 320;
|
|
||||||
pLayerCfg.PixelFormat = LTDC_PIXEL_FORMAT_RGB565;
|
|
||||||
pLayerCfg.Alpha = 255;
|
|
||||||
pLayerCfg.Alpha0 = 0;
|
|
||||||
pLayerCfg.BlendingFactor1 = LTDC_BLENDING_FACTOR1_PAxCA;
|
|
||||||
pLayerCfg.BlendingFactor2 = LTDC_BLENDING_FACTOR2_PAxCA;
|
|
||||||
pLayerCfg.FBStartAdress = 0xD0000000;
|
|
||||||
pLayerCfg.ImageWidth = 240;
|
|
||||||
pLayerCfg.ImageHeight = 320;
|
|
||||||
pLayerCfg.Backcolor.Blue = 0;
|
|
||||||
pLayerCfg.Backcolor.Green = 0;
|
|
||||||
pLayerCfg.Backcolor.Red = 0;
|
|
||||||
if (HAL_LTDC_ConfigLayer(&hltdc, &pLayerCfg, 0) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
/* USER CODE BEGIN LTDC_Init 2 */
|
|
||||||
|
|
||||||
/* USER CODE END LTDC_Init 2 */
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief SPI5 Initialization Function
|
|
||||||
* @param None
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
static void MX_SPI5_Init(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* USER CODE BEGIN SPI5_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE END SPI5_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE BEGIN SPI5_Init 1 */
|
|
||||||
|
|
||||||
/* USER CODE END SPI5_Init 1 */
|
|
||||||
/* SPI5 parameter configuration*/
|
|
||||||
hspi5.Instance = SPI5;
|
|
||||||
hspi5.Init.Mode = SPI_MODE_MASTER;
|
|
||||||
hspi5.Init.Direction = SPI_DIRECTION_2LINES;
|
|
||||||
hspi5.Init.DataSize = SPI_DATASIZE_8BIT;
|
|
||||||
hspi5.Init.CLKPolarity = SPI_POLARITY_LOW;
|
|
||||||
hspi5.Init.CLKPhase = SPI_PHASE_1EDGE;
|
|
||||||
hspi5.Init.NSS = SPI_NSS_SOFT;
|
|
||||||
hspi5.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_16;
|
|
||||||
hspi5.Init.FirstBit = SPI_FIRSTBIT_MSB;
|
|
||||||
hspi5.Init.TIMode = SPI_TIMODE_DISABLE;
|
|
||||||
hspi5.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
|
|
||||||
hspi5.Init.CRCPolynomial = 10;
|
|
||||||
if (HAL_SPI_Init(&hspi5) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
/* USER CODE BEGIN SPI5_Init 2 */
|
|
||||||
|
|
||||||
/* USER CODE END SPI5_Init 2 */
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief TIM1 Initialization Function
|
|
||||||
* @param None
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
static void MX_TIM1_Init(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* USER CODE BEGIN TIM1_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE END TIM1_Init 0 */
|
|
||||||
|
|
||||||
TIM_ClockConfigTypeDef sClockSourceConfig = {0};
|
|
||||||
TIM_MasterConfigTypeDef sMasterConfig = {0};
|
|
||||||
|
|
||||||
/* USER CODE BEGIN TIM1_Init 1 */
|
|
||||||
|
|
||||||
/* USER CODE END TIM1_Init 1 */
|
|
||||||
htim1.Instance = TIM1;
|
|
||||||
htim1.Init.Prescaler = 0;
|
|
||||||
htim1.Init.CounterMode = TIM_COUNTERMODE_UP;
|
|
||||||
htim1.Init.Period = 65535;
|
|
||||||
htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
|
||||||
htim1.Init.RepetitionCounter = 0;
|
|
||||||
htim1.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
|
|
||||||
if (HAL_TIM_Base_Init(&htim1) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
|
|
||||||
if (HAL_TIM_ConfigClockSource(&htim1, &sClockSourceConfig) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
|
|
||||||
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
|
|
||||||
if (HAL_TIMEx_MasterConfigSynchronization(&htim1, &sMasterConfig) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
/* USER CODE BEGIN TIM1_Init 2 */
|
|
||||||
|
|
||||||
/* USER CODE END TIM1_Init 2 */
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief USART1 Initialization Function
|
|
||||||
* @param None
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
static void MX_USART1_UART_Init(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* USER CODE BEGIN USART1_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE END USART1_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE BEGIN USART1_Init 1 */
|
|
||||||
|
|
||||||
/* USER CODE END USART1_Init 1 */
|
|
||||||
huart1.Instance = USART1;
|
|
||||||
huart1.Init.BaudRate = 115200;
|
|
||||||
huart1.Init.WordLength = UART_WORDLENGTH_8B;
|
|
||||||
huart1.Init.StopBits = UART_STOPBITS_1;
|
|
||||||
huart1.Init.Parity = UART_PARITY_NONE;
|
|
||||||
huart1.Init.Mode = UART_MODE_TX_RX;
|
|
||||||
huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
|
|
||||||
huart1.Init.OverSampling = UART_OVERSAMPLING_16;
|
|
||||||
if (HAL_UART_Init(&huart1) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
/* USER CODE BEGIN USART1_Init 2 */
|
|
||||||
|
|
||||||
/* USER CODE END USART1_Init 2 */
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/* FMC initialization function */
|
|
||||||
static void MX_FMC_Init(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* USER CODE BEGIN FMC_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE END FMC_Init 0 */
|
|
||||||
|
|
||||||
FMC_SDRAM_TimingTypeDef SdramTiming = {0};
|
|
||||||
|
|
||||||
/* USER CODE BEGIN FMC_Init 1 */
|
|
||||||
|
|
||||||
/* USER CODE END FMC_Init 1 */
|
|
||||||
|
|
||||||
/** Perform the SDRAM1 memory initialization sequence
|
|
||||||
*/
|
|
||||||
hsdram1.Instance = FMC_SDRAM_DEVICE;
|
|
||||||
/* hsdram1.Init */
|
|
||||||
hsdram1.Init.SDBank = FMC_SDRAM_BANK2;
|
|
||||||
hsdram1.Init.ColumnBitsNumber = FMC_SDRAM_COLUMN_BITS_NUM_8;
|
|
||||||
hsdram1.Init.RowBitsNumber = FMC_SDRAM_ROW_BITS_NUM_12;
|
|
||||||
hsdram1.Init.MemoryDataWidth = FMC_SDRAM_MEM_BUS_WIDTH_16;
|
|
||||||
hsdram1.Init.InternalBankNumber = FMC_SDRAM_INTERN_BANKS_NUM_4;
|
|
||||||
hsdram1.Init.CASLatency = FMC_SDRAM_CAS_LATENCY_3;
|
|
||||||
hsdram1.Init.WriteProtection = FMC_SDRAM_WRITE_PROTECTION_DISABLE;
|
|
||||||
hsdram1.Init.SDClockPeriod = FMC_SDRAM_CLOCK_PERIOD_2;
|
|
||||||
hsdram1.Init.ReadBurst = FMC_SDRAM_RBURST_DISABLE;
|
|
||||||
hsdram1.Init.ReadPipeDelay = FMC_SDRAM_RPIPE_DELAY_1;
|
|
||||||
/* SdramTiming */
|
|
||||||
SdramTiming.LoadToActiveDelay = 2;
|
|
||||||
SdramTiming.ExitSelfRefreshDelay = 7;
|
|
||||||
SdramTiming.SelfRefreshTime = 4;
|
|
||||||
SdramTiming.RowCycleDelay = 7;
|
|
||||||
SdramTiming.WriteRecoveryTime = 3;
|
|
||||||
SdramTiming.RPDelay = 2;
|
|
||||||
SdramTiming.RCDDelay = 2;
|
|
||||||
|
|
||||||
if (HAL_SDRAM_Init(&hsdram1, &SdramTiming) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler( );
|
|
||||||
}
|
|
||||||
|
|
||||||
/* USER CODE BEGIN FMC_Init 2 */
|
|
||||||
|
|
||||||
/* USER CODE END FMC_Init 2 */
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief GPIO Initialization Function
|
|
||||||
* @param None
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
static void MX_GPIO_Init(void)
|
|
||||||
{
|
|
||||||
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
|
||||||
/* USER CODE BEGIN MX_GPIO_Init_1 */
|
|
||||||
|
|
||||||
/* USER CODE END MX_GPIO_Init_1 */
|
|
||||||
|
|
||||||
/* GPIO Ports Clock Enable */
|
|
||||||
__HAL_RCC_GPIOE_CLK_ENABLE();
|
|
||||||
__HAL_RCC_GPIOC_CLK_ENABLE();
|
|
||||||
__HAL_RCC_GPIOF_CLK_ENABLE();
|
|
||||||
__HAL_RCC_GPIOH_CLK_ENABLE();
|
|
||||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
|
||||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
|
||||||
__HAL_RCC_GPIOG_CLK_ENABLE();
|
|
||||||
__HAL_RCC_GPIOD_CLK_ENABLE();
|
|
||||||
|
|
||||||
/*Configure GPIO pin Output Level */
|
|
||||||
HAL_GPIO_WritePin(GPIOE, RedLight_Pin|YellowLight_Pin|GreenLight_Pin|WalkLight_Pin, GPIO_PIN_RESET);
|
|
||||||
|
|
||||||
/*Configure GPIO pin Output Level */
|
|
||||||
HAL_GPIO_WritePin(GPIOC, NCS_MEMS_SPI_Pin|CSX_Pin|OTG_FS_PSO_Pin, GPIO_PIN_RESET);
|
|
||||||
|
|
||||||
/*Configure GPIO pin Output Level */
|
|
||||||
HAL_GPIO_WritePin(ACP_RST_GPIO_Port, ACP_RST_Pin, GPIO_PIN_RESET);
|
|
||||||
|
|
||||||
/*Configure GPIO pin Output Level */
|
|
||||||
HAL_GPIO_WritePin(GPIOD, RDX_Pin|WRX_DCX_Pin, GPIO_PIN_RESET);
|
|
||||||
|
|
||||||
/*Configure GPIO pin Output Level */
|
|
||||||
HAL_GPIO_WritePin(GPIOG, LD3_Pin|LD4_Pin, GPIO_PIN_RESET);
|
|
||||||
|
|
||||||
/*Configure GPIO pins : RedLight_Pin YellowLight_Pin GreenLight_Pin WalkLight_Pin */
|
|
||||||
GPIO_InitStruct.Pin = RedLight_Pin|YellowLight_Pin|GreenLight_Pin|WalkLight_Pin;
|
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
||||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
|
||||||
HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
|
|
||||||
|
|
||||||
/*Configure GPIO pins : NCS_MEMS_SPI_Pin CSX_Pin OTG_FS_PSO_Pin */
|
|
||||||
GPIO_InitStruct.Pin = NCS_MEMS_SPI_Pin|CSX_Pin|OTG_FS_PSO_Pin;
|
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
||||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
|
||||||
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
|
|
||||||
|
|
||||||
/*Configure GPIO pins : B1_Pin MEMS_INT1_Pin MEMS_INT2_Pin TP_INT1_Pin */
|
|
||||||
GPIO_InitStruct.Pin = B1_Pin|MEMS_INT1_Pin|MEMS_INT2_Pin|TP_INT1_Pin;
|
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_EVT_RISING;
|
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
||||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
|
||||||
|
|
||||||
/*Configure GPIO pin : ACP_RST_Pin */
|
|
||||||
GPIO_InitStruct.Pin = ACP_RST_Pin;
|
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
||||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
|
||||||
HAL_GPIO_Init(ACP_RST_GPIO_Port, &GPIO_InitStruct);
|
|
||||||
|
|
||||||
/*Configure GPIO pin : OTG_FS_OC_Pin */
|
|
||||||
GPIO_InitStruct.Pin = OTG_FS_OC_Pin;
|
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_EVT_RISING;
|
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
||||||
HAL_GPIO_Init(OTG_FS_OC_GPIO_Port, &GPIO_InitStruct);
|
|
||||||
|
|
||||||
/*Configure GPIO pin : BOOT1_Pin */
|
|
||||||
GPIO_InitStruct.Pin = BOOT1_Pin;
|
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
||||||
HAL_GPIO_Init(BOOT1_GPIO_Port, &GPIO_InitStruct);
|
|
||||||
|
|
||||||
/*Configure GPIO pin : TE_Pin */
|
|
||||||
GPIO_InitStruct.Pin = TE_Pin;
|
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
||||||
HAL_GPIO_Init(TE_GPIO_Port, &GPIO_InitStruct);
|
|
||||||
|
|
||||||
/*Configure GPIO pins : RDX_Pin WRX_DCX_Pin */
|
|
||||||
GPIO_InitStruct.Pin = RDX_Pin|WRX_DCX_Pin;
|
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
||||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
|
||||||
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
|
|
||||||
|
|
||||||
/*Configure GPIO pins : LD3_Pin LD4_Pin */
|
|
||||||
GPIO_InitStruct.Pin = LD3_Pin|LD4_Pin;
|
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
||||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
|
||||||
HAL_GPIO_Init(GPIOG, &GPIO_InitStruct);
|
|
||||||
|
|
||||||
/* USER CODE BEGIN MX_GPIO_Init_2 */
|
|
||||||
|
|
||||||
/* USER CODE END MX_GPIO_Init_2 */
|
|
||||||
}
|
|
||||||
|
|
||||||
/* USER CODE BEGIN 4 */
|
|
||||||
|
|
||||||
/* USER CODE END 4 */
|
|
||||||
|
|
||||||
/* USER CODE BEGIN Header_StartDefaultTask */
|
|
||||||
/**
|
|
||||||
* @brief Function implementing the defaultTask thread.
|
|
||||||
* @param argument: Not used
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
/* USER CODE END Header_StartDefaultTask */
|
|
||||||
void StartDefaultTask(void const * argument)
|
|
||||||
{
|
|
||||||
/* init code for USB_HOST */
|
|
||||||
MX_USB_HOST_Init();
|
|
||||||
/* USER CODE BEGIN 5 */
|
|
||||||
/* Infinite loop */
|
|
||||||
for(;;)
|
|
||||||
{
|
|
||||||
osDelay(1);
|
|
||||||
}
|
|
||||||
/* USER CODE END 5 */
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Period elapsed callback in non blocking mode
|
|
||||||
* @note This function is called when TIM6 interrupt took place, inside
|
|
||||||
* HAL_TIM_IRQHandler(). It makes a direct call to HAL_IncTick() to increment
|
|
||||||
* a global variable "uwTick" used as application time base.
|
|
||||||
* @param htim : TIM handle
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
|
|
||||||
{
|
|
||||||
/* USER CODE BEGIN Callback 0 */
|
|
||||||
|
|
||||||
/* USER CODE END Callback 0 */
|
|
||||||
if (htim->Instance == TIM6)
|
|
||||||
{
|
|
||||||
HAL_IncTick();
|
|
||||||
}
|
|
||||||
/* USER CODE BEGIN Callback 1 */
|
|
||||||
|
|
||||||
/* USER CODE END Callback 1 */
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief This function is executed in case of error occurrence.
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
void Error_Handler(void)
|
|
||||||
{
|
|
||||||
/* USER CODE BEGIN Error_Handler_Debug */
|
|
||||||
/* User can add his own implementation to report the HAL error return state */
|
|
||||||
__disable_irq();
|
|
||||||
while (1)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
/* USER CODE END Error_Handler_Debug */
|
|
||||||
}
|
|
||||||
#ifdef USE_FULL_ASSERT
|
|
||||||
/**
|
|
||||||
* @brief Reports the name of the source file and the source line number
|
|
||||||
* where the assert_param error has occurred.
|
|
||||||
* @param file: pointer to the source file name
|
|
||||||
* @param line: assert_param error line source number
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
void assert_failed(uint8_t *file, uint32_t line)
|
|
||||||
{
|
|
||||||
/* USER CODE BEGIN 6 */
|
|
||||||
/* User can add his own implementation to report the file name and line number,
|
|
||||||
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
|
|
||||||
/* USER CODE END 6 */
|
|
||||||
}
|
|
||||||
#endif /* USE_FULL_ASSERT */
|
|
||||||
@@ -1,92 +0,0 @@
|
|||||||
/*
|
|
||||||
* breadboard.c
|
|
||||||
*
|
|
||||||
* Created on: Sep 17, 2025
|
|
||||||
* Author: ja
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* #define RedLight_Pin GPIO_PIN_2
|
|
||||||
* #define RedLight_GPIO_Port GPIOE
|
|
||||||
*
|
|
||||||
* #define YellowLight_Pin GPIO_PIN_3
|
|
||||||
* #define YellowLight_GPIO_Port GPIOE
|
|
||||||
*
|
|
||||||
* #define GreenLight_Pin GPIO_PIN_4
|
|
||||||
* #define GreenLight_GPIO_Port GPIOE
|
|
||||||
*
|
|
||||||
* RedLight: PE2
|
|
||||||
* YellowLight: PE3
|
|
||||||
* GreenLight: PE4
|
|
||||||
* WalkLight: PE5
|
|
||||||
*
|
|
||||||
* Done: Traffic Light
|
|
||||||
* TODO: async? Walk Signal, Light Dimmer
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "main.h"
|
|
||||||
#include "breadboard.h"
|
|
||||||
|
|
||||||
#define R_Pin RedLight_Pin
|
|
||||||
#define Y_Pin YellowLight_Pin
|
|
||||||
#define G_Pin GreenLight_Pin
|
|
||||||
#define W_Pin WalkLight_Pin
|
|
||||||
|
|
||||||
#define R_Prt RedLight_GPIO_Port
|
|
||||||
#define Y_Prt YellowLight_GPIO_Port
|
|
||||||
#define G_Prt GreenLight_GPIO_Port
|
|
||||||
#define W_Prt WalkLight_GPIO_Port
|
|
||||||
|
|
||||||
uint32_t trafftick_last;
|
|
||||||
|
|
||||||
uint8_t trafflight_i = 0;
|
|
||||||
|
|
||||||
void
|
|
||||||
starttick(void)
|
|
||||||
{
|
|
||||||
trafftick_last = HAL_GetTick();
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
trafflight(int traffSPD)
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
HAL_GPIO_TogglePin(R_Prt, R_Pin);
|
|
||||||
HAL_Delay(traffSPD);
|
|
||||||
HAL_GPIO_TogglePin(R_Prt, R_Pin);
|
|
||||||
|
|
||||||
HAL_GPIO_TogglePin(Y_Prt, Y_Pin);
|
|
||||||
HAL_Delay(traffSPD);
|
|
||||||
HAL_GPIO_TogglePin(Y_Prt, Y_Pin);
|
|
||||||
|
|
||||||
HAL_GPIO_TogglePin(G_Prt, G_Pin);
|
|
||||||
HAL_Delay(traffSPD);
|
|
||||||
HAL_GPIO_TogglePin(G_Prt, G_Pin);
|
|
||||||
*/
|
|
||||||
|
|
||||||
uint32_t trafftick_curr = HAL_GetTick();
|
|
||||||
|
|
||||||
if ((trafftick_curr - trafftick_last) >= traffSPD) {
|
|
||||||
HAL_GPIO_WritePin(
|
|
||||||
R_Prt, R_Pin |
|
|
||||||
Y_Prt, Y_Pin |
|
|
||||||
G_Prt, G_Pin,
|
|
||||||
GPIO_PIN_RESET
|
|
||||||
);
|
|
||||||
|
|
||||||
switch (trafflight_i) {
|
|
||||||
case 0:
|
|
||||||
HAL_GPIO_WritePin(R_Prt, R_Pin);
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
HAL_GPIO_WritePin(Y_Prt, Y_Pin);
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
HAL_GPIO_WritePin(G_Prt, G_Pin);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
trafflight_i = (trafflight_i + 1) % 3;
|
|
||||||
trafftick_last = trafftick_curr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
635E684B79701B039C64EA45C3F84D30=76D5CABA7E36F5DD0D38ED323FA426B4
|
|
||||||
66BE74F758C12D739921AEA421D593D3=0
|
|
||||||
DC22A860405A8BF2F2C095E5B6529F12=BB3BD6F58A87E81DE6E549B37335B23A
|
|
||||||
eclipse.preferences.version=1
|
|
||||||
@@ -1,82 +0,0 @@
|
|||||||
/*
|
|
||||||
* breadboard.c
|
|
||||||
*
|
|
||||||
* Created on: Sep 17, 2025
|
|
||||||
* Author: ja
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* #define RedLight_Pin GPIO_PIN_2
|
|
||||||
* #define RedLight_GPIO_Port GPIOE
|
|
||||||
*
|
|
||||||
* #define YellowLight_Pin GPIO_PIN_3
|
|
||||||
* #define YellowLight_GPIO_Port GPIOE
|
|
||||||
*
|
|
||||||
* #define GreenLight_Pin GPIO_PIN_4
|
|
||||||
* #define GreenLight_GPIO_Port GPIOE
|
|
||||||
*
|
|
||||||
* RedLight: PE2
|
|
||||||
* YellowLight: PE3
|
|
||||||
* GreenLight: PE4
|
|
||||||
* WalkLight: PE5
|
|
||||||
*
|
|
||||||
* Done: Traffic Light
|
|
||||||
* TODO: async? Walk Signal, Light Dimmer
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "main.h"
|
|
||||||
#include "breadboard.h"
|
|
||||||
|
|
||||||
#define R_Pin RedLight_Pin
|
|
||||||
#define Y_Pin YellowLight_Pin
|
|
||||||
#define G_Pin GreenLight_Pin
|
|
||||||
#define W_Pin WalkLight_Pin
|
|
||||||
|
|
||||||
#define R_Prt RedLight_GPIO_Port
|
|
||||||
#define Y_Prt YellowLight_GPIO_Port
|
|
||||||
#define G_Prt GreenLight_GPIO_Port
|
|
||||||
#define W_Prt WalkLight_GPIO_Port
|
|
||||||
|
|
||||||
uint32_t trafftick_last;
|
|
||||||
|
|
||||||
uint8_t trafflight_i = 0;
|
|
||||||
|
|
||||||
void
|
|
||||||
starttick(void)
|
|
||||||
{
|
|
||||||
trafftick_last = HAL_GetTick();
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
trafflight(int traffSPD)
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
HAL_GPIO_TogglePin(R_Prt, R_Pin);
|
|
||||||
HAL_Delay(traffSPD);
|
|
||||||
HAL_GPIO_TogglePin(R_Prt, R_Pin);
|
|
||||||
|
|
||||||
HAL_GPIO_TogglePin(Y_Prt, Y_Pin);
|
|
||||||
HAL_Delay(traffSPD);
|
|
||||||
HAL_GPIO_TogglePin(Y_Prt, Y_Pin);
|
|
||||||
|
|
||||||
HAL_GPIO_TogglePin(G_Prt, G_Pin);
|
|
||||||
HAL_Delay(traffSPD);
|
|
||||||
HAL_GPIO_TogglePin(G_Prt, G_Pin);
|
|
||||||
*/
|
|
||||||
|
|
||||||
uint32_t trafftick_curr = HAL_GetTick();
|
|
||||||
|
|
||||||
if ((trafftick_curr - trafftick_last) >= traffSPD) {
|
|
||||||
HAL_GPIO_WritePin(
|
|
||||||
R_Prt, R_Pin |
|
|
||||||
Y_Prt, Y_Pin |
|
|
||||||
G_Prt, G_Pin,
|
|
||||||
GPIO_PIN_RESET
|
|
||||||
);
|
|
||||||
|
|
||||||
switch (trafflight_i) {
|
|
||||||
case 0:
|
|
||||||
HAL_GPIO_WritePin();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,69 +0,0 @@
|
|||||||
/*
|
|
||||||
* breadboard.c
|
|
||||||
*
|
|
||||||
* Created on: Sep 17, 2025
|
|
||||||
* Author: ja
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* #define RedLight_Pin GPIO_PIN_2
|
|
||||||
* #define RedLight_GPIO_Port GPIOE
|
|
||||||
*
|
|
||||||
* #define YellowLight_Pin GPIO_PIN_3
|
|
||||||
* #define YellowLight_GPIO_Port GPIOE
|
|
||||||
*
|
|
||||||
* #define GreenLight_Pin GPIO_PIN_4
|
|
||||||
* #define GreenLight_GPIO_Port GPIOE
|
|
||||||
*
|
|
||||||
* RedLight: PE2
|
|
||||||
* YellowLight: PE3
|
|
||||||
* GreenLight: PE4
|
|
||||||
* WalkLight: PE5
|
|
||||||
*
|
|
||||||
* Done: Traffic Light
|
|
||||||
* TODO: async? Walk Signal, Light Dimmer
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "main.h"
|
|
||||||
#include "breadboard.h"
|
|
||||||
|
|
||||||
#define R_Pin RedLight_Pin
|
|
||||||
#define Y_Pin YellowLight_Pin
|
|
||||||
#define G_Pin GreenLight_Pin
|
|
||||||
#define W_Pin WalkLight_Pin
|
|
||||||
|
|
||||||
#define R_Prt RedLight_GPIO_Port
|
|
||||||
#define Y_Prt YellowLight_GPIO_Port
|
|
||||||
#define G_Prt GreenLight_GPIO_Port
|
|
||||||
#define W_Prt WalkLight_GPIO_Port
|
|
||||||
|
|
||||||
uint32_t trafftick_last;
|
|
||||||
|
|
||||||
void
|
|
||||||
starttick(void)
|
|
||||||
{
|
|
||||||
trafftick_last = HAL_GetTick();
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
trafflight(int traffSPD)
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
HAL_GPIO_TogglePin(R_Prt, R_Pin);
|
|
||||||
HAL_Delay(traffSPD);
|
|
||||||
HAL_GPIO_TogglePin(R_Prt, R_Pin);
|
|
||||||
|
|
||||||
HAL_GPIO_TogglePin(Y_Prt, Y_Pin);
|
|
||||||
HAL_Delay(traffSPD);
|
|
||||||
HAL_GPIO_TogglePin(Y_Prt, Y_Pin);
|
|
||||||
|
|
||||||
HAL_GPIO_TogglePin(G_Prt, G_Pin);
|
|
||||||
HAL_Delay(traffSPD);
|
|
||||||
HAL_GPIO_TogglePin(G_Prt, G_Pin);
|
|
||||||
*/
|
|
||||||
|
|
||||||
uint32_t trafftick_curr = HAL_GetTick();
|
|
||||||
|
|
||||||
if ((trafftick_curr - trafftick_last) >= traffSPD)
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,499 @@
|
|||||||
|
/* USER CODE BEGIN Header */
|
||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
* @file : main.c
|
||||||
|
* @brief : Main program body
|
||||||
|
******************************************************************************
|
||||||
|
* @attention
|
||||||
|
*
|
||||||
|
* Copyright (c) 2025 STMicroelectronics.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This software is licensed under terms that can be found in the LICENSE file
|
||||||
|
* in the root directory of this software component.
|
||||||
|
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||||
|
*
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
/* USER CODE END Header */
|
||||||
|
/* Includes ------------------------------------------------------------------*/
|
||||||
|
#include "main.h"
|
||||||
|
#include "cmsis_os.h"
|
||||||
|
|
||||||
|
/* Private includes ----------------------------------------------------------*/
|
||||||
|
/* USER CODE BEGIN Includes */
|
||||||
|
#include "breadboard.h"
|
||||||
|
#include <stdbool.h>
|
||||||
|
/* USER CODE END Includes */
|
||||||
|
|
||||||
|
/* Private typedef -----------------------------------------------------------*/
|
||||||
|
/* USER CODE BEGIN PTD */
|
||||||
|
|
||||||
|
/* USER CODE END PTD */
|
||||||
|
|
||||||
|
/* Private define ------------------------------------------------------------*/
|
||||||
|
/* USER CODE BEGIN PD */
|
||||||
|
|
||||||
|
/* USER CODE END PD */
|
||||||
|
|
||||||
|
/* Private macro -------------------------------------------------------------*/
|
||||||
|
/* USER CODE BEGIN PM */
|
||||||
|
|
||||||
|
/* USER CODE END PM */
|
||||||
|
|
||||||
|
/* Private variables ---------------------------------------------------------*/
|
||||||
|
CRC_HandleTypeDef hcrc;
|
||||||
|
|
||||||
|
DMA2D_HandleTypeDef hdma2d;
|
||||||
|
|
||||||
|
TIM_HandleTypeDef htim1;
|
||||||
|
|
||||||
|
osThreadId defaultTaskHandle;
|
||||||
|
/* USER CODE BEGIN PV */
|
||||||
|
|
||||||
|
/* USER CODE END PV */
|
||||||
|
|
||||||
|
/* Private function prototypes -----------------------------------------------*/
|
||||||
|
void SystemClock_Config(void);
|
||||||
|
static void MX_GPIO_Init(void);
|
||||||
|
static void MX_CRC_Init(void);
|
||||||
|
static void MX_DMA2D_Init(void);
|
||||||
|
static void MX_TIM1_Init(void);
|
||||||
|
void StartDefaultTask(void const * argument);
|
||||||
|
|
||||||
|
void SetTrafficLights(TrafficSate s);
|
||||||
|
|
||||||
|
/* USER CODE BEGIN PFP */
|
||||||
|
|
||||||
|
/* USER CODE END PFP */
|
||||||
|
|
||||||
|
/* Private user code ---------------------------------------------------------*/
|
||||||
|
|
||||||
|
/* USER CODE BEGIN 0 */
|
||||||
|
|
||||||
|
enum class TrafficState {
|
||||||
|
GREEN,
|
||||||
|
YELLOW,
|
||||||
|
RED
|
||||||
|
};
|
||||||
|
|
||||||
|
TrafficState currentState = TrafficState::GREEN;
|
||||||
|
uint32_t stateStartTime = 0; // HAL_GetTick() at the start of this state
|
||||||
|
bool buttonPressed = false;
|
||||||
|
bool pedestrianNextCycle = false;
|
||||||
|
|
||||||
|
const uint32_t DURATION_GREEN = 5000;
|
||||||
|
const uint32_t DURATION_YELLOW = 3000;
|
||||||
|
const uint32_t DURATION_RED = 5000;
|
||||||
|
const uint32_t DURATION_RED_PED = 7000;
|
||||||
|
|
||||||
|
/* USER CODE END 0 */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief The application entry point.
|
||||||
|
* @retval int
|
||||||
|
*/
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* USER CODE BEGIN 1 */
|
||||||
|
|
||||||
|
/* USER CODE END 1 */
|
||||||
|
|
||||||
|
/* MCU Configuration--------------------------------------------------------*/
|
||||||
|
|
||||||
|
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
|
||||||
|
HAL_Init();
|
||||||
|
|
||||||
|
/* USER CODE BEGIN Init */
|
||||||
|
|
||||||
|
/* USER CODE END Init */
|
||||||
|
|
||||||
|
/* Configure the system clock */
|
||||||
|
SystemClock_Config();
|
||||||
|
|
||||||
|
/* USER CODE BEGIN SysInit */
|
||||||
|
|
||||||
|
stateStartTime = HAL_GetTick();
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
|
||||||
|
/* USER CODE END SysInit */
|
||||||
|
|
||||||
|
/* Initialize all configured peripherals */
|
||||||
|
MX_GPIO_Init();
|
||||||
|
MX_CRC_Init();
|
||||||
|
MX_DMA2D_Init();
|
||||||
|
MX_TIM1_Init();
|
||||||
|
/* USER CODE BEGIN 2 */
|
||||||
|
|
||||||
|
/* USER CODE END 2 */
|
||||||
|
|
||||||
|
/* USER CODE BEGIN RTOS_MUTEX */
|
||||||
|
/* add mutexes, ... */
|
||||||
|
/* USER CODE END RTOS_MUTEX */
|
||||||
|
|
||||||
|
/* USER CODE BEGIN RTOS_SEMAPHORES */
|
||||||
|
/* add semaphores, ... */
|
||||||
|
/* USER CODE END RTOS_SEMAPHORES */
|
||||||
|
|
||||||
|
/* USER CODE BEGIN RTOS_TIMERS */
|
||||||
|
/* start timers, add new ones, ... */
|
||||||
|
/* USER CODE END RTOS_TIMERS */
|
||||||
|
|
||||||
|
/* USER CODE BEGIN RTOS_QUEUES */
|
||||||
|
/* add queues, ... */
|
||||||
|
/* USER CODE END RTOS_QUEUES */
|
||||||
|
|
||||||
|
/* Create the thread(s) */
|
||||||
|
/* definition and creation of defaultTask */
|
||||||
|
//osThreadDef(defaultTask, StartDefaultTask, osPriorityNormal, 0, 4096);
|
||||||
|
//defaultTaskHandle = osThreadCreate(osThread(defaultTask), NULL);
|
||||||
|
|
||||||
|
/* USER CODE BEGIN RTOS_THREADS */
|
||||||
|
/* add threads, ... */
|
||||||
|
/* USER CODE END RTOS_THREADS */
|
||||||
|
|
||||||
|
/* Start scheduler */
|
||||||
|
osKernelStart();
|
||||||
|
|
||||||
|
/* We should never get here as control is now taken by the scheduler */
|
||||||
|
|
||||||
|
/* Infinite loop */
|
||||||
|
/* USER CODE BEGIN WHILE */
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
uint32_t now = HAL_GetTick();
|
||||||
|
uint32_t elapsed = now - stateStartTime;
|
||||||
|
|
||||||
|
/*
|
||||||
|
switch(currentState)
|
||||||
|
{
|
||||||
|
case TrafficState::GREEN:
|
||||||
|
if (elapsed >= DURATION_GREEN) {
|
||||||
|
currentState = TrafficState::YELLOW;
|
||||||
|
stateStartTime = now;
|
||||||
|
buttonPressed = false; // reset the button-flag for the new cycle
|
||||||
|
} else if (buttonPressed) {
|
||||||
|
//idk
|
||||||
|
buttonPressed = true;
|
||||||
|
currentState = TrafficState::YELLOW;
|
||||||
|
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case TrafficState::YELLOW:
|
||||||
|
break;
|
||||||
|
case TrafficState::RED:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
switch(currentState)
|
||||||
|
{
|
||||||
|
case TrafficState::GREEN:
|
||||||
|
if (butonPressedThisCycle)
|
||||||
|
{
|
||||||
|
currentState = TrafficState::YELLOW;
|
||||||
|
stateStartTime = now;
|
||||||
|
buttonPressedThisCycle = false;
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
} else if (buttonPressedThisCycle)
|
||||||
|
{
|
||||||
|
buttonPressedThisCycle = true;
|
||||||
|
currentState = TrafficState::YELLOW;
|
||||||
|
stateStartTime = now;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* USER CODE END WHILE */
|
||||||
|
|
||||||
|
/* USER CODE BEGIN 3 */
|
||||||
|
}
|
||||||
|
/* USER CODE END 3 */
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief System Clock Configuration
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void SystemClock_Config(void)
|
||||||
|
{
|
||||||
|
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
|
||||||
|
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
|
||||||
|
|
||||||
|
/** Configure the main internal regulator output voltage
|
||||||
|
*/
|
||||||
|
__HAL_RCC_PWR_CLK_ENABLE();
|
||||||
|
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE3);
|
||||||
|
|
||||||
|
/** Initializes the RCC Oscillators according to the specified parameters
|
||||||
|
* in the RCC_OscInitTypeDef structure.
|
||||||
|
*/
|
||||||
|
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
|
||||||
|
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
|
||||||
|
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
|
||||||
|
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
||||||
|
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
|
||||||
|
RCC_OscInitStruct.PLL.PLLM = 8;
|
||||||
|
RCC_OscInitStruct.PLL.PLLN = 72;
|
||||||
|
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
|
||||||
|
RCC_OscInitStruct.PLL.PLLQ = 3;
|
||||||
|
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Initializes the CPU, AHB and APB buses clocks
|
||||||
|
*/
|
||||||
|
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|
||||||
|
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
|
||||||
|
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
|
||||||
|
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
|
||||||
|
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
|
||||||
|
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
|
||||||
|
|
||||||
|
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief CRC Initialization Function
|
||||||
|
* @param None
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
static void MX_CRC_Init(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* USER CODE BEGIN CRC_Init 0 */
|
||||||
|
|
||||||
|
/* USER CODE END CRC_Init 0 */
|
||||||
|
|
||||||
|
/* USER CODE BEGIN CRC_Init 1 */
|
||||||
|
|
||||||
|
/* USER CODE END CRC_Init 1 */
|
||||||
|
hcrc.Instance = CRC;
|
||||||
|
if (HAL_CRC_Init(&hcrc) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
/* USER CODE BEGIN CRC_Init 2 */
|
||||||
|
|
||||||
|
/* USER CODE END CRC_Init 2 */
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief DMA2D Initialization Function
|
||||||
|
* @param None
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
static void MX_DMA2D_Init(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* USER CODE BEGIN DMA2D_Init 0 */
|
||||||
|
|
||||||
|
/* USER CODE END DMA2D_Init 0 */
|
||||||
|
|
||||||
|
/* USER CODE BEGIN DMA2D_Init 1 */
|
||||||
|
|
||||||
|
/* USER CODE END DMA2D_Init 1 */
|
||||||
|
hdma2d.Instance = DMA2D;
|
||||||
|
hdma2d.Init.Mode = DMA2D_M2M;
|
||||||
|
hdma2d.Init.ColorMode = DMA2D_OUTPUT_ARGB8888;
|
||||||
|
hdma2d.Init.OutputOffset = 0;
|
||||||
|
hdma2d.LayerCfg[1].InputOffset = 0;
|
||||||
|
hdma2d.LayerCfg[1].InputColorMode = DMA2D_INPUT_ARGB8888;
|
||||||
|
hdma2d.LayerCfg[1].AlphaMode = DMA2D_NO_MODIF_ALPHA;
|
||||||
|
hdma2d.LayerCfg[1].InputAlpha = 0;
|
||||||
|
if (HAL_DMA2D_Init(&hdma2d) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
if (HAL_DMA2D_ConfigLayer(&hdma2d, 1) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
/* USER CODE BEGIN DMA2D_Init 2 */
|
||||||
|
|
||||||
|
/* USER CODE END DMA2D_Init 2 */
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief TIM1 Initialization Function
|
||||||
|
* @param None
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
static void MX_TIM1_Init(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* USER CODE BEGIN TIM1_Init 0 */
|
||||||
|
|
||||||
|
/* USER CODE END TIM1_Init 0 */
|
||||||
|
|
||||||
|
TIM_ClockConfigTypeDef sClockSourceConfig = {0};
|
||||||
|
TIM_MasterConfigTypeDef sMasterConfig = {0};
|
||||||
|
|
||||||
|
/* USER CODE BEGIN TIM1_Init 1 */
|
||||||
|
|
||||||
|
/* USER CODE END TIM1_Init 1 */
|
||||||
|
htim1.Instance = TIM1;
|
||||||
|
htim1.Init.Prescaler = 0;
|
||||||
|
htim1.Init.CounterMode = TIM_COUNTERMODE_UP;
|
||||||
|
htim1.Init.Period = 65535;
|
||||||
|
htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
||||||
|
htim1.Init.RepetitionCounter = 0;
|
||||||
|
htim1.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
|
||||||
|
if (HAL_TIM_Base_Init(&htim1) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
|
||||||
|
if (HAL_TIM_ConfigClockSource(&htim1, &sClockSourceConfig) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
|
||||||
|
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
|
||||||
|
if (HAL_TIMEx_MasterConfigSynchronization(&htim1, &sMasterConfig) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
/* USER CODE BEGIN TIM1_Init 2 */
|
||||||
|
|
||||||
|
/* USER CODE END TIM1_Init 2 */
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief GPIO Initialization Function
|
||||||
|
* @param None
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
static void MX_GPIO_Init(void)
|
||||||
|
{
|
||||||
|
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||||
|
/* USER CODE BEGIN MX_GPIO_Init_1 */
|
||||||
|
|
||||||
|
/* USER CODE END MX_GPIO_Init_1 */
|
||||||
|
|
||||||
|
/* GPIO Ports Clock Enable */
|
||||||
|
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||||
|
__HAL_RCC_GPIOD_CLK_ENABLE();
|
||||||
|
|
||||||
|
/*Configure GPIO pin Output Level */
|
||||||
|
HAL_GPIO_WritePin(GPIOD, White_Pin|Red_Pin|Yellow_Pin|Green_Pin, GPIO_PIN_RESET);
|
||||||
|
|
||||||
|
/*Configure GPIO pin : PedButton_Pin */
|
||||||
|
GPIO_InitStruct.Pin = PedButton_Pin;
|
||||||
|
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
|
||||||
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
|
HAL_GPIO_Init(PedButton_GPIO_Port, &GPIO_InitStruct);
|
||||||
|
|
||||||
|
/*Configure GPIO pins : White_Pin Red_Pin Yellow_Pin Green_Pin */
|
||||||
|
GPIO_InitStruct.Pin = White_Pin|Red_Pin|Yellow_Pin|Green_Pin;
|
||||||
|
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||||
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||||
|
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
|
||||||
|
|
||||||
|
/* EXTI interrupt init*/
|
||||||
|
HAL_NVIC_SetPriority(EXTI15_10_IRQn, 15, 0);
|
||||||
|
HAL_NVIC_EnableIRQ(EXTI15_10_IRQn);
|
||||||
|
|
||||||
|
/* USER CODE BEGIN MX_GPIO_Init_2 */
|
||||||
|
|
||||||
|
/* USER CODE END MX_GPIO_Init_2 */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* USER CODE BEGIN 4 */
|
||||||
|
|
||||||
|
void HAL_GPIO_EXTI_CallBack(uint16_t GPIO_Pin)
|
||||||
|
{
|
||||||
|
static uint32_t lastInterruptTime = 0;
|
||||||
|
uint32_t now = HAL_GetTick();
|
||||||
|
if (now - lastInterruptTime < 100) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
lastInterruptTime = now;
|
||||||
|
|
||||||
|
bool buttonPressedThisCycle = false; // temporary, get rid of this
|
||||||
|
|
||||||
|
if (buttonPressed) { // buttonPressedHere?
|
||||||
|
buttonPressedThisCycle = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* USER CODE END 4 */
|
||||||
|
|
||||||
|
/* USER CODE BEGIN Header_StartDefaultTask */
|
||||||
|
/**
|
||||||
|
* @brief Function implementing the defaultTask thread.
|
||||||
|
* @param argument: Not used
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
/* USER CODE END Header_StartDefaultTask */
|
||||||
|
void StartDefaultTask(void const * argument)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN 5 */
|
||||||
|
/* Infinite loop */
|
||||||
|
for(;;)
|
||||||
|
{
|
||||||
|
osDelay(1);
|
||||||
|
}
|
||||||
|
/* USER CODE END 5 */
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Period elapsed callback in non blocking mode
|
||||||
|
* @note This function is called when TIM6 interrupt took place, inside
|
||||||
|
* HAL_TIM_IRQHandler(). It makes a direct call to HAL_IncTick() to increment
|
||||||
|
* a global variable "uwTick" used as application time base.
|
||||||
|
* @param htim : TIM handle
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN Callback 0 */
|
||||||
|
|
||||||
|
/* USER CODE END Callback 0 */
|
||||||
|
if (htim->Instance == TIM6)
|
||||||
|
{
|
||||||
|
HAL_IncTick();
|
||||||
|
}
|
||||||
|
/* USER CODE BEGIN Callback 1 */
|
||||||
|
|
||||||
|
/* USER CODE END Callback 1 */
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function is executed in case of error occurrence.
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void Error_Handler(void)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN Error_Handler_Debug */
|
||||||
|
/* User can add his own implementation to report the HAL error return state */
|
||||||
|
__disable_irq();
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
/* USER CODE END Error_Handler_Debug */
|
||||||
|
}
|
||||||
|
#ifdef USE_FULL_ASSERT
|
||||||
|
/**
|
||||||
|
* @brief Reports the name of the source file and the source line number
|
||||||
|
* where the assert_param error has occurred.
|
||||||
|
* @param file: pointer to the source file name
|
||||||
|
* @param line: assert_param error line source number
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void assert_failed(uint8_t *file, uint32_t line)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN 6 */
|
||||||
|
/* User can add his own implementation to report the file name and line number,
|
||||||
|
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
|
||||||
|
/* USER CODE END 6 */
|
||||||
|
}
|
||||||
|
#endif /* USE_FULL_ASSERT */
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
/*
|
|
||||||
* breadboard.cpp
|
|
||||||
*
|
|
||||||
* Created on: Sep 22, 2025
|
|
||||||
* Author: ja
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "breadboard.h"
|
|
||||||
|
|
||||||
void SetTrafficLights(TrafficState s)
|
|
||||||
{
|
|
||||||
HAL_GPIO_WritePin(LED_Port,
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,499 @@
|
|||||||
|
/* USER CODE BEGIN Header */
|
||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
* @file : main.c
|
||||||
|
* @brief : Main program body
|
||||||
|
******************************************************************************
|
||||||
|
* @attention
|
||||||
|
*
|
||||||
|
* Copyright (c) 2025 STMicroelectronics.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This software is licensed under terms that can be found in the LICENSE file
|
||||||
|
* in the root directory of this software component.
|
||||||
|
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||||
|
*
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
/* USER CODE END Header */
|
||||||
|
/* Includes ------------------------------------------------------------------*/
|
||||||
|
#include "main.h"
|
||||||
|
#include "cmsis_os.h"
|
||||||
|
|
||||||
|
/* Private includes ----------------------------------------------------------*/
|
||||||
|
/* USER CODE BEGIN Includes */
|
||||||
|
#include "breadboard.h"
|
||||||
|
#include <stdbool.h>
|
||||||
|
/* USER CODE END Includes */
|
||||||
|
|
||||||
|
/* Private typedef -----------------------------------------------------------*/
|
||||||
|
/* USER CODE BEGIN PTD */
|
||||||
|
|
||||||
|
/* USER CODE END PTD */
|
||||||
|
|
||||||
|
/* Private define ------------------------------------------------------------*/
|
||||||
|
/* USER CODE BEGIN PD */
|
||||||
|
|
||||||
|
/* USER CODE END PD */
|
||||||
|
|
||||||
|
/* Private macro -------------------------------------------------------------*/
|
||||||
|
/* USER CODE BEGIN PM */
|
||||||
|
|
||||||
|
/* USER CODE END PM */
|
||||||
|
|
||||||
|
/* Private variables ---------------------------------------------------------*/
|
||||||
|
CRC_HandleTypeDef hcrc;
|
||||||
|
|
||||||
|
DMA2D_HandleTypeDef hdma2d;
|
||||||
|
|
||||||
|
TIM_HandleTypeDef htim1;
|
||||||
|
|
||||||
|
osThreadId defaultTaskHandle;
|
||||||
|
/* USER CODE BEGIN PV */
|
||||||
|
|
||||||
|
/* USER CODE END PV */
|
||||||
|
|
||||||
|
/* Private function prototypes -----------------------------------------------*/
|
||||||
|
void SystemClock_Config(void);
|
||||||
|
static void MX_GPIO_Init(void);
|
||||||
|
static void MX_CRC_Init(void);
|
||||||
|
static void MX_DMA2D_Init(void);
|
||||||
|
static void MX_TIM1_Init(void);
|
||||||
|
void StartDefaultTask(void const * argument);
|
||||||
|
|
||||||
|
void SetTrafficLights(TrafficSate s);
|
||||||
|
|
||||||
|
/* USER CODE BEGIN PFP */
|
||||||
|
|
||||||
|
/* USER CODE END PFP */
|
||||||
|
|
||||||
|
/* Private user code ---------------------------------------------------------*/
|
||||||
|
|
||||||
|
/* USER CODE BEGIN 0 */
|
||||||
|
|
||||||
|
enum class TrafficState {
|
||||||
|
GREEN,
|
||||||
|
YELLOW,
|
||||||
|
RED
|
||||||
|
};
|
||||||
|
|
||||||
|
TrafficState currentState = TrafficState::GREEN;
|
||||||
|
uint32_t stateStartTime = 0; // HAL_GetTick() at the start of this state
|
||||||
|
bool buttonPressed = false;
|
||||||
|
bool pedestrianNextCycle = false;
|
||||||
|
|
||||||
|
const uint32_t DURATION_GREEN = 5000;
|
||||||
|
const uint32_t DURATION_YELLOW = 3000;
|
||||||
|
const uint32_t DURATION_RED = 5000;
|
||||||
|
const uint32_t DURATION_RED_PED = 7000;
|
||||||
|
|
||||||
|
/* USER CODE END 0 */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief The application entry point.
|
||||||
|
* @retval int
|
||||||
|
*/
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* USER CODE BEGIN 1 */
|
||||||
|
|
||||||
|
/* USER CODE END 1 */
|
||||||
|
|
||||||
|
/* MCU Configuration--------------------------------------------------------*/
|
||||||
|
|
||||||
|
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
|
||||||
|
HAL_Init();
|
||||||
|
|
||||||
|
/* USER CODE BEGIN Init */
|
||||||
|
|
||||||
|
/* USER CODE END Init */
|
||||||
|
|
||||||
|
/* Configure the system clock */
|
||||||
|
SystemClock_Config();
|
||||||
|
|
||||||
|
/* USER CODE BEGIN SysInit */
|
||||||
|
|
||||||
|
stateStartTime = HAL_GetTick();
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
|
||||||
|
/* USER CODE END SysInit */
|
||||||
|
|
||||||
|
/* Initialize all configured peripherals */
|
||||||
|
MX_GPIO_Init();
|
||||||
|
MX_CRC_Init();
|
||||||
|
MX_DMA2D_Init();
|
||||||
|
MX_TIM1_Init();
|
||||||
|
/* USER CODE BEGIN 2 */
|
||||||
|
|
||||||
|
/* USER CODE END 2 */
|
||||||
|
|
||||||
|
/* USER CODE BEGIN RTOS_MUTEX */
|
||||||
|
/* add mutexes, ... */
|
||||||
|
/* USER CODE END RTOS_MUTEX */
|
||||||
|
|
||||||
|
/* USER CODE BEGIN RTOS_SEMAPHORES */
|
||||||
|
/* add semaphores, ... */
|
||||||
|
/* USER CODE END RTOS_SEMAPHORES */
|
||||||
|
|
||||||
|
/* USER CODE BEGIN RTOS_TIMERS */
|
||||||
|
/* start timers, add new ones, ... */
|
||||||
|
/* USER CODE END RTOS_TIMERS */
|
||||||
|
|
||||||
|
/* USER CODE BEGIN RTOS_QUEUES */
|
||||||
|
/* add queues, ... */
|
||||||
|
/* USER CODE END RTOS_QUEUES */
|
||||||
|
|
||||||
|
/* Create the thread(s) */
|
||||||
|
/* definition and creation of defaultTask */
|
||||||
|
//osThreadDef(defaultTask, StartDefaultTask, osPriorityNormal, 0, 4096);
|
||||||
|
//defaultTaskHandle = osThreadCreate(osThread(defaultTask), NULL);
|
||||||
|
|
||||||
|
/* USER CODE BEGIN RTOS_THREADS */
|
||||||
|
/* add threads, ... */
|
||||||
|
/* USER CODE END RTOS_THREADS */
|
||||||
|
|
||||||
|
/* Start scheduler */
|
||||||
|
osKernelStart();
|
||||||
|
|
||||||
|
/* We should never get here as control is now taken by the scheduler */
|
||||||
|
|
||||||
|
/* Infinite loop */
|
||||||
|
/* USER CODE BEGIN WHILE */
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
uint32_t now = HAL_GetTick();
|
||||||
|
uint32_t elapsed = now - stateStartTime;
|
||||||
|
|
||||||
|
/*
|
||||||
|
switch(currentState)
|
||||||
|
{
|
||||||
|
case TrafficState::GREEN:
|
||||||
|
if (elapsed >= DURATION_GREEN) {
|
||||||
|
currentState = TrafficState::YELLOW;
|
||||||
|
stateStartTime = now;
|
||||||
|
buttonPressed = false; // reset the button-flag for the new cycle
|
||||||
|
} else if (buttonPressed) {
|
||||||
|
//idk
|
||||||
|
buttonPressed = true;
|
||||||
|
currentState = TrafficState::YELLOW;
|
||||||
|
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case TrafficState::YELLOW:
|
||||||
|
break;
|
||||||
|
case TrafficState::RED:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
switch(currentState)
|
||||||
|
{
|
||||||
|
case TrafficState::GREEN:
|
||||||
|
if (butonPressedThisCycle)
|
||||||
|
{
|
||||||
|
currentState = TrafficState::YELLOW;
|
||||||
|
stateStartTime = now;
|
||||||
|
buttonPressedThisCycle = false;
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
} else if (elapsed >= DURATION_GREEN)
|
||||||
|
{
|
||||||
|
buttonPressedThisCycle = true;
|
||||||
|
currentState = TrafficState::YELLOW;
|
||||||
|
stateStartTime = now;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* USER CODE END WHILE */
|
||||||
|
|
||||||
|
/* USER CODE BEGIN 3 */
|
||||||
|
}
|
||||||
|
/* USER CODE END 3 */
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief System Clock Configuration
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void SystemClock_Config(void)
|
||||||
|
{
|
||||||
|
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
|
||||||
|
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
|
||||||
|
|
||||||
|
/** Configure the main internal regulator output voltage
|
||||||
|
*/
|
||||||
|
__HAL_RCC_PWR_CLK_ENABLE();
|
||||||
|
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE3);
|
||||||
|
|
||||||
|
/** Initializes the RCC Oscillators according to the specified parameters
|
||||||
|
* in the RCC_OscInitTypeDef structure.
|
||||||
|
*/
|
||||||
|
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
|
||||||
|
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
|
||||||
|
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
|
||||||
|
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
||||||
|
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
|
||||||
|
RCC_OscInitStruct.PLL.PLLM = 8;
|
||||||
|
RCC_OscInitStruct.PLL.PLLN = 72;
|
||||||
|
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
|
||||||
|
RCC_OscInitStruct.PLL.PLLQ = 3;
|
||||||
|
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Initializes the CPU, AHB and APB buses clocks
|
||||||
|
*/
|
||||||
|
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|
||||||
|
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
|
||||||
|
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
|
||||||
|
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
|
||||||
|
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
|
||||||
|
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
|
||||||
|
|
||||||
|
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief CRC Initialization Function
|
||||||
|
* @param None
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
static void MX_CRC_Init(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* USER CODE BEGIN CRC_Init 0 */
|
||||||
|
|
||||||
|
/* USER CODE END CRC_Init 0 */
|
||||||
|
|
||||||
|
/* USER CODE BEGIN CRC_Init 1 */
|
||||||
|
|
||||||
|
/* USER CODE END CRC_Init 1 */
|
||||||
|
hcrc.Instance = CRC;
|
||||||
|
if (HAL_CRC_Init(&hcrc) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
/* USER CODE BEGIN CRC_Init 2 */
|
||||||
|
|
||||||
|
/* USER CODE END CRC_Init 2 */
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief DMA2D Initialization Function
|
||||||
|
* @param None
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
static void MX_DMA2D_Init(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* USER CODE BEGIN DMA2D_Init 0 */
|
||||||
|
|
||||||
|
/* USER CODE END DMA2D_Init 0 */
|
||||||
|
|
||||||
|
/* USER CODE BEGIN DMA2D_Init 1 */
|
||||||
|
|
||||||
|
/* USER CODE END DMA2D_Init 1 */
|
||||||
|
hdma2d.Instance = DMA2D;
|
||||||
|
hdma2d.Init.Mode = DMA2D_M2M;
|
||||||
|
hdma2d.Init.ColorMode = DMA2D_OUTPUT_ARGB8888;
|
||||||
|
hdma2d.Init.OutputOffset = 0;
|
||||||
|
hdma2d.LayerCfg[1].InputOffset = 0;
|
||||||
|
hdma2d.LayerCfg[1].InputColorMode = DMA2D_INPUT_ARGB8888;
|
||||||
|
hdma2d.LayerCfg[1].AlphaMode = DMA2D_NO_MODIF_ALPHA;
|
||||||
|
hdma2d.LayerCfg[1].InputAlpha = 0;
|
||||||
|
if (HAL_DMA2D_Init(&hdma2d) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
if (HAL_DMA2D_ConfigLayer(&hdma2d, 1) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
/* USER CODE BEGIN DMA2D_Init 2 */
|
||||||
|
|
||||||
|
/* USER CODE END DMA2D_Init 2 */
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief TIM1 Initialization Function
|
||||||
|
* @param None
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
static void MX_TIM1_Init(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* USER CODE BEGIN TIM1_Init 0 */
|
||||||
|
|
||||||
|
/* USER CODE END TIM1_Init 0 */
|
||||||
|
|
||||||
|
TIM_ClockConfigTypeDef sClockSourceConfig = {0};
|
||||||
|
TIM_MasterConfigTypeDef sMasterConfig = {0};
|
||||||
|
|
||||||
|
/* USER CODE BEGIN TIM1_Init 1 */
|
||||||
|
|
||||||
|
/* USER CODE END TIM1_Init 1 */
|
||||||
|
htim1.Instance = TIM1;
|
||||||
|
htim1.Init.Prescaler = 0;
|
||||||
|
htim1.Init.CounterMode = TIM_COUNTERMODE_UP;
|
||||||
|
htim1.Init.Period = 65535;
|
||||||
|
htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
||||||
|
htim1.Init.RepetitionCounter = 0;
|
||||||
|
htim1.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
|
||||||
|
if (HAL_TIM_Base_Init(&htim1) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
|
||||||
|
if (HAL_TIM_ConfigClockSource(&htim1, &sClockSourceConfig) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
|
||||||
|
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
|
||||||
|
if (HAL_TIMEx_MasterConfigSynchronization(&htim1, &sMasterConfig) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
/* USER CODE BEGIN TIM1_Init 2 */
|
||||||
|
|
||||||
|
/* USER CODE END TIM1_Init 2 */
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief GPIO Initialization Function
|
||||||
|
* @param None
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
static void MX_GPIO_Init(void)
|
||||||
|
{
|
||||||
|
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||||
|
/* USER CODE BEGIN MX_GPIO_Init_1 */
|
||||||
|
|
||||||
|
/* USER CODE END MX_GPIO_Init_1 */
|
||||||
|
|
||||||
|
/* GPIO Ports Clock Enable */
|
||||||
|
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||||
|
__HAL_RCC_GPIOD_CLK_ENABLE();
|
||||||
|
|
||||||
|
/*Configure GPIO pin Output Level */
|
||||||
|
HAL_GPIO_WritePin(GPIOD, White_Pin|Red_Pin|Yellow_Pin|Green_Pin, GPIO_PIN_RESET);
|
||||||
|
|
||||||
|
/*Configure GPIO pin : PedButton_Pin */
|
||||||
|
GPIO_InitStruct.Pin = PedButton_Pin;
|
||||||
|
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
|
||||||
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
|
HAL_GPIO_Init(PedButton_GPIO_Port, &GPIO_InitStruct);
|
||||||
|
|
||||||
|
/*Configure GPIO pins : White_Pin Red_Pin Yellow_Pin Green_Pin */
|
||||||
|
GPIO_InitStruct.Pin = White_Pin|Red_Pin|Yellow_Pin|Green_Pin;
|
||||||
|
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||||
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||||
|
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
|
||||||
|
|
||||||
|
/* EXTI interrupt init*/
|
||||||
|
HAL_NVIC_SetPriority(EXTI15_10_IRQn, 15, 0);
|
||||||
|
HAL_NVIC_EnableIRQ(EXTI15_10_IRQn);
|
||||||
|
|
||||||
|
/* USER CODE BEGIN MX_GPIO_Init_2 */
|
||||||
|
|
||||||
|
/* USER CODE END MX_GPIO_Init_2 */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* USER CODE BEGIN 4 */
|
||||||
|
|
||||||
|
void HAL_GPIO_EXTI_CallBack(uint16_t GPIO_Pin)
|
||||||
|
{
|
||||||
|
static uint32_t lastInterruptTime = 0;
|
||||||
|
uint32_t now = HAL_GetTick();
|
||||||
|
if (now - lastInterruptTime < 100) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
lastInterruptTime = now;
|
||||||
|
|
||||||
|
bool buttonPressedThisCycle = false; // temporary, get rid of this
|
||||||
|
|
||||||
|
if (buttonPressed) { // buttonPressedHere?
|
||||||
|
buttonPressedThisCycle = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* USER CODE END 4 */
|
||||||
|
|
||||||
|
/* USER CODE BEGIN Header_StartDefaultTask */
|
||||||
|
/**
|
||||||
|
* @brief Function implementing the defaultTask thread.
|
||||||
|
* @param argument: Not used
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
/* USER CODE END Header_StartDefaultTask */
|
||||||
|
void StartDefaultTask(void const * argument)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN 5 */
|
||||||
|
/* Infinite loop */
|
||||||
|
for(;;)
|
||||||
|
{
|
||||||
|
osDelay(1);
|
||||||
|
}
|
||||||
|
/* USER CODE END 5 */
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Period elapsed callback in non blocking mode
|
||||||
|
* @note This function is called when TIM6 interrupt took place, inside
|
||||||
|
* HAL_TIM_IRQHandler(). It makes a direct call to HAL_IncTick() to increment
|
||||||
|
* a global variable "uwTick" used as application time base.
|
||||||
|
* @param htim : TIM handle
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN Callback 0 */
|
||||||
|
|
||||||
|
/* USER CODE END Callback 0 */
|
||||||
|
if (htim->Instance == TIM6)
|
||||||
|
{
|
||||||
|
HAL_IncTick();
|
||||||
|
}
|
||||||
|
/* USER CODE BEGIN Callback 1 */
|
||||||
|
|
||||||
|
/* USER CODE END Callback 1 */
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function is executed in case of error occurrence.
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void Error_Handler(void)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN Error_Handler_Debug */
|
||||||
|
/* User can add his own implementation to report the HAL error return state */
|
||||||
|
__disable_irq();
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
/* USER CODE END Error_Handler_Debug */
|
||||||
|
}
|
||||||
|
#ifdef USE_FULL_ASSERT
|
||||||
|
/**
|
||||||
|
* @brief Reports the name of the source file and the source line number
|
||||||
|
* where the assert_param error has occurred.
|
||||||
|
* @param file: pointer to the source file name
|
||||||
|
* @param line: assert_param error line source number
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void assert_failed(uint8_t *file, uint32_t line)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN 6 */
|
||||||
|
/* User can add his own implementation to report the file name and line number,
|
||||||
|
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
|
||||||
|
/* USER CODE END 6 */
|
||||||
|
}
|
||||||
|
#endif /* USE_FULL_ASSERT */
|
||||||
@@ -1,97 +0,0 @@
|
|||||||
/*
|
|
||||||
* breadboard.c
|
|
||||||
*
|
|
||||||
* Created on: Sep 17, 2025
|
|
||||||
* Author: ja
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* #define RedLight_Pin GPIO_PIN_2
|
|
||||||
* #define RedLight_GPIO_Port GPIOE
|
|
||||||
*
|
|
||||||
* #define YellowLight_Pin GPIO_PIN_3
|
|
||||||
* #define YellowLight_GPIO_Port GPIOE
|
|
||||||
*
|
|
||||||
* #define GreenLight_Pin GPIO_PIN_4
|
|
||||||
* #define GreenLight_GPIO_Port GPIOE
|
|
||||||
*
|
|
||||||
* RedLight: PE2
|
|
||||||
* YellowLight: PE3
|
|
||||||
* GreenLight: PE4
|
|
||||||
* WalkLight: PE5
|
|
||||||
*
|
|
||||||
* Done: Traffic Light
|
|
||||||
* TODO: async? Walk Signal, Light Dimmer
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "main.h"
|
|
||||||
#include "breadboard.h"
|
|
||||||
|
|
||||||
#define R_Pin RedLight_Pin
|
|
||||||
#define Y_Pin YellowLight_Pin
|
|
||||||
#define G_Pin GreenLight_Pin
|
|
||||||
#define W_Pin WalkLight_Pin
|
|
||||||
|
|
||||||
#define R_Prt RedLight_GPIO_Port
|
|
||||||
#define Y_Prt YellowLight_GPIO_Port
|
|
||||||
#define G_Prt GreenLight_GPIO_Port
|
|
||||||
#define W_Prt WalkLight_GPIO_Port
|
|
||||||
|
|
||||||
uint32_t trafftick_last;
|
|
||||||
uint32_t walktick_last;
|
|
||||||
|
|
||||||
uint8_t trafflight_i = 0;
|
|
||||||
|
|
||||||
void
|
|
||||||
starttick(void)
|
|
||||||
{
|
|
||||||
trafftick_last = HAL_GetTick();
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
trafflight(int traffSPD)
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
HAL_GPIO_TogglePin(R_Prt, R_Pin);
|
|
||||||
HAL_Delay(traffSPD);
|
|
||||||
HAL_GPIO_TogglePin(R_Prt, R_Pin);
|
|
||||||
|
|
||||||
HAL_GPIO_TogglePin(Y_Prt, Y_Pin);
|
|
||||||
HAL_Delay(traffSPD);
|
|
||||||
HAL_GPIO_TogglePin(Y_Prt, Y_Pin);
|
|
||||||
|
|
||||||
HAL_GPIO_TogglePin(G_Prt, G_Pin);
|
|
||||||
HAL_Delay(traffSPD);
|
|
||||||
HAL_GPIO_TogglePin(G_Prt, G_Pin);
|
|
||||||
*/
|
|
||||||
|
|
||||||
uint32_t trafftick_curr = HAL_GetTick();
|
|
||||||
|
|
||||||
if ((trafftick_curr - trafftick_last) >= traffSPD) {
|
|
||||||
HAL_GPIO_WritePin(
|
|
||||||
R_Prt, R_Pin |
|
|
||||||
Y_Prt, Y_Pin |
|
|
||||||
G_Prt, G_Pin,
|
|
||||||
GPIO_PIN_RESET
|
|
||||||
);
|
|
||||||
|
|
||||||
switch (trafflight_i) {
|
|
||||||
case 0:
|
|
||||||
HAL_GPIO_WritePin(R_Prt, R_Pin);
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
HAL_GPIO_WritePin(Y_Prt, Y_Pin);
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
HAL_GPIO_WritePin(G_Prt, G_Pin);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
trafflight_i = (trafflight_i + 1) % 3;
|
|
||||||
trafftick_last = trafftick_curr;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((trafftick_curr - walktick_last) >= walkSPD) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
/*
|
|
||||||
* breadboard.cpp
|
|
||||||
*
|
|
||||||
* Created on: Sep 22, 2025
|
|
||||||
* Author: ja
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "breadboard.h"
|
|
||||||
|
|
||||||
void breadboard(void)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
@@ -1,85 +0,0 @@
|
|||||||
/*
|
|
||||||
* breadboard.c
|
|
||||||
*
|
|
||||||
* Created on: Sep 17, 2025
|
|
||||||
* Author: ja
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* #define RedLight_Pin GPIO_PIN_2
|
|
||||||
* #define RedLight_GPIO_Port GPIOE
|
|
||||||
*
|
|
||||||
* #define YellowLight_Pin GPIO_PIN_3
|
|
||||||
* #define YellowLight_GPIO_Port GPIOE
|
|
||||||
*
|
|
||||||
* #define GreenLight_Pin GPIO_PIN_4
|
|
||||||
* #define GreenLight_GPIO_Port GPIOE
|
|
||||||
*
|
|
||||||
* RedLight: PE2
|
|
||||||
* YellowLight: PE3
|
|
||||||
* GreenLight: PE4
|
|
||||||
* WalkLight: PE5
|
|
||||||
*
|
|
||||||
* Done: Traffic Light
|
|
||||||
* TODO: async? Walk Signal, Light Dimmer
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "main.h"
|
|
||||||
#include "breadboard.h"
|
|
||||||
|
|
||||||
#define R_Pin RedLight_Pin
|
|
||||||
#define Y_Pin YellowLight_Pin
|
|
||||||
#define G_Pin GreenLight_Pin
|
|
||||||
#define W_Pin WalkLight_Pin
|
|
||||||
|
|
||||||
#define R_Prt RedLight_GPIO_Port
|
|
||||||
#define Y_Prt YellowLight_GPIO_Port
|
|
||||||
#define G_Prt GreenLight_GPIO_Port
|
|
||||||
#define W_Prt WalkLight_GPIO_Port
|
|
||||||
|
|
||||||
uint32_t redlight_last;
|
|
||||||
uint32_t ylwlight_last;
|
|
||||||
uint32_t grnlight_last;
|
|
||||||
|
|
||||||
void
|
|
||||||
starttick(void)
|
|
||||||
{
|
|
||||||
trafftick_last = HAL_GetTick();
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
trafflight(int traffSPD)
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
HAL_GPIO_TogglePin(R_Prt, R_Pin);
|
|
||||||
HAL_Delay(traffSPD);
|
|
||||||
HAL_GPIO_TogglePin(R_Prt, R_Pin);
|
|
||||||
|
|
||||||
HAL_GPIO_TogglePin(Y_Prt, Y_Pin);
|
|
||||||
HAL_Delay(traffSPD);
|
|
||||||
HAL_GPIO_TogglePin(Y_Prt, Y_Pin);
|
|
||||||
|
|
||||||
HAL_GPIO_TogglePin(G_Prt, G_Pin);
|
|
||||||
HAL_Delay(traffSPD);
|
|
||||||
HAL_GPIO_TogglePin(G_Prt, G_Pin);
|
|
||||||
*/
|
|
||||||
|
|
||||||
uint32_t trafftick_curr = HAL_GetTick();
|
|
||||||
int ldelay2 = traffSPD * 2;
|
|
||||||
int ldelay3 = traffSPD * 3;
|
|
||||||
|
|
||||||
if ((trafftick_curr - redlight_last) >= traffSPD) {
|
|
||||||
redlight_last = trafftick_curr;
|
|
||||||
HAL_GPIO_TogglePin(R_Prt, R_Pin);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((trafftick_curr - ylwlight_last) >= ldelay2) {
|
|
||||||
ylwlight_last = trafftick_curr;
|
|
||||||
HAL_GPIO_TogglePin(Y_Prt, Y_Pin);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((trafftick_curr - trafftick_last) >= ldelay3) {
|
|
||||||
grnlight_last = trafftick_curr;
|
|
||||||
HAL_GPIO_TogglePin(G_Prt, G_Pin);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,334 @@
|
|||||||
|
/* USER CODE BEGIN Header */
|
||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
* @file : main.c
|
||||||
|
* @brief : Main program body
|
||||||
|
******************************************************************************
|
||||||
|
* @attention
|
||||||
|
*
|
||||||
|
* Copyright (c) 2025 STMicroelectronics.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This software is licensed under terms that can be found in the LICENSE file
|
||||||
|
* in the root directory of this software component.
|
||||||
|
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||||
|
*
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
// Feeling sneaky.
|
||||||
|
extern "C" {
|
||||||
|
/* USER CODE END Header */
|
||||||
|
/* Includes ------------------------------------------------------------------*/
|
||||||
|
#include "main.h"
|
||||||
|
|
||||||
|
/* Private function prototypes -----------------------------------------------*/
|
||||||
|
void SystemClock_Config(void);
|
||||||
|
static void MX_GPIO_Init(void);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Private user code ---------------------------------------------------------*/
|
||||||
|
/* USER CODE BEGIN 0 */
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
enum class TrafficState { GREEN, YELLOW, RED };
|
||||||
|
void SetTrafficLights(TrafficState s);
|
||||||
|
|
||||||
|
TrafficState currentState = TrafficState::GREEN;
|
||||||
|
uint32_t stateStartTime = 0; //HAL_GetTick() at the start of this state
|
||||||
|
bool buttonPressedThisCycle = false;
|
||||||
|
bool pedestrianNextCycle = false;
|
||||||
|
bool pedestrianThisCycle = false;
|
||||||
|
|
||||||
|
const uint32_t DURATION_GREEN = 5000;
|
||||||
|
const uint32_t DURATION_YELLOW = 3000;
|
||||||
|
const uint32_t DURATION_RED_NOPED = 5000;
|
||||||
|
const uint32_t DURATION_RED_PED = 7000;
|
||||||
|
|
||||||
|
/* USER CODE END 0 */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief The application entry point.
|
||||||
|
* @retval int
|
||||||
|
*/
|
||||||
|
|
||||||
|
void SetTrafficLights(TrafficState s)
|
||||||
|
{
|
||||||
|
// reset all
|
||||||
|
HAL_GPIO_WritePin(GPIOD, Green_Pin, GPIO_PIN_RESET);
|
||||||
|
HAL_GPIO_WritePin(GPIOD, Yellow_Pin, GPIO_PIN_RESET);
|
||||||
|
HAL_GPIO_WritePin(GPIOD, Red_Pin, GPIO_PIN_SET);
|
||||||
|
|
||||||
|
switch (s)
|
||||||
|
{
|
||||||
|
case TrafficState::GREEN :
|
||||||
|
HAL_GPIO_WritePin(GPIOD, Green_Pin, GPIO_PIN_SET);
|
||||||
|
break;
|
||||||
|
case TrafficState::YELLOW :
|
||||||
|
HAL_GPIO_WritePin(GPIOD, Yellow_Pin, GPIO_PIN_SET);
|
||||||
|
break;
|
||||||
|
case TrafficState::RED:
|
||||||
|
HAL_GPIO_WritePin(GPIOD, Red_Pin, GPIO_PIN_SET);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
HAL_Init();
|
||||||
|
|
||||||
|
/* USER CODE BEGIN Init */
|
||||||
|
|
||||||
|
/* USER CODE END Init */
|
||||||
|
|
||||||
|
/* Configure the system clock */
|
||||||
|
SystemClock_Config();
|
||||||
|
MX_GPIO_Init();
|
||||||
|
|
||||||
|
stateStartTime = HAL_GetTick();
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
/* USER CODE END WHILE */
|
||||||
|
uint32_t now = HAL_GetTick();
|
||||||
|
uint32_t elapsed = now - stateStartTime;
|
||||||
|
|
||||||
|
switch(currentState)
|
||||||
|
{
|
||||||
|
case TrafficState::GREEN:
|
||||||
|
if (buttonPressedThisCycle)
|
||||||
|
pedestrianThisCycle = true;
|
||||||
|
|
||||||
|
/*
|
||||||
|
if (buttonPressedThisCycle)
|
||||||
|
{
|
||||||
|
currentState = TrafficState::YELLOW;
|
||||||
|
stateStartTime = now;
|
||||||
|
buttonPressedThisCycle = false;
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pedestrianNextCycle = false;
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
else if (elapsed >= DURATION_GREEN)
|
||||||
|
{
|
||||||
|
currentState = TrafficState::YELLOW;
|
||||||
|
stateStartTime = now;
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case TrafficState::YELLOW:
|
||||||
|
if (buttonPressedThisCycle || pedestrianNextCycle)
|
||||||
|
pedestrianThisCycle = true;
|
||||||
|
|
||||||
|
if (elapsed >= DURATION_YELLOW)
|
||||||
|
{
|
||||||
|
currentState = TrafficState::RED;
|
||||||
|
stateStartTime = now;
|
||||||
|
buttonPressedThisCycle = false; //TODO add pressed pedestrian button in yellow
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
// If Ped Button was pressed during GREEN or YELLOW, we need to enable WHITE this cycle
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case TrafficState::RED:
|
||||||
|
/*
|
||||||
|
if (pedestrianNextCycle)
|
||||||
|
{
|
||||||
|
HAL_GPIO_WritePin(GPIOD,White_Pin,GPIO_PIN_SET); // turn on Pedestrian LED
|
||||||
|
if (elapsed >= DURATION_RED_PED)
|
||||||
|
{
|
||||||
|
HAL_GPIO_WritePin(GPIOD,White_Pin,GPIO_PIN_RESET);
|
||||||
|
pedestrianNextCycle = false;
|
||||||
|
currentState = TrafficState::GREEN;
|
||||||
|
stateStartTime = now;
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
HAL_GPIO_WritePin(GPIOD,White_Pin,GPIO_PIN_RESET);
|
||||||
|
if(elapsed >= DURATION_RED_PED)
|
||||||
|
{
|
||||||
|
currentState = TrafficState::GREEN;
|
||||||
|
stateStartTime = now;
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (buttonPressedThisCycle)
|
||||||
|
pedestrianNextCycle = true;
|
||||||
|
|
||||||
|
if (pedestrianThisCycle) {
|
||||||
|
HAL_GPIO_WritePin(White_GPIO_Port, White_Pin, GPIO_PIN_RESET);
|
||||||
|
pedestrianThisCycle = false;
|
||||||
|
pedestrianNextcycle = false;
|
||||||
|
currentState = TrafficState::GREEN;
|
||||||
|
stateStartTime = now;
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
buttonPressedThisCycle = false;
|
||||||
|
} else {
|
||||||
|
HAL_GPIO_WritePin(White_GPIO_Port, White_Pin, GPIO_PIN_RESET);
|
||||||
|
if (elapsed >= DURATION_RED_NOPED)
|
||||||
|
{
|
||||||
|
currentState = TrafficState::GREEN;
|
||||||
|
stateStartTime = now;
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
buttonPressedThisCycle = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/* USER CODE BEGIN 3 */
|
||||||
|
}
|
||||||
|
/* USER CODE END 3 */
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief System Clock Configuration
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
|
||||||
|
void SystemClock_Config(void)
|
||||||
|
{
|
||||||
|
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
|
||||||
|
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
|
||||||
|
|
||||||
|
/** Configure the main internal regulator output voltage
|
||||||
|
*/
|
||||||
|
__HAL_RCC_PWR_CLK_ENABLE();
|
||||||
|
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE3);
|
||||||
|
|
||||||
|
/** Initializes the RCC Oscillators according to the specified parameters
|
||||||
|
* in the RCC_OscInitTypeDef structure.
|
||||||
|
*/
|
||||||
|
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
|
||||||
|
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
|
||||||
|
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
|
||||||
|
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
||||||
|
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
|
||||||
|
RCC_OscInitStruct.PLL.PLLM = 8;
|
||||||
|
RCC_OscInitStruct.PLL.PLLN = 50;
|
||||||
|
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4;
|
||||||
|
RCC_OscInitStruct.PLL.PLLQ = 7;
|
||||||
|
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Initializes the CPU, AHB and APB buses clocks
|
||||||
|
*/
|
||||||
|
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|
||||||
|
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
|
||||||
|
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
|
||||||
|
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
|
||||||
|
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV8;
|
||||||
|
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV4;
|
||||||
|
|
||||||
|
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief GPIO Initialization Function
|
||||||
|
* @param None
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
static void MX_GPIO_Init(void)
|
||||||
|
{
|
||||||
|
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||||
|
/* USER CODE BEGIN MX_GPIO_Init_1 */
|
||||||
|
|
||||||
|
/* USER CODE END MX_GPIO_Init_1 */
|
||||||
|
|
||||||
|
/* GPIO Ports Clock Enable */
|
||||||
|
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||||
|
__HAL_RCC_GPIOD_CLK_ENABLE();
|
||||||
|
|
||||||
|
/*Configure GPIO pin Output Level */
|
||||||
|
HAL_GPIO_WritePin(GPIOD, White_Pin|Red_Pin|Yellow_Pin|Green_Pin, GPIO_PIN_RESET);
|
||||||
|
|
||||||
|
/*Configure GPIO pin : PedButton_Pin */
|
||||||
|
GPIO_InitStruct.Pin = PedButton_Pin;
|
||||||
|
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
|
||||||
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
|
HAL_GPIO_Init(PedButton_GPIO_Port, &GPIO_InitStruct);
|
||||||
|
|
||||||
|
/*Configure GPIO pins : White_Pin Red_Pin Yellow_Pin Green_Pin */
|
||||||
|
GPIO_InitStruct.Pin = White_Pin|Red_Pin|Yellow_Pin|Green_Pin;
|
||||||
|
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||||
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||||
|
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
|
||||||
|
|
||||||
|
/* EXTI interrupt init*/
|
||||||
|
HAL_NVIC_SetPriority(EXTI15_10_IRQn, 15, 0);
|
||||||
|
HAL_NVIC_EnableIRQ(EXTI15_10_IRQn);
|
||||||
|
|
||||||
|
/* USER CODE BEGIN MX_GPIO_Init_2 */
|
||||||
|
|
||||||
|
/* USER CODE END MX_GPIO_Init_2 */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* USER CODE BEGIN 4 */
|
||||||
|
void HAL_GPIO_EXTI_CallBack(uint16_t GPIO_Pin)
|
||||||
|
{
|
||||||
|
static uint32_t lastInterruptTime = 0;
|
||||||
|
uint32_t now = HAL_GetTick();
|
||||||
|
|
||||||
|
// software debounce
|
||||||
|
if (now - lastInterruptTime < 100)
|
||||||
|
return;
|
||||||
|
|
||||||
|
lastInterruptTime = now;
|
||||||
|
|
||||||
|
if (GPIO_Pin == PedButton_Pin)
|
||||||
|
buttonPressedThisCycle = true;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void HAL_GPIO_EXTI_IRQHandler()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/* USER CODE END 4 */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function is executed in case of error occurrence.
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void Error_Handler(void)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN Error_Handler_Debug */
|
||||||
|
/* User can add his own implementation to report the HAL error return state */
|
||||||
|
__disable_irq();
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
/* USER CODE END Error_Handler_Debug */
|
||||||
|
}
|
||||||
|
#ifdef USE_FULL_ASSERT
|
||||||
|
/**
|
||||||
|
* @brief Reports the name of the source file and the source line number
|
||||||
|
* where the assert_param error has occurred.
|
||||||
|
* @param file: pointer to the source file name
|
||||||
|
* @param line: assert_param error line source number
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void assert_failed(uint8_t *file, uint32_t line)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN 6 */
|
||||||
|
/* User can add his own implementation to report the file name and line number,
|
||||||
|
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
|
||||||
|
/* USER CODE END 6 */
|
||||||
|
}
|
||||||
|
#endif /* USE_FULL_ASSERT */
|
||||||
|
|
||||||
@@ -1,730 +0,0 @@
|
|||||||
/* USER CODE BEGIN Header */
|
|
||||||
/**
|
|
||||||
******************************************************************************
|
|
||||||
* @file : main.c
|
|
||||||
* @brief : Main program body
|
|
||||||
******************************************************************************
|
|
||||||
* @attention
|
|
||||||
*
|
|
||||||
* Copyright (c) 2025 STMicroelectronics.
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* This software is licensed under terms that can be found in the LICENSE file
|
|
||||||
* in the root directory of this software component.
|
|
||||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
|
||||||
*
|
|
||||||
******************************************************************************
|
|
||||||
*/
|
|
||||||
/* USER CODE END Header */
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
|
||||||
#include "main.h"
|
|
||||||
#include "cmsis_os.h"
|
|
||||||
#include "usb_host.h"
|
|
||||||
|
|
||||||
/* Private includes ----------------------------------------------------------*/
|
|
||||||
/* USER CODE BEGIN Includes */
|
|
||||||
#include "breadboard.h"
|
|
||||||
|
|
||||||
/* USER CODE END Includes */
|
|
||||||
|
|
||||||
/* Private typedef -----------------------------------------------------------*/
|
|
||||||
/* USER CODE BEGIN PTD */
|
|
||||||
|
|
||||||
/* USER CODE END PTD */
|
|
||||||
|
|
||||||
/* Private define ------------------------------------------------------------*/
|
|
||||||
/* USER CODE BEGIN PD */
|
|
||||||
|
|
||||||
/* USER CODE END PD */
|
|
||||||
|
|
||||||
/* Private macro -------------------------------------------------------------*/
|
|
||||||
/* USER CODE BEGIN PM */
|
|
||||||
|
|
||||||
/* USER CODE END PM */
|
|
||||||
|
|
||||||
/* Private variables ---------------------------------------------------------*/
|
|
||||||
CRC_HandleTypeDef hcrc;
|
|
||||||
|
|
||||||
DMA2D_HandleTypeDef hdma2d;
|
|
||||||
|
|
||||||
I2C_HandleTypeDef hi2c3;
|
|
||||||
|
|
||||||
LTDC_HandleTypeDef hltdc;
|
|
||||||
|
|
||||||
SPI_HandleTypeDef hspi5;
|
|
||||||
|
|
||||||
TIM_HandleTypeDef htim1;
|
|
||||||
|
|
||||||
UART_HandleTypeDef huart1;
|
|
||||||
|
|
||||||
SDRAM_HandleTypeDef hsdram1;
|
|
||||||
|
|
||||||
osThreadId defaultTaskHandle;
|
|
||||||
/* USER CODE BEGIN PV */
|
|
||||||
|
|
||||||
/* USER CODE END PV */
|
|
||||||
|
|
||||||
/* Private function prototypes -----------------------------------------------*/
|
|
||||||
void SystemClock_Config(void);
|
|
||||||
static void MX_GPIO_Init(void);
|
|
||||||
static void MX_CRC_Init(void);
|
|
||||||
static void MX_DMA2D_Init(void);
|
|
||||||
static void MX_FMC_Init(void);
|
|
||||||
static void MX_I2C3_Init(void);
|
|
||||||
static void MX_LTDC_Init(void);
|
|
||||||
static void MX_SPI5_Init(void);
|
|
||||||
static void MX_TIM1_Init(void);
|
|
||||||
static void MX_USART1_UART_Init(void);
|
|
||||||
void StartDefaultTask(void const * argument);
|
|
||||||
|
|
||||||
/* USER CODE BEGIN PFP */
|
|
||||||
|
|
||||||
/* USER CODE END PFP */
|
|
||||||
|
|
||||||
/* Private user code ---------------------------------------------------------*/
|
|
||||||
/* USER CODE BEGIN 0 */
|
|
||||||
|
|
||||||
/* USER CODE END 0 */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief The application entry point.
|
|
||||||
* @retval int
|
|
||||||
*/
|
|
||||||
int main(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* USER CODE BEGIN 1 */
|
|
||||||
|
|
||||||
/* USER CODE END 1 */
|
|
||||||
|
|
||||||
/* MCU Configuration--------------------------------------------------------*/
|
|
||||||
|
|
||||||
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
|
|
||||||
HAL_Init();
|
|
||||||
|
|
||||||
/* USER CODE BEGIN Init */
|
|
||||||
|
|
||||||
/* USER CODE END Init */
|
|
||||||
|
|
||||||
/* Configure the system clock */
|
|
||||||
SystemClock_Config();
|
|
||||||
|
|
||||||
/* USER CODE BEGIN SysInit */
|
|
||||||
|
|
||||||
/* USER CODE END SysInit */
|
|
||||||
|
|
||||||
/* Initialize all configured peripherals */
|
|
||||||
MX_GPIO_Init();
|
|
||||||
MX_CRC_Init();
|
|
||||||
MX_DMA2D_Init();
|
|
||||||
MX_FMC_Init();
|
|
||||||
MX_I2C3_Init();
|
|
||||||
MX_LTDC_Init();
|
|
||||||
MX_SPI5_Init();
|
|
||||||
MX_TIM1_Init();
|
|
||||||
MX_USART1_UART_Init();
|
|
||||||
/* USER CODE BEGIN 2 */
|
|
||||||
|
|
||||||
/* USER CODE END 2 */
|
|
||||||
|
|
||||||
/* USER CODE BEGIN RTOS_MUTEX */
|
|
||||||
/* add mutexes, ... */
|
|
||||||
/* USER CODE END RTOS_MUTEX */
|
|
||||||
|
|
||||||
/* USER CODE BEGIN RTOS_SEMAPHORES */
|
|
||||||
/* add semaphores, ... */
|
|
||||||
/* USER CODE END RTOS_SEMAPHORES */
|
|
||||||
|
|
||||||
/* USER CODE BEGIN RTOS_TIMERS */
|
|
||||||
/* start timers, add new ones, ... */
|
|
||||||
/* USER CODE END RTOS_TIMERS */
|
|
||||||
|
|
||||||
/* USER CODE BEGIN RTOS_QUEUES */
|
|
||||||
/* add queues, ... */
|
|
||||||
/* USER CODE END RTOS_QUEUES */
|
|
||||||
|
|
||||||
/* Create the thread(s) */
|
|
||||||
/* definition and creation of defaultTask */
|
|
||||||
//osThreadDef(defaultTask, StartDefaultTask, osPriorityNormal, 0, 4096);
|
|
||||||
//defaultTaskHandle = osThreadCreate(osThread(defaultTask), NULL);
|
|
||||||
|
|
||||||
/* USER CODE BEGIN RTOS_THREADS */
|
|
||||||
/* add threads, ... */
|
|
||||||
/* USER CODE END RTOS_THREADS */
|
|
||||||
|
|
||||||
/* Start scheduler */
|
|
||||||
//osKernelStart();
|
|
||||||
|
|
||||||
/* We should never get here as control is now taken by the scheduler */
|
|
||||||
|
|
||||||
/* Infinite loop */
|
|
||||||
/* USER CODE BEGIN WHILE */
|
|
||||||
while (1)
|
|
||||||
{
|
|
||||||
breadboard(333);
|
|
||||||
/* USER CODE END WHILE */
|
|
||||||
|
|
||||||
/* USER CODE BEGIN 3 */
|
|
||||||
}
|
|
||||||
/* USER CODE END 3 */
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief System Clock Configuration
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
void SystemClock_Config(void)
|
|
||||||
{
|
|
||||||
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
|
|
||||||
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
|
|
||||||
|
|
||||||
/** Configure the main internal regulator output voltage
|
|
||||||
*/
|
|
||||||
__HAL_RCC_PWR_CLK_ENABLE();
|
|
||||||
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE3);
|
|
||||||
|
|
||||||
/** Initializes the RCC Oscillators according to the specified parameters
|
|
||||||
* in the RCC_OscInitTypeDef structure.
|
|
||||||
*/
|
|
||||||
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
|
|
||||||
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
|
|
||||||
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
|
||||||
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
|
|
||||||
RCC_OscInitStruct.PLL.PLLM = 4;
|
|
||||||
RCC_OscInitStruct.PLL.PLLN = 72;
|
|
||||||
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
|
|
||||||
RCC_OscInitStruct.PLL.PLLQ = 3;
|
|
||||||
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Initializes the CPU, AHB and APB buses clocks
|
|
||||||
*/
|
|
||||||
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|
|
||||||
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
|
|
||||||
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
|
|
||||||
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
|
|
||||||
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
|
|
||||||
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
|
|
||||||
|
|
||||||
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief CRC Initialization Function
|
|
||||||
* @param None
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
static void MX_CRC_Init(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* USER CODE BEGIN CRC_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE END CRC_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE BEGIN CRC_Init 1 */
|
|
||||||
|
|
||||||
/* USER CODE END CRC_Init 1 */
|
|
||||||
hcrc.Instance = CRC;
|
|
||||||
if (HAL_CRC_Init(&hcrc) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
/* USER CODE BEGIN CRC_Init 2 */
|
|
||||||
|
|
||||||
/* USER CODE END CRC_Init 2 */
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief DMA2D Initialization Function
|
|
||||||
* @param None
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
static void MX_DMA2D_Init(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* USER CODE BEGIN DMA2D_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE END DMA2D_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE BEGIN DMA2D_Init 1 */
|
|
||||||
|
|
||||||
/* USER CODE END DMA2D_Init 1 */
|
|
||||||
hdma2d.Instance = DMA2D;
|
|
||||||
hdma2d.Init.Mode = DMA2D_M2M;
|
|
||||||
hdma2d.Init.ColorMode = DMA2D_OUTPUT_ARGB8888;
|
|
||||||
hdma2d.Init.OutputOffset = 0;
|
|
||||||
hdma2d.LayerCfg[1].InputOffset = 0;
|
|
||||||
hdma2d.LayerCfg[1].InputColorMode = DMA2D_INPUT_ARGB8888;
|
|
||||||
hdma2d.LayerCfg[1].AlphaMode = DMA2D_NO_MODIF_ALPHA;
|
|
||||||
hdma2d.LayerCfg[1].InputAlpha = 0;
|
|
||||||
if (HAL_DMA2D_Init(&hdma2d) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
if (HAL_DMA2D_ConfigLayer(&hdma2d, 1) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
/* USER CODE BEGIN DMA2D_Init 2 */
|
|
||||||
|
|
||||||
/* USER CODE END DMA2D_Init 2 */
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief I2C3 Initialization Function
|
|
||||||
* @param None
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
static void MX_I2C3_Init(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* USER CODE BEGIN I2C3_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE END I2C3_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE BEGIN I2C3_Init 1 */
|
|
||||||
|
|
||||||
/* USER CODE END I2C3_Init 1 */
|
|
||||||
hi2c3.Instance = I2C3;
|
|
||||||
hi2c3.Init.ClockSpeed = 100000;
|
|
||||||
hi2c3.Init.DutyCycle = I2C_DUTYCYCLE_2;
|
|
||||||
hi2c3.Init.OwnAddress1 = 0;
|
|
||||||
hi2c3.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
|
|
||||||
hi2c3.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
|
|
||||||
hi2c3.Init.OwnAddress2 = 0;
|
|
||||||
hi2c3.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
|
|
||||||
hi2c3.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
|
|
||||||
if (HAL_I2C_Init(&hi2c3) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Configure Analogue filter
|
|
||||||
*/
|
|
||||||
if (HAL_I2CEx_ConfigAnalogFilter(&hi2c3, I2C_ANALOGFILTER_ENABLE) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Configure Digital filter
|
|
||||||
*/
|
|
||||||
if (HAL_I2CEx_ConfigDigitalFilter(&hi2c3, 0) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
/* USER CODE BEGIN I2C3_Init 2 */
|
|
||||||
|
|
||||||
/* USER CODE END I2C3_Init 2 */
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief LTDC Initialization Function
|
|
||||||
* @param None
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
static void MX_LTDC_Init(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* USER CODE BEGIN LTDC_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE END LTDC_Init 0 */
|
|
||||||
|
|
||||||
LTDC_LayerCfgTypeDef pLayerCfg = {0};
|
|
||||||
|
|
||||||
/* USER CODE BEGIN LTDC_Init 1 */
|
|
||||||
|
|
||||||
/* USER CODE END LTDC_Init 1 */
|
|
||||||
hltdc.Instance = LTDC;
|
|
||||||
hltdc.Init.HSPolarity = LTDC_HSPOLARITY_AL;
|
|
||||||
hltdc.Init.VSPolarity = LTDC_VSPOLARITY_AL;
|
|
||||||
hltdc.Init.DEPolarity = LTDC_DEPOLARITY_AL;
|
|
||||||
hltdc.Init.PCPolarity = LTDC_PCPOLARITY_IPC;
|
|
||||||
hltdc.Init.HorizontalSync = 9;
|
|
||||||
hltdc.Init.VerticalSync = 1;
|
|
||||||
hltdc.Init.AccumulatedHBP = 29;
|
|
||||||
hltdc.Init.AccumulatedVBP = 3;
|
|
||||||
hltdc.Init.AccumulatedActiveW = 269;
|
|
||||||
hltdc.Init.AccumulatedActiveH = 323;
|
|
||||||
hltdc.Init.TotalWidth = 279;
|
|
||||||
hltdc.Init.TotalHeigh = 327;
|
|
||||||
hltdc.Init.Backcolor.Blue = 0;
|
|
||||||
hltdc.Init.Backcolor.Green = 0;
|
|
||||||
hltdc.Init.Backcolor.Red = 0;
|
|
||||||
if (HAL_LTDC_Init(&hltdc) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
pLayerCfg.WindowX0 = 0;
|
|
||||||
pLayerCfg.WindowX1 = 240;
|
|
||||||
pLayerCfg.WindowY0 = 0;
|
|
||||||
pLayerCfg.WindowY1 = 320;
|
|
||||||
pLayerCfg.PixelFormat = LTDC_PIXEL_FORMAT_RGB565;
|
|
||||||
pLayerCfg.Alpha = 255;
|
|
||||||
pLayerCfg.Alpha0 = 0;
|
|
||||||
pLayerCfg.BlendingFactor1 = LTDC_BLENDING_FACTOR1_PAxCA;
|
|
||||||
pLayerCfg.BlendingFactor2 = LTDC_BLENDING_FACTOR2_PAxCA;
|
|
||||||
pLayerCfg.FBStartAdress = 0xD0000000;
|
|
||||||
pLayerCfg.ImageWidth = 240;
|
|
||||||
pLayerCfg.ImageHeight = 320;
|
|
||||||
pLayerCfg.Backcolor.Blue = 0;
|
|
||||||
pLayerCfg.Backcolor.Green = 0;
|
|
||||||
pLayerCfg.Backcolor.Red = 0;
|
|
||||||
if (HAL_LTDC_ConfigLayer(&hltdc, &pLayerCfg, 0) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
/* USER CODE BEGIN LTDC_Init 2 */
|
|
||||||
|
|
||||||
/* USER CODE END LTDC_Init 2 */
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief SPI5 Initialization Function
|
|
||||||
* @param None
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
static void MX_SPI5_Init(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* USER CODE BEGIN SPI5_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE END SPI5_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE BEGIN SPI5_Init 1 */
|
|
||||||
|
|
||||||
/* USER CODE END SPI5_Init 1 */
|
|
||||||
/* SPI5 parameter configuration*/
|
|
||||||
hspi5.Instance = SPI5;
|
|
||||||
hspi5.Init.Mode = SPI_MODE_MASTER;
|
|
||||||
hspi5.Init.Direction = SPI_DIRECTION_2LINES;
|
|
||||||
hspi5.Init.DataSize = SPI_DATASIZE_8BIT;
|
|
||||||
hspi5.Init.CLKPolarity = SPI_POLARITY_LOW;
|
|
||||||
hspi5.Init.CLKPhase = SPI_PHASE_1EDGE;
|
|
||||||
hspi5.Init.NSS = SPI_NSS_SOFT;
|
|
||||||
hspi5.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_16;
|
|
||||||
hspi5.Init.FirstBit = SPI_FIRSTBIT_MSB;
|
|
||||||
hspi5.Init.TIMode = SPI_TIMODE_DISABLE;
|
|
||||||
hspi5.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
|
|
||||||
hspi5.Init.CRCPolynomial = 10;
|
|
||||||
if (HAL_SPI_Init(&hspi5) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
/* USER CODE BEGIN SPI5_Init 2 */
|
|
||||||
|
|
||||||
/* USER CODE END SPI5_Init 2 */
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief TIM1 Initialization Function
|
|
||||||
* @param None
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
static void MX_TIM1_Init(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* USER CODE BEGIN TIM1_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE END TIM1_Init 0 */
|
|
||||||
|
|
||||||
TIM_ClockConfigTypeDef sClockSourceConfig = {0};
|
|
||||||
TIM_MasterConfigTypeDef sMasterConfig = {0};
|
|
||||||
|
|
||||||
/* USER CODE BEGIN TIM1_Init 1 */
|
|
||||||
|
|
||||||
/* USER CODE END TIM1_Init 1 */
|
|
||||||
htim1.Instance = TIM1;
|
|
||||||
htim1.Init.Prescaler = 0;
|
|
||||||
htim1.Init.CounterMode = TIM_COUNTERMODE_UP;
|
|
||||||
htim1.Init.Period = 65535;
|
|
||||||
htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
|
||||||
htim1.Init.RepetitionCounter = 0;
|
|
||||||
htim1.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
|
|
||||||
if (HAL_TIM_Base_Init(&htim1) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
|
|
||||||
if (HAL_TIM_ConfigClockSource(&htim1, &sClockSourceConfig) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
|
|
||||||
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
|
|
||||||
if (HAL_TIMEx_MasterConfigSynchronization(&htim1, &sMasterConfig) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
/* USER CODE BEGIN TIM1_Init 2 */
|
|
||||||
|
|
||||||
/* USER CODE END TIM1_Init 2 */
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief USART1 Initialization Function
|
|
||||||
* @param None
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
static void MX_USART1_UART_Init(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* USER CODE BEGIN USART1_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE END USART1_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE BEGIN USART1_Init 1 */
|
|
||||||
|
|
||||||
/* USER CODE END USART1_Init 1 */
|
|
||||||
huart1.Instance = USART1;
|
|
||||||
huart1.Init.BaudRate = 115200;
|
|
||||||
huart1.Init.WordLength = UART_WORDLENGTH_8B;
|
|
||||||
huart1.Init.StopBits = UART_STOPBITS_1;
|
|
||||||
huart1.Init.Parity = UART_PARITY_NONE;
|
|
||||||
huart1.Init.Mode = UART_MODE_TX_RX;
|
|
||||||
huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
|
|
||||||
huart1.Init.OverSampling = UART_OVERSAMPLING_16;
|
|
||||||
if (HAL_UART_Init(&huart1) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
/* USER CODE BEGIN USART1_Init 2 */
|
|
||||||
|
|
||||||
/* USER CODE END USART1_Init 2 */
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/* FMC initialization function */
|
|
||||||
static void MX_FMC_Init(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* USER CODE BEGIN FMC_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE END FMC_Init 0 */
|
|
||||||
|
|
||||||
FMC_SDRAM_TimingTypeDef SdramTiming = {0};
|
|
||||||
|
|
||||||
/* USER CODE BEGIN FMC_Init 1 */
|
|
||||||
|
|
||||||
/* USER CODE END FMC_Init 1 */
|
|
||||||
|
|
||||||
/** Perform the SDRAM1 memory initialization sequence
|
|
||||||
*/
|
|
||||||
hsdram1.Instance = FMC_SDRAM_DEVICE;
|
|
||||||
/* hsdram1.Init */
|
|
||||||
hsdram1.Init.SDBank = FMC_SDRAM_BANK2;
|
|
||||||
hsdram1.Init.ColumnBitsNumber = FMC_SDRAM_COLUMN_BITS_NUM_8;
|
|
||||||
hsdram1.Init.RowBitsNumber = FMC_SDRAM_ROW_BITS_NUM_12;
|
|
||||||
hsdram1.Init.MemoryDataWidth = FMC_SDRAM_MEM_BUS_WIDTH_16;
|
|
||||||
hsdram1.Init.InternalBankNumber = FMC_SDRAM_INTERN_BANKS_NUM_4;
|
|
||||||
hsdram1.Init.CASLatency = FMC_SDRAM_CAS_LATENCY_3;
|
|
||||||
hsdram1.Init.WriteProtection = FMC_SDRAM_WRITE_PROTECTION_DISABLE;
|
|
||||||
hsdram1.Init.SDClockPeriod = FMC_SDRAM_CLOCK_PERIOD_2;
|
|
||||||
hsdram1.Init.ReadBurst = FMC_SDRAM_RBURST_DISABLE;
|
|
||||||
hsdram1.Init.ReadPipeDelay = FMC_SDRAM_RPIPE_DELAY_1;
|
|
||||||
/* SdramTiming */
|
|
||||||
SdramTiming.LoadToActiveDelay = 2;
|
|
||||||
SdramTiming.ExitSelfRefreshDelay = 7;
|
|
||||||
SdramTiming.SelfRefreshTime = 4;
|
|
||||||
SdramTiming.RowCycleDelay = 7;
|
|
||||||
SdramTiming.WriteRecoveryTime = 3;
|
|
||||||
SdramTiming.RPDelay = 2;
|
|
||||||
SdramTiming.RCDDelay = 2;
|
|
||||||
|
|
||||||
if (HAL_SDRAM_Init(&hsdram1, &SdramTiming) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler( );
|
|
||||||
}
|
|
||||||
|
|
||||||
/* USER CODE BEGIN FMC_Init 2 */
|
|
||||||
|
|
||||||
/* USER CODE END FMC_Init 2 */
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief GPIO Initialization Function
|
|
||||||
* @param None
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
static void MX_GPIO_Init(void)
|
|
||||||
{
|
|
||||||
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
|
||||||
/* USER CODE BEGIN MX_GPIO_Init_1 */
|
|
||||||
|
|
||||||
/* USER CODE END MX_GPIO_Init_1 */
|
|
||||||
|
|
||||||
/* GPIO Ports Clock Enable */
|
|
||||||
__HAL_RCC_GPIOE_CLK_ENABLE();
|
|
||||||
__HAL_RCC_GPIOC_CLK_ENABLE();
|
|
||||||
__HAL_RCC_GPIOF_CLK_ENABLE();
|
|
||||||
__HAL_RCC_GPIOH_CLK_ENABLE();
|
|
||||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
|
||||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
|
||||||
__HAL_RCC_GPIOG_CLK_ENABLE();
|
|
||||||
__HAL_RCC_GPIOD_CLK_ENABLE();
|
|
||||||
|
|
||||||
/*Configure GPIO pin Output Level */
|
|
||||||
HAL_GPIO_WritePin(GPIOE, RedLight_Pin|YellowLight_Pin|GreenLight_Pin|WalkLight_Pin, GPIO_PIN_RESET);
|
|
||||||
|
|
||||||
/*Configure GPIO pin Output Level */
|
|
||||||
HAL_GPIO_WritePin(GPIOC, NCS_MEMS_SPI_Pin|CSX_Pin|OTG_FS_PSO_Pin, GPIO_PIN_RESET);
|
|
||||||
|
|
||||||
/*Configure GPIO pin Output Level */
|
|
||||||
HAL_GPIO_WritePin(ACP_RST_GPIO_Port, ACP_RST_Pin, GPIO_PIN_RESET);
|
|
||||||
|
|
||||||
/*Configure GPIO pin Output Level */
|
|
||||||
HAL_GPIO_WritePin(GPIOD, RDX_Pin|WRX_DCX_Pin, GPIO_PIN_RESET);
|
|
||||||
|
|
||||||
/*Configure GPIO pin Output Level */
|
|
||||||
HAL_GPIO_WritePin(GPIOG, LD3_Pin|LD4_Pin, GPIO_PIN_RESET);
|
|
||||||
|
|
||||||
/*Configure GPIO pins : RedLight_Pin YellowLight_Pin GreenLight_Pin WalkLight_Pin */
|
|
||||||
GPIO_InitStruct.Pin = RedLight_Pin|YellowLight_Pin|GreenLight_Pin|WalkLight_Pin;
|
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
||||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
|
||||||
HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
|
|
||||||
|
|
||||||
/*Configure GPIO pins : NCS_MEMS_SPI_Pin CSX_Pin OTG_FS_PSO_Pin */
|
|
||||||
GPIO_InitStruct.Pin = NCS_MEMS_SPI_Pin|CSX_Pin|OTG_FS_PSO_Pin;
|
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
||||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
|
||||||
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
|
|
||||||
|
|
||||||
/*Configure GPIO pins : B1_Pin MEMS_INT1_Pin MEMS_INT2_Pin TP_INT1_Pin */
|
|
||||||
GPIO_InitStruct.Pin = B1_Pin|MEMS_INT1_Pin|MEMS_INT2_Pin|TP_INT1_Pin;
|
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_EVT_RISING;
|
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
||||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
|
||||||
|
|
||||||
/*Configure GPIO pin : ACP_RST_Pin */
|
|
||||||
GPIO_InitStruct.Pin = ACP_RST_Pin;
|
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
||||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
|
||||||
HAL_GPIO_Init(ACP_RST_GPIO_Port, &GPIO_InitStruct);
|
|
||||||
|
|
||||||
/*Configure GPIO pin : OTG_FS_OC_Pin */
|
|
||||||
GPIO_InitStruct.Pin = OTG_FS_OC_Pin;
|
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_EVT_RISING;
|
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
||||||
HAL_GPIO_Init(OTG_FS_OC_GPIO_Port, &GPIO_InitStruct);
|
|
||||||
|
|
||||||
/*Configure GPIO pin : BOOT1_Pin */
|
|
||||||
GPIO_InitStruct.Pin = BOOT1_Pin;
|
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
||||||
HAL_GPIO_Init(BOOT1_GPIO_Port, &GPIO_InitStruct);
|
|
||||||
|
|
||||||
/*Configure GPIO pin : TE_Pin */
|
|
||||||
GPIO_InitStruct.Pin = TE_Pin;
|
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
||||||
HAL_GPIO_Init(TE_GPIO_Port, &GPIO_InitStruct);
|
|
||||||
|
|
||||||
/*Configure GPIO pins : RDX_Pin WRX_DCX_Pin */
|
|
||||||
GPIO_InitStruct.Pin = RDX_Pin|WRX_DCX_Pin;
|
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
||||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
|
||||||
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
|
|
||||||
|
|
||||||
/*Configure GPIO pins : LD3_Pin LD4_Pin */
|
|
||||||
GPIO_InitStruct.Pin = LD3_Pin|LD4_Pin;
|
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
||||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
|
||||||
HAL_GPIO_Init(GPIOG, &GPIO_InitStruct);
|
|
||||||
|
|
||||||
/* USER CODE BEGIN MX_GPIO_Init_2 */
|
|
||||||
|
|
||||||
/* USER CODE END MX_GPIO_Init_2 */
|
|
||||||
}
|
|
||||||
|
|
||||||
/* USER CODE BEGIN 4 */
|
|
||||||
|
|
||||||
/* USER CODE END 4 */
|
|
||||||
|
|
||||||
/* USER CODE BEGIN Header_StartDefaultTask */
|
|
||||||
/**
|
|
||||||
* @brief Function implementing the defaultTask thread.
|
|
||||||
* @param argument: Not used
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
/* USER CODE END Header_StartDefaultTask */
|
|
||||||
void StartDefaultTask(void const * argument)
|
|
||||||
{
|
|
||||||
/* init code for USB_HOST */
|
|
||||||
MX_USB_HOST_Init();
|
|
||||||
/* USER CODE BEGIN 5 */
|
|
||||||
/* Infinite loop */
|
|
||||||
for(;;)
|
|
||||||
{
|
|
||||||
osDelay(1);
|
|
||||||
}
|
|
||||||
/* USER CODE END 5 */
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Period elapsed callback in non blocking mode
|
|
||||||
* @note This function is called when TIM6 interrupt took place, inside
|
|
||||||
* HAL_TIM_IRQHandler(). It makes a direct call to HAL_IncTick() to increment
|
|
||||||
* a global variable "uwTick" used as application time base.
|
|
||||||
* @param htim : TIM handle
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
|
|
||||||
{
|
|
||||||
/* USER CODE BEGIN Callback 0 */
|
|
||||||
|
|
||||||
/* USER CODE END Callback 0 */
|
|
||||||
if (htim->Instance == TIM6)
|
|
||||||
{
|
|
||||||
HAL_IncTick();
|
|
||||||
}
|
|
||||||
/* USER CODE BEGIN Callback 1 */
|
|
||||||
|
|
||||||
/* USER CODE END Callback 1 */
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief This function is executed in case of error occurrence.
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
void Error_Handler(void)
|
|
||||||
{
|
|
||||||
/* USER CODE BEGIN Error_Handler_Debug */
|
|
||||||
/* User can add his own implementation to report the HAL error return state */
|
|
||||||
__disable_irq();
|
|
||||||
while (1)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
/* USER CODE END Error_Handler_Debug */
|
|
||||||
}
|
|
||||||
#ifdef USE_FULL_ASSERT
|
|
||||||
/**
|
|
||||||
* @brief Reports the name of the source file and the source line number
|
|
||||||
* where the assert_param error has occurred.
|
|
||||||
* @param file: pointer to the source file name
|
|
||||||
* @param line: assert_param error line source number
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
void assert_failed(uint8_t *file, uint32_t line)
|
|
||||||
{
|
|
||||||
/* USER CODE BEGIN 6 */
|
|
||||||
/* User can add his own implementation to report the file name and line number,
|
|
||||||
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
|
|
||||||
/* USER CODE END 6 */
|
|
||||||
}
|
|
||||||
#endif /* USE_FULL_ASSERT */
|
|
||||||
@@ -0,0 +1,525 @@
|
|||||||
|
/* USER CODE BEGIN Header */
|
||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
* @file : main.c
|
||||||
|
* @brief : Main program body
|
||||||
|
******************************************************************************
|
||||||
|
* @attention
|
||||||
|
*
|
||||||
|
* Copyright (c) 2025 STMicroelectronics.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This software is licensed under terms that can be found in the LICENSE file
|
||||||
|
* in the root directory of this software component.
|
||||||
|
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||||
|
*
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
/* USER CODE END Header */
|
||||||
|
/* Includes ------------------------------------------------------------------*/
|
||||||
|
#include "main.h"
|
||||||
|
#include "cmsis_os.h"
|
||||||
|
|
||||||
|
/* Private includes ----------------------------------------------------------*/
|
||||||
|
/* USER CODE BEGIN Includes */
|
||||||
|
#include "breadboard.h"
|
||||||
|
#include <stdbool.h>
|
||||||
|
/* USER CODE END Includes */
|
||||||
|
|
||||||
|
/* Private typedef -----------------------------------------------------------*/
|
||||||
|
/* USER CODE BEGIN PTD */
|
||||||
|
|
||||||
|
/* USER CODE END PTD */
|
||||||
|
|
||||||
|
/* Private define ------------------------------------------------------------*/
|
||||||
|
/* USER CODE BEGIN PD */
|
||||||
|
|
||||||
|
/* USER CODE END PD */
|
||||||
|
|
||||||
|
/* Private macro -------------------------------------------------------------*/
|
||||||
|
/* USER CODE BEGIN PM */
|
||||||
|
|
||||||
|
/* USER CODE END PM */
|
||||||
|
|
||||||
|
/* Private variables ---------------------------------------------------------*/
|
||||||
|
CRC_HandleTypeDef hcrc;
|
||||||
|
|
||||||
|
DMA2D_HandleTypeDef hdma2d;
|
||||||
|
|
||||||
|
TIM_HandleTypeDef htim1;
|
||||||
|
|
||||||
|
osThreadId defaultTaskHandle;
|
||||||
|
/* USER CODE BEGIN PV */
|
||||||
|
|
||||||
|
/* USER CODE END PV */
|
||||||
|
|
||||||
|
/* Private function prototypes -----------------------------------------------*/
|
||||||
|
void SystemClock_Config(void);
|
||||||
|
static void MX_GPIO_Init(void);
|
||||||
|
static void MX_CRC_Init(void);
|
||||||
|
static void MX_DMA2D_Init(void);
|
||||||
|
static void MX_TIM1_Init(void);
|
||||||
|
void StartDefaultTask(void const * argument);
|
||||||
|
|
||||||
|
void SetTrafficLights(TrafficSate s);
|
||||||
|
|
||||||
|
/* USER CODE BEGIN PFP */
|
||||||
|
|
||||||
|
/* USER CODE END PFP */
|
||||||
|
|
||||||
|
/* Private user code ---------------------------------------------------------*/
|
||||||
|
|
||||||
|
/* USER CODE BEGIN 0 */
|
||||||
|
|
||||||
|
enum class TrafficState {
|
||||||
|
GREEN,
|
||||||
|
YELLOW,
|
||||||
|
RED
|
||||||
|
};
|
||||||
|
|
||||||
|
TrafficState currentState = TrafficState::GREEN;
|
||||||
|
uint32_t stateStartTime = 0; // HAL_GetTick() at the start of this state
|
||||||
|
bool buttonPressed = false;
|
||||||
|
bool pedestrianNextCycle = false;
|
||||||
|
|
||||||
|
const uint32_t DURATION_GREEN = 5000;
|
||||||
|
const uint32_t DURATION_YELLOW = 3000;
|
||||||
|
const uint32_t DURATION_RED = 5000;
|
||||||
|
const uint32_t DURATION_RED_PED = 7000;
|
||||||
|
|
||||||
|
/* USER CODE END 0 */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief The application entry point.
|
||||||
|
* @retval int
|
||||||
|
*/
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* USER CODE BEGIN 1 */
|
||||||
|
|
||||||
|
/* USER CODE END 1 */
|
||||||
|
|
||||||
|
/* MCU Configuration--------------------------------------------------------*/
|
||||||
|
|
||||||
|
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
|
||||||
|
HAL_Init();
|
||||||
|
|
||||||
|
/* USER CODE BEGIN Init */
|
||||||
|
|
||||||
|
/* USER CODE END Init */
|
||||||
|
|
||||||
|
/* Configure the system clock */
|
||||||
|
SystemClock_Config();
|
||||||
|
|
||||||
|
/* USER CODE BEGIN SysInit */
|
||||||
|
|
||||||
|
stateStartTime = HAL_GetTick();
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
|
||||||
|
/* USER CODE END SysInit */
|
||||||
|
|
||||||
|
/* Initialize all configured peripherals */
|
||||||
|
MX_GPIO_Init();
|
||||||
|
MX_CRC_Init();
|
||||||
|
MX_DMA2D_Init();
|
||||||
|
MX_TIM1_Init();
|
||||||
|
/* USER CODE BEGIN 2 */
|
||||||
|
|
||||||
|
/* USER CODE END 2 */
|
||||||
|
|
||||||
|
/* USER CODE BEGIN RTOS_MUTEX */
|
||||||
|
/* add mutexes, ... */
|
||||||
|
/* USER CODE END RTOS_MUTEX */
|
||||||
|
|
||||||
|
/* USER CODE BEGIN RTOS_SEMAPHORES */
|
||||||
|
/* add semaphores, ... */
|
||||||
|
/* USER CODE END RTOS_SEMAPHORES */
|
||||||
|
|
||||||
|
/* USER CODE BEGIN RTOS_TIMERS */
|
||||||
|
/* start timers, add new ones, ... */
|
||||||
|
/* USER CODE END RTOS_TIMERS */
|
||||||
|
|
||||||
|
/* USER CODE BEGIN RTOS_QUEUES */
|
||||||
|
/* add queues, ... */
|
||||||
|
/* USER CODE END RTOS_QUEUES */
|
||||||
|
|
||||||
|
/* Create the thread(s) */
|
||||||
|
/* definition and creation of defaultTask */
|
||||||
|
//osThreadDef(defaultTask, StartDefaultTask, osPriorityNormal, 0, 4096);
|
||||||
|
//defaultTaskHandle = osThreadCreate(osThread(defaultTask), NULL);
|
||||||
|
|
||||||
|
/* USER CODE BEGIN RTOS_THREADS */
|
||||||
|
/* add threads, ... */
|
||||||
|
/* USER CODE END RTOS_THREADS */
|
||||||
|
|
||||||
|
/* Start scheduler */
|
||||||
|
osKernelStart();
|
||||||
|
|
||||||
|
/* We should never get here as control is now taken by the scheduler */
|
||||||
|
|
||||||
|
/* Infinite loop */
|
||||||
|
/* USER CODE BEGIN WHILE */
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
uint32_t now = HAL_GetTick();
|
||||||
|
uint32_t elapsed = now - stateStartTime;
|
||||||
|
|
||||||
|
/*
|
||||||
|
switch(currentState)
|
||||||
|
{
|
||||||
|
case TrafficState::GREEN:
|
||||||
|
if (elapsed >= DURATION_GREEN) {
|
||||||
|
currentState = TrafficState::YELLOW;
|
||||||
|
stateStartTime = now;
|
||||||
|
buttonPressed = false; // reset the button-flag for the new cycle
|
||||||
|
} else if (buttonPressed) {
|
||||||
|
//idk
|
||||||
|
buttonPressed = true;
|
||||||
|
currentState = TrafficState::YELLOW;
|
||||||
|
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case TrafficState::YELLOW:
|
||||||
|
break;
|
||||||
|
case TrafficState::RED:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
switch(currentState)
|
||||||
|
{
|
||||||
|
case TrafficState::GREEN:
|
||||||
|
if (butonPressedThisCycle)
|
||||||
|
{
|
||||||
|
currentState = TrafficState::YELLOW;
|
||||||
|
stateStartTime = now;
|
||||||
|
buttonPressedThisCycle = false;
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
} else if (elapsed >= DURATION_GREEN)
|
||||||
|
{
|
||||||
|
buttonPressedThisCycle = true;
|
||||||
|
currentState = TrafficState::YELLOW;
|
||||||
|
stateStartTime = now;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case TrafficState::YELLOW:
|
||||||
|
if (elapsed >= DURATION_YELLOW)
|
||||||
|
{
|
||||||
|
currentState = TrafficState::RED;
|
||||||
|
stateStartTime = now;
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
// if ped button was pressed during GREEN or YELLOW,
|
||||||
|
// we need to enable WHITE ...
|
||||||
|
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case TrafficState::RED:
|
||||||
|
if (pedestrianNextCycle)
|
||||||
|
{
|
||||||
|
HAL_GPIO_WritePin(White_GPIO_Port, White_Pin, GPIO_PIN_SET);
|
||||||
|
if (elapsed >= DURATION_RED_PED)
|
||||||
|
{
|
||||||
|
HAL_GPIO_WritePin(White_GPIO_Port, White_Pin, GPIO_PIN_RESET);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/* USER CODE END WHILE */
|
||||||
|
|
||||||
|
/* USER CODE BEGIN 3 */
|
||||||
|
}
|
||||||
|
/* USER CODE END 3 */
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief System Clock Configuration
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void SystemClock_Config(void)
|
||||||
|
{
|
||||||
|
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
|
||||||
|
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
|
||||||
|
|
||||||
|
/** Configure the main internal regulator output voltage
|
||||||
|
*/
|
||||||
|
__HAL_RCC_PWR_CLK_ENABLE();
|
||||||
|
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE3);
|
||||||
|
|
||||||
|
/** Initializes the RCC Oscillators according to the specified parameters
|
||||||
|
* in the RCC_OscInitTypeDef structure.
|
||||||
|
*/
|
||||||
|
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
|
||||||
|
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
|
||||||
|
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
|
||||||
|
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
||||||
|
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
|
||||||
|
RCC_OscInitStruct.PLL.PLLM = 8;
|
||||||
|
RCC_OscInitStruct.PLL.PLLN = 72;
|
||||||
|
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
|
||||||
|
RCC_OscInitStruct.PLL.PLLQ = 3;
|
||||||
|
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Initializes the CPU, AHB and APB buses clocks
|
||||||
|
*/
|
||||||
|
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|
||||||
|
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
|
||||||
|
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
|
||||||
|
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
|
||||||
|
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
|
||||||
|
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
|
||||||
|
|
||||||
|
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief CRC Initialization Function
|
||||||
|
* @param None
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
static void MX_CRC_Init(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* USER CODE BEGIN CRC_Init 0 */
|
||||||
|
|
||||||
|
/* USER CODE END CRC_Init 0 */
|
||||||
|
|
||||||
|
/* USER CODE BEGIN CRC_Init 1 */
|
||||||
|
|
||||||
|
/* USER CODE END CRC_Init 1 */
|
||||||
|
hcrc.Instance = CRC;
|
||||||
|
if (HAL_CRC_Init(&hcrc) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
/* USER CODE BEGIN CRC_Init 2 */
|
||||||
|
|
||||||
|
/* USER CODE END CRC_Init 2 */
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief DMA2D Initialization Function
|
||||||
|
* @param None
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
static void MX_DMA2D_Init(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* USER CODE BEGIN DMA2D_Init 0 */
|
||||||
|
|
||||||
|
/* USER CODE END DMA2D_Init 0 */
|
||||||
|
|
||||||
|
/* USER CODE BEGIN DMA2D_Init 1 */
|
||||||
|
|
||||||
|
/* USER CODE END DMA2D_Init 1 */
|
||||||
|
hdma2d.Instance = DMA2D;
|
||||||
|
hdma2d.Init.Mode = DMA2D_M2M;
|
||||||
|
hdma2d.Init.ColorMode = DMA2D_OUTPUT_ARGB8888;
|
||||||
|
hdma2d.Init.OutputOffset = 0;
|
||||||
|
hdma2d.LayerCfg[1].InputOffset = 0;
|
||||||
|
hdma2d.LayerCfg[1].InputColorMode = DMA2D_INPUT_ARGB8888;
|
||||||
|
hdma2d.LayerCfg[1].AlphaMode = DMA2D_NO_MODIF_ALPHA;
|
||||||
|
hdma2d.LayerCfg[1].InputAlpha = 0;
|
||||||
|
if (HAL_DMA2D_Init(&hdma2d) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
if (HAL_DMA2D_ConfigLayer(&hdma2d, 1) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
/* USER CODE BEGIN DMA2D_Init 2 */
|
||||||
|
|
||||||
|
/* USER CODE END DMA2D_Init 2 */
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief TIM1 Initialization Function
|
||||||
|
* @param None
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
static void MX_TIM1_Init(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* USER CODE BEGIN TIM1_Init 0 */
|
||||||
|
|
||||||
|
/* USER CODE END TIM1_Init 0 */
|
||||||
|
|
||||||
|
TIM_ClockConfigTypeDef sClockSourceConfig = {0};
|
||||||
|
TIM_MasterConfigTypeDef sMasterConfig = {0};
|
||||||
|
|
||||||
|
/* USER CODE BEGIN TIM1_Init 1 */
|
||||||
|
|
||||||
|
/* USER CODE END TIM1_Init 1 */
|
||||||
|
htim1.Instance = TIM1;
|
||||||
|
htim1.Init.Prescaler = 0;
|
||||||
|
htim1.Init.CounterMode = TIM_COUNTERMODE_UP;
|
||||||
|
htim1.Init.Period = 65535;
|
||||||
|
htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
||||||
|
htim1.Init.RepetitionCounter = 0;
|
||||||
|
htim1.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
|
||||||
|
if (HAL_TIM_Base_Init(&htim1) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
|
||||||
|
if (HAL_TIM_ConfigClockSource(&htim1, &sClockSourceConfig) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
|
||||||
|
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
|
||||||
|
if (HAL_TIMEx_MasterConfigSynchronization(&htim1, &sMasterConfig) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
/* USER CODE BEGIN TIM1_Init 2 */
|
||||||
|
|
||||||
|
/* USER CODE END TIM1_Init 2 */
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief GPIO Initialization Function
|
||||||
|
* @param None
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
static void MX_GPIO_Init(void)
|
||||||
|
{
|
||||||
|
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||||
|
/* USER CODE BEGIN MX_GPIO_Init_1 */
|
||||||
|
|
||||||
|
/* USER CODE END MX_GPIO_Init_1 */
|
||||||
|
|
||||||
|
/* GPIO Ports Clock Enable */
|
||||||
|
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||||
|
__HAL_RCC_GPIOD_CLK_ENABLE();
|
||||||
|
|
||||||
|
/*Configure GPIO pin Output Level */
|
||||||
|
HAL_GPIO_WritePin(GPIOD, White_Pin|Red_Pin|Yellow_Pin|Green_Pin, GPIO_PIN_RESET);
|
||||||
|
|
||||||
|
/*Configure GPIO pin : PedButton_Pin */
|
||||||
|
GPIO_InitStruct.Pin = PedButton_Pin;
|
||||||
|
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
|
||||||
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
|
HAL_GPIO_Init(PedButton_GPIO_Port, &GPIO_InitStruct);
|
||||||
|
|
||||||
|
/*Configure GPIO pins : White_Pin Red_Pin Yellow_Pin Green_Pin */
|
||||||
|
GPIO_InitStruct.Pin = White_Pin|Red_Pin|Yellow_Pin|Green_Pin;
|
||||||
|
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||||
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||||
|
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
|
||||||
|
|
||||||
|
/* EXTI interrupt init*/
|
||||||
|
HAL_NVIC_SetPriority(EXTI15_10_IRQn, 15, 0);
|
||||||
|
HAL_NVIC_EnableIRQ(EXTI15_10_IRQn);
|
||||||
|
|
||||||
|
/* USER CODE BEGIN MX_GPIO_Init_2 */
|
||||||
|
|
||||||
|
/* USER CODE END MX_GPIO_Init_2 */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* USER CODE BEGIN 4 */
|
||||||
|
|
||||||
|
void HAL_GPIO_EXTI_CallBack(uint16_t GPIO_Pin)
|
||||||
|
{
|
||||||
|
static uint32_t lastInterruptTime = 0;
|
||||||
|
uint32_t now = HAL_GetTick();
|
||||||
|
if (now - lastInterruptTime < 100) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
lastInterruptTime = now;
|
||||||
|
|
||||||
|
bool buttonPressedThisCycle = false; // temporary, get rid of this
|
||||||
|
|
||||||
|
if (buttonPressed) { // buttonPressedHere?
|
||||||
|
buttonPressedThisCycle = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* USER CODE END 4 */
|
||||||
|
|
||||||
|
/* USER CODE BEGIN Header_StartDefaultTask */
|
||||||
|
/**
|
||||||
|
* @brief Function implementing the defaultTask thread.
|
||||||
|
* @param argument: Not used
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
/* USER CODE END Header_StartDefaultTask */
|
||||||
|
void StartDefaultTask(void const * argument)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN 5 */
|
||||||
|
/* Infinite loop */
|
||||||
|
for(;;)
|
||||||
|
{
|
||||||
|
osDelay(1);
|
||||||
|
}
|
||||||
|
/* USER CODE END 5 */
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Period elapsed callback in non blocking mode
|
||||||
|
* @note This function is called when TIM6 interrupt took place, inside
|
||||||
|
* HAL_TIM_IRQHandler(). It makes a direct call to HAL_IncTick() to increment
|
||||||
|
* a global variable "uwTick" used as application time base.
|
||||||
|
* @param htim : TIM handle
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN Callback 0 */
|
||||||
|
|
||||||
|
/* USER CODE END Callback 0 */
|
||||||
|
if (htim->Instance == TIM6)
|
||||||
|
{
|
||||||
|
HAL_IncTick();
|
||||||
|
}
|
||||||
|
/* USER CODE BEGIN Callback 1 */
|
||||||
|
|
||||||
|
/* USER CODE END Callback 1 */
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function is executed in case of error occurrence.
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void Error_Handler(void)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN Error_Handler_Debug */
|
||||||
|
/* User can add his own implementation to report the HAL error return state */
|
||||||
|
__disable_irq();
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
/* USER CODE END Error_Handler_Debug */
|
||||||
|
}
|
||||||
|
#ifdef USE_FULL_ASSERT
|
||||||
|
/**
|
||||||
|
* @brief Reports the name of the source file and the source line number
|
||||||
|
* where the assert_param error has occurred.
|
||||||
|
* @param file: pointer to the source file name
|
||||||
|
* @param line: assert_param error line source number
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void assert_failed(uint8_t *file, uint32_t line)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN 6 */
|
||||||
|
/* User can add his own implementation to report the file name and line number,
|
||||||
|
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
|
||||||
|
/* USER CODE END 6 */
|
||||||
|
}
|
||||||
|
#endif /* USE_FULL_ASSERT */
|
||||||
@@ -0,0 +1,513 @@
|
|||||||
|
/* USER CODE BEGIN Header */
|
||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
* @file : main.c
|
||||||
|
* @brief : Main program body
|
||||||
|
******************************************************************************
|
||||||
|
* @attention
|
||||||
|
*
|
||||||
|
* Copyright (c) 2025 STMicroelectronics.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This software is licensed under terms that can be found in the LICENSE file
|
||||||
|
* in the root directory of this software component.
|
||||||
|
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||||
|
*
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
/* USER CODE END Header */
|
||||||
|
/* Includes ------------------------------------------------------------------*/
|
||||||
|
#include "main.h"
|
||||||
|
#include "cmsis_os.h"
|
||||||
|
|
||||||
|
/* Private includes ----------------------------------------------------------*/
|
||||||
|
/* USER CODE BEGIN Includes */
|
||||||
|
#include "breadboard.h"
|
||||||
|
#include <stdbool.h>
|
||||||
|
/* USER CODE END Includes */
|
||||||
|
|
||||||
|
/* Private typedef -----------------------------------------------------------*/
|
||||||
|
/* USER CODE BEGIN PTD */
|
||||||
|
|
||||||
|
/* USER CODE END PTD */
|
||||||
|
|
||||||
|
/* Private define ------------------------------------------------------------*/
|
||||||
|
/* USER CODE BEGIN PD */
|
||||||
|
|
||||||
|
/* USER CODE END PD */
|
||||||
|
|
||||||
|
/* Private macro -------------------------------------------------------------*/
|
||||||
|
/* USER CODE BEGIN PM */
|
||||||
|
|
||||||
|
/* USER CODE END PM */
|
||||||
|
|
||||||
|
/* Private variables ---------------------------------------------------------*/
|
||||||
|
CRC_HandleTypeDef hcrc;
|
||||||
|
|
||||||
|
DMA2D_HandleTypeDef hdma2d;
|
||||||
|
|
||||||
|
TIM_HandleTypeDef htim1;
|
||||||
|
|
||||||
|
osThreadId defaultTaskHandle;
|
||||||
|
/* USER CODE BEGIN PV */
|
||||||
|
|
||||||
|
/* USER CODE END PV */
|
||||||
|
|
||||||
|
/* Private function prototypes -----------------------------------------------*/
|
||||||
|
void SystemClock_Config(void);
|
||||||
|
static void MX_GPIO_Init(void);
|
||||||
|
static void MX_CRC_Init(void);
|
||||||
|
static void MX_DMA2D_Init(void);
|
||||||
|
static void MX_TIM1_Init(void);
|
||||||
|
void StartDefaultTask(void const * argument);
|
||||||
|
|
||||||
|
void SetTrafficLights(TrafficSate s);
|
||||||
|
|
||||||
|
/* USER CODE BEGIN PFP */
|
||||||
|
|
||||||
|
/* USER CODE END PFP */
|
||||||
|
|
||||||
|
/* Private user code ---------------------------------------------------------*/
|
||||||
|
|
||||||
|
/* USER CODE BEGIN 0 */
|
||||||
|
|
||||||
|
enum class TrafficState {
|
||||||
|
GREEN,
|
||||||
|
YELLOW,
|
||||||
|
RED
|
||||||
|
};
|
||||||
|
|
||||||
|
TrafficState currentState = TrafficState::GREEN;
|
||||||
|
uint32_t stateStartTime = 0; // HAL_GetTick() at the start of this state
|
||||||
|
bool buttonPressed = false;
|
||||||
|
bool pedestrianNextCycle = false;
|
||||||
|
|
||||||
|
const uint32_t DURATION_GREEN = 5000;
|
||||||
|
const uint32_t DURATION_YELLOW = 3000;
|
||||||
|
const uint32_t DURATION_RED = 5000;
|
||||||
|
const uint32_t DURATION_RED_PED = 7000;
|
||||||
|
|
||||||
|
/* USER CODE END 0 */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief The application entry point.
|
||||||
|
* @retval int
|
||||||
|
*/
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* USER CODE BEGIN 1 */
|
||||||
|
|
||||||
|
/* USER CODE END 1 */
|
||||||
|
|
||||||
|
/* MCU Configuration--------------------------------------------------------*/
|
||||||
|
|
||||||
|
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
|
||||||
|
HAL_Init();
|
||||||
|
|
||||||
|
/* USER CODE BEGIN Init */
|
||||||
|
|
||||||
|
/* USER CODE END Init */
|
||||||
|
|
||||||
|
/* Configure the system clock */
|
||||||
|
SystemClock_Config();
|
||||||
|
|
||||||
|
/* USER CODE BEGIN SysInit */
|
||||||
|
|
||||||
|
stateStartTime = HAL_GetTick();
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
|
||||||
|
/* USER CODE END SysInit */
|
||||||
|
|
||||||
|
/* Initialize all configured peripherals */
|
||||||
|
MX_GPIO_Init();
|
||||||
|
MX_CRC_Init();
|
||||||
|
MX_DMA2D_Init();
|
||||||
|
MX_TIM1_Init();
|
||||||
|
/* USER CODE BEGIN 2 */
|
||||||
|
|
||||||
|
/* USER CODE END 2 */
|
||||||
|
|
||||||
|
/* USER CODE BEGIN RTOS_MUTEX */
|
||||||
|
/* add mutexes, ... */
|
||||||
|
/* USER CODE END RTOS_MUTEX */
|
||||||
|
|
||||||
|
/* USER CODE BEGIN RTOS_SEMAPHORES */
|
||||||
|
/* add semaphores, ... */
|
||||||
|
/* USER CODE END RTOS_SEMAPHORES */
|
||||||
|
|
||||||
|
/* USER CODE BEGIN RTOS_TIMERS */
|
||||||
|
/* start timers, add new ones, ... */
|
||||||
|
/* USER CODE END RTOS_TIMERS */
|
||||||
|
|
||||||
|
/* USER CODE BEGIN RTOS_QUEUES */
|
||||||
|
/* add queues, ... */
|
||||||
|
/* USER CODE END RTOS_QUEUES */
|
||||||
|
|
||||||
|
/* Create the thread(s) */
|
||||||
|
/* definition and creation of defaultTask */
|
||||||
|
//osThreadDef(defaultTask, StartDefaultTask, osPriorityNormal, 0, 4096);
|
||||||
|
//defaultTaskHandle = osThreadCreate(osThread(defaultTask), NULL);
|
||||||
|
|
||||||
|
/* USER CODE BEGIN RTOS_THREADS */
|
||||||
|
/* add threads, ... */
|
||||||
|
/* USER CODE END RTOS_THREADS */
|
||||||
|
|
||||||
|
/* Start scheduler */
|
||||||
|
osKernelStart();
|
||||||
|
|
||||||
|
/* We should never get here as control is now taken by the scheduler */
|
||||||
|
|
||||||
|
/* Infinite loop */
|
||||||
|
/* USER CODE BEGIN WHILE */
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
uint32_t now = HAL_GetTick();
|
||||||
|
uint32_t elapsed = now - stateStartTime;
|
||||||
|
|
||||||
|
/*
|
||||||
|
switch(currentState)
|
||||||
|
{
|
||||||
|
case TrafficState::GREEN:
|
||||||
|
if (elapsed >= DURATION_GREEN) {
|
||||||
|
currentState = TrafficState::YELLOW;
|
||||||
|
stateStartTime = now;
|
||||||
|
buttonPressed = false; // reset the button-flag for the new cycle
|
||||||
|
} else if (buttonPressed) {
|
||||||
|
//idk
|
||||||
|
buttonPressed = true;
|
||||||
|
currentState = TrafficState::YELLOW;
|
||||||
|
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case TrafficState::YELLOW:
|
||||||
|
break;
|
||||||
|
case TrafficState::RED:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
switch(currentState)
|
||||||
|
{
|
||||||
|
case TrafficState::GREEN:
|
||||||
|
if (butonPressedThisCycle)
|
||||||
|
{
|
||||||
|
currentState = TrafficState::YELLOW;
|
||||||
|
stateStartTime = now;
|
||||||
|
buttonPressedThisCycle = false;
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
} else if (elapsed >= DURATION_GREEN)
|
||||||
|
{
|
||||||
|
buttonPressedThisCycle = true;
|
||||||
|
currentState = TrafficState::YELLOW;
|
||||||
|
stateStartTime = now;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case TrafficState::YELLOW:
|
||||||
|
if (elapsed >= DURATION_YELLOW)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case TrafficState::RED:
|
||||||
|
//
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/* USER CODE END WHILE */
|
||||||
|
|
||||||
|
/* USER CODE BEGIN 3 */
|
||||||
|
}
|
||||||
|
/* USER CODE END 3 */
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief System Clock Configuration
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void SystemClock_Config(void)
|
||||||
|
{
|
||||||
|
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
|
||||||
|
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
|
||||||
|
|
||||||
|
/** Configure the main internal regulator output voltage
|
||||||
|
*/
|
||||||
|
__HAL_RCC_PWR_CLK_ENABLE();
|
||||||
|
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE3);
|
||||||
|
|
||||||
|
/** Initializes the RCC Oscillators according to the specified parameters
|
||||||
|
* in the RCC_OscInitTypeDef structure.
|
||||||
|
*/
|
||||||
|
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
|
||||||
|
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
|
||||||
|
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
|
||||||
|
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
||||||
|
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
|
||||||
|
RCC_OscInitStruct.PLL.PLLM = 8;
|
||||||
|
RCC_OscInitStruct.PLL.PLLN = 72;
|
||||||
|
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
|
||||||
|
RCC_OscInitStruct.PLL.PLLQ = 3;
|
||||||
|
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Initializes the CPU, AHB and APB buses clocks
|
||||||
|
*/
|
||||||
|
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|
||||||
|
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
|
||||||
|
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
|
||||||
|
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
|
||||||
|
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
|
||||||
|
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
|
||||||
|
|
||||||
|
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief CRC Initialization Function
|
||||||
|
* @param None
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
static void MX_CRC_Init(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* USER CODE BEGIN CRC_Init 0 */
|
||||||
|
|
||||||
|
/* USER CODE END CRC_Init 0 */
|
||||||
|
|
||||||
|
/* USER CODE BEGIN CRC_Init 1 */
|
||||||
|
|
||||||
|
/* USER CODE END CRC_Init 1 */
|
||||||
|
hcrc.Instance = CRC;
|
||||||
|
if (HAL_CRC_Init(&hcrc) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
/* USER CODE BEGIN CRC_Init 2 */
|
||||||
|
|
||||||
|
/* USER CODE END CRC_Init 2 */
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief DMA2D Initialization Function
|
||||||
|
* @param None
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
static void MX_DMA2D_Init(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* USER CODE BEGIN DMA2D_Init 0 */
|
||||||
|
|
||||||
|
/* USER CODE END DMA2D_Init 0 */
|
||||||
|
|
||||||
|
/* USER CODE BEGIN DMA2D_Init 1 */
|
||||||
|
|
||||||
|
/* USER CODE END DMA2D_Init 1 */
|
||||||
|
hdma2d.Instance = DMA2D;
|
||||||
|
hdma2d.Init.Mode = DMA2D_M2M;
|
||||||
|
hdma2d.Init.ColorMode = DMA2D_OUTPUT_ARGB8888;
|
||||||
|
hdma2d.Init.OutputOffset = 0;
|
||||||
|
hdma2d.LayerCfg[1].InputOffset = 0;
|
||||||
|
hdma2d.LayerCfg[1].InputColorMode = DMA2D_INPUT_ARGB8888;
|
||||||
|
hdma2d.LayerCfg[1].AlphaMode = DMA2D_NO_MODIF_ALPHA;
|
||||||
|
hdma2d.LayerCfg[1].InputAlpha = 0;
|
||||||
|
if (HAL_DMA2D_Init(&hdma2d) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
if (HAL_DMA2D_ConfigLayer(&hdma2d, 1) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
/* USER CODE BEGIN DMA2D_Init 2 */
|
||||||
|
|
||||||
|
/* USER CODE END DMA2D_Init 2 */
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief TIM1 Initialization Function
|
||||||
|
* @param None
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
static void MX_TIM1_Init(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* USER CODE BEGIN TIM1_Init 0 */
|
||||||
|
|
||||||
|
/* USER CODE END TIM1_Init 0 */
|
||||||
|
|
||||||
|
TIM_ClockConfigTypeDef sClockSourceConfig = {0};
|
||||||
|
TIM_MasterConfigTypeDef sMasterConfig = {0};
|
||||||
|
|
||||||
|
/* USER CODE BEGIN TIM1_Init 1 */
|
||||||
|
|
||||||
|
/* USER CODE END TIM1_Init 1 */
|
||||||
|
htim1.Instance = TIM1;
|
||||||
|
htim1.Init.Prescaler = 0;
|
||||||
|
htim1.Init.CounterMode = TIM_COUNTERMODE_UP;
|
||||||
|
htim1.Init.Period = 65535;
|
||||||
|
htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
||||||
|
htim1.Init.RepetitionCounter = 0;
|
||||||
|
htim1.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
|
||||||
|
if (HAL_TIM_Base_Init(&htim1) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
|
||||||
|
if (HAL_TIM_ConfigClockSource(&htim1, &sClockSourceConfig) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
|
||||||
|
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
|
||||||
|
if (HAL_TIMEx_MasterConfigSynchronization(&htim1, &sMasterConfig) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
/* USER CODE BEGIN TIM1_Init 2 */
|
||||||
|
|
||||||
|
/* USER CODE END TIM1_Init 2 */
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief GPIO Initialization Function
|
||||||
|
* @param None
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
static void MX_GPIO_Init(void)
|
||||||
|
{
|
||||||
|
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||||
|
/* USER CODE BEGIN MX_GPIO_Init_1 */
|
||||||
|
|
||||||
|
/* USER CODE END MX_GPIO_Init_1 */
|
||||||
|
|
||||||
|
/* GPIO Ports Clock Enable */
|
||||||
|
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||||
|
__HAL_RCC_GPIOD_CLK_ENABLE();
|
||||||
|
|
||||||
|
/*Configure GPIO pin Output Level */
|
||||||
|
HAL_GPIO_WritePin(GPIOD, White_Pin|Red_Pin|Yellow_Pin|Green_Pin, GPIO_PIN_RESET);
|
||||||
|
|
||||||
|
/*Configure GPIO pin : PedButton_Pin */
|
||||||
|
GPIO_InitStruct.Pin = PedButton_Pin;
|
||||||
|
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
|
||||||
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
|
HAL_GPIO_Init(PedButton_GPIO_Port, &GPIO_InitStruct);
|
||||||
|
|
||||||
|
/*Configure GPIO pins : White_Pin Red_Pin Yellow_Pin Green_Pin */
|
||||||
|
GPIO_InitStruct.Pin = White_Pin|Red_Pin|Yellow_Pin|Green_Pin;
|
||||||
|
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||||
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||||
|
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
|
||||||
|
|
||||||
|
/* EXTI interrupt init*/
|
||||||
|
HAL_NVIC_SetPriority(EXTI15_10_IRQn, 15, 0);
|
||||||
|
HAL_NVIC_EnableIRQ(EXTI15_10_IRQn);
|
||||||
|
|
||||||
|
/* USER CODE BEGIN MX_GPIO_Init_2 */
|
||||||
|
|
||||||
|
/* USER CODE END MX_GPIO_Init_2 */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* USER CODE BEGIN 4 */
|
||||||
|
|
||||||
|
void HAL_GPIO_EXTI_CallBack(uint16_t GPIO_Pin)
|
||||||
|
{
|
||||||
|
static uint32_t lastInterruptTime = 0;
|
||||||
|
uint32_t now = HAL_GetTick();
|
||||||
|
if (now - lastInterruptTime < 100) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
lastInterruptTime = now;
|
||||||
|
|
||||||
|
bool buttonPressedThisCycle = false; // temporary, get rid of this
|
||||||
|
|
||||||
|
if (buttonPressed) { // buttonPressedHere?
|
||||||
|
buttonPressedThisCycle = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* USER CODE END 4 */
|
||||||
|
|
||||||
|
/* USER CODE BEGIN Header_StartDefaultTask */
|
||||||
|
/**
|
||||||
|
* @brief Function implementing the defaultTask thread.
|
||||||
|
* @param argument: Not used
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
/* USER CODE END Header_StartDefaultTask */
|
||||||
|
void StartDefaultTask(void const * argument)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN 5 */
|
||||||
|
/* Infinite loop */
|
||||||
|
for(;;)
|
||||||
|
{
|
||||||
|
osDelay(1);
|
||||||
|
}
|
||||||
|
/* USER CODE END 5 */
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Period elapsed callback in non blocking mode
|
||||||
|
* @note This function is called when TIM6 interrupt took place, inside
|
||||||
|
* HAL_TIM_IRQHandler(). It makes a direct call to HAL_IncTick() to increment
|
||||||
|
* a global variable "uwTick" used as application time base.
|
||||||
|
* @param htim : TIM handle
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN Callback 0 */
|
||||||
|
|
||||||
|
/* USER CODE END Callback 0 */
|
||||||
|
if (htim->Instance == TIM6)
|
||||||
|
{
|
||||||
|
HAL_IncTick();
|
||||||
|
}
|
||||||
|
/* USER CODE BEGIN Callback 1 */
|
||||||
|
|
||||||
|
/* USER CODE END Callback 1 */
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function is executed in case of error occurrence.
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void Error_Handler(void)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN Error_Handler_Debug */
|
||||||
|
/* User can add his own implementation to report the HAL error return state */
|
||||||
|
__disable_irq();
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
/* USER CODE END Error_Handler_Debug */
|
||||||
|
}
|
||||||
|
#ifdef USE_FULL_ASSERT
|
||||||
|
/**
|
||||||
|
* @brief Reports the name of the source file and the source line number
|
||||||
|
* where the assert_param error has occurred.
|
||||||
|
* @param file: pointer to the source file name
|
||||||
|
* @param line: assert_param error line source number
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void assert_failed(uint8_t *file, uint32_t line)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN 6 */
|
||||||
|
/* User can add his own implementation to report the file name and line number,
|
||||||
|
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
|
||||||
|
/* USER CODE END 6 */
|
||||||
|
}
|
||||||
|
#endif /* USE_FULL_ASSERT */
|
||||||
@@ -0,0 +1,480 @@
|
|||||||
|
/* USER CODE BEGIN Header */
|
||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
* @file : main.c
|
||||||
|
* @brief : Main program body
|
||||||
|
******************************************************************************
|
||||||
|
* @attention
|
||||||
|
*
|
||||||
|
* Copyright (c) 2025 STMicroelectronics.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This software is licensed under terms that can be found in the LICENSE file
|
||||||
|
* in the root directory of this software component.
|
||||||
|
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||||
|
*
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
/* USER CODE END Header */
|
||||||
|
/* Includes ------------------------------------------------------------------*/
|
||||||
|
#include "main.h"
|
||||||
|
#include "cmsis_os.h"
|
||||||
|
|
||||||
|
/* Private includes ----------------------------------------------------------*/
|
||||||
|
/* USER CODE BEGIN Includes */
|
||||||
|
#include "breadboard.h"
|
||||||
|
#include <stdbool.h>
|
||||||
|
/* USER CODE END Includes */
|
||||||
|
|
||||||
|
/* Private typedef -----------------------------------------------------------*/
|
||||||
|
/* USER CODE BEGIN PTD */
|
||||||
|
|
||||||
|
/* USER CODE END PTD */
|
||||||
|
|
||||||
|
/* Private define ------------------------------------------------------------*/
|
||||||
|
/* USER CODE BEGIN PD */
|
||||||
|
|
||||||
|
/* USER CODE END PD */
|
||||||
|
|
||||||
|
/* Private macro -------------------------------------------------------------*/
|
||||||
|
/* USER CODE BEGIN PM */
|
||||||
|
|
||||||
|
/* USER CODE END PM */
|
||||||
|
|
||||||
|
/* Private variables ---------------------------------------------------------*/
|
||||||
|
CRC_HandleTypeDef hcrc;
|
||||||
|
|
||||||
|
DMA2D_HandleTypeDef hdma2d;
|
||||||
|
|
||||||
|
TIM_HandleTypeDef htim1;
|
||||||
|
|
||||||
|
osThreadId defaultTaskHandle;
|
||||||
|
/* USER CODE BEGIN PV */
|
||||||
|
|
||||||
|
/* USER CODE END PV */
|
||||||
|
|
||||||
|
/* Private function prototypes -----------------------------------------------*/
|
||||||
|
void SystemClock_Config(void);
|
||||||
|
static void MX_GPIO_Init(void);
|
||||||
|
static void MX_CRC_Init(void);
|
||||||
|
static void MX_DMA2D_Init(void);
|
||||||
|
static void MX_TIM1_Init(void);
|
||||||
|
void StartDefaultTask(void const * argument);
|
||||||
|
|
||||||
|
void SetTrafficLights(TrafficSate s);
|
||||||
|
|
||||||
|
/* USER CODE BEGIN PFP */
|
||||||
|
|
||||||
|
/* USER CODE END PFP */
|
||||||
|
|
||||||
|
/* Private user code ---------------------------------------------------------*/
|
||||||
|
|
||||||
|
/* USER CODE BEGIN 0 */
|
||||||
|
|
||||||
|
enum class TrafficState {
|
||||||
|
GREEN,
|
||||||
|
YELLOW,
|
||||||
|
RED
|
||||||
|
};
|
||||||
|
|
||||||
|
TrafficState currentState = TrafficState::GREEN;
|
||||||
|
uint32_t stateStartTime = 0; // HAL_GetTick() at the start of this state
|
||||||
|
bool buttonPressed = false;
|
||||||
|
bool pedestrianNextCycle = false;
|
||||||
|
|
||||||
|
const uint32_t DURATION_GREEN = 5000;
|
||||||
|
const uint32_t DURATION_YELLOW = 3000;
|
||||||
|
const uint32_t DURATION_RED = 5000;
|
||||||
|
const uint32_t DURATION_RED_PED = 7000;
|
||||||
|
|
||||||
|
/* USER CODE END 0 */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief The application entry point.
|
||||||
|
* @retval int
|
||||||
|
*/
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* USER CODE BEGIN 1 */
|
||||||
|
|
||||||
|
/* USER CODE END 1 */
|
||||||
|
|
||||||
|
/* MCU Configuration--------------------------------------------------------*/
|
||||||
|
|
||||||
|
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
|
||||||
|
HAL_Init();
|
||||||
|
|
||||||
|
/* USER CODE BEGIN Init */
|
||||||
|
|
||||||
|
/* USER CODE END Init */
|
||||||
|
|
||||||
|
/* Configure the system clock */
|
||||||
|
SystemClock_Config();
|
||||||
|
|
||||||
|
/* USER CODE BEGIN SysInit */
|
||||||
|
|
||||||
|
stateStartTime = HAL_GetTick();
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
|
||||||
|
/* USER CODE END SysInit */
|
||||||
|
|
||||||
|
/* Initialize all configured peripherals */
|
||||||
|
MX_GPIO_Init();
|
||||||
|
MX_CRC_Init();
|
||||||
|
MX_DMA2D_Init();
|
||||||
|
MX_TIM1_Init();
|
||||||
|
/* USER CODE BEGIN 2 */
|
||||||
|
|
||||||
|
/* USER CODE END 2 */
|
||||||
|
|
||||||
|
/* USER CODE BEGIN RTOS_MUTEX */
|
||||||
|
/* add mutexes, ... */
|
||||||
|
/* USER CODE END RTOS_MUTEX */
|
||||||
|
|
||||||
|
/* USER CODE BEGIN RTOS_SEMAPHORES */
|
||||||
|
/* add semaphores, ... */
|
||||||
|
/* USER CODE END RTOS_SEMAPHORES */
|
||||||
|
|
||||||
|
/* USER CODE BEGIN RTOS_TIMERS */
|
||||||
|
/* start timers, add new ones, ... */
|
||||||
|
/* USER CODE END RTOS_TIMERS */
|
||||||
|
|
||||||
|
/* USER CODE BEGIN RTOS_QUEUES */
|
||||||
|
/* add queues, ... */
|
||||||
|
/* USER CODE END RTOS_QUEUES */
|
||||||
|
|
||||||
|
/* Create the thread(s) */
|
||||||
|
/* definition and creation of defaultTask */
|
||||||
|
//osThreadDef(defaultTask, StartDefaultTask, osPriorityNormal, 0, 4096);
|
||||||
|
//defaultTaskHandle = osThreadCreate(osThread(defaultTask), NULL);
|
||||||
|
|
||||||
|
/* USER CODE BEGIN RTOS_THREADS */
|
||||||
|
/* add threads, ... */
|
||||||
|
/* USER CODE END RTOS_THREADS */
|
||||||
|
|
||||||
|
/* Start scheduler */
|
||||||
|
osKernelStart();
|
||||||
|
|
||||||
|
/* We should never get here as control is now taken by the scheduler */
|
||||||
|
|
||||||
|
/* Infinite loop */
|
||||||
|
/* USER CODE BEGIN WHILE */
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
uint32_t now = HAL_GetTick();
|
||||||
|
uint32_t elapsed = now - stateStartTime;
|
||||||
|
|
||||||
|
switch(currentState)
|
||||||
|
{
|
||||||
|
case TrafficState::GREEN:
|
||||||
|
if (elapsed >= DURATION_GREEN) {
|
||||||
|
currentState = TrafficState::YELLOW;
|
||||||
|
stateStartTime = now;
|
||||||
|
buttonPressed = false; // reset the button-flag for the new cycle
|
||||||
|
} else if (buttonPressed) {
|
||||||
|
//idk
|
||||||
|
buttonPressed = true;
|
||||||
|
currentState = TrafficState::YELLOW;
|
||||||
|
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case TrafficState::YELLOW:
|
||||||
|
break;
|
||||||
|
case TrafficState::RED:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/* USER CODE END WHILE */
|
||||||
|
|
||||||
|
/* USER CODE BEGIN 3 */
|
||||||
|
}
|
||||||
|
/* USER CODE END 3 */
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief System Clock Configuration
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void SystemClock_Config(void)
|
||||||
|
{
|
||||||
|
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
|
||||||
|
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
|
||||||
|
|
||||||
|
/** Configure the main internal regulator output voltage
|
||||||
|
*/
|
||||||
|
__HAL_RCC_PWR_CLK_ENABLE();
|
||||||
|
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE3);
|
||||||
|
|
||||||
|
/** Initializes the RCC Oscillators according to the specified parameters
|
||||||
|
* in the RCC_OscInitTypeDef structure.
|
||||||
|
*/
|
||||||
|
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
|
||||||
|
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
|
||||||
|
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
|
||||||
|
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
||||||
|
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
|
||||||
|
RCC_OscInitStruct.PLL.PLLM = 8;
|
||||||
|
RCC_OscInitStruct.PLL.PLLN = 72;
|
||||||
|
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
|
||||||
|
RCC_OscInitStruct.PLL.PLLQ = 3;
|
||||||
|
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Initializes the CPU, AHB and APB buses clocks
|
||||||
|
*/
|
||||||
|
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|
||||||
|
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
|
||||||
|
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
|
||||||
|
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
|
||||||
|
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
|
||||||
|
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
|
||||||
|
|
||||||
|
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief CRC Initialization Function
|
||||||
|
* @param None
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
static void MX_CRC_Init(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* USER CODE BEGIN CRC_Init 0 */
|
||||||
|
|
||||||
|
/* USER CODE END CRC_Init 0 */
|
||||||
|
|
||||||
|
/* USER CODE BEGIN CRC_Init 1 */
|
||||||
|
|
||||||
|
/* USER CODE END CRC_Init 1 */
|
||||||
|
hcrc.Instance = CRC;
|
||||||
|
if (HAL_CRC_Init(&hcrc) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
/* USER CODE BEGIN CRC_Init 2 */
|
||||||
|
|
||||||
|
/* USER CODE END CRC_Init 2 */
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief DMA2D Initialization Function
|
||||||
|
* @param None
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
static void MX_DMA2D_Init(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* USER CODE BEGIN DMA2D_Init 0 */
|
||||||
|
|
||||||
|
/* USER CODE END DMA2D_Init 0 */
|
||||||
|
|
||||||
|
/* USER CODE BEGIN DMA2D_Init 1 */
|
||||||
|
|
||||||
|
/* USER CODE END DMA2D_Init 1 */
|
||||||
|
hdma2d.Instance = DMA2D;
|
||||||
|
hdma2d.Init.Mode = DMA2D_M2M;
|
||||||
|
hdma2d.Init.ColorMode = DMA2D_OUTPUT_ARGB8888;
|
||||||
|
hdma2d.Init.OutputOffset = 0;
|
||||||
|
hdma2d.LayerCfg[1].InputOffset = 0;
|
||||||
|
hdma2d.LayerCfg[1].InputColorMode = DMA2D_INPUT_ARGB8888;
|
||||||
|
hdma2d.LayerCfg[1].AlphaMode = DMA2D_NO_MODIF_ALPHA;
|
||||||
|
hdma2d.LayerCfg[1].InputAlpha = 0;
|
||||||
|
if (HAL_DMA2D_Init(&hdma2d) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
if (HAL_DMA2D_ConfigLayer(&hdma2d, 1) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
/* USER CODE BEGIN DMA2D_Init 2 */
|
||||||
|
|
||||||
|
/* USER CODE END DMA2D_Init 2 */
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief TIM1 Initialization Function
|
||||||
|
* @param None
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
static void MX_TIM1_Init(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* USER CODE BEGIN TIM1_Init 0 */
|
||||||
|
|
||||||
|
/* USER CODE END TIM1_Init 0 */
|
||||||
|
|
||||||
|
TIM_ClockConfigTypeDef sClockSourceConfig = {0};
|
||||||
|
TIM_MasterConfigTypeDef sMasterConfig = {0};
|
||||||
|
|
||||||
|
/* USER CODE BEGIN TIM1_Init 1 */
|
||||||
|
|
||||||
|
/* USER CODE END TIM1_Init 1 */
|
||||||
|
htim1.Instance = TIM1;
|
||||||
|
htim1.Init.Prescaler = 0;
|
||||||
|
htim1.Init.CounterMode = TIM_COUNTERMODE_UP;
|
||||||
|
htim1.Init.Period = 65535;
|
||||||
|
htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
||||||
|
htim1.Init.RepetitionCounter = 0;
|
||||||
|
htim1.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
|
||||||
|
if (HAL_TIM_Base_Init(&htim1) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
|
||||||
|
if (HAL_TIM_ConfigClockSource(&htim1, &sClockSourceConfig) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
|
||||||
|
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
|
||||||
|
if (HAL_TIMEx_MasterConfigSynchronization(&htim1, &sMasterConfig) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
/* USER CODE BEGIN TIM1_Init 2 */
|
||||||
|
|
||||||
|
/* USER CODE END TIM1_Init 2 */
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief GPIO Initialization Function
|
||||||
|
* @param None
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
static void MX_GPIO_Init(void)
|
||||||
|
{
|
||||||
|
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||||
|
/* USER CODE BEGIN MX_GPIO_Init_1 */
|
||||||
|
|
||||||
|
/* USER CODE END MX_GPIO_Init_1 */
|
||||||
|
|
||||||
|
/* GPIO Ports Clock Enable */
|
||||||
|
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||||
|
__HAL_RCC_GPIOD_CLK_ENABLE();
|
||||||
|
|
||||||
|
/*Configure GPIO pin Output Level */
|
||||||
|
HAL_GPIO_WritePin(GPIOD, White_Pin|Red_Pin|Yellow_Pin|Green_Pin, GPIO_PIN_RESET);
|
||||||
|
|
||||||
|
/*Configure GPIO pin : PedButton_Pin */
|
||||||
|
GPIO_InitStruct.Pin = PedButton_Pin;
|
||||||
|
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
|
||||||
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
|
HAL_GPIO_Init(PedButton_GPIO_Port, &GPIO_InitStruct);
|
||||||
|
|
||||||
|
/*Configure GPIO pins : White_Pin Red_Pin Yellow_Pin Green_Pin */
|
||||||
|
GPIO_InitStruct.Pin = White_Pin|Red_Pin|Yellow_Pin|Green_Pin;
|
||||||
|
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||||
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||||
|
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
|
||||||
|
|
||||||
|
/* EXTI interrupt init*/
|
||||||
|
HAL_NVIC_SetPriority(EXTI15_10_IRQn, 15, 0);
|
||||||
|
HAL_NVIC_EnableIRQ(EXTI15_10_IRQn);
|
||||||
|
|
||||||
|
/* USER CODE BEGIN MX_GPIO_Init_2 */
|
||||||
|
|
||||||
|
/* USER CODE END MX_GPIO_Init_2 */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* USER CODE BEGIN 4 */
|
||||||
|
|
||||||
|
void HAL_GPIO_EXTI_CallBack(uint16_t GPIO_Pin)
|
||||||
|
{
|
||||||
|
static uint32_t lastInterruptTime = 0;
|
||||||
|
uint32_t now = HAL_GetTick();
|
||||||
|
if (now - lastInterruptTime < 100) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
lastInterruptTime = now;
|
||||||
|
|
||||||
|
bool buttonPressedThisCycle = false; // temporary, get rid of this
|
||||||
|
|
||||||
|
if (buttonPressed) { // buttonPressedHere?
|
||||||
|
buttonPressedThisCycle = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* USER CODE END 4 */
|
||||||
|
|
||||||
|
/* USER CODE BEGIN Header_StartDefaultTask */
|
||||||
|
/**
|
||||||
|
* @brief Function implementing the defaultTask thread.
|
||||||
|
* @param argument: Not used
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
/* USER CODE END Header_StartDefaultTask */
|
||||||
|
void StartDefaultTask(void const * argument)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN 5 */
|
||||||
|
/* Infinite loop */
|
||||||
|
for(;;)
|
||||||
|
{
|
||||||
|
osDelay(1);
|
||||||
|
}
|
||||||
|
/* USER CODE END 5 */
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Period elapsed callback in non blocking mode
|
||||||
|
* @note This function is called when TIM6 interrupt took place, inside
|
||||||
|
* HAL_TIM_IRQHandler(). It makes a direct call to HAL_IncTick() to increment
|
||||||
|
* a global variable "uwTick" used as application time base.
|
||||||
|
* @param htim : TIM handle
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN Callback 0 */
|
||||||
|
|
||||||
|
/* USER CODE END Callback 0 */
|
||||||
|
if (htim->Instance == TIM6)
|
||||||
|
{
|
||||||
|
HAL_IncTick();
|
||||||
|
}
|
||||||
|
/* USER CODE BEGIN Callback 1 */
|
||||||
|
|
||||||
|
/* USER CODE END Callback 1 */
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function is executed in case of error occurrence.
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void Error_Handler(void)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN Error_Handler_Debug */
|
||||||
|
/* User can add his own implementation to report the HAL error return state */
|
||||||
|
__disable_irq();
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
/* USER CODE END Error_Handler_Debug */
|
||||||
|
}
|
||||||
|
#ifdef USE_FULL_ASSERT
|
||||||
|
/**
|
||||||
|
* @brief Reports the name of the source file and the source line number
|
||||||
|
* where the assert_param error has occurred.
|
||||||
|
* @param file: pointer to the source file name
|
||||||
|
* @param line: assert_param error line source number
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void assert_failed(uint8_t *file, uint32_t line)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN 6 */
|
||||||
|
/* User can add his own implementation to report the file name and line number,
|
||||||
|
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
|
||||||
|
/* USER CODE END 6 */
|
||||||
|
}
|
||||||
|
#endif /* USE_FULL_ASSERT */
|
||||||
@@ -1,730 +0,0 @@
|
|||||||
/* USER CODE BEGIN Header */
|
|
||||||
/**
|
|
||||||
******************************************************************************
|
|
||||||
* @file : main.c
|
|
||||||
* @brief : Main program body
|
|
||||||
******************************************************************************
|
|
||||||
* @attention
|
|
||||||
*
|
|
||||||
* Copyright (c) 2025 STMicroelectronics.
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* This software is licensed under terms that can be found in the LICENSE file
|
|
||||||
* in the root directory of this software component.
|
|
||||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
|
||||||
*
|
|
||||||
******************************************************************************
|
|
||||||
*/
|
|
||||||
/* USER CODE END Header */
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
|
||||||
#include "main.h"
|
|
||||||
#include "cmsis_os.h"
|
|
||||||
#include "usb_host.h"
|
|
||||||
|
|
||||||
/* Private includes ----------------------------------------------------------*/
|
|
||||||
/* USER CODE BEGIN Includes */
|
|
||||||
#include "breadboard.h"
|
|
||||||
|
|
||||||
/* USER CODE END Includes */
|
|
||||||
|
|
||||||
/* Private typedef -----------------------------------------------------------*/
|
|
||||||
/* USER CODE BEGIN PTD */
|
|
||||||
|
|
||||||
/* USER CODE END PTD */
|
|
||||||
|
|
||||||
/* Private define ------------------------------------------------------------*/
|
|
||||||
/* USER CODE BEGIN PD */
|
|
||||||
|
|
||||||
/* USER CODE END PD */
|
|
||||||
|
|
||||||
/* Private macro -------------------------------------------------------------*/
|
|
||||||
/* USER CODE BEGIN PM */
|
|
||||||
|
|
||||||
/* USER CODE END PM */
|
|
||||||
|
|
||||||
/* Private variables ---------------------------------------------------------*/
|
|
||||||
CRC_HandleTypeDef hcrc;
|
|
||||||
|
|
||||||
DMA2D_HandleTypeDef hdma2d;
|
|
||||||
|
|
||||||
I2C_HandleTypeDef hi2c3;
|
|
||||||
|
|
||||||
LTDC_HandleTypeDef hltdc;
|
|
||||||
|
|
||||||
SPI_HandleTypeDef hspi5;
|
|
||||||
|
|
||||||
TIM_HandleTypeDef htim1;
|
|
||||||
|
|
||||||
UART_HandleTypeDef huart1;
|
|
||||||
|
|
||||||
SDRAM_HandleTypeDef hsdram1;
|
|
||||||
|
|
||||||
osThreadId defaultTaskHandle;
|
|
||||||
/* USER CODE BEGIN PV */
|
|
||||||
|
|
||||||
/* USER CODE END PV */
|
|
||||||
|
|
||||||
/* Private function prototypes -----------------------------------------------*/
|
|
||||||
void SystemClock_Config(void);
|
|
||||||
static void MX_GPIO_Init(void);
|
|
||||||
static void MX_CRC_Init(void);
|
|
||||||
static void MX_DMA2D_Init(void);
|
|
||||||
static void MX_FMC_Init(void);
|
|
||||||
static void MX_I2C3_Init(void);
|
|
||||||
static void MX_LTDC_Init(void);
|
|
||||||
static void MX_SPI5_Init(void);
|
|
||||||
static void MX_TIM1_Init(void);
|
|
||||||
static void MX_USART1_UART_Init(void);
|
|
||||||
void StartDefaultTask(void const * argument);
|
|
||||||
|
|
||||||
/* USER CODE BEGIN PFP */
|
|
||||||
|
|
||||||
/* USER CODE END PFP */
|
|
||||||
|
|
||||||
/* Private user code ---------------------------------------------------------*/
|
|
||||||
/* USER CODE BEGIN 0 */
|
|
||||||
|
|
||||||
/* USER CODE END 0 */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief The application entry point.
|
|
||||||
* @retval int
|
|
||||||
*/
|
|
||||||
int main(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* USER CODE BEGIN 1 */
|
|
||||||
|
|
||||||
/* USER CODE END 1 */
|
|
||||||
|
|
||||||
/* MCU Configuration--------------------------------------------------------*/
|
|
||||||
|
|
||||||
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
|
|
||||||
HAL_Init();
|
|
||||||
|
|
||||||
/* USER CODE BEGIN Init */
|
|
||||||
|
|
||||||
/* USER CODE END Init */
|
|
||||||
|
|
||||||
/* Configure the system clock */
|
|
||||||
SystemClock_Config();
|
|
||||||
|
|
||||||
/* USER CODE BEGIN SysInit */
|
|
||||||
|
|
||||||
/* USER CODE END SysInit */
|
|
||||||
|
|
||||||
/* Initialize all configured peripherals */
|
|
||||||
MX_GPIO_Init();
|
|
||||||
MX_CRC_Init();
|
|
||||||
MX_DMA2D_Init();
|
|
||||||
MX_FMC_Init();
|
|
||||||
MX_I2C3_Init();
|
|
||||||
MX_LTDC_Init();
|
|
||||||
MX_SPI5_Init();
|
|
||||||
MX_TIM1_Init();
|
|
||||||
MX_USART1_UART_Init();
|
|
||||||
/* USER CODE BEGIN 2 */
|
|
||||||
|
|
||||||
/* USER CODE END 2 */
|
|
||||||
|
|
||||||
/* USER CODE BEGIN RTOS_MUTEX */
|
|
||||||
/* add mutexes, ... */
|
|
||||||
/* USER CODE END RTOS_MUTEX */
|
|
||||||
|
|
||||||
/* USER CODE BEGIN RTOS_SEMAPHORES */
|
|
||||||
/* add semaphores, ... */
|
|
||||||
/* USER CODE END RTOS_SEMAPHORES */
|
|
||||||
|
|
||||||
/* USER CODE BEGIN RTOS_TIMERS */
|
|
||||||
/* start timers, add new ones, ... */
|
|
||||||
/* USER CODE END RTOS_TIMERS */
|
|
||||||
|
|
||||||
/* USER CODE BEGIN RTOS_QUEUES */
|
|
||||||
/* add queues, ... */
|
|
||||||
/* USER CODE END RTOS_QUEUES */
|
|
||||||
|
|
||||||
/* Create the thread(s) */
|
|
||||||
/* definition and creation of defaultTask */
|
|
||||||
//osThreadDef(defaultTask, StartDefaultTask, osPriorityNormal, 0, 4096);
|
|
||||||
//defaultTaskHandle = osThreadCreate(osThread(defaultTask), NULL);
|
|
||||||
|
|
||||||
/* USER CODE BEGIN RTOS_THREADS */
|
|
||||||
/* add threads, ... */
|
|
||||||
/* USER CODE END RTOS_THREADS */
|
|
||||||
|
|
||||||
/* Start scheduler */
|
|
||||||
//osKernelStart();
|
|
||||||
|
|
||||||
/* We should never get here as control is now taken by the scheduler */
|
|
||||||
|
|
||||||
/* Infinite loop */
|
|
||||||
/* USER CODE BEGIN WHILE */
|
|
||||||
while (1)
|
|
||||||
{
|
|
||||||
trafflight(2000, 10*1000);
|
|
||||||
/* USER CODE END WHILE */
|
|
||||||
|
|
||||||
/* USER CODE BEGIN 3 */
|
|
||||||
}
|
|
||||||
/* USER CODE END 3 */
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief System Clock Configuration
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
void SystemClock_Config(void)
|
|
||||||
{
|
|
||||||
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
|
|
||||||
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
|
|
||||||
|
|
||||||
/** Configure the main internal regulator output voltage
|
|
||||||
*/
|
|
||||||
__HAL_RCC_PWR_CLK_ENABLE();
|
|
||||||
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE3);
|
|
||||||
|
|
||||||
/** Initializes the RCC Oscillators according to the specified parameters
|
|
||||||
* in the RCC_OscInitTypeDef structure.
|
|
||||||
*/
|
|
||||||
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
|
|
||||||
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
|
|
||||||
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
|
||||||
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
|
|
||||||
RCC_OscInitStruct.PLL.PLLM = 4;
|
|
||||||
RCC_OscInitStruct.PLL.PLLN = 72;
|
|
||||||
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
|
|
||||||
RCC_OscInitStruct.PLL.PLLQ = 3;
|
|
||||||
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Initializes the CPU, AHB and APB buses clocks
|
|
||||||
*/
|
|
||||||
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|
|
||||||
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
|
|
||||||
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
|
|
||||||
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
|
|
||||||
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
|
|
||||||
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
|
|
||||||
|
|
||||||
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief CRC Initialization Function
|
|
||||||
* @param None
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
static void MX_CRC_Init(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* USER CODE BEGIN CRC_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE END CRC_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE BEGIN CRC_Init 1 */
|
|
||||||
|
|
||||||
/* USER CODE END CRC_Init 1 */
|
|
||||||
hcrc.Instance = CRC;
|
|
||||||
if (HAL_CRC_Init(&hcrc) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
/* USER CODE BEGIN CRC_Init 2 */
|
|
||||||
|
|
||||||
/* USER CODE END CRC_Init 2 */
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief DMA2D Initialization Function
|
|
||||||
* @param None
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
static void MX_DMA2D_Init(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* USER CODE BEGIN DMA2D_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE END DMA2D_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE BEGIN DMA2D_Init 1 */
|
|
||||||
|
|
||||||
/* USER CODE END DMA2D_Init 1 */
|
|
||||||
hdma2d.Instance = DMA2D;
|
|
||||||
hdma2d.Init.Mode = DMA2D_M2M;
|
|
||||||
hdma2d.Init.ColorMode = DMA2D_OUTPUT_ARGB8888;
|
|
||||||
hdma2d.Init.OutputOffset = 0;
|
|
||||||
hdma2d.LayerCfg[1].InputOffset = 0;
|
|
||||||
hdma2d.LayerCfg[1].InputColorMode = DMA2D_INPUT_ARGB8888;
|
|
||||||
hdma2d.LayerCfg[1].AlphaMode = DMA2D_NO_MODIF_ALPHA;
|
|
||||||
hdma2d.LayerCfg[1].InputAlpha = 0;
|
|
||||||
if (HAL_DMA2D_Init(&hdma2d) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
if (HAL_DMA2D_ConfigLayer(&hdma2d, 1) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
/* USER CODE BEGIN DMA2D_Init 2 */
|
|
||||||
|
|
||||||
/* USER CODE END DMA2D_Init 2 */
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief I2C3 Initialization Function
|
|
||||||
* @param None
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
static void MX_I2C3_Init(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* USER CODE BEGIN I2C3_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE END I2C3_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE BEGIN I2C3_Init 1 */
|
|
||||||
|
|
||||||
/* USER CODE END I2C3_Init 1 */
|
|
||||||
hi2c3.Instance = I2C3;
|
|
||||||
hi2c3.Init.ClockSpeed = 100000;
|
|
||||||
hi2c3.Init.DutyCycle = I2C_DUTYCYCLE_2;
|
|
||||||
hi2c3.Init.OwnAddress1 = 0;
|
|
||||||
hi2c3.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
|
|
||||||
hi2c3.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
|
|
||||||
hi2c3.Init.OwnAddress2 = 0;
|
|
||||||
hi2c3.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
|
|
||||||
hi2c3.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
|
|
||||||
if (HAL_I2C_Init(&hi2c3) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Configure Analogue filter
|
|
||||||
*/
|
|
||||||
if (HAL_I2CEx_ConfigAnalogFilter(&hi2c3, I2C_ANALOGFILTER_ENABLE) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Configure Digital filter
|
|
||||||
*/
|
|
||||||
if (HAL_I2CEx_ConfigDigitalFilter(&hi2c3, 0) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
/* USER CODE BEGIN I2C3_Init 2 */
|
|
||||||
|
|
||||||
/* USER CODE END I2C3_Init 2 */
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief LTDC Initialization Function
|
|
||||||
* @param None
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
static void MX_LTDC_Init(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* USER CODE BEGIN LTDC_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE END LTDC_Init 0 */
|
|
||||||
|
|
||||||
LTDC_LayerCfgTypeDef pLayerCfg = {0};
|
|
||||||
|
|
||||||
/* USER CODE BEGIN LTDC_Init 1 */
|
|
||||||
|
|
||||||
/* USER CODE END LTDC_Init 1 */
|
|
||||||
hltdc.Instance = LTDC;
|
|
||||||
hltdc.Init.HSPolarity = LTDC_HSPOLARITY_AL;
|
|
||||||
hltdc.Init.VSPolarity = LTDC_VSPOLARITY_AL;
|
|
||||||
hltdc.Init.DEPolarity = LTDC_DEPOLARITY_AL;
|
|
||||||
hltdc.Init.PCPolarity = LTDC_PCPOLARITY_IPC;
|
|
||||||
hltdc.Init.HorizontalSync = 9;
|
|
||||||
hltdc.Init.VerticalSync = 1;
|
|
||||||
hltdc.Init.AccumulatedHBP = 29;
|
|
||||||
hltdc.Init.AccumulatedVBP = 3;
|
|
||||||
hltdc.Init.AccumulatedActiveW = 269;
|
|
||||||
hltdc.Init.AccumulatedActiveH = 323;
|
|
||||||
hltdc.Init.TotalWidth = 279;
|
|
||||||
hltdc.Init.TotalHeigh = 327;
|
|
||||||
hltdc.Init.Backcolor.Blue = 0;
|
|
||||||
hltdc.Init.Backcolor.Green = 0;
|
|
||||||
hltdc.Init.Backcolor.Red = 0;
|
|
||||||
if (HAL_LTDC_Init(&hltdc) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
pLayerCfg.WindowX0 = 0;
|
|
||||||
pLayerCfg.WindowX1 = 240;
|
|
||||||
pLayerCfg.WindowY0 = 0;
|
|
||||||
pLayerCfg.WindowY1 = 320;
|
|
||||||
pLayerCfg.PixelFormat = LTDC_PIXEL_FORMAT_RGB565;
|
|
||||||
pLayerCfg.Alpha = 255;
|
|
||||||
pLayerCfg.Alpha0 = 0;
|
|
||||||
pLayerCfg.BlendingFactor1 = LTDC_BLENDING_FACTOR1_PAxCA;
|
|
||||||
pLayerCfg.BlendingFactor2 = LTDC_BLENDING_FACTOR2_PAxCA;
|
|
||||||
pLayerCfg.FBStartAdress = 0xD0000000;
|
|
||||||
pLayerCfg.ImageWidth = 240;
|
|
||||||
pLayerCfg.ImageHeight = 320;
|
|
||||||
pLayerCfg.Backcolor.Blue = 0;
|
|
||||||
pLayerCfg.Backcolor.Green = 0;
|
|
||||||
pLayerCfg.Backcolor.Red = 0;
|
|
||||||
if (HAL_LTDC_ConfigLayer(&hltdc, &pLayerCfg, 0) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
/* USER CODE BEGIN LTDC_Init 2 */
|
|
||||||
|
|
||||||
/* USER CODE END LTDC_Init 2 */
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief SPI5 Initialization Function
|
|
||||||
* @param None
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
static void MX_SPI5_Init(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* USER CODE BEGIN SPI5_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE END SPI5_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE BEGIN SPI5_Init 1 */
|
|
||||||
|
|
||||||
/* USER CODE END SPI5_Init 1 */
|
|
||||||
/* SPI5 parameter configuration*/
|
|
||||||
hspi5.Instance = SPI5;
|
|
||||||
hspi5.Init.Mode = SPI_MODE_MASTER;
|
|
||||||
hspi5.Init.Direction = SPI_DIRECTION_2LINES;
|
|
||||||
hspi5.Init.DataSize = SPI_DATASIZE_8BIT;
|
|
||||||
hspi5.Init.CLKPolarity = SPI_POLARITY_LOW;
|
|
||||||
hspi5.Init.CLKPhase = SPI_PHASE_1EDGE;
|
|
||||||
hspi5.Init.NSS = SPI_NSS_SOFT;
|
|
||||||
hspi5.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_16;
|
|
||||||
hspi5.Init.FirstBit = SPI_FIRSTBIT_MSB;
|
|
||||||
hspi5.Init.TIMode = SPI_TIMODE_DISABLE;
|
|
||||||
hspi5.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
|
|
||||||
hspi5.Init.CRCPolynomial = 10;
|
|
||||||
if (HAL_SPI_Init(&hspi5) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
/* USER CODE BEGIN SPI5_Init 2 */
|
|
||||||
|
|
||||||
/* USER CODE END SPI5_Init 2 */
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief TIM1 Initialization Function
|
|
||||||
* @param None
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
static void MX_TIM1_Init(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* USER CODE BEGIN TIM1_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE END TIM1_Init 0 */
|
|
||||||
|
|
||||||
TIM_ClockConfigTypeDef sClockSourceConfig = {0};
|
|
||||||
TIM_MasterConfigTypeDef sMasterConfig = {0};
|
|
||||||
|
|
||||||
/* USER CODE BEGIN TIM1_Init 1 */
|
|
||||||
|
|
||||||
/* USER CODE END TIM1_Init 1 */
|
|
||||||
htim1.Instance = TIM1;
|
|
||||||
htim1.Init.Prescaler = 0;
|
|
||||||
htim1.Init.CounterMode = TIM_COUNTERMODE_UP;
|
|
||||||
htim1.Init.Period = 65535;
|
|
||||||
htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
|
||||||
htim1.Init.RepetitionCounter = 0;
|
|
||||||
htim1.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
|
|
||||||
if (HAL_TIM_Base_Init(&htim1) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
|
|
||||||
if (HAL_TIM_ConfigClockSource(&htim1, &sClockSourceConfig) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
|
|
||||||
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
|
|
||||||
if (HAL_TIMEx_MasterConfigSynchronization(&htim1, &sMasterConfig) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
/* USER CODE BEGIN TIM1_Init 2 */
|
|
||||||
|
|
||||||
/* USER CODE END TIM1_Init 2 */
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief USART1 Initialization Function
|
|
||||||
* @param None
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
static void MX_USART1_UART_Init(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* USER CODE BEGIN USART1_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE END USART1_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE BEGIN USART1_Init 1 */
|
|
||||||
|
|
||||||
/* USER CODE END USART1_Init 1 */
|
|
||||||
huart1.Instance = USART1;
|
|
||||||
huart1.Init.BaudRate = 115200;
|
|
||||||
huart1.Init.WordLength = UART_WORDLENGTH_8B;
|
|
||||||
huart1.Init.StopBits = UART_STOPBITS_1;
|
|
||||||
huart1.Init.Parity = UART_PARITY_NONE;
|
|
||||||
huart1.Init.Mode = UART_MODE_TX_RX;
|
|
||||||
huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
|
|
||||||
huart1.Init.OverSampling = UART_OVERSAMPLING_16;
|
|
||||||
if (HAL_UART_Init(&huart1) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
/* USER CODE BEGIN USART1_Init 2 */
|
|
||||||
|
|
||||||
/* USER CODE END USART1_Init 2 */
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/* FMC initialization function */
|
|
||||||
static void MX_FMC_Init(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* USER CODE BEGIN FMC_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE END FMC_Init 0 */
|
|
||||||
|
|
||||||
FMC_SDRAM_TimingTypeDef SdramTiming = {0};
|
|
||||||
|
|
||||||
/* USER CODE BEGIN FMC_Init 1 */
|
|
||||||
|
|
||||||
/* USER CODE END FMC_Init 1 */
|
|
||||||
|
|
||||||
/** Perform the SDRAM1 memory initialization sequence
|
|
||||||
*/
|
|
||||||
hsdram1.Instance = FMC_SDRAM_DEVICE;
|
|
||||||
/* hsdram1.Init */
|
|
||||||
hsdram1.Init.SDBank = FMC_SDRAM_BANK2;
|
|
||||||
hsdram1.Init.ColumnBitsNumber = FMC_SDRAM_COLUMN_BITS_NUM_8;
|
|
||||||
hsdram1.Init.RowBitsNumber = FMC_SDRAM_ROW_BITS_NUM_12;
|
|
||||||
hsdram1.Init.MemoryDataWidth = FMC_SDRAM_MEM_BUS_WIDTH_16;
|
|
||||||
hsdram1.Init.InternalBankNumber = FMC_SDRAM_INTERN_BANKS_NUM_4;
|
|
||||||
hsdram1.Init.CASLatency = FMC_SDRAM_CAS_LATENCY_3;
|
|
||||||
hsdram1.Init.WriteProtection = FMC_SDRAM_WRITE_PROTECTION_DISABLE;
|
|
||||||
hsdram1.Init.SDClockPeriod = FMC_SDRAM_CLOCK_PERIOD_2;
|
|
||||||
hsdram1.Init.ReadBurst = FMC_SDRAM_RBURST_DISABLE;
|
|
||||||
hsdram1.Init.ReadPipeDelay = FMC_SDRAM_RPIPE_DELAY_1;
|
|
||||||
/* SdramTiming */
|
|
||||||
SdramTiming.LoadToActiveDelay = 2;
|
|
||||||
SdramTiming.ExitSelfRefreshDelay = 7;
|
|
||||||
SdramTiming.SelfRefreshTime = 4;
|
|
||||||
SdramTiming.RowCycleDelay = 7;
|
|
||||||
SdramTiming.WriteRecoveryTime = 3;
|
|
||||||
SdramTiming.RPDelay = 2;
|
|
||||||
SdramTiming.RCDDelay = 2;
|
|
||||||
|
|
||||||
if (HAL_SDRAM_Init(&hsdram1, &SdramTiming) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler( );
|
|
||||||
}
|
|
||||||
|
|
||||||
/* USER CODE BEGIN FMC_Init 2 */
|
|
||||||
|
|
||||||
/* USER CODE END FMC_Init 2 */
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief GPIO Initialization Function
|
|
||||||
* @param None
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
static void MX_GPIO_Init(void)
|
|
||||||
{
|
|
||||||
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
|
||||||
/* USER CODE BEGIN MX_GPIO_Init_1 */
|
|
||||||
|
|
||||||
/* USER CODE END MX_GPIO_Init_1 */
|
|
||||||
|
|
||||||
/* GPIO Ports Clock Enable */
|
|
||||||
__HAL_RCC_GPIOE_CLK_ENABLE();
|
|
||||||
__HAL_RCC_GPIOC_CLK_ENABLE();
|
|
||||||
__HAL_RCC_GPIOF_CLK_ENABLE();
|
|
||||||
__HAL_RCC_GPIOH_CLK_ENABLE();
|
|
||||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
|
||||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
|
||||||
__HAL_RCC_GPIOG_CLK_ENABLE();
|
|
||||||
__HAL_RCC_GPIOD_CLK_ENABLE();
|
|
||||||
|
|
||||||
/*Configure GPIO pin Output Level */
|
|
||||||
HAL_GPIO_WritePin(GPIOE, RedLight_Pin|YellowLight_Pin|GreenLight_Pin|WalkLight_Pin, GPIO_PIN_RESET);
|
|
||||||
|
|
||||||
/*Configure GPIO pin Output Level */
|
|
||||||
HAL_GPIO_WritePin(GPIOC, NCS_MEMS_SPI_Pin|CSX_Pin|OTG_FS_PSO_Pin, GPIO_PIN_RESET);
|
|
||||||
|
|
||||||
/*Configure GPIO pin Output Level */
|
|
||||||
HAL_GPIO_WritePin(ACP_RST_GPIO_Port, ACP_RST_Pin, GPIO_PIN_RESET);
|
|
||||||
|
|
||||||
/*Configure GPIO pin Output Level */
|
|
||||||
HAL_GPIO_WritePin(GPIOD, RDX_Pin|WRX_DCX_Pin, GPIO_PIN_RESET);
|
|
||||||
|
|
||||||
/*Configure GPIO pin Output Level */
|
|
||||||
HAL_GPIO_WritePin(GPIOG, LD3_Pin|LD4_Pin, GPIO_PIN_RESET);
|
|
||||||
|
|
||||||
/*Configure GPIO pins : RedLight_Pin YellowLight_Pin GreenLight_Pin WalkLight_Pin */
|
|
||||||
GPIO_InitStruct.Pin = RedLight_Pin|YellowLight_Pin|GreenLight_Pin|WalkLight_Pin;
|
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
||||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
|
||||||
HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
|
|
||||||
|
|
||||||
/*Configure GPIO pins : NCS_MEMS_SPI_Pin CSX_Pin OTG_FS_PSO_Pin */
|
|
||||||
GPIO_InitStruct.Pin = NCS_MEMS_SPI_Pin|CSX_Pin|OTG_FS_PSO_Pin;
|
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
||||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
|
||||||
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
|
|
||||||
|
|
||||||
/*Configure GPIO pins : B1_Pin MEMS_INT1_Pin MEMS_INT2_Pin TP_INT1_Pin */
|
|
||||||
GPIO_InitStruct.Pin = B1_Pin|MEMS_INT1_Pin|MEMS_INT2_Pin|TP_INT1_Pin;
|
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_EVT_RISING;
|
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
||||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
|
||||||
|
|
||||||
/*Configure GPIO pin : ACP_RST_Pin */
|
|
||||||
GPIO_InitStruct.Pin = ACP_RST_Pin;
|
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
||||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
|
||||||
HAL_GPIO_Init(ACP_RST_GPIO_Port, &GPIO_InitStruct);
|
|
||||||
|
|
||||||
/*Configure GPIO pin : OTG_FS_OC_Pin */
|
|
||||||
GPIO_InitStruct.Pin = OTG_FS_OC_Pin;
|
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_EVT_RISING;
|
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
||||||
HAL_GPIO_Init(OTG_FS_OC_GPIO_Port, &GPIO_InitStruct);
|
|
||||||
|
|
||||||
/*Configure GPIO pin : BOOT1_Pin */
|
|
||||||
GPIO_InitStruct.Pin = BOOT1_Pin;
|
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
||||||
HAL_GPIO_Init(BOOT1_GPIO_Port, &GPIO_InitStruct);
|
|
||||||
|
|
||||||
/*Configure GPIO pin : TE_Pin */
|
|
||||||
GPIO_InitStruct.Pin = TE_Pin;
|
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
||||||
HAL_GPIO_Init(TE_GPIO_Port, &GPIO_InitStruct);
|
|
||||||
|
|
||||||
/*Configure GPIO pins : RDX_Pin WRX_DCX_Pin */
|
|
||||||
GPIO_InitStruct.Pin = RDX_Pin|WRX_DCX_Pin;
|
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
||||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
|
||||||
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
|
|
||||||
|
|
||||||
/*Configure GPIO pins : LD3_Pin LD4_Pin */
|
|
||||||
GPIO_InitStruct.Pin = LD3_Pin|LD4_Pin;
|
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
||||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
|
||||||
HAL_GPIO_Init(GPIOG, &GPIO_InitStruct);
|
|
||||||
|
|
||||||
/* USER CODE BEGIN MX_GPIO_Init_2 */
|
|
||||||
|
|
||||||
/* USER CODE END MX_GPIO_Init_2 */
|
|
||||||
}
|
|
||||||
|
|
||||||
/* USER CODE BEGIN 4 */
|
|
||||||
|
|
||||||
/* USER CODE END 4 */
|
|
||||||
|
|
||||||
/* USER CODE BEGIN Header_StartDefaultTask */
|
|
||||||
/**
|
|
||||||
* @brief Function implementing the defaultTask thread.
|
|
||||||
* @param argument: Not used
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
/* USER CODE END Header_StartDefaultTask */
|
|
||||||
void StartDefaultTask(void const * argument)
|
|
||||||
{
|
|
||||||
/* init code for USB_HOST */
|
|
||||||
MX_USB_HOST_Init();
|
|
||||||
/* USER CODE BEGIN 5 */
|
|
||||||
/* Infinite loop */
|
|
||||||
for(;;)
|
|
||||||
{
|
|
||||||
osDelay(1);
|
|
||||||
}
|
|
||||||
/* USER CODE END 5 */
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Period elapsed callback in non blocking mode
|
|
||||||
* @note This function is called when TIM6 interrupt took place, inside
|
|
||||||
* HAL_TIM_IRQHandler(). It makes a direct call to HAL_IncTick() to increment
|
|
||||||
* a global variable "uwTick" used as application time base.
|
|
||||||
* @param htim : TIM handle
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
|
|
||||||
{
|
|
||||||
/* USER CODE BEGIN Callback 0 */
|
|
||||||
|
|
||||||
/* USER CODE END Callback 0 */
|
|
||||||
if (htim->Instance == TIM6)
|
|
||||||
{
|
|
||||||
HAL_IncTick();
|
|
||||||
}
|
|
||||||
/* USER CODE BEGIN Callback 1 */
|
|
||||||
|
|
||||||
/* USER CODE END Callback 1 */
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief This function is executed in case of error occurrence.
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
void Error_Handler(void)
|
|
||||||
{
|
|
||||||
/* USER CODE BEGIN Error_Handler_Debug */
|
|
||||||
/* User can add his own implementation to report the HAL error return state */
|
|
||||||
__disable_irq();
|
|
||||||
while (1)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
/* USER CODE END Error_Handler_Debug */
|
|
||||||
}
|
|
||||||
#ifdef USE_FULL_ASSERT
|
|
||||||
/**
|
|
||||||
* @brief Reports the name of the source file and the source line number
|
|
||||||
* where the assert_param error has occurred.
|
|
||||||
* @param file: pointer to the source file name
|
|
||||||
* @param line: assert_param error line source number
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
void assert_failed(uint8_t *file, uint32_t line)
|
|
||||||
{
|
|
||||||
/* USER CODE BEGIN 6 */
|
|
||||||
/* User can add his own implementation to report the file name and line number,
|
|
||||||
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
|
|
||||||
/* USER CODE END 6 */
|
|
||||||
}
|
|
||||||
#endif /* USE_FULL_ASSERT */
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
/*
|
|
||||||
* breadboard.cpp
|
|
||||||
*
|
|
||||||
* Created on: Sep 22, 2025
|
|
||||||
* Author: ja
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "breadboard.h"
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,90 +0,0 @@
|
|||||||
/*
|
|
||||||
* breadboard.c
|
|
||||||
*
|
|
||||||
* Created on: Sep 17, 2025
|
|
||||||
* Author: ja
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* #define RedLight_Pin GPIO_PIN_2
|
|
||||||
* #define RedLight_GPIO_Port GPIOE
|
|
||||||
*
|
|
||||||
* #define YellowLight_Pin GPIO_PIN_3
|
|
||||||
* #define YellowLight_GPIO_Port GPIOE
|
|
||||||
*
|
|
||||||
* #define GreenLight_Pin GPIO_PIN_4
|
|
||||||
* #define GreenLight_GPIO_Port GPIOE
|
|
||||||
*
|
|
||||||
* RedLight: PE2
|
|
||||||
* YellowLight: PE3
|
|
||||||
* GreenLight: PE4
|
|
||||||
* WalkLight: PE5
|
|
||||||
*
|
|
||||||
* Done: Traffic Light
|
|
||||||
* TODO: Light Dimmer
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "main.h"
|
|
||||||
#include "breadboard.h"
|
|
||||||
|
|
||||||
#define R_Pin RedLight_Pin
|
|
||||||
#define Y_Pin YellowLight_Pin
|
|
||||||
#define G_Pin GreenLight_Pin
|
|
||||||
#define W_Pin WalkLight_Pin
|
|
||||||
|
|
||||||
#define R_Prt RedLight_GPIO_Port
|
|
||||||
#define Y_Prt YellowLight_GPIO_Port
|
|
||||||
#define G_Prt GreenLight_GPIO_Port
|
|
||||||
#define W_Prt WalkLight_GPIO_Port
|
|
||||||
|
|
||||||
uint32_t trafftick_last;
|
|
||||||
uint32_t walktick_last;
|
|
||||||
|
|
||||||
uint8_t trafflight_index = 0;
|
|
||||||
|
|
||||||
void
|
|
||||||
starttick(void)
|
|
||||||
{
|
|
||||||
trafftick_last = HAL_GetTick();
|
|
||||||
walktick_last = HAL_GetTick();
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
trafflight(int traffSPD, int walkSPD)
|
|
||||||
{
|
|
||||||
uint32_t trafftick_curr = HAL_GetTick();
|
|
||||||
|
|
||||||
if ((trafftick_curr - trafftick_last) >= traffSPD) {
|
|
||||||
HAL_GPIO_WritePin(R_Prt, R_Pin, GPIO_PIN_RESET);
|
|
||||||
HAL_GPIO_WritePin(Y_Prt, Y_Pin, GPIO_PIN_RESET);
|
|
||||||
HAL_GPIO_WritePin(G_Prt, G_Pin, GPIO_PIN_RESET);
|
|
||||||
|
|
||||||
switch (trafflight_index) {
|
|
||||||
case 0:
|
|
||||||
HAL_GPIO_WritePin(R_Prt, R_Pin, GPIO_PIN_SET);
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
HAL_GPIO_WritePin(Y_Prt, Y_Pin, GPIO_PIN_SET);
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
HAL_GPIO_WritePin(G_Prt, G_Pin, GPIO_PIN_SET);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 0:
|
|
||||||
HAL_GPIO_WritePin(G_Prt, G_Pin, GPIO_PIN_SET);
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
HAL_GPIO_WritePin(Y_Prt, Y_Pin, GPIO_PIN_SET);
|
|
||||||
break;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
trafflight_index = (trafflight_index + 1) % 3;
|
|
||||||
trafftick_last = trafftick_curr;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((trafftick_curr - walktick_last) >= walkSPD) {
|
|
||||||
HAL_GPIO_TogglePin(W_Prt, W_Pin);
|
|
||||||
walktick_last = trafftick_curr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,71 +0,0 @@
|
|||||||
/*
|
|
||||||
* breadboard.c
|
|
||||||
*
|
|
||||||
* Created on: Sep 17, 2025
|
|
||||||
* Author: ja
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* #define RedLight_Pin GPIO_PIN_2
|
|
||||||
* #define RedLight_GPIO_Port GPIOE
|
|
||||||
*
|
|
||||||
* #define YellowLight_Pin GPIO_PIN_3
|
|
||||||
* #define YellowLight_GPIO_Port GPIOE
|
|
||||||
*
|
|
||||||
* #define GreenLight_Pin GPIO_PIN_4
|
|
||||||
* #define GreenLight_GPIO_Port GPIOE
|
|
||||||
*
|
|
||||||
* RedLight: PE2
|
|
||||||
* YellowLight: PE3
|
|
||||||
* GreenLight: PE4
|
|
||||||
* WalkLight: PE5
|
|
||||||
*
|
|
||||||
* Done: Traffic Light
|
|
||||||
* TODO: async? Walk Signal, Light Dimmer
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "main.h"
|
|
||||||
#include "breadboard.h"
|
|
||||||
|
|
||||||
#define R_Pin RedLight_Pin
|
|
||||||
#define Y_Pin YellowLight_Pin
|
|
||||||
#define G_Pin GreenLight_Pin
|
|
||||||
#define W_Pin WalkLight_Pin
|
|
||||||
|
|
||||||
#define R_Prt RedLight_GPIO_Port
|
|
||||||
#define Y_Prt YellowLight_GPIO_Port
|
|
||||||
#define G_Prt GreenLight_GPIO_Port
|
|
||||||
#define W_Prt WalkLight_GPIO_Port
|
|
||||||
|
|
||||||
uint32_t redlight_last;
|
|
||||||
uint32_t ylwlight_last;
|
|
||||||
uint32_t grnlight_last;
|
|
||||||
|
|
||||||
void
|
|
||||||
starttick(void)
|
|
||||||
{
|
|
||||||
redlight_last = HAL_GetTick();
|
|
||||||
ylwlight_last = HAL_GetTick();
|
|
||||||
grnlight_last = HAL_GetTick();
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
trafflight(int traffSPD)
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
HAL_GPIO_TogglePin(R_Prt, R_Pin);
|
|
||||||
HAL_Delay(traffSPD);
|
|
||||||
HAL_GPIO_TogglePin(R_Prt, R_Pin);
|
|
||||||
|
|
||||||
HAL_GPIO_TogglePin(Y_Prt, Y_Pin);
|
|
||||||
HAL_Delay(traffSPD);
|
|
||||||
HAL_GPIO_TogglePin(Y_Prt, Y_Pin);
|
|
||||||
|
|
||||||
HAL_GPIO_TogglePin(G_Prt, G_Pin);
|
|
||||||
HAL_Delay(traffSPD);
|
|
||||||
HAL_GPIO_TogglePin(G_Prt, G_Pin);
|
|
||||||
*/
|
|
||||||
|
|
||||||
uint32_t trafftick_curr = HAL_GetTick();
|
|
||||||
int ldelay2 = traffSPD * 2;
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,314 @@
|
|||||||
|
/* USER CODE BEGIN Header */
|
||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
* @file : main.c
|
||||||
|
* @brief : Main program body
|
||||||
|
******************************************************************************
|
||||||
|
* @attention
|
||||||
|
*
|
||||||
|
* Copyright (c) 2025 STMicroelectronics.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This software is licensed under terms that can be found in the LICENSE file
|
||||||
|
* in the root directory of this software component.
|
||||||
|
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||||
|
*
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
// Feeling sneaky.
|
||||||
|
extern "C" {
|
||||||
|
/* USER CODE END Header */
|
||||||
|
/* Includes ------------------------------------------------------------------*/
|
||||||
|
#include "main.h"
|
||||||
|
|
||||||
|
/* Private function prototypes -----------------------------------------------*/
|
||||||
|
void SystemClock_Config(void);
|
||||||
|
static void MX_GPIO_Init(void);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Private user code ---------------------------------------------------------*/
|
||||||
|
/* USER CODE BEGIN 0 */
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
enum class TrafficState { GREEN, YELLOW, RED };
|
||||||
|
void SetTrafficLights(TrafficState s);
|
||||||
|
|
||||||
|
TrafficState currentState = TrafficState::GREEN;
|
||||||
|
uint32_t stateStartTime = 0; //HAL_GetTick() at the start of this state
|
||||||
|
bool buttonPressedThisCycle = false;
|
||||||
|
bool pedestrianNextCycle = false;
|
||||||
|
bool pedestrianThisCycle = false;
|
||||||
|
|
||||||
|
const uint32_t DURATION_GREEN = 5000;
|
||||||
|
const uint32_t DURATION_YELLOW = 3000;
|
||||||
|
const uint32_t DURATION_RED_NOPED = 5000;
|
||||||
|
const uint32_t DURATION_RED_PED = 7000;
|
||||||
|
|
||||||
|
/* USER CODE END 0 */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief The application entry point.
|
||||||
|
* @retval int
|
||||||
|
*/
|
||||||
|
|
||||||
|
void SetTrafficLights(TrafficState s)
|
||||||
|
{
|
||||||
|
// reset all
|
||||||
|
HAL_GPIO_WritePin(GPIOD, Green_Pin, GPIO_PIN_RESET);
|
||||||
|
HAL_GPIO_WritePin(GPIOD, Yellow_Pin, GPIO_PIN_RESET);
|
||||||
|
HAL_GPIO_WritePin(GPIOD, Red_Pin, GPIO_PIN_SET);
|
||||||
|
|
||||||
|
switch (s)
|
||||||
|
{
|
||||||
|
case TrafficState::GREEN :
|
||||||
|
HAL_GPIO_WritePin(GPIOD, Green_Pin, GPIO_PIN_SET);
|
||||||
|
break;
|
||||||
|
case TrafficState::YELLOW :
|
||||||
|
HAL_GPIO_WritePin(GPIOD, Yellow_Pin, GPIO_PIN_SET);
|
||||||
|
break;
|
||||||
|
case TrafficState::RED:
|
||||||
|
HAL_GPIO_WritePin(GPIOD, Red_Pin, GPIO_PIN_SET);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
HAL_Init();
|
||||||
|
|
||||||
|
/* USER CODE BEGIN Init */
|
||||||
|
|
||||||
|
/* USER CODE END Init */
|
||||||
|
|
||||||
|
/* Configure the system clock */
|
||||||
|
SystemClock_Config();
|
||||||
|
MX_GPIO_Init();
|
||||||
|
|
||||||
|
stateStartTime = HAL_GetTick();
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
/* USER CODE END WHILE */
|
||||||
|
uint32_t now = HAL_GetTick();
|
||||||
|
uint32_t elapsed = now - stateStartTime;
|
||||||
|
|
||||||
|
switch(currentState)
|
||||||
|
{
|
||||||
|
case TrafficState::GREEN:
|
||||||
|
if (buttonPressedThisCycle)
|
||||||
|
pedestrianThisCycle = true;
|
||||||
|
|
||||||
|
/*
|
||||||
|
if (buttonPressedThisCycle)
|
||||||
|
{
|
||||||
|
currentState = TrafficState::YELLOW;
|
||||||
|
stateStartTime = now;
|
||||||
|
buttonPressedThisCycle = false;
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pedestrianNextCycle = false;
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
else if (elapsed >= DURATION_GREEN)
|
||||||
|
{
|
||||||
|
currentState = TrafficState::YELLOW;
|
||||||
|
stateStartTime = now;
|
||||||
|
//buttonPressedThisCycle = false;
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case TrafficState::YELLOW:
|
||||||
|
if (buttonPressedThisCycle || pedestrianNextCycle)
|
||||||
|
pedestrianThisCycle = true;
|
||||||
|
|
||||||
|
if (elapsed >= DURATION_YELLOW)
|
||||||
|
{
|
||||||
|
currentState = TrafficState::RED;
|
||||||
|
stateStartTime = now;
|
||||||
|
buttonPressedThisCycle = false; //TODO add pressed pedestrian button in yellow
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
// If Ped Button was pressed during GREEN or YELLOW, we need to enable WHITE this cycle
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case TrafficState::RED:
|
||||||
|
if (pedestrianNextCycle)
|
||||||
|
{
|
||||||
|
HAL_GPIO_WritePin(GPIOD,White_Pin,GPIO_PIN_SET); // turn on Pedestrian LED
|
||||||
|
if (elapsed >= DURATION_RED_PED)
|
||||||
|
{
|
||||||
|
HAL_GPIO_WritePin(GPIOD,White_Pin,GPIO_PIN_RESET);
|
||||||
|
pedestrianNextCycle = false;
|
||||||
|
currentState = TrafficState::GREEN;
|
||||||
|
stateStartTime = now;
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
HAL_GPIO_WritePin(GPIOD,White_Pin,GPIO_PIN_RESET);
|
||||||
|
if(elapsed >= DURATION_RED_PED)
|
||||||
|
{
|
||||||
|
currentState = TrafficState::GREEN;
|
||||||
|
stateStartTime = now;
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/* USER CODE BEGIN 3 */
|
||||||
|
}
|
||||||
|
/* USER CODE END 3 */
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief System Clock Configuration
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void SystemClock_Config(void)
|
||||||
|
{
|
||||||
|
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
|
||||||
|
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
|
||||||
|
|
||||||
|
/** Configure the main internal regulator output voltage
|
||||||
|
*/
|
||||||
|
__HAL_RCC_PWR_CLK_ENABLE();
|
||||||
|
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE3);
|
||||||
|
|
||||||
|
/** Initializes the RCC Oscillators according to the specified parameters
|
||||||
|
* in the RCC_OscInitTypeDef structure.
|
||||||
|
*/
|
||||||
|
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
|
||||||
|
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
|
||||||
|
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
|
||||||
|
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
||||||
|
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
|
||||||
|
RCC_OscInitStruct.PLL.PLLM = 8;
|
||||||
|
RCC_OscInitStruct.PLL.PLLN = 50;
|
||||||
|
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4;
|
||||||
|
RCC_OscInitStruct.PLL.PLLQ = 7;
|
||||||
|
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Initializes the CPU, AHB and APB buses clocks
|
||||||
|
*/
|
||||||
|
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|
||||||
|
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
|
||||||
|
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
|
||||||
|
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
|
||||||
|
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV8;
|
||||||
|
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV4;
|
||||||
|
|
||||||
|
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief GPIO Initialization Function
|
||||||
|
* @param None
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
static void MX_GPIO_Init(void)
|
||||||
|
{
|
||||||
|
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||||
|
/* USER CODE BEGIN MX_GPIO_Init_1 */
|
||||||
|
|
||||||
|
/* USER CODE END MX_GPIO_Init_1 */
|
||||||
|
|
||||||
|
/* GPIO Ports Clock Enable */
|
||||||
|
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||||
|
__HAL_RCC_GPIOD_CLK_ENABLE();
|
||||||
|
|
||||||
|
/*Configure GPIO pin Output Level */
|
||||||
|
HAL_GPIO_WritePin(GPIOD, White_Pin|Red_Pin|Yellow_Pin|Green_Pin, GPIO_PIN_RESET);
|
||||||
|
|
||||||
|
/*Configure GPIO pin : PedButton_Pin */
|
||||||
|
GPIO_InitStruct.Pin = PedButton_Pin;
|
||||||
|
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
|
||||||
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
|
HAL_GPIO_Init(PedButton_GPIO_Port, &GPIO_InitStruct);
|
||||||
|
|
||||||
|
/*Configure GPIO pins : White_Pin Red_Pin Yellow_Pin Green_Pin */
|
||||||
|
GPIO_InitStruct.Pin = White_Pin|Red_Pin|Yellow_Pin|Green_Pin;
|
||||||
|
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||||
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||||
|
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
|
||||||
|
|
||||||
|
/* EXTI interrupt init*/
|
||||||
|
HAL_NVIC_SetPriority(EXTI15_10_IRQn, 15, 0);
|
||||||
|
HAL_NVIC_EnableIRQ(EXTI15_10_IRQn);
|
||||||
|
|
||||||
|
/* USER CODE BEGIN MX_GPIO_Init_2 */
|
||||||
|
|
||||||
|
/* USER CODE END MX_GPIO_Init_2 */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* USER CODE BEGIN 4 */
|
||||||
|
void HAL_GPIO_EXTI_CallBack()
|
||||||
|
{
|
||||||
|
static uint32_t lastInterruptTime = 0;
|
||||||
|
uint32_t now = HAL_GetTick();
|
||||||
|
if(now - lastInterruptTime < 100)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
lastInterruptTime = now;
|
||||||
|
|
||||||
|
if (PedButton_Pin)
|
||||||
|
{
|
||||||
|
buttonPressedThisCycle = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void HAL_GPIO_EXTI_IRQHandler()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/* USER CODE END 4 */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function is executed in case of error occurrence.
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void Error_Handler(void)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN Error_Handler_Debug */
|
||||||
|
/* User can add his own implementation to report the HAL error return state */
|
||||||
|
__disable_irq();
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
/* USER CODE END Error_Handler_Debug */
|
||||||
|
}
|
||||||
|
#ifdef USE_FULL_ASSERT
|
||||||
|
/**
|
||||||
|
* @brief Reports the name of the source file and the source line number
|
||||||
|
* where the assert_param error has occurred.
|
||||||
|
* @param file: pointer to the source file name
|
||||||
|
* @param line: assert_param error line source number
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void assert_failed(uint8_t *file, uint32_t line)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN 6 */
|
||||||
|
/* User can add his own implementation to report the file name and line number,
|
||||||
|
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
|
||||||
|
/* USER CODE END 6 */
|
||||||
|
}
|
||||||
|
#endif /* USE_FULL_ASSERT */
|
||||||
|
|
||||||
@@ -1,72 +0,0 @@
|
|||||||
/*
|
|
||||||
* breadboard.c
|
|
||||||
*
|
|
||||||
* Created on: Sep 17, 2025
|
|
||||||
* Author: ja
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* #define RedLight_Pin GPIO_PIN_2
|
|
||||||
* #define RedLight_GPIO_Port GPIOE
|
|
||||||
*
|
|
||||||
* #define YellowLight_Pin GPIO_PIN_3
|
|
||||||
* #define YellowLight_GPIO_Port GPIOE
|
|
||||||
*
|
|
||||||
* #define GreenLight_Pin GPIO_PIN_4
|
|
||||||
* #define GreenLight_GPIO_Port GPIOE
|
|
||||||
*
|
|
||||||
* RedLight: PE2
|
|
||||||
* YellowLight: PE3
|
|
||||||
* GreenLight: PE4
|
|
||||||
* WalkLight: PE5
|
|
||||||
*
|
|
||||||
* Done: Traffic Light
|
|
||||||
* TODO: async? Walk Signal, Light Dimmer
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "main.h"
|
|
||||||
#include "breadboard.h"
|
|
||||||
|
|
||||||
#define R_Pin RedLight_Pin
|
|
||||||
#define Y_Pin YellowLight_Pin
|
|
||||||
#define G_Pin GreenLight_Pin
|
|
||||||
#define W_Pin WalkLight_Pin
|
|
||||||
|
|
||||||
#define R_Prt RedLight_GPIO_Port
|
|
||||||
#define Y_Prt YellowLight_GPIO_Port
|
|
||||||
#define G_Prt GreenLight_GPIO_Port
|
|
||||||
#define W_Prt WalkLight_GPIO_Port
|
|
||||||
|
|
||||||
uint32_t trafftick_last;
|
|
||||||
|
|
||||||
uint8_t trafflight_i = 0;
|
|
||||||
|
|
||||||
void
|
|
||||||
starttick(void)
|
|
||||||
{
|
|
||||||
trafftick_last = HAL_GetTick();
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
trafflight(int traffSPD)
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
HAL_GPIO_TogglePin(R_Prt, R_Pin);
|
|
||||||
HAL_Delay(traffSPD);
|
|
||||||
HAL_GPIO_TogglePin(R_Prt, R_Pin);
|
|
||||||
|
|
||||||
HAL_GPIO_TogglePin(Y_Prt, Y_Pin);
|
|
||||||
HAL_Delay(traffSPD);
|
|
||||||
HAL_GPIO_TogglePin(Y_Prt, Y_Pin);
|
|
||||||
|
|
||||||
HAL_GPIO_TogglePin(G_Prt, G_Pin);
|
|
||||||
HAL_Delay(traffSPD);
|
|
||||||
HAL_GPIO_TogglePin(G_Prt, G_Pin);
|
|
||||||
*/
|
|
||||||
|
|
||||||
uint32_t trafftick_curr = HAL_GetTick();
|
|
||||||
|
|
||||||
if ((trafftick_curr - trafftick_last) >= traffSPD) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
/*
|
|
||||||
* breadboard.c
|
|
||||||
*
|
|
||||||
* Created on: Sep 12, 2025
|
|
||||||
* Author: ja
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stdbool.h>
|
|
||||||
#include "main.h"
|
|
||||||
|
|
||||||
void
|
|
||||||
breadboard(int DELAY_MS)
|
|
||||||
{
|
|
||||||
bool Purple = (HAL_GPIO_ReadPin(BTN_PRPL_GPIO_Port, BTN_PRPL_Pin) == GPIO_PIN_SET); // PD5
|
|
||||||
bool Grey = (HAL_GPIO_ReadPin(BTN_GREY_GPIO_Port, BTN_GREY_Pin) == GPIO_PIN_SET); // PD7
|
|
||||||
|
|
||||||
if (Purple || Grey) { // inverted for ease of debug, assignment calls for (Purple && Grey)
|
|
||||||
HAL_GPIO_WritePin(LED_EXT_GPIO_Port, LED_EXT_Pin, GPIO_PIN_SET); // PB4
|
|
||||||
} else {
|
|
||||||
HAL_GPIO_WritePin(LED_EXT_GPIO_Port, LED_EXT_Pin, GPIO_PIN_RESET); // PB4
|
|
||||||
}
|
|
||||||
|
|
||||||
HAL_Delay(DELAY_MS); // milliseconds of delay after execution
|
|
||||||
|
|
||||||
/*
|
|
||||||
// Always flash:
|
|
||||||
HAL_GPIO_WritePin(GPIOB, LED_EXT_Pin, GPIO_PIN_SET); // PB4 ON
|
|
||||||
HAL_Delay(DELAY_MS);
|
|
||||||
HAL_GPIO_WritePin(GPIOB, LED_EXT_Pin, GPIO_PIN_RESET); // PB4 OFF
|
|
||||||
HAL_Delay(DELAY_MS);
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,322 @@
|
|||||||
|
/* USER CODE BEGIN Header */
|
||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
* @file : main.c
|
||||||
|
* @brief : Main program body
|
||||||
|
******************************************************************************
|
||||||
|
* @attention
|
||||||
|
*
|
||||||
|
* Copyright (c) 2025 STMicroelectronics.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This software is licensed under terms that can be found in the LICENSE file
|
||||||
|
* in the root directory of this software component.
|
||||||
|
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||||
|
*
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
// Feeling sneaky.
|
||||||
|
extern "C" {
|
||||||
|
/* USER CODE END Header */
|
||||||
|
/* Includes ------------------------------------------------------------------*/
|
||||||
|
#include "main.h"
|
||||||
|
|
||||||
|
/* Private function prototypes -----------------------------------------------*/
|
||||||
|
void SystemClock_Config(void);
|
||||||
|
static void MX_GPIO_Init(void);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Private user code ---------------------------------------------------------*/
|
||||||
|
/* USER CODE BEGIN 0 */
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
enum class TrafficState { GREEN, YELLOW, RED };
|
||||||
|
void SetTrafficLights(TrafficState s);
|
||||||
|
|
||||||
|
TrafficState currentState = TrafficState::GREEN;
|
||||||
|
uint32_t stateStartTime = 0; //HAL_GetTick() at the start of this state
|
||||||
|
bool buttonPressedThisCycle = false;
|
||||||
|
bool pedestrianNextCycle = false;
|
||||||
|
bool pedestrianThisCycle = false;
|
||||||
|
|
||||||
|
const uint32_t DURATION_GREEN = 5000;
|
||||||
|
const uint32_t DURATION_YELLOW = 3000;
|
||||||
|
const uint32_t DURATION_RED_NOPED = 5000;
|
||||||
|
const uint32_t DURATION_RED_PED = 7000;
|
||||||
|
|
||||||
|
/* USER CODE END 0 */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief The application entry point.
|
||||||
|
* @retval int
|
||||||
|
*/
|
||||||
|
|
||||||
|
void SetTrafficLights(TrafficState s)
|
||||||
|
{
|
||||||
|
// reset all
|
||||||
|
HAL_GPIO_WritePin(GPIOD, Green_Pin, GPIO_PIN_RESET);
|
||||||
|
HAL_GPIO_WritePin(GPIOD, Yellow_Pin, GPIO_PIN_RESET);
|
||||||
|
HAL_GPIO_WritePin(GPIOD, Red_Pin, GPIO_PIN_SET);
|
||||||
|
|
||||||
|
switch (s)
|
||||||
|
{
|
||||||
|
case TrafficState::GREEN :
|
||||||
|
HAL_GPIO_WritePin(GPIOD, Green_Pin, GPIO_PIN_SET);
|
||||||
|
break;
|
||||||
|
case TrafficState::YELLOW :
|
||||||
|
HAL_GPIO_WritePin(GPIOD, Yellow_Pin, GPIO_PIN_SET);
|
||||||
|
break;
|
||||||
|
case TrafficState::RED:
|
||||||
|
HAL_GPIO_WritePin(GPIOD, Red_Pin, GPIO_PIN_SET);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
HAL_Init();
|
||||||
|
|
||||||
|
/* USER CODE BEGIN Init */
|
||||||
|
|
||||||
|
/* USER CODE END Init */
|
||||||
|
|
||||||
|
/* Configure the system clock */
|
||||||
|
SystemClock_Config();
|
||||||
|
MX_GPIO_Init();
|
||||||
|
|
||||||
|
stateStartTime = HAL_GetTick();
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
/* USER CODE END WHILE */
|
||||||
|
uint32_t now = HAL_GetTick();
|
||||||
|
uint32_t elapsed = now - stateStartTime;
|
||||||
|
|
||||||
|
switch(currentState)
|
||||||
|
{
|
||||||
|
case TrafficState::GREEN:
|
||||||
|
if (buttonPressedThisCycle)
|
||||||
|
pedestrianThisCycle = true;
|
||||||
|
|
||||||
|
/*
|
||||||
|
if (buttonPressedThisCycle)
|
||||||
|
{
|
||||||
|
currentState = TrafficState::YELLOW;
|
||||||
|
stateStartTime = now;
|
||||||
|
buttonPressedThisCycle = false;
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pedestrianNextCycle = false;
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
else if (elapsed >= DURATION_GREEN)
|
||||||
|
{
|
||||||
|
currentState = TrafficState::YELLOW;
|
||||||
|
stateStartTime = now;
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case TrafficState::YELLOW:
|
||||||
|
if (buttonPressedThisCycle || pedestrianNextCycle)
|
||||||
|
pedestrianThisCycle = true;
|
||||||
|
|
||||||
|
if (elapsed >= DURATION_YELLOW)
|
||||||
|
{
|
||||||
|
currentState = TrafficState::RED;
|
||||||
|
stateStartTime = now;
|
||||||
|
buttonPressedThisCycle = false; //TODO add pressed pedestrian button in yellow
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
// If Ped Button was pressed during GREEN or YELLOW, we need to enable WHITE this cycle
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case TrafficState::RED:
|
||||||
|
/*
|
||||||
|
if (pedestrianNextCycle)
|
||||||
|
{
|
||||||
|
HAL_GPIO_WritePin(GPIOD,White_Pin,GPIO_PIN_SET); // turn on Pedestrian LED
|
||||||
|
if (elapsed >= DURATION_RED_PED)
|
||||||
|
{
|
||||||
|
HAL_GPIO_WritePin(GPIOD,White_Pin,GPIO_PIN_RESET);
|
||||||
|
pedestrianNextCycle = false;
|
||||||
|
currentState = TrafficState::GREEN;
|
||||||
|
stateStartTime = now;
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
HAL_GPIO_WritePin(GPIOD,White_Pin,GPIO_PIN_RESET);
|
||||||
|
if(elapsed >= DURATION_RED_PED)
|
||||||
|
{
|
||||||
|
currentState = TrafficState::GREEN;
|
||||||
|
stateStartTime = now;
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (buttonPressedThisCycle)
|
||||||
|
pedestrianNextCycle = true;
|
||||||
|
|
||||||
|
if (pedestrianThisCycle) {
|
||||||
|
HAL_GPIO_WritePin(White_GPIO_Port);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/* USER CODE BEGIN 3 */
|
||||||
|
}
|
||||||
|
/* USER CODE END 3 */
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief System Clock Configuration
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void SystemClock_Config(void)
|
||||||
|
{
|
||||||
|
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
|
||||||
|
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
|
||||||
|
|
||||||
|
/** Configure the main internal regulator output voltage
|
||||||
|
*/
|
||||||
|
__HAL_RCC_PWR_CLK_ENABLE();
|
||||||
|
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE3);
|
||||||
|
|
||||||
|
/** Initializes the RCC Oscillators according to the specified parameters
|
||||||
|
* in the RCC_OscInitTypeDef structure.
|
||||||
|
*/
|
||||||
|
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
|
||||||
|
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
|
||||||
|
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
|
||||||
|
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
||||||
|
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
|
||||||
|
RCC_OscInitStruct.PLL.PLLM = 8;
|
||||||
|
RCC_OscInitStruct.PLL.PLLN = 50;
|
||||||
|
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4;
|
||||||
|
RCC_OscInitStruct.PLL.PLLQ = 7;
|
||||||
|
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Initializes the CPU, AHB and APB buses clocks
|
||||||
|
*/
|
||||||
|
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|
||||||
|
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
|
||||||
|
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
|
||||||
|
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
|
||||||
|
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV8;
|
||||||
|
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV4;
|
||||||
|
|
||||||
|
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief GPIO Initialization Function
|
||||||
|
* @param None
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
static void MX_GPIO_Init(void)
|
||||||
|
{
|
||||||
|
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||||
|
/* USER CODE BEGIN MX_GPIO_Init_1 */
|
||||||
|
|
||||||
|
/* USER CODE END MX_GPIO_Init_1 */
|
||||||
|
|
||||||
|
/* GPIO Ports Clock Enable */
|
||||||
|
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||||
|
__HAL_RCC_GPIOD_CLK_ENABLE();
|
||||||
|
|
||||||
|
/*Configure GPIO pin Output Level */
|
||||||
|
HAL_GPIO_WritePin(GPIOD, White_Pin|Red_Pin|Yellow_Pin|Green_Pin, GPIO_PIN_RESET);
|
||||||
|
|
||||||
|
/*Configure GPIO pin : PedButton_Pin */
|
||||||
|
GPIO_InitStruct.Pin = PedButton_Pin;
|
||||||
|
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
|
||||||
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
|
HAL_GPIO_Init(PedButton_GPIO_Port, &GPIO_InitStruct);
|
||||||
|
|
||||||
|
/*Configure GPIO pins : White_Pin Red_Pin Yellow_Pin Green_Pin */
|
||||||
|
GPIO_InitStruct.Pin = White_Pin|Red_Pin|Yellow_Pin|Green_Pin;
|
||||||
|
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||||
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||||
|
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
|
||||||
|
|
||||||
|
/* EXTI interrupt init*/
|
||||||
|
HAL_NVIC_SetPriority(EXTI15_10_IRQn, 15, 0);
|
||||||
|
HAL_NVIC_EnableIRQ(EXTI15_10_IRQn);
|
||||||
|
|
||||||
|
/* USER CODE BEGIN MX_GPIO_Init_2 */
|
||||||
|
|
||||||
|
/* USER CODE END MX_GPIO_Init_2 */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* USER CODE BEGIN 4 */
|
||||||
|
void HAL_GPIO_EXTI_CallBack()
|
||||||
|
{
|
||||||
|
static uint32_t lastInterruptTime = 0;
|
||||||
|
uint32_t now = HAL_GetTick();
|
||||||
|
if(now - lastInterruptTime < 100)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
lastInterruptTime = now;
|
||||||
|
|
||||||
|
if (PedButton_Pin)
|
||||||
|
{
|
||||||
|
buttonPressedThisCycle = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void HAL_GPIO_EXTI_IRQHandler()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/* USER CODE END 4 */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function is executed in case of error occurrence.
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void Error_Handler(void)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN Error_Handler_Debug */
|
||||||
|
/* User can add his own implementation to report the HAL error return state */
|
||||||
|
__disable_irq();
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
/* USER CODE END Error_Handler_Debug */
|
||||||
|
}
|
||||||
|
#ifdef USE_FULL_ASSERT
|
||||||
|
/**
|
||||||
|
* @brief Reports the name of the source file and the source line number
|
||||||
|
* where the assert_param error has occurred.
|
||||||
|
* @param file: pointer to the source file name
|
||||||
|
* @param line: assert_param error line source number
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void assert_failed(uint8_t *file, uint32_t line)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN 6 */
|
||||||
|
/* User can add his own implementation to report the file name and line number,
|
||||||
|
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
|
||||||
|
/* USER CODE END 6 */
|
||||||
|
}
|
||||||
|
#endif /* USE_FULL_ASSERT */
|
||||||
|
|
||||||
@@ -1,83 +0,0 @@
|
|||||||
/*
|
|
||||||
* breadboard.c
|
|
||||||
*
|
|
||||||
* Created on: Sep 17, 2025
|
|
||||||
* Author: ja
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* #define RedLight_Pin GPIO_PIN_2
|
|
||||||
* #define RedLight_GPIO_Port GPIOE
|
|
||||||
*
|
|
||||||
* #define YellowLight_Pin GPIO_PIN_3
|
|
||||||
* #define YellowLight_GPIO_Port GPIOE
|
|
||||||
*
|
|
||||||
* #define GreenLight_Pin GPIO_PIN_4
|
|
||||||
* #define GreenLight_GPIO_Port GPIOE
|
|
||||||
*
|
|
||||||
* RedLight: PE2
|
|
||||||
* YellowLight: PE3
|
|
||||||
* GreenLight: PE4
|
|
||||||
* WalkLight: PE5
|
|
||||||
*
|
|
||||||
* Done: Traffic Light
|
|
||||||
* TODO: async? Walk Signal, Light Dimmer
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "main.h"
|
|
||||||
#include "breadboard.h"
|
|
||||||
|
|
||||||
#define R_Pin RedLight_Pin
|
|
||||||
#define Y_Pin YellowLight_Pin
|
|
||||||
#define G_Pin GreenLight_Pin
|
|
||||||
#define W_Pin WalkLight_Pin
|
|
||||||
|
|
||||||
#define R_Prt RedLight_GPIO_Port
|
|
||||||
#define Y_Prt YellowLight_GPIO_Port
|
|
||||||
#define G_Prt GreenLight_GPIO_Port
|
|
||||||
#define W_Prt WalkLight_GPIO_Port
|
|
||||||
|
|
||||||
uint32_t redlight_last;
|
|
||||||
uint32_t ylwlight_last;
|
|
||||||
uint32_t grnlight_last;
|
|
||||||
|
|
||||||
void
|
|
||||||
starttick(void)
|
|
||||||
{
|
|
||||||
trafftick_last = HAL_GetTick();
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
trafflight(int traffSPD)
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
HAL_GPIO_TogglePin(R_Prt, R_Pin);
|
|
||||||
HAL_Delay(traffSPD);
|
|
||||||
HAL_GPIO_TogglePin(R_Prt, R_Pin);
|
|
||||||
|
|
||||||
HAL_GPIO_TogglePin(Y_Prt, Y_Pin);
|
|
||||||
HAL_Delay(traffSPD);
|
|
||||||
HAL_GPIO_TogglePin(Y_Prt, Y_Pin);
|
|
||||||
|
|
||||||
HAL_GPIO_TogglePin(G_Prt, G_Pin);
|
|
||||||
HAL_Delay(traffSPD);
|
|
||||||
HAL_GPIO_TogglePin(G_Prt, G_Pin);
|
|
||||||
*/
|
|
||||||
|
|
||||||
uint32_t trafftick_curr = HAL_GetTick();
|
|
||||||
int ldelay2 = traffSPD * 2;
|
|
||||||
int ldelay3 = traffSPD * 3;
|
|
||||||
|
|
||||||
if ((trafftick_curr - redlight_last) >= traffSPD) {
|
|
||||||
trafftick_last = trafftick_curr;
|
|
||||||
HAL_GPIO_TogglePin(R_Prt, R_Pin);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((trafftick_curr - trafftick_last) >= ldelay2) {
|
|
||||||
HAL_GPIO_TogglePin(Y_Prt, Y_Pin);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((trafftick_curr - trafftick_last) >= ldelay3) {
|
|
||||||
HAL_GPIO_TogglePin(G_Prt, G_Pin);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,82 +0,0 @@
|
|||||||
/* USER CODE BEGIN Header */
|
|
||||||
/**
|
|
||||||
******************************************************************************
|
|
||||||
* @file : main.h
|
|
||||||
* @brief : Header for main.c file.
|
|
||||||
* This file contains the common defines of the application.
|
|
||||||
******************************************************************************
|
|
||||||
* @attention
|
|
||||||
*
|
|
||||||
* Copyright (c) 2025 STMicroelectronics.
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* This software is licensed under terms that can be found in the LICENSE file
|
|
||||||
* in the root directory of this software component.
|
|
||||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
|
||||||
*
|
|
||||||
******************************************************************************
|
|
||||||
*/
|
|
||||||
/* USER CODE END Header */
|
|
||||||
|
|
||||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
|
||||||
#ifndef __MAIN_H
|
|
||||||
#define __MAIN_H
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
|
||||||
#include "stm32f4xx_hal.h"
|
|
||||||
|
|
||||||
/* Private includes ----------------------------------------------------------*/
|
|
||||||
/* USER CODE BEGIN Includes */
|
|
||||||
|
|
||||||
/* USER CODE END Includes */
|
|
||||||
|
|
||||||
/* Exported types ------------------------------------------------------------*/
|
|
||||||
/* USER CODE BEGIN ET */
|
|
||||||
|
|
||||||
/* USER CODE END ET */
|
|
||||||
|
|
||||||
/* Exported constants --------------------------------------------------------*/
|
|
||||||
/* USER CODE BEGIN EC */
|
|
||||||
|
|
||||||
/* USER CODE END EC */
|
|
||||||
|
|
||||||
/* Exported macro ------------------------------------------------------------*/
|
|
||||||
/* USER CODE BEGIN EM */
|
|
||||||
|
|
||||||
/* USER CODE END EM */
|
|
||||||
|
|
||||||
/* Exported functions prototypes ---------------------------------------------*/
|
|
||||||
void Error_Handler(void);
|
|
||||||
|
|
||||||
/* USER CODE BEGIN EFP */
|
|
||||||
|
|
||||||
/* USER CODE END EFP */
|
|
||||||
|
|
||||||
/* Private defines -----------------------------------------------------------*/
|
|
||||||
#define PedButton_Pin GPIO_PIN_14
|
|
||||||
#define PedButton_GPIO_Port GPIOA
|
|
||||||
#define PedButton_EXTI_IRQn EXTI15_10_IRQn
|
|
||||||
#define White_Pin GPIO_PIN_1
|
|
||||||
#define White_GPIO_Port GPIOD
|
|
||||||
#define Red_Pin GPIO_PIN_3
|
|
||||||
#define Red_GPIO_Port GPIOD
|
|
||||||
#define Yellow_Pin GPIO_PIN_5
|
|
||||||
#define Yellow_GPIO_Port GPIOD
|
|
||||||
#define Green_Pin GPIO_PIN_7
|
|
||||||
#define Green_GPIO_Port GPIOD
|
|
||||||
|
|
||||||
/* USER CODE BEGIN Private defines */
|
|
||||||
|
|
||||||
#define Traffic_GPIO_Port GPIOD
|
|
||||||
|
|
||||||
/* USER CODE END Private defines */
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /* __MAIN_H */
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
/*
|
|
||||||
* breadboard.h
|
|
||||||
*
|
|
||||||
* Created on: Sep 20, 2025
|
|
||||||
* Author: ja
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef INC_BREADBOARD_H_
|
|
||||||
#define INC_BREADBOARD_H_
|
|
||||||
|
|
||||||
void trafflight(int);
|
|
||||||
|
|
||||||
#endif /* INC_BREADBOARD_H_ */
|
|
||||||
@@ -1,95 +0,0 @@
|
|||||||
/*
|
|
||||||
* breadboard.c
|
|
||||||
*
|
|
||||||
* Created on: Sep 17, 2025
|
|
||||||
* Author: ja
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* #define RedLight_Pin GPIO_PIN_2
|
|
||||||
* #define RedLight_GPIO_Port GPIOE
|
|
||||||
*
|
|
||||||
* #define YellowLight_Pin GPIO_PIN_3
|
|
||||||
* #define YellowLight_GPIO_Port GPIOE
|
|
||||||
*
|
|
||||||
* #define GreenLight_Pin GPIO_PIN_4
|
|
||||||
* #define GreenLight_GPIO_Port GPIOE
|
|
||||||
*
|
|
||||||
* RedLight: PE2
|
|
||||||
* YellowLight: PE3
|
|
||||||
* GreenLight: PE4
|
|
||||||
* WalkLight: PE5
|
|
||||||
*
|
|
||||||
* Done: Traffic Light
|
|
||||||
* TODO: async? Walk Signal, Light Dimmer
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "main.h"
|
|
||||||
#include "breadboard.h"
|
|
||||||
|
|
||||||
#define R_Pin RedLight_Pin
|
|
||||||
#define Y_Pin YellowLight_Pin
|
|
||||||
#define G_Pin GreenLight_Pin
|
|
||||||
#define W_Pin WalkLight_Pin
|
|
||||||
|
|
||||||
#define R_Prt RedLight_GPIO_Port
|
|
||||||
#define Y_Prt YellowLight_GPIO_Port
|
|
||||||
#define G_Prt GreenLight_GPIO_Port
|
|
||||||
#define W_Prt WalkLight_GPIO_Port
|
|
||||||
|
|
||||||
uint32_t trafftick_last;
|
|
||||||
uint32_t walktick_last;
|
|
||||||
|
|
||||||
uint8_t trafflight_i = 0;
|
|
||||||
|
|
||||||
void
|
|
||||||
starttick(void)
|
|
||||||
{
|
|
||||||
trafftick_last = HAL_GetTick();
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
trafflight(int traffSPD)
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
HAL_GPIO_TogglePin(R_Prt, R_Pin);
|
|
||||||
HAL_Delay(traffSPD);
|
|
||||||
HAL_GPIO_TogglePin(R_Prt, R_Pin);
|
|
||||||
|
|
||||||
HAL_GPIO_TogglePin(Y_Prt, Y_Pin);
|
|
||||||
HAL_Delay(traffSPD);
|
|
||||||
HAL_GPIO_TogglePin(Y_Prt, Y_Pin);
|
|
||||||
|
|
||||||
HAL_GPIO_TogglePin(G_Prt, G_Pin);
|
|
||||||
HAL_Delay(traffSPD);
|
|
||||||
HAL_GPIO_TogglePin(G_Prt, G_Pin);
|
|
||||||
*/
|
|
||||||
|
|
||||||
uint32_t trafftick_curr = HAL_GetTick();
|
|
||||||
|
|
||||||
if ((trafftick_curr - trafftick_last) >= traffSPD) {
|
|
||||||
HAL_GPIO_WritePin(R_Prt, R_Pin, GPIO_PIN_RESET);
|
|
||||||
HAL_GPIO_WritePin(Y_Prt, Y_Pin, GPIO_PIN_RESET);
|
|
||||||
HAL_GPIO_WritePin(G_Prt, G_Pin, GPIO_PIN_RESET);
|
|
||||||
|
|
||||||
switch (trafflight_i) {
|
|
||||||
case 0:
|
|
||||||
HAL_GPIO_WritePin(R_Prt, R_Pin);
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
HAL_GPIO_WritePin(Y_Prt, Y_Pin);
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
HAL_GPIO_WritePin(G_Prt, G_Pin);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
trafflight_i = (trafflight_i + 1) % 3;
|
|
||||||
trafftick_last = trafftick_curr;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((trafftick_curr - walktick_last) >= walkSPD) {
|
|
||||||
HAL_GPIO_TogglePin(W_Prt, W_Pin);
|
|
||||||
walktick_last = trafftick_curr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,311 @@
|
|||||||
|
/* USER CODE BEGIN Header */
|
||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
* @file : main.c
|
||||||
|
* @brief : Main program body
|
||||||
|
******************************************************************************
|
||||||
|
* @attention
|
||||||
|
*
|
||||||
|
* Copyright (c) 2025 STMicroelectronics.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This software is licensed under terms that can be found in the LICENSE file
|
||||||
|
* in the root directory of this software component.
|
||||||
|
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||||
|
*
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
// Feeling sneaky.
|
||||||
|
extern "C" {
|
||||||
|
/* USER CODE END Header */
|
||||||
|
/* Includes ------------------------------------------------------------------*/
|
||||||
|
#include "main.h"
|
||||||
|
|
||||||
|
/* Private function prototypes -----------------------------------------------*/
|
||||||
|
void SystemClock_Config(void);
|
||||||
|
static void MX_GPIO_Init(void);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Private user code ---------------------------------------------------------*/
|
||||||
|
/* USER CODE BEGIN 0 */
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
enum class TrafficState { GREEN, YELLOW, RED };
|
||||||
|
void SetTrafficLights(TrafficState s);
|
||||||
|
|
||||||
|
TrafficState currentState = TrafficState::GREEN;
|
||||||
|
uint32_t stateStartTime = 0; //HAL_GetTick() at the start of this state
|
||||||
|
bool buttonPressedThisCycle = false;
|
||||||
|
bool pedestrianNextCycle = false;
|
||||||
|
bool pedestrianThisCycle = false;
|
||||||
|
|
||||||
|
const uint32_t DURATION_GREEN = 5000;
|
||||||
|
const uint32_t DURATION_YELLOW = 3000;
|
||||||
|
const uint32_t DURATION_RED_NOPED = 5000;
|
||||||
|
const uint32_t DURATION_RED_PED = 7000;
|
||||||
|
|
||||||
|
/* USER CODE END 0 */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief The application entry point.
|
||||||
|
* @retval int
|
||||||
|
*/
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
HAL_Init();
|
||||||
|
|
||||||
|
/* USER CODE BEGIN Init */
|
||||||
|
|
||||||
|
/* USER CODE END Init */
|
||||||
|
|
||||||
|
/* Configure the system clock */
|
||||||
|
SystemClock_Config();
|
||||||
|
MX_GPIO_Init();
|
||||||
|
|
||||||
|
stateStartTime = HAL_GetTick();
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
/* USER CODE END WHILE */
|
||||||
|
uint32_t now = HAL_GetTick();
|
||||||
|
uint32_t elapsed = now - stateStartTime;
|
||||||
|
|
||||||
|
switch(currentState)
|
||||||
|
{
|
||||||
|
case TrafficState::GREEN:
|
||||||
|
if (buttonPressedThisCycle)
|
||||||
|
pedestrianThisCycle = true;
|
||||||
|
|
||||||
|
/*
|
||||||
|
if (buttonPressedThisCycle)
|
||||||
|
{
|
||||||
|
currentState = TrafficState::YELLOW;
|
||||||
|
stateStartTime = now;
|
||||||
|
buttonPressedThisCycle = false;
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pedestrianNextCycle = false;
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
else if (elapsed >= DURATION_GREEN)
|
||||||
|
{
|
||||||
|
currentState = TrafficState::YELLOW;
|
||||||
|
stateStartTime = now;
|
||||||
|
buttonPressedThisCycle = false;
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case TrafficState::YELLOW:
|
||||||
|
if (buttonPressedThisCycle || pedestrianNextCycle)
|
||||||
|
pedestrianThisCycle = true;
|
||||||
|
|
||||||
|
if (elapsed >= DURATION_YELLOW)
|
||||||
|
{
|
||||||
|
currentState = TrafficState::RED;
|
||||||
|
stateStartTime = now;
|
||||||
|
buttonPressedThisCycle = false; //TODO add pressed pedestrian button in yellow
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
// If Ped Button was pressed during GREEN or YELLOW, we need to enable WHITE this cycle
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case TrafficState::RED:
|
||||||
|
if (pedestrianNextCycle)
|
||||||
|
{
|
||||||
|
HAL_GPIO_WritePin(GPIOD,White_Pin,GPIO_PIN_SET); // turn on Pedestrian LED
|
||||||
|
if (elapsed >= DURATION_RED_PED)
|
||||||
|
{
|
||||||
|
HAL_GPIO_WritePin(GPIOD,White_Pin,GPIO_PIN_RESET);
|
||||||
|
pedestrianNextCycle = false;
|
||||||
|
currentState = TrafficState::GREEN;
|
||||||
|
stateStartTime = now;
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
HAL_GPIO_WritePin(GPIOD,White_Pin,GPIO_PIN_RESET);
|
||||||
|
if(elapsed >= DURATION_RED_PED)
|
||||||
|
{
|
||||||
|
currentState = TrafficState::GREEN;
|
||||||
|
stateStartTime = now;
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/* USER CODE BEGIN 3 */
|
||||||
|
}
|
||||||
|
/* USER CODE END 3 */
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief System Clock Configuration
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void SystemClock_Config(void)
|
||||||
|
{
|
||||||
|
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
|
||||||
|
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
|
||||||
|
|
||||||
|
/** Configure the main internal regulator output voltage
|
||||||
|
*/
|
||||||
|
__HAL_RCC_PWR_CLK_ENABLE();
|
||||||
|
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE3);
|
||||||
|
|
||||||
|
/** Initializes the RCC Oscillators according to the specified parameters
|
||||||
|
* in the RCC_OscInitTypeDef structure.
|
||||||
|
*/
|
||||||
|
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
|
||||||
|
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
|
||||||
|
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
|
||||||
|
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
||||||
|
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
|
||||||
|
RCC_OscInitStruct.PLL.PLLM = 8;
|
||||||
|
RCC_OscInitStruct.PLL.PLLN = 50;
|
||||||
|
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4;
|
||||||
|
RCC_OscInitStruct.PLL.PLLQ = 7;
|
||||||
|
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Initializes the CPU, AHB and APB buses clocks
|
||||||
|
*/
|
||||||
|
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|
||||||
|
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
|
||||||
|
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
|
||||||
|
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
|
||||||
|
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV8;
|
||||||
|
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV4;
|
||||||
|
|
||||||
|
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief GPIO Initialization Function
|
||||||
|
* @param None
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
static void MX_GPIO_Init(void)
|
||||||
|
{
|
||||||
|
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||||
|
/* USER CODE BEGIN MX_GPIO_Init_1 */
|
||||||
|
|
||||||
|
/* USER CODE END MX_GPIO_Init_1 */
|
||||||
|
|
||||||
|
/* GPIO Ports Clock Enable */
|
||||||
|
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||||
|
__HAL_RCC_GPIOD_CLK_ENABLE();
|
||||||
|
|
||||||
|
/*Configure GPIO pin Output Level */
|
||||||
|
HAL_GPIO_WritePin(GPIOD, White_Pin|Red_Pin|Yellow_Pin|Green_Pin, GPIO_PIN_RESET);
|
||||||
|
|
||||||
|
/*Configure GPIO pin : PedButton_Pin */
|
||||||
|
GPIO_InitStruct.Pin = PedButton_Pin;
|
||||||
|
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
|
||||||
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
|
HAL_GPIO_Init(PedButton_GPIO_Port, &GPIO_InitStruct);
|
||||||
|
|
||||||
|
/*Configure GPIO pins : White_Pin Red_Pin Yellow_Pin Green_Pin */
|
||||||
|
GPIO_InitStruct.Pin = White_Pin|Red_Pin|Yellow_Pin|Green_Pin;
|
||||||
|
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||||
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||||
|
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
|
||||||
|
|
||||||
|
/* EXTI interrupt init*/
|
||||||
|
HAL_NVIC_SetPriority(EXTI15_10_IRQn, 15, 0);
|
||||||
|
HAL_NVIC_EnableIRQ(EXTI15_10_IRQn);
|
||||||
|
|
||||||
|
/* USER CODE BEGIN MX_GPIO_Init_2 */
|
||||||
|
|
||||||
|
/* USER CODE END MX_GPIO_Init_2 */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* USER CODE BEGIN 4 */
|
||||||
|
void HAL_GPIO_EXTI_CallBack()
|
||||||
|
{
|
||||||
|
static uint32_t lastInterruptTime = 0;
|
||||||
|
uint32_t now = HAL_GetTick();
|
||||||
|
if(now - lastInterruptTime < 100)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
lastInterruptTime = now;
|
||||||
|
|
||||||
|
if (PedButton_Pin)
|
||||||
|
{
|
||||||
|
buttonPressedThisCycle = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void HAL_GPIO_EXTI_IRQHandler()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/* USER CODE END 4 */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function is executed in case of error occurrence.
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void Error_Handler(void)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN Error_Handler_Debug */
|
||||||
|
/* User can add his own implementation to report the HAL error return state */
|
||||||
|
__disable_irq();
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
/* USER CODE END Error_Handler_Debug */
|
||||||
|
}
|
||||||
|
#ifdef USE_FULL_ASSERT
|
||||||
|
/**
|
||||||
|
* @brief Reports the name of the source file and the source line number
|
||||||
|
* where the assert_param error has occurred.
|
||||||
|
* @param file: pointer to the source file name
|
||||||
|
* @param line: assert_param error line source number
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void assert_failed(uint8_t *file, uint32_t line)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN 6 */
|
||||||
|
/* User can add his own implementation to report the file name and line number,
|
||||||
|
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
|
||||||
|
/* USER CODE END 6 */
|
||||||
|
}
|
||||||
|
#endif /* USE_FULL_ASSERT */
|
||||||
|
|
||||||
|
void SetTrafficLights(TrafficState s)
|
||||||
|
{
|
||||||
|
// reset all
|
||||||
|
HAL_GPIO_WritePin(GPIOD, Green_Pin, GPIO_PIN_RESET);
|
||||||
|
HAL_GPIO_WritePin(GPIOD, Yellow_Pin, GPIO_PIN_RESET);
|
||||||
|
HAL_GPIO_WritePin(GPIOD, Red_Pin, GPIO_PIN_SET);
|
||||||
|
|
||||||
|
switch (s)
|
||||||
|
{
|
||||||
|
case TrafficState::GREEN :
|
||||||
|
HAL_GPIO_WritePin(GPIOD, Green_Pin, GPIO_PIN_SET);
|
||||||
|
break;
|
||||||
|
case TrafficState::YELLOW :
|
||||||
|
HAL_GPIO_WritePin(GPIOD, Yellow_Pin, GPIO_PIN_SET);
|
||||||
|
break;
|
||||||
|
case TrafficState::RED:
|
||||||
|
HAL_GPIO_WritePin(GPIOD, Red_Pin, GPIO_PIN_SET);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,84 +0,0 @@
|
|||||||
/*
|
|
||||||
* breadboard.c
|
|
||||||
*
|
|
||||||
* Created on: Sep 17, 2025
|
|
||||||
* Author: ja
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* #define RedLight_Pin GPIO_PIN_2
|
|
||||||
* #define RedLight_GPIO_Port GPIOE
|
|
||||||
*
|
|
||||||
* #define YellowLight_Pin GPIO_PIN_3
|
|
||||||
* #define YellowLight_GPIO_Port GPIOE
|
|
||||||
*
|
|
||||||
* #define GreenLight_Pin GPIO_PIN_4
|
|
||||||
* #define GreenLight_GPIO_Port GPIOE
|
|
||||||
*
|
|
||||||
* RedLight: PE2
|
|
||||||
* YellowLight: PE3
|
|
||||||
* GreenLight: PE4
|
|
||||||
* WalkLight: PE5
|
|
||||||
*
|
|
||||||
* Done: Traffic Light
|
|
||||||
* TODO: async? Walk Signal, Light Dimmer
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "main.h"
|
|
||||||
#include "breadboard.h"
|
|
||||||
|
|
||||||
#define R_Pin RedLight_Pin
|
|
||||||
#define Y_Pin YellowLight_Pin
|
|
||||||
#define G_Pin GreenLight_Pin
|
|
||||||
#define W_Pin WalkLight_Pin
|
|
||||||
|
|
||||||
#define R_Prt RedLight_GPIO_Port
|
|
||||||
#define Y_Prt YellowLight_GPIO_Port
|
|
||||||
#define G_Prt GreenLight_GPIO_Port
|
|
||||||
#define W_Prt WalkLight_GPIO_Port
|
|
||||||
|
|
||||||
uint32_t redlight_last;
|
|
||||||
uint32_t ylwlight_last;
|
|
||||||
uint32_t grnlight_last;
|
|
||||||
|
|
||||||
void
|
|
||||||
starttick(void)
|
|
||||||
{
|
|
||||||
trafftick_last = HAL_GetTick();
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
trafflight(int traffSPD)
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
HAL_GPIO_TogglePin(R_Prt, R_Pin);
|
|
||||||
HAL_Delay(traffSPD);
|
|
||||||
HAL_GPIO_TogglePin(R_Prt, R_Pin);
|
|
||||||
|
|
||||||
HAL_GPIO_TogglePin(Y_Prt, Y_Pin);
|
|
||||||
HAL_Delay(traffSPD);
|
|
||||||
HAL_GPIO_TogglePin(Y_Prt, Y_Pin);
|
|
||||||
|
|
||||||
HAL_GPIO_TogglePin(G_Prt, G_Pin);
|
|
||||||
HAL_Delay(traffSPD);
|
|
||||||
HAL_GPIO_TogglePin(G_Prt, G_Pin);
|
|
||||||
*/
|
|
||||||
|
|
||||||
uint32_t trafftick_curr = HAL_GetTick();
|
|
||||||
int ldelay2 = traffSPD * 2;
|
|
||||||
int ldelay3 = traffSPD * 3;
|
|
||||||
|
|
||||||
if ((trafftick_curr - redlight_last) >= traffSPD) {
|
|
||||||
redlight_last = trafftick_curr;
|
|
||||||
HAL_GPIO_TogglePin(R_Prt, R_Pin);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((trafftick_curr - grnlight_last) >= ldelay2) {
|
|
||||||
grnlight_last = trafftick_curr;
|
|
||||||
HAL_GPIO_TogglePin(Y_Prt, Y_Pin);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((trafftick_curr - trafftick_last) >= ldelay3) {
|
|
||||||
HAL_GPIO_TogglePin(G_Prt, G_Pin);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,514 @@
|
|||||||
|
/* USER CODE BEGIN Header */
|
||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
* @file : main.c
|
||||||
|
* @brief : Main program body
|
||||||
|
******************************************************************************
|
||||||
|
* @attention
|
||||||
|
*
|
||||||
|
* Copyright (c) 2025 STMicroelectronics.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This software is licensed under terms that can be found in the LICENSE file
|
||||||
|
* in the root directory of this software component.
|
||||||
|
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||||
|
*
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
/* USER CODE END Header */
|
||||||
|
/* Includes ------------------------------------------------------------------*/
|
||||||
|
#include "main.h"
|
||||||
|
#include "cmsis_os.h"
|
||||||
|
|
||||||
|
/* Private includes ----------------------------------------------------------*/
|
||||||
|
/* USER CODE BEGIN Includes */
|
||||||
|
#include "breadboard.h"
|
||||||
|
#include <stdbool.h>
|
||||||
|
/* USER CODE END Includes */
|
||||||
|
|
||||||
|
/* Private typedef -----------------------------------------------------------*/
|
||||||
|
/* USER CODE BEGIN PTD */
|
||||||
|
|
||||||
|
/* USER CODE END PTD */
|
||||||
|
|
||||||
|
/* Private define ------------------------------------------------------------*/
|
||||||
|
/* USER CODE BEGIN PD */
|
||||||
|
|
||||||
|
/* USER CODE END PD */
|
||||||
|
|
||||||
|
/* Private macro -------------------------------------------------------------*/
|
||||||
|
/* USER CODE BEGIN PM */
|
||||||
|
|
||||||
|
/* USER CODE END PM */
|
||||||
|
|
||||||
|
/* Private variables ---------------------------------------------------------*/
|
||||||
|
CRC_HandleTypeDef hcrc;
|
||||||
|
|
||||||
|
DMA2D_HandleTypeDef hdma2d;
|
||||||
|
|
||||||
|
TIM_HandleTypeDef htim1;
|
||||||
|
|
||||||
|
osThreadId defaultTaskHandle;
|
||||||
|
/* USER CODE BEGIN PV */
|
||||||
|
|
||||||
|
/* USER CODE END PV */
|
||||||
|
|
||||||
|
/* Private function prototypes -----------------------------------------------*/
|
||||||
|
void SystemClock_Config(void);
|
||||||
|
static void MX_GPIO_Init(void);
|
||||||
|
static void MX_CRC_Init(void);
|
||||||
|
static void MX_DMA2D_Init(void);
|
||||||
|
static void MX_TIM1_Init(void);
|
||||||
|
void StartDefaultTask(void const * argument);
|
||||||
|
|
||||||
|
void SetTrafficLights(TrafficSate s);
|
||||||
|
|
||||||
|
/* USER CODE BEGIN PFP */
|
||||||
|
|
||||||
|
/* USER CODE END PFP */
|
||||||
|
|
||||||
|
/* Private user code ---------------------------------------------------------*/
|
||||||
|
|
||||||
|
/* USER CODE BEGIN 0 */
|
||||||
|
|
||||||
|
enum class TrafficState {
|
||||||
|
GREEN,
|
||||||
|
YELLOW,
|
||||||
|
RED
|
||||||
|
};
|
||||||
|
|
||||||
|
TrafficState currentState = TrafficState::GREEN;
|
||||||
|
uint32_t stateStartTime = 0; // HAL_GetTick() at the start of this state
|
||||||
|
bool buttonPressed = false;
|
||||||
|
bool pedestrianNextCycle = false;
|
||||||
|
|
||||||
|
const uint32_t DURATION_GREEN = 5000;
|
||||||
|
const uint32_t DURATION_YELLOW = 3000;
|
||||||
|
const uint32_t DURATION_RED = 5000;
|
||||||
|
const uint32_t DURATION_RED_PED = 7000;
|
||||||
|
|
||||||
|
/* USER CODE END 0 */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief The application entry point.
|
||||||
|
* @retval int
|
||||||
|
*/
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* USER CODE BEGIN 1 */
|
||||||
|
|
||||||
|
/* USER CODE END 1 */
|
||||||
|
|
||||||
|
/* MCU Configuration--------------------------------------------------------*/
|
||||||
|
|
||||||
|
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
|
||||||
|
HAL_Init();
|
||||||
|
|
||||||
|
/* USER CODE BEGIN Init */
|
||||||
|
|
||||||
|
/* USER CODE END Init */
|
||||||
|
|
||||||
|
/* Configure the system clock */
|
||||||
|
SystemClock_Config();
|
||||||
|
|
||||||
|
/* USER CODE BEGIN SysInit */
|
||||||
|
|
||||||
|
stateStartTime = HAL_GetTick();
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
|
||||||
|
/* USER CODE END SysInit */
|
||||||
|
|
||||||
|
/* Initialize all configured peripherals */
|
||||||
|
MX_GPIO_Init();
|
||||||
|
MX_CRC_Init();
|
||||||
|
MX_DMA2D_Init();
|
||||||
|
MX_TIM1_Init();
|
||||||
|
/* USER CODE BEGIN 2 */
|
||||||
|
|
||||||
|
/* USER CODE END 2 */
|
||||||
|
|
||||||
|
/* USER CODE BEGIN RTOS_MUTEX */
|
||||||
|
/* add mutexes, ... */
|
||||||
|
/* USER CODE END RTOS_MUTEX */
|
||||||
|
|
||||||
|
/* USER CODE BEGIN RTOS_SEMAPHORES */
|
||||||
|
/* add semaphores, ... */
|
||||||
|
/* USER CODE END RTOS_SEMAPHORES */
|
||||||
|
|
||||||
|
/* USER CODE BEGIN RTOS_TIMERS */
|
||||||
|
/* start timers, add new ones, ... */
|
||||||
|
/* USER CODE END RTOS_TIMERS */
|
||||||
|
|
||||||
|
/* USER CODE BEGIN RTOS_QUEUES */
|
||||||
|
/* add queues, ... */
|
||||||
|
/* USER CODE END RTOS_QUEUES */
|
||||||
|
|
||||||
|
/* Create the thread(s) */
|
||||||
|
/* definition and creation of defaultTask */
|
||||||
|
//osThreadDef(defaultTask, StartDefaultTask, osPriorityNormal, 0, 4096);
|
||||||
|
//defaultTaskHandle = osThreadCreate(osThread(defaultTask), NULL);
|
||||||
|
|
||||||
|
/* USER CODE BEGIN RTOS_THREADS */
|
||||||
|
/* add threads, ... */
|
||||||
|
/* USER CODE END RTOS_THREADS */
|
||||||
|
|
||||||
|
/* Start scheduler */
|
||||||
|
osKernelStart();
|
||||||
|
|
||||||
|
/* We should never get here as control is now taken by the scheduler */
|
||||||
|
|
||||||
|
/* Infinite loop */
|
||||||
|
/* USER CODE BEGIN WHILE */
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
uint32_t now = HAL_GetTick();
|
||||||
|
uint32_t elapsed = now - stateStartTime;
|
||||||
|
|
||||||
|
/*
|
||||||
|
switch(currentState)
|
||||||
|
{
|
||||||
|
case TrafficState::GREEN:
|
||||||
|
if (elapsed >= DURATION_GREEN) {
|
||||||
|
currentState = TrafficState::YELLOW;
|
||||||
|
stateStartTime = now;
|
||||||
|
buttonPressed = false; // reset the button-flag for the new cycle
|
||||||
|
} else if (buttonPressed) {
|
||||||
|
//idk
|
||||||
|
buttonPressed = true;
|
||||||
|
currentState = TrafficState::YELLOW;
|
||||||
|
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case TrafficState::YELLOW:
|
||||||
|
break;
|
||||||
|
case TrafficState::RED:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
switch(currentState)
|
||||||
|
{
|
||||||
|
case TrafficState::GREEN:
|
||||||
|
if (butonPressedThisCycle)
|
||||||
|
{
|
||||||
|
currentState = TrafficState::YELLOW;
|
||||||
|
stateStartTime = now;
|
||||||
|
buttonPressedThisCycle = false;
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
} else if (elapsed >= DURATION_GREEN)
|
||||||
|
{
|
||||||
|
buttonPressedThisCycle = true;
|
||||||
|
currentState = TrafficState::YELLOW;
|
||||||
|
stateStartTime = now;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case TrafficState::YELLOW:
|
||||||
|
if (elapsed >= DURATION_YELLOW)
|
||||||
|
{
|
||||||
|
currentState = TrafficState::RED;
|
||||||
|
stateStartTime = now;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case TrafficState::RED:
|
||||||
|
//
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/* USER CODE END WHILE */
|
||||||
|
|
||||||
|
/* USER CODE BEGIN 3 */
|
||||||
|
}
|
||||||
|
/* USER CODE END 3 */
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief System Clock Configuration
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void SystemClock_Config(void)
|
||||||
|
{
|
||||||
|
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
|
||||||
|
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
|
||||||
|
|
||||||
|
/** Configure the main internal regulator output voltage
|
||||||
|
*/
|
||||||
|
__HAL_RCC_PWR_CLK_ENABLE();
|
||||||
|
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE3);
|
||||||
|
|
||||||
|
/** Initializes the RCC Oscillators according to the specified parameters
|
||||||
|
* in the RCC_OscInitTypeDef structure.
|
||||||
|
*/
|
||||||
|
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
|
||||||
|
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
|
||||||
|
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
|
||||||
|
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
||||||
|
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
|
||||||
|
RCC_OscInitStruct.PLL.PLLM = 8;
|
||||||
|
RCC_OscInitStruct.PLL.PLLN = 72;
|
||||||
|
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
|
||||||
|
RCC_OscInitStruct.PLL.PLLQ = 3;
|
||||||
|
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Initializes the CPU, AHB and APB buses clocks
|
||||||
|
*/
|
||||||
|
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|
||||||
|
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
|
||||||
|
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
|
||||||
|
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
|
||||||
|
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
|
||||||
|
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
|
||||||
|
|
||||||
|
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief CRC Initialization Function
|
||||||
|
* @param None
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
static void MX_CRC_Init(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* USER CODE BEGIN CRC_Init 0 */
|
||||||
|
|
||||||
|
/* USER CODE END CRC_Init 0 */
|
||||||
|
|
||||||
|
/* USER CODE BEGIN CRC_Init 1 */
|
||||||
|
|
||||||
|
/* USER CODE END CRC_Init 1 */
|
||||||
|
hcrc.Instance = CRC;
|
||||||
|
if (HAL_CRC_Init(&hcrc) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
/* USER CODE BEGIN CRC_Init 2 */
|
||||||
|
|
||||||
|
/* USER CODE END CRC_Init 2 */
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief DMA2D Initialization Function
|
||||||
|
* @param None
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
static void MX_DMA2D_Init(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* USER CODE BEGIN DMA2D_Init 0 */
|
||||||
|
|
||||||
|
/* USER CODE END DMA2D_Init 0 */
|
||||||
|
|
||||||
|
/* USER CODE BEGIN DMA2D_Init 1 */
|
||||||
|
|
||||||
|
/* USER CODE END DMA2D_Init 1 */
|
||||||
|
hdma2d.Instance = DMA2D;
|
||||||
|
hdma2d.Init.Mode = DMA2D_M2M;
|
||||||
|
hdma2d.Init.ColorMode = DMA2D_OUTPUT_ARGB8888;
|
||||||
|
hdma2d.Init.OutputOffset = 0;
|
||||||
|
hdma2d.LayerCfg[1].InputOffset = 0;
|
||||||
|
hdma2d.LayerCfg[1].InputColorMode = DMA2D_INPUT_ARGB8888;
|
||||||
|
hdma2d.LayerCfg[1].AlphaMode = DMA2D_NO_MODIF_ALPHA;
|
||||||
|
hdma2d.LayerCfg[1].InputAlpha = 0;
|
||||||
|
if (HAL_DMA2D_Init(&hdma2d) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
if (HAL_DMA2D_ConfigLayer(&hdma2d, 1) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
/* USER CODE BEGIN DMA2D_Init 2 */
|
||||||
|
|
||||||
|
/* USER CODE END DMA2D_Init 2 */
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief TIM1 Initialization Function
|
||||||
|
* @param None
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
static void MX_TIM1_Init(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* USER CODE BEGIN TIM1_Init 0 */
|
||||||
|
|
||||||
|
/* USER CODE END TIM1_Init 0 */
|
||||||
|
|
||||||
|
TIM_ClockConfigTypeDef sClockSourceConfig = {0};
|
||||||
|
TIM_MasterConfigTypeDef sMasterConfig = {0};
|
||||||
|
|
||||||
|
/* USER CODE BEGIN TIM1_Init 1 */
|
||||||
|
|
||||||
|
/* USER CODE END TIM1_Init 1 */
|
||||||
|
htim1.Instance = TIM1;
|
||||||
|
htim1.Init.Prescaler = 0;
|
||||||
|
htim1.Init.CounterMode = TIM_COUNTERMODE_UP;
|
||||||
|
htim1.Init.Period = 65535;
|
||||||
|
htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
||||||
|
htim1.Init.RepetitionCounter = 0;
|
||||||
|
htim1.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
|
||||||
|
if (HAL_TIM_Base_Init(&htim1) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
|
||||||
|
if (HAL_TIM_ConfigClockSource(&htim1, &sClockSourceConfig) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
|
||||||
|
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
|
||||||
|
if (HAL_TIMEx_MasterConfigSynchronization(&htim1, &sMasterConfig) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
/* USER CODE BEGIN TIM1_Init 2 */
|
||||||
|
|
||||||
|
/* USER CODE END TIM1_Init 2 */
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief GPIO Initialization Function
|
||||||
|
* @param None
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
static void MX_GPIO_Init(void)
|
||||||
|
{
|
||||||
|
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||||
|
/* USER CODE BEGIN MX_GPIO_Init_1 */
|
||||||
|
|
||||||
|
/* USER CODE END MX_GPIO_Init_1 */
|
||||||
|
|
||||||
|
/* GPIO Ports Clock Enable */
|
||||||
|
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||||
|
__HAL_RCC_GPIOD_CLK_ENABLE();
|
||||||
|
|
||||||
|
/*Configure GPIO pin Output Level */
|
||||||
|
HAL_GPIO_WritePin(GPIOD, White_Pin|Red_Pin|Yellow_Pin|Green_Pin, GPIO_PIN_RESET);
|
||||||
|
|
||||||
|
/*Configure GPIO pin : PedButton_Pin */
|
||||||
|
GPIO_InitStruct.Pin = PedButton_Pin;
|
||||||
|
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
|
||||||
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
|
HAL_GPIO_Init(PedButton_GPIO_Port, &GPIO_InitStruct);
|
||||||
|
|
||||||
|
/*Configure GPIO pins : White_Pin Red_Pin Yellow_Pin Green_Pin */
|
||||||
|
GPIO_InitStruct.Pin = White_Pin|Red_Pin|Yellow_Pin|Green_Pin;
|
||||||
|
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||||
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||||
|
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
|
||||||
|
|
||||||
|
/* EXTI interrupt init*/
|
||||||
|
HAL_NVIC_SetPriority(EXTI15_10_IRQn, 15, 0);
|
||||||
|
HAL_NVIC_EnableIRQ(EXTI15_10_IRQn);
|
||||||
|
|
||||||
|
/* USER CODE BEGIN MX_GPIO_Init_2 */
|
||||||
|
|
||||||
|
/* USER CODE END MX_GPIO_Init_2 */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* USER CODE BEGIN 4 */
|
||||||
|
|
||||||
|
void HAL_GPIO_EXTI_CallBack(uint16_t GPIO_Pin)
|
||||||
|
{
|
||||||
|
static uint32_t lastInterruptTime = 0;
|
||||||
|
uint32_t now = HAL_GetTick();
|
||||||
|
if (now - lastInterruptTime < 100) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
lastInterruptTime = now;
|
||||||
|
|
||||||
|
bool buttonPressedThisCycle = false; // temporary, get rid of this
|
||||||
|
|
||||||
|
if (buttonPressed) { // buttonPressedHere?
|
||||||
|
buttonPressedThisCycle = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* USER CODE END 4 */
|
||||||
|
|
||||||
|
/* USER CODE BEGIN Header_StartDefaultTask */
|
||||||
|
/**
|
||||||
|
* @brief Function implementing the defaultTask thread.
|
||||||
|
* @param argument: Not used
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
/* USER CODE END Header_StartDefaultTask */
|
||||||
|
void StartDefaultTask(void const * argument)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN 5 */
|
||||||
|
/* Infinite loop */
|
||||||
|
for(;;)
|
||||||
|
{
|
||||||
|
osDelay(1);
|
||||||
|
}
|
||||||
|
/* USER CODE END 5 */
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Period elapsed callback in non blocking mode
|
||||||
|
* @note This function is called when TIM6 interrupt took place, inside
|
||||||
|
* HAL_TIM_IRQHandler(). It makes a direct call to HAL_IncTick() to increment
|
||||||
|
* a global variable "uwTick" used as application time base.
|
||||||
|
* @param htim : TIM handle
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN Callback 0 */
|
||||||
|
|
||||||
|
/* USER CODE END Callback 0 */
|
||||||
|
if (htim->Instance == TIM6)
|
||||||
|
{
|
||||||
|
HAL_IncTick();
|
||||||
|
}
|
||||||
|
/* USER CODE BEGIN Callback 1 */
|
||||||
|
|
||||||
|
/* USER CODE END Callback 1 */
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function is executed in case of error occurrence.
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void Error_Handler(void)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN Error_Handler_Debug */
|
||||||
|
/* User can add his own implementation to report the HAL error return state */
|
||||||
|
__disable_irq();
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
/* USER CODE END Error_Handler_Debug */
|
||||||
|
}
|
||||||
|
#ifdef USE_FULL_ASSERT
|
||||||
|
/**
|
||||||
|
* @brief Reports the name of the source file and the source line number
|
||||||
|
* where the assert_param error has occurred.
|
||||||
|
* @param file: pointer to the source file name
|
||||||
|
* @param line: assert_param error line source number
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void assert_failed(uint8_t *file, uint32_t line)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN 6 */
|
||||||
|
/* User can add his own implementation to report the file name and line number,
|
||||||
|
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
|
||||||
|
/* USER CODE END 6 */
|
||||||
|
}
|
||||||
|
#endif /* USE_FULL_ASSERT */
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
/*
|
|
||||||
* breadboard.cpp
|
|
||||||
*
|
|
||||||
* Created on: Sep 22, 2025
|
|
||||||
* Author: ja
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "breadboard.h"
|
|
||||||
|
|
||||||
void SetTrafficLights(TrafficState s)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,729 +0,0 @@
|
|||||||
/* USER CODE BEGIN Header */
|
|
||||||
/**
|
|
||||||
******************************************************************************
|
|
||||||
* @file : main.c
|
|
||||||
* @brief : Main program body
|
|
||||||
******************************************************************************
|
|
||||||
* @attention
|
|
||||||
*
|
|
||||||
* Copyright (c) 2025 STMicroelectronics.
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* This software is licensed under terms that can be found in the LICENSE file
|
|
||||||
* in the root directory of this software component.
|
|
||||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
|
||||||
*
|
|
||||||
******************************************************************************
|
|
||||||
*/
|
|
||||||
/* USER CODE END Header */
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
|
||||||
#include "main.h"
|
|
||||||
#include "cmsis_os.h"
|
|
||||||
#include "usb_host.h"
|
|
||||||
|
|
||||||
/* Private includes ----------------------------------------------------------*/
|
|
||||||
/* USER CODE BEGIN Includes */
|
|
||||||
|
|
||||||
/* USER CODE END Includes */
|
|
||||||
|
|
||||||
/* Private typedef -----------------------------------------------------------*/
|
|
||||||
/* USER CODE BEGIN PTD */
|
|
||||||
|
|
||||||
/* USER CODE END PTD */
|
|
||||||
|
|
||||||
/* Private define ------------------------------------------------------------*/
|
|
||||||
/* USER CODE BEGIN PD */
|
|
||||||
|
|
||||||
/* USER CODE END PD */
|
|
||||||
|
|
||||||
/* Private macro -------------------------------------------------------------*/
|
|
||||||
/* USER CODE BEGIN PM */
|
|
||||||
|
|
||||||
/* USER CODE END PM */
|
|
||||||
|
|
||||||
/* Private variables ---------------------------------------------------------*/
|
|
||||||
CRC_HandleTypeDef hcrc;
|
|
||||||
|
|
||||||
DMA2D_HandleTypeDef hdma2d;
|
|
||||||
|
|
||||||
I2C_HandleTypeDef hi2c3;
|
|
||||||
|
|
||||||
LTDC_HandleTypeDef hltdc;
|
|
||||||
|
|
||||||
SPI_HandleTypeDef hspi5;
|
|
||||||
|
|
||||||
TIM_HandleTypeDef htim1;
|
|
||||||
|
|
||||||
UART_HandleTypeDef huart1;
|
|
||||||
|
|
||||||
SDRAM_HandleTypeDef hsdram1;
|
|
||||||
|
|
||||||
osThreadId defaultTaskHandle;
|
|
||||||
/* USER CODE BEGIN PV */
|
|
||||||
|
|
||||||
/* USER CODE END PV */
|
|
||||||
|
|
||||||
/* Private function prototypes -----------------------------------------------*/
|
|
||||||
void SystemClock_Config(void);
|
|
||||||
static void MX_GPIO_Init(void);
|
|
||||||
static void MX_CRC_Init(void);
|
|
||||||
static void MX_DMA2D_Init(void);
|
|
||||||
static void MX_FMC_Init(void);
|
|
||||||
static void MX_I2C3_Init(void);
|
|
||||||
static void MX_LTDC_Init(void);
|
|
||||||
static void MX_SPI5_Init(void);
|
|
||||||
static void MX_TIM1_Init(void);
|
|
||||||
static void MX_USART1_UART_Init(void);
|
|
||||||
void StartDefaultTask(void const * argument);
|
|
||||||
|
|
||||||
/* USER CODE BEGIN PFP */
|
|
||||||
|
|
||||||
/* USER CODE END PFP */
|
|
||||||
|
|
||||||
/* Private user code ---------------------------------------------------------*/
|
|
||||||
/* USER CODE BEGIN 0 */
|
|
||||||
|
|
||||||
/* USER CODE END 0 */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief The application entry point.
|
|
||||||
* @retval int
|
|
||||||
*/
|
|
||||||
int main(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* USER CODE BEGIN 1 */
|
|
||||||
|
|
||||||
/* USER CODE END 1 */
|
|
||||||
|
|
||||||
/* MCU Configuration--------------------------------------------------------*/
|
|
||||||
|
|
||||||
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
|
|
||||||
HAL_Init();
|
|
||||||
|
|
||||||
/* USER CODE BEGIN Init */
|
|
||||||
|
|
||||||
/* USER CODE END Init */
|
|
||||||
|
|
||||||
/* Configure the system clock */
|
|
||||||
SystemClock_Config();
|
|
||||||
|
|
||||||
/* USER CODE BEGIN SysInit */
|
|
||||||
|
|
||||||
/* USER CODE END SysInit */
|
|
||||||
|
|
||||||
/* Initialize all configured peripherals */
|
|
||||||
MX_GPIO_Init();
|
|
||||||
MX_CRC_Init();
|
|
||||||
MX_DMA2D_Init();
|
|
||||||
MX_FMC_Init();
|
|
||||||
MX_I2C3_Init();
|
|
||||||
MX_LTDC_Init();
|
|
||||||
MX_SPI5_Init();
|
|
||||||
MX_TIM1_Init();
|
|
||||||
MX_USART1_UART_Init();
|
|
||||||
/* USER CODE BEGIN 2 */
|
|
||||||
|
|
||||||
/* USER CODE END 2 */
|
|
||||||
|
|
||||||
/* USER CODE BEGIN RTOS_MUTEX */
|
|
||||||
/* add mutexes, ... */
|
|
||||||
/* USER CODE END RTOS_MUTEX */
|
|
||||||
|
|
||||||
/* USER CODE BEGIN RTOS_SEMAPHORES */
|
|
||||||
/* add semaphores, ... */
|
|
||||||
/* USER CODE END RTOS_SEMAPHORES */
|
|
||||||
|
|
||||||
/* USER CODE BEGIN RTOS_TIMERS */
|
|
||||||
/* start timers, add new ones, ... */
|
|
||||||
/* USER CODE END RTOS_TIMERS */
|
|
||||||
|
|
||||||
/* USER CODE BEGIN RTOS_QUEUES */
|
|
||||||
/* add queues, ... */
|
|
||||||
/* USER CODE END RTOS_QUEUES */
|
|
||||||
|
|
||||||
/* Create the thread(s) */
|
|
||||||
/* definition and creation of defaultTask */
|
|
||||||
//osThreadDef(defaultTask, StartDefaultTask, osPriorityNormal, 0, 4096);
|
|
||||||
//defaultTaskHandle = osThreadCreate(osThread(defaultTask), NULL);
|
|
||||||
|
|
||||||
/* USER CODE BEGIN RTOS_THREADS */
|
|
||||||
/* add threads, ... */
|
|
||||||
/* USER CODE END RTOS_THREADS */
|
|
||||||
|
|
||||||
/* Start scheduler */
|
|
||||||
//osKernelStart();
|
|
||||||
|
|
||||||
/* We should never get here as control is now taken by the scheduler */
|
|
||||||
|
|
||||||
/* Infinite loop */
|
|
||||||
/* USER CODE BEGIN WHILE */
|
|
||||||
while (1)
|
|
||||||
{
|
|
||||||
breadboard(333);
|
|
||||||
/* USER CODE END WHILE */
|
|
||||||
|
|
||||||
/* USER CODE BEGIN 3 */
|
|
||||||
}
|
|
||||||
/* USER CODE END 3 */
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief System Clock Configuration
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
void SystemClock_Config(void)
|
|
||||||
{
|
|
||||||
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
|
|
||||||
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
|
|
||||||
|
|
||||||
/** Configure the main internal regulator output voltage
|
|
||||||
*/
|
|
||||||
__HAL_RCC_PWR_CLK_ENABLE();
|
|
||||||
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE3);
|
|
||||||
|
|
||||||
/** Initializes the RCC Oscillators according to the specified parameters
|
|
||||||
* in the RCC_OscInitTypeDef structure.
|
|
||||||
*/
|
|
||||||
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
|
|
||||||
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
|
|
||||||
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
|
||||||
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
|
|
||||||
RCC_OscInitStruct.PLL.PLLM = 4;
|
|
||||||
RCC_OscInitStruct.PLL.PLLN = 72;
|
|
||||||
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
|
|
||||||
RCC_OscInitStruct.PLL.PLLQ = 3;
|
|
||||||
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Initializes the CPU, AHB and APB buses clocks
|
|
||||||
*/
|
|
||||||
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|
|
||||||
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
|
|
||||||
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
|
|
||||||
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
|
|
||||||
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
|
|
||||||
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
|
|
||||||
|
|
||||||
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief CRC Initialization Function
|
|
||||||
* @param None
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
static void MX_CRC_Init(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* USER CODE BEGIN CRC_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE END CRC_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE BEGIN CRC_Init 1 */
|
|
||||||
|
|
||||||
/* USER CODE END CRC_Init 1 */
|
|
||||||
hcrc.Instance = CRC;
|
|
||||||
if (HAL_CRC_Init(&hcrc) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
/* USER CODE BEGIN CRC_Init 2 */
|
|
||||||
|
|
||||||
/* USER CODE END CRC_Init 2 */
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief DMA2D Initialization Function
|
|
||||||
* @param None
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
static void MX_DMA2D_Init(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* USER CODE BEGIN DMA2D_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE END DMA2D_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE BEGIN DMA2D_Init 1 */
|
|
||||||
|
|
||||||
/* USER CODE END DMA2D_Init 1 */
|
|
||||||
hdma2d.Instance = DMA2D;
|
|
||||||
hdma2d.Init.Mode = DMA2D_M2M;
|
|
||||||
hdma2d.Init.ColorMode = DMA2D_OUTPUT_ARGB8888;
|
|
||||||
hdma2d.Init.OutputOffset = 0;
|
|
||||||
hdma2d.LayerCfg[1].InputOffset = 0;
|
|
||||||
hdma2d.LayerCfg[1].InputColorMode = DMA2D_INPUT_ARGB8888;
|
|
||||||
hdma2d.LayerCfg[1].AlphaMode = DMA2D_NO_MODIF_ALPHA;
|
|
||||||
hdma2d.LayerCfg[1].InputAlpha = 0;
|
|
||||||
if (HAL_DMA2D_Init(&hdma2d) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
if (HAL_DMA2D_ConfigLayer(&hdma2d, 1) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
/* USER CODE BEGIN DMA2D_Init 2 */
|
|
||||||
|
|
||||||
/* USER CODE END DMA2D_Init 2 */
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief I2C3 Initialization Function
|
|
||||||
* @param None
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
static void MX_I2C3_Init(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* USER CODE BEGIN I2C3_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE END I2C3_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE BEGIN I2C3_Init 1 */
|
|
||||||
|
|
||||||
/* USER CODE END I2C3_Init 1 */
|
|
||||||
hi2c3.Instance = I2C3;
|
|
||||||
hi2c3.Init.ClockSpeed = 100000;
|
|
||||||
hi2c3.Init.DutyCycle = I2C_DUTYCYCLE_2;
|
|
||||||
hi2c3.Init.OwnAddress1 = 0;
|
|
||||||
hi2c3.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
|
|
||||||
hi2c3.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
|
|
||||||
hi2c3.Init.OwnAddress2 = 0;
|
|
||||||
hi2c3.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
|
|
||||||
hi2c3.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
|
|
||||||
if (HAL_I2C_Init(&hi2c3) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Configure Analogue filter
|
|
||||||
*/
|
|
||||||
if (HAL_I2CEx_ConfigAnalogFilter(&hi2c3, I2C_ANALOGFILTER_ENABLE) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Configure Digital filter
|
|
||||||
*/
|
|
||||||
if (HAL_I2CEx_ConfigDigitalFilter(&hi2c3, 0) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
/* USER CODE BEGIN I2C3_Init 2 */
|
|
||||||
|
|
||||||
/* USER CODE END I2C3_Init 2 */
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief LTDC Initialization Function
|
|
||||||
* @param None
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
static void MX_LTDC_Init(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* USER CODE BEGIN LTDC_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE END LTDC_Init 0 */
|
|
||||||
|
|
||||||
LTDC_LayerCfgTypeDef pLayerCfg = {0};
|
|
||||||
|
|
||||||
/* USER CODE BEGIN LTDC_Init 1 */
|
|
||||||
|
|
||||||
/* USER CODE END LTDC_Init 1 */
|
|
||||||
hltdc.Instance = LTDC;
|
|
||||||
hltdc.Init.HSPolarity = LTDC_HSPOLARITY_AL;
|
|
||||||
hltdc.Init.VSPolarity = LTDC_VSPOLARITY_AL;
|
|
||||||
hltdc.Init.DEPolarity = LTDC_DEPOLARITY_AL;
|
|
||||||
hltdc.Init.PCPolarity = LTDC_PCPOLARITY_IPC;
|
|
||||||
hltdc.Init.HorizontalSync = 9;
|
|
||||||
hltdc.Init.VerticalSync = 1;
|
|
||||||
hltdc.Init.AccumulatedHBP = 29;
|
|
||||||
hltdc.Init.AccumulatedVBP = 3;
|
|
||||||
hltdc.Init.AccumulatedActiveW = 269;
|
|
||||||
hltdc.Init.AccumulatedActiveH = 323;
|
|
||||||
hltdc.Init.TotalWidth = 279;
|
|
||||||
hltdc.Init.TotalHeigh = 327;
|
|
||||||
hltdc.Init.Backcolor.Blue = 0;
|
|
||||||
hltdc.Init.Backcolor.Green = 0;
|
|
||||||
hltdc.Init.Backcolor.Red = 0;
|
|
||||||
if (HAL_LTDC_Init(&hltdc) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
pLayerCfg.WindowX0 = 0;
|
|
||||||
pLayerCfg.WindowX1 = 240;
|
|
||||||
pLayerCfg.WindowY0 = 0;
|
|
||||||
pLayerCfg.WindowY1 = 320;
|
|
||||||
pLayerCfg.PixelFormat = LTDC_PIXEL_FORMAT_RGB565;
|
|
||||||
pLayerCfg.Alpha = 255;
|
|
||||||
pLayerCfg.Alpha0 = 0;
|
|
||||||
pLayerCfg.BlendingFactor1 = LTDC_BLENDING_FACTOR1_PAxCA;
|
|
||||||
pLayerCfg.BlendingFactor2 = LTDC_BLENDING_FACTOR2_PAxCA;
|
|
||||||
pLayerCfg.FBStartAdress = 0xD0000000;
|
|
||||||
pLayerCfg.ImageWidth = 240;
|
|
||||||
pLayerCfg.ImageHeight = 320;
|
|
||||||
pLayerCfg.Backcolor.Blue = 0;
|
|
||||||
pLayerCfg.Backcolor.Green = 0;
|
|
||||||
pLayerCfg.Backcolor.Red = 0;
|
|
||||||
if (HAL_LTDC_ConfigLayer(&hltdc, &pLayerCfg, 0) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
/* USER CODE BEGIN LTDC_Init 2 */
|
|
||||||
|
|
||||||
/* USER CODE END LTDC_Init 2 */
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief SPI5 Initialization Function
|
|
||||||
* @param None
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
static void MX_SPI5_Init(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* USER CODE BEGIN SPI5_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE END SPI5_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE BEGIN SPI5_Init 1 */
|
|
||||||
|
|
||||||
/* USER CODE END SPI5_Init 1 */
|
|
||||||
/* SPI5 parameter configuration*/
|
|
||||||
hspi5.Instance = SPI5;
|
|
||||||
hspi5.Init.Mode = SPI_MODE_MASTER;
|
|
||||||
hspi5.Init.Direction = SPI_DIRECTION_2LINES;
|
|
||||||
hspi5.Init.DataSize = SPI_DATASIZE_8BIT;
|
|
||||||
hspi5.Init.CLKPolarity = SPI_POLARITY_LOW;
|
|
||||||
hspi5.Init.CLKPhase = SPI_PHASE_1EDGE;
|
|
||||||
hspi5.Init.NSS = SPI_NSS_SOFT;
|
|
||||||
hspi5.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_16;
|
|
||||||
hspi5.Init.FirstBit = SPI_FIRSTBIT_MSB;
|
|
||||||
hspi5.Init.TIMode = SPI_TIMODE_DISABLE;
|
|
||||||
hspi5.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
|
|
||||||
hspi5.Init.CRCPolynomial = 10;
|
|
||||||
if (HAL_SPI_Init(&hspi5) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
/* USER CODE BEGIN SPI5_Init 2 */
|
|
||||||
|
|
||||||
/* USER CODE END SPI5_Init 2 */
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief TIM1 Initialization Function
|
|
||||||
* @param None
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
static void MX_TIM1_Init(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* USER CODE BEGIN TIM1_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE END TIM1_Init 0 */
|
|
||||||
|
|
||||||
TIM_ClockConfigTypeDef sClockSourceConfig = {0};
|
|
||||||
TIM_MasterConfigTypeDef sMasterConfig = {0};
|
|
||||||
|
|
||||||
/* USER CODE BEGIN TIM1_Init 1 */
|
|
||||||
|
|
||||||
/* USER CODE END TIM1_Init 1 */
|
|
||||||
htim1.Instance = TIM1;
|
|
||||||
htim1.Init.Prescaler = 0;
|
|
||||||
htim1.Init.CounterMode = TIM_COUNTERMODE_UP;
|
|
||||||
htim1.Init.Period = 65535;
|
|
||||||
htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
|
||||||
htim1.Init.RepetitionCounter = 0;
|
|
||||||
htim1.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
|
|
||||||
if (HAL_TIM_Base_Init(&htim1) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
|
|
||||||
if (HAL_TIM_ConfigClockSource(&htim1, &sClockSourceConfig) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
|
|
||||||
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
|
|
||||||
if (HAL_TIMEx_MasterConfigSynchronization(&htim1, &sMasterConfig) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
/* USER CODE BEGIN TIM1_Init 2 */
|
|
||||||
|
|
||||||
/* USER CODE END TIM1_Init 2 */
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief USART1 Initialization Function
|
|
||||||
* @param None
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
static void MX_USART1_UART_Init(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* USER CODE BEGIN USART1_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE END USART1_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE BEGIN USART1_Init 1 */
|
|
||||||
|
|
||||||
/* USER CODE END USART1_Init 1 */
|
|
||||||
huart1.Instance = USART1;
|
|
||||||
huart1.Init.BaudRate = 115200;
|
|
||||||
huart1.Init.WordLength = UART_WORDLENGTH_8B;
|
|
||||||
huart1.Init.StopBits = UART_STOPBITS_1;
|
|
||||||
huart1.Init.Parity = UART_PARITY_NONE;
|
|
||||||
huart1.Init.Mode = UART_MODE_TX_RX;
|
|
||||||
huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
|
|
||||||
huart1.Init.OverSampling = UART_OVERSAMPLING_16;
|
|
||||||
if (HAL_UART_Init(&huart1) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
/* USER CODE BEGIN USART1_Init 2 */
|
|
||||||
|
|
||||||
/* USER CODE END USART1_Init 2 */
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/* FMC initialization function */
|
|
||||||
static void MX_FMC_Init(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* USER CODE BEGIN FMC_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE END FMC_Init 0 */
|
|
||||||
|
|
||||||
FMC_SDRAM_TimingTypeDef SdramTiming = {0};
|
|
||||||
|
|
||||||
/* USER CODE BEGIN FMC_Init 1 */
|
|
||||||
|
|
||||||
/* USER CODE END FMC_Init 1 */
|
|
||||||
|
|
||||||
/** Perform the SDRAM1 memory initialization sequence
|
|
||||||
*/
|
|
||||||
hsdram1.Instance = FMC_SDRAM_DEVICE;
|
|
||||||
/* hsdram1.Init */
|
|
||||||
hsdram1.Init.SDBank = FMC_SDRAM_BANK2;
|
|
||||||
hsdram1.Init.ColumnBitsNumber = FMC_SDRAM_COLUMN_BITS_NUM_8;
|
|
||||||
hsdram1.Init.RowBitsNumber = FMC_SDRAM_ROW_BITS_NUM_12;
|
|
||||||
hsdram1.Init.MemoryDataWidth = FMC_SDRAM_MEM_BUS_WIDTH_16;
|
|
||||||
hsdram1.Init.InternalBankNumber = FMC_SDRAM_INTERN_BANKS_NUM_4;
|
|
||||||
hsdram1.Init.CASLatency = FMC_SDRAM_CAS_LATENCY_3;
|
|
||||||
hsdram1.Init.WriteProtection = FMC_SDRAM_WRITE_PROTECTION_DISABLE;
|
|
||||||
hsdram1.Init.SDClockPeriod = FMC_SDRAM_CLOCK_PERIOD_2;
|
|
||||||
hsdram1.Init.ReadBurst = FMC_SDRAM_RBURST_DISABLE;
|
|
||||||
hsdram1.Init.ReadPipeDelay = FMC_SDRAM_RPIPE_DELAY_1;
|
|
||||||
/* SdramTiming */
|
|
||||||
SdramTiming.LoadToActiveDelay = 2;
|
|
||||||
SdramTiming.ExitSelfRefreshDelay = 7;
|
|
||||||
SdramTiming.SelfRefreshTime = 4;
|
|
||||||
SdramTiming.RowCycleDelay = 7;
|
|
||||||
SdramTiming.WriteRecoveryTime = 3;
|
|
||||||
SdramTiming.RPDelay = 2;
|
|
||||||
SdramTiming.RCDDelay = 2;
|
|
||||||
|
|
||||||
if (HAL_SDRAM_Init(&hsdram1, &SdramTiming) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler( );
|
|
||||||
}
|
|
||||||
|
|
||||||
/* USER CODE BEGIN FMC_Init 2 */
|
|
||||||
|
|
||||||
/* USER CODE END FMC_Init 2 */
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief GPIO Initialization Function
|
|
||||||
* @param None
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
static void MX_GPIO_Init(void)
|
|
||||||
{
|
|
||||||
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
|
||||||
/* USER CODE BEGIN MX_GPIO_Init_1 */
|
|
||||||
|
|
||||||
/* USER CODE END MX_GPIO_Init_1 */
|
|
||||||
|
|
||||||
/* GPIO Ports Clock Enable */
|
|
||||||
__HAL_RCC_GPIOE_CLK_ENABLE();
|
|
||||||
__HAL_RCC_GPIOC_CLK_ENABLE();
|
|
||||||
__HAL_RCC_GPIOF_CLK_ENABLE();
|
|
||||||
__HAL_RCC_GPIOH_CLK_ENABLE();
|
|
||||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
|
||||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
|
||||||
__HAL_RCC_GPIOG_CLK_ENABLE();
|
|
||||||
__HAL_RCC_GPIOD_CLK_ENABLE();
|
|
||||||
|
|
||||||
/*Configure GPIO pin Output Level */
|
|
||||||
HAL_GPIO_WritePin(GPIOE, RedLight_Pin|YellowLight_Pin|GreenLight_Pin, GPIO_PIN_RESET);
|
|
||||||
|
|
||||||
/*Configure GPIO pin Output Level */
|
|
||||||
HAL_GPIO_WritePin(GPIOC, NCS_MEMS_SPI_Pin|CSX_Pin|OTG_FS_PSO_Pin, GPIO_PIN_RESET);
|
|
||||||
|
|
||||||
/*Configure GPIO pin Output Level */
|
|
||||||
HAL_GPIO_WritePin(ACP_RST_GPIO_Port, ACP_RST_Pin, GPIO_PIN_RESET);
|
|
||||||
|
|
||||||
/*Configure GPIO pin Output Level */
|
|
||||||
HAL_GPIO_WritePin(GPIOD, RDX_Pin|WRX_DCX_Pin, GPIO_PIN_RESET);
|
|
||||||
|
|
||||||
/*Configure GPIO pin Output Level */
|
|
||||||
HAL_GPIO_WritePin(GPIOG, LD3_Pin|LD4_Pin, GPIO_PIN_RESET);
|
|
||||||
|
|
||||||
/*Configure GPIO pins : RedLight_Pin YellowLight_Pin GreenLight_Pin */
|
|
||||||
GPIO_InitStruct.Pin = RedLight_Pin|YellowLight_Pin|GreenLight_Pin;
|
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
||||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
|
||||||
HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
|
|
||||||
|
|
||||||
/*Configure GPIO pins : NCS_MEMS_SPI_Pin CSX_Pin OTG_FS_PSO_Pin */
|
|
||||||
GPIO_InitStruct.Pin = NCS_MEMS_SPI_Pin|CSX_Pin|OTG_FS_PSO_Pin;
|
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
||||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
|
||||||
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
|
|
||||||
|
|
||||||
/*Configure GPIO pins : B1_Pin MEMS_INT1_Pin MEMS_INT2_Pin TP_INT1_Pin */
|
|
||||||
GPIO_InitStruct.Pin = B1_Pin|MEMS_INT1_Pin|MEMS_INT2_Pin|TP_INT1_Pin;
|
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_EVT_RISING;
|
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
||||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
|
||||||
|
|
||||||
/*Configure GPIO pin : ACP_RST_Pin */
|
|
||||||
GPIO_InitStruct.Pin = ACP_RST_Pin;
|
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
||||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
|
||||||
HAL_GPIO_Init(ACP_RST_GPIO_Port, &GPIO_InitStruct);
|
|
||||||
|
|
||||||
/*Configure GPIO pin : OTG_FS_OC_Pin */
|
|
||||||
GPIO_InitStruct.Pin = OTG_FS_OC_Pin;
|
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_EVT_RISING;
|
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
||||||
HAL_GPIO_Init(OTG_FS_OC_GPIO_Port, &GPIO_InitStruct);
|
|
||||||
|
|
||||||
/*Configure GPIO pin : BOOT1_Pin */
|
|
||||||
GPIO_InitStruct.Pin = BOOT1_Pin;
|
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
||||||
HAL_GPIO_Init(BOOT1_GPIO_Port, &GPIO_InitStruct);
|
|
||||||
|
|
||||||
/*Configure GPIO pin : TE_Pin */
|
|
||||||
GPIO_InitStruct.Pin = TE_Pin;
|
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
||||||
HAL_GPIO_Init(TE_GPIO_Port, &GPIO_InitStruct);
|
|
||||||
|
|
||||||
/*Configure GPIO pins : RDX_Pin WRX_DCX_Pin */
|
|
||||||
GPIO_InitStruct.Pin = RDX_Pin|WRX_DCX_Pin;
|
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
||||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
|
||||||
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
|
|
||||||
|
|
||||||
/*Configure GPIO pins : LD3_Pin LD4_Pin */
|
|
||||||
GPIO_InitStruct.Pin = LD3_Pin|LD4_Pin;
|
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
||||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
|
||||||
HAL_GPIO_Init(GPIOG, &GPIO_InitStruct);
|
|
||||||
|
|
||||||
/* USER CODE BEGIN MX_GPIO_Init_2 */
|
|
||||||
|
|
||||||
/* USER CODE END MX_GPIO_Init_2 */
|
|
||||||
}
|
|
||||||
|
|
||||||
/* USER CODE BEGIN 4 */
|
|
||||||
|
|
||||||
/* USER CODE END 4 */
|
|
||||||
|
|
||||||
/* USER CODE BEGIN Header_StartDefaultTask */
|
|
||||||
/**
|
|
||||||
* @brief Function implementing the defaultTask thread.
|
|
||||||
* @param argument: Not used
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
/* USER CODE END Header_StartDefaultTask */
|
|
||||||
void StartDefaultTask(void const * argument)
|
|
||||||
{
|
|
||||||
/* init code for USB_HOST */
|
|
||||||
MX_USB_HOST_Init();
|
|
||||||
/* USER CODE BEGIN 5 */
|
|
||||||
/* Infinite loop */
|
|
||||||
for(;;)
|
|
||||||
{
|
|
||||||
osDelay(1);
|
|
||||||
}
|
|
||||||
/* USER CODE END 5 */
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Period elapsed callback in non blocking mode
|
|
||||||
* @note This function is called when TIM6 interrupt took place, inside
|
|
||||||
* HAL_TIM_IRQHandler(). It makes a direct call to HAL_IncTick() to increment
|
|
||||||
* a global variable "uwTick" used as application time base.
|
|
||||||
* @param htim : TIM handle
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
|
|
||||||
{
|
|
||||||
/* USER CODE BEGIN Callback 0 */
|
|
||||||
|
|
||||||
/* USER CODE END Callback 0 */
|
|
||||||
if (htim->Instance == TIM6)
|
|
||||||
{
|
|
||||||
HAL_IncTick();
|
|
||||||
}
|
|
||||||
/* USER CODE BEGIN Callback 1 */
|
|
||||||
|
|
||||||
/* USER CODE END Callback 1 */
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief This function is executed in case of error occurrence.
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
void Error_Handler(void)
|
|
||||||
{
|
|
||||||
/* USER CODE BEGIN Error_Handler_Debug */
|
|
||||||
/* User can add his own implementation to report the HAL error return state */
|
|
||||||
__disable_irq();
|
|
||||||
while (1)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
/* USER CODE END Error_Handler_Debug */
|
|
||||||
}
|
|
||||||
#ifdef USE_FULL_ASSERT
|
|
||||||
/**
|
|
||||||
* @brief Reports the name of the source file and the source line number
|
|
||||||
* where the assert_param error has occurred.
|
|
||||||
* @param file: pointer to the source file name
|
|
||||||
* @param line: assert_param error line source number
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
void assert_failed(uint8_t *file, uint32_t line)
|
|
||||||
{
|
|
||||||
/* USER CODE BEGIN 6 */
|
|
||||||
/* User can add his own implementation to report the file name and line number,
|
|
||||||
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
|
|
||||||
/* USER CODE END 6 */
|
|
||||||
}
|
|
||||||
#endif /* USE_FULL_ASSERT */
|
|
||||||
@@ -0,0 +1,342 @@
|
|||||||
|
/* USER CODE BEGIN Header */
|
||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
* @file : main.c
|
||||||
|
* @brief : Main program body
|
||||||
|
******************************************************************************
|
||||||
|
* @attention
|
||||||
|
*
|
||||||
|
* Copyright (c) 2025 STMicroelectronics.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This software is licensed under terms that can be found in the LICENSE file
|
||||||
|
* in the root directory of this software component.
|
||||||
|
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||||
|
*
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
// Feeling sneaky.
|
||||||
|
extern "C" {
|
||||||
|
/* USER CODE END Header */
|
||||||
|
/* Includes ------------------------------------------------------------------*/
|
||||||
|
#include "main.h"
|
||||||
|
|
||||||
|
/* Private function prototypes -----------------------------------------------*/
|
||||||
|
void SystemClock_Config(void);
|
||||||
|
static void MX_GPIO_Init(void);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Private user code ---------------------------------------------------------*/
|
||||||
|
/* USER CODE BEGIN 0 */
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
enum class TrafficState { GREEN, YELLOW, RED };
|
||||||
|
void SetTrafficLights(TrafficState s);
|
||||||
|
|
||||||
|
TrafficState currentState = TrafficState::GREEN;
|
||||||
|
uint32_t stateStartTime = 0; //HAL_GetTick() at the start of this state
|
||||||
|
bool buttonPressedThisCycle = false;
|
||||||
|
bool pedestrianNextCycle = false;
|
||||||
|
bool pedestrianThisCycle = false;
|
||||||
|
|
||||||
|
const uint32_t DURATION_GREEN = 5000;
|
||||||
|
const uint32_t DURATION_YELLOW = 3000;
|
||||||
|
const uint32_t DURATION_RED_NOPED = 5000;
|
||||||
|
const uint32_t DURATION_RED_PED = 7000;
|
||||||
|
|
||||||
|
/* USER CODE END 0 */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief The application entry point.
|
||||||
|
* @retval int
|
||||||
|
*/
|
||||||
|
|
||||||
|
void SetTrafficLights(TrafficState s)
|
||||||
|
{
|
||||||
|
// reset all
|
||||||
|
HAL_GPIO_WritePin(GPIOD, Green_Pin, GPIO_PIN_RESET);
|
||||||
|
HAL_GPIO_WritePin(GPIOD, Yellow_Pin, GPIO_PIN_RESET);
|
||||||
|
HAL_GPIO_WritePin(GPIOD, Red_Pin, GPIO_PIN_SET);
|
||||||
|
|
||||||
|
switch (s)
|
||||||
|
{
|
||||||
|
case TrafficState::GREEN :
|
||||||
|
HAL_GPIO_WritePin(GPIOD, Green_Pin, GPIO_PIN_SET);
|
||||||
|
break;
|
||||||
|
case TrafficState::YELLOW :
|
||||||
|
HAL_GPIO_WritePin(GPIOD, Yellow_Pin, GPIO_PIN_SET);
|
||||||
|
break;
|
||||||
|
case TrafficState::RED:
|
||||||
|
HAL_GPIO_WritePin(GPIOD, Red_Pin, GPIO_PIN_SET);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
HAL_Init();
|
||||||
|
|
||||||
|
/* USER CODE BEGIN Init */
|
||||||
|
|
||||||
|
/* USER CODE END Init */
|
||||||
|
|
||||||
|
/* Configure the system clock */
|
||||||
|
SystemClock_Config();
|
||||||
|
MX_GPIO_Init();
|
||||||
|
|
||||||
|
stateStartTime = HAL_GetTick();
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
/* USER CODE END WHILE */
|
||||||
|
uint32_t now = HAL_GetTick();
|
||||||
|
uint32_t elapsed = now - stateStartTime;
|
||||||
|
|
||||||
|
switch(currentState)
|
||||||
|
{
|
||||||
|
case TrafficState::GREEN:
|
||||||
|
if (buttonPressedThisCycle)
|
||||||
|
pedestrianThisCycle = true;
|
||||||
|
|
||||||
|
/*
|
||||||
|
if (buttonPressedThisCycle)
|
||||||
|
{
|
||||||
|
currentState = TrafficState::YELLOW;
|
||||||
|
stateStartTime = now;
|
||||||
|
buttonPressedThisCycle = false;
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pedestrianNextCycle = false;
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
else if (elapsed >= DURATION_GREEN)
|
||||||
|
{
|
||||||
|
currentState = TrafficState::YELLOW;
|
||||||
|
stateStartTime = now;
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case TrafficState::YELLOW:
|
||||||
|
if (buttonPressedThisCycle || pedestrianNextCycle)
|
||||||
|
pedestrianThisCycle = true;
|
||||||
|
|
||||||
|
if (elapsed >= DURATION_YELLOW)
|
||||||
|
{
|
||||||
|
currentState = TrafficState::RED;
|
||||||
|
stateStartTime = now;
|
||||||
|
buttonPressedThisCycle = false; //TODO add pressed pedestrian button in yellow
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
// If Ped Button was pressed during GREEN or YELLOW, we need to enable WHITE this cycle
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case TrafficState::RED:
|
||||||
|
/*
|
||||||
|
if (pedestrianNextCycle)
|
||||||
|
{
|
||||||
|
HAL_GPIO_WritePin(GPIOD,White_Pin,GPIO_PIN_SET); // turn on Pedestrian LED
|
||||||
|
if (elapsed >= DURATION_RED_PED)
|
||||||
|
{
|
||||||
|
HAL_GPIO_WritePin(GPIOD,White_Pin,GPIO_PIN_RESET);
|
||||||
|
pedestrianNextCycle = false;
|
||||||
|
currentState = TrafficState::GREEN;
|
||||||
|
stateStartTime = now;
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
HAL_GPIO_WritePin(GPIOD,White_Pin,GPIO_PIN_RESET);
|
||||||
|
if(elapsed >= DURATION_RED_PED)
|
||||||
|
{
|
||||||
|
currentState = TrafficState::GREEN;
|
||||||
|
stateStartTime = now;
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (buttonPressedThisCycle)
|
||||||
|
pedestrianNextCycle = true;
|
||||||
|
|
||||||
|
if (pedestrianThisCycle) {
|
||||||
|
HAL_GPIO_WritePin(White_GPIO_Port, White_Pin, GPIO_PIN_RESET);
|
||||||
|
pedestrianThisCycle = false;
|
||||||
|
pedestrianNextcycle = false;
|
||||||
|
currentState = TrafficState::GREEN;
|
||||||
|
stateStartTime = now;
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
buttonPressedThisCycle = false;
|
||||||
|
} else {
|
||||||
|
HAL_GPIO_WritePin(White_GPIO_Port, White_Pin, GPIO_PIN_RESET);
|
||||||
|
if (elapsed >= DURATION_RED_NOPED)
|
||||||
|
{
|
||||||
|
currentState = TrafficState::GREEN;
|
||||||
|
stateStartTime = now;
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
buttonPressedThisCycle = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/* USER CODE BEGIN 3 */
|
||||||
|
}
|
||||||
|
/* USER CODE END 3 */
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief System Clock Configuration
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
|
||||||
|
void SystemClock_Config(void)
|
||||||
|
{
|
||||||
|
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
|
||||||
|
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
|
||||||
|
|
||||||
|
/** Configure the main internal regulator output voltage
|
||||||
|
*/
|
||||||
|
__HAL_RCC_PWR_CLK_ENABLE();
|
||||||
|
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE3);
|
||||||
|
|
||||||
|
/** Initializes the RCC Oscillators according to the specified parameters
|
||||||
|
* in the RCC_OscInitTypeDef structure.
|
||||||
|
*/
|
||||||
|
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
|
||||||
|
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
|
||||||
|
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
|
||||||
|
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
||||||
|
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
|
||||||
|
RCC_OscInitStruct.PLL.PLLM = 8;
|
||||||
|
RCC_OscInitStruct.PLL.PLLN = 50;
|
||||||
|
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4;
|
||||||
|
RCC_OscInitStruct.PLL.PLLQ = 7;
|
||||||
|
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Initializes the CPU, AHB and APB buses clocks
|
||||||
|
*/
|
||||||
|
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|
||||||
|
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
|
||||||
|
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
|
||||||
|
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
|
||||||
|
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV8;
|
||||||
|
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV4;
|
||||||
|
|
||||||
|
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief GPIO Initialization Function
|
||||||
|
* @param None
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
static void MX_GPIO_Init(void)
|
||||||
|
{
|
||||||
|
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||||
|
/* USER CODE BEGIN MX_GPIO_Init_1 */
|
||||||
|
|
||||||
|
/* USER CODE END MX_GPIO_Init_1 */
|
||||||
|
|
||||||
|
/* GPIO Ports Clock Enable */
|
||||||
|
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||||
|
__HAL_RCC_GPIOD_CLK_ENABLE();
|
||||||
|
|
||||||
|
/*Configure GPIO pin Output Level */
|
||||||
|
HAL_GPIO_WritePin(GPIOD, White_Pin|Red_Pin|Yellow_Pin|Green_Pin, GPIO_PIN_RESET);
|
||||||
|
|
||||||
|
/*Configure GPIO pin : PedButton_Pin */
|
||||||
|
GPIO_InitStruct.Pin = PedButton_Pin;
|
||||||
|
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
|
||||||
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
|
HAL_GPIO_Init(PedButton_GPIO_Port, &GPIO_InitStruct);
|
||||||
|
|
||||||
|
/*Configure GPIO pins : White_Pin Red_Pin Yellow_Pin Green_Pin */
|
||||||
|
GPIO_InitStruct.Pin = White_Pin|Red_Pin|Yellow_Pin|Green_Pin;
|
||||||
|
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||||
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||||
|
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
|
||||||
|
|
||||||
|
/* EXTI interrupt init*/
|
||||||
|
HAL_NVIC_SetPriority(EXTI15_10_IRQn, 15, 0);
|
||||||
|
HAL_NVIC_EnableIRQ(EXTI15_10_IRQn);
|
||||||
|
|
||||||
|
/* USER CODE BEGIN MX_GPIO_Init_2 */
|
||||||
|
|
||||||
|
/* USER CODE END MX_GPIO_Init_2 */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* USER CODE BEGIN 4 */
|
||||||
|
|
||||||
|
/*
|
||||||
|
extern "C" void EXTI15_10_IRQHandler()
|
||||||
|
{
|
||||||
|
HAL_GPIO_EXTI_IRQHandler(PedButton_Pin);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
void HAL_GPIO_EXTI_CallBack(uint16_t GPIO_Pin)
|
||||||
|
{
|
||||||
|
static uint32_t lastInterruptTime = 0;
|
||||||
|
uint32_t now = HAL_GetTick();
|
||||||
|
|
||||||
|
// software debounce
|
||||||
|
if (now - lastInterruptTime < 100)
|
||||||
|
return;
|
||||||
|
|
||||||
|
lastInterruptTime = now;
|
||||||
|
|
||||||
|
if (GPIO_Pin == PedButton_Pin)
|
||||||
|
buttonPressedThisCycle = true;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void HAL_GPIO_EXTI_IRQHandler()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/* USER CODE END 4 */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function is executed in case of error occurrence.
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void Error_Handler(void)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN Error_Handler_Debug */
|
||||||
|
/* User can add his own implementation to report the HAL error return state */
|
||||||
|
__disable_irq();
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
/* USER CODE END Error_Handler_Debug */
|
||||||
|
}
|
||||||
|
#ifdef USE_FULL_ASSERT
|
||||||
|
/**
|
||||||
|
* @brief Reports the name of the source file and the source line number
|
||||||
|
* where the assert_param error has occurred.
|
||||||
|
* @param file: pointer to the source file name
|
||||||
|
* @param line: assert_param error line source number
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void assert_failed(uint8_t *file, uint32_t line)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN 6 */
|
||||||
|
/* User can add his own implementation to report the file name and line number,
|
||||||
|
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
|
||||||
|
/* USER CODE END 6 */
|
||||||
|
}
|
||||||
|
#endif /* USE_FULL_ASSERT */
|
||||||
|
|
||||||
@@ -1,74 +0,0 @@
|
|||||||
/*
|
|
||||||
* breadboard.c
|
|
||||||
*
|
|
||||||
* Created on: Sep 17, 2025
|
|
||||||
* Author: ja
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* #define RedLight_Pin GPIO_PIN_2
|
|
||||||
* #define RedLight_GPIO_Port GPIOE
|
|
||||||
*
|
|
||||||
* #define YellowLight_Pin GPIO_PIN_3
|
|
||||||
* #define YellowLight_GPIO_Port GPIOE
|
|
||||||
*
|
|
||||||
* #define GreenLight_Pin GPIO_PIN_4
|
|
||||||
* #define GreenLight_GPIO_Port GPIOE
|
|
||||||
*
|
|
||||||
* RedLight: PE2
|
|
||||||
* YellowLight: PE3
|
|
||||||
* GreenLight: PE4
|
|
||||||
* WalkLight: PE5
|
|
||||||
*
|
|
||||||
* Done: Traffic Light
|
|
||||||
* TODO: async? Walk Signal, Light Dimmer
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "main.h"
|
|
||||||
#include "breadboard.h"
|
|
||||||
|
|
||||||
#define R_Pin RedLight_Pin
|
|
||||||
#define Y_Pin YellowLight_Pin
|
|
||||||
#define G_Pin GreenLight_Pin
|
|
||||||
#define W_Pin WalkLight_Pin
|
|
||||||
|
|
||||||
#define R_Prt RedLight_GPIO_Port
|
|
||||||
#define Y_Prt YellowLight_GPIO_Port
|
|
||||||
#define G_Prt GreenLight_GPIO_Port
|
|
||||||
#define W_Prt WalkLight_GPIO_Port
|
|
||||||
|
|
||||||
uint32_t trafftick_last;
|
|
||||||
|
|
||||||
uint8_t trafflight_i = 0;
|
|
||||||
|
|
||||||
void
|
|
||||||
starttick(void)
|
|
||||||
{
|
|
||||||
trafftick_last = HAL_GetTick();
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
trafflight(int traffSPD)
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
HAL_GPIO_TogglePin(R_Prt, R_Pin);
|
|
||||||
HAL_Delay(traffSPD);
|
|
||||||
HAL_GPIO_TogglePin(R_Prt, R_Pin);
|
|
||||||
|
|
||||||
HAL_GPIO_TogglePin(Y_Prt, Y_Pin);
|
|
||||||
HAL_Delay(traffSPD);
|
|
||||||
HAL_GPIO_TogglePin(Y_Prt, Y_Pin);
|
|
||||||
|
|
||||||
HAL_GPIO_TogglePin(G_Prt, G_Pin);
|
|
||||||
HAL_Delay(traffSPD);
|
|
||||||
HAL_GPIO_TogglePin(G_Prt, G_Pin);
|
|
||||||
*/
|
|
||||||
|
|
||||||
uint32_t trafftick_curr = HAL_GetTick();
|
|
||||||
|
|
||||||
if ((trafftick_curr - trafftick_last) >= traffSPD) {
|
|
||||||
HAL_GPIO_WritePin();
|
|
||||||
switch (trafflight_i) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -17,13 +17,13 @@
|
|||||||
*/
|
*/
|
||||||
/* USER CODE END Header */
|
/* USER CODE END Header */
|
||||||
/* Includes ------------------------------------------------------------------*/
|
/* Includes ------------------------------------------------------------------*/
|
||||||
#include <breadboard.h>
|
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include "cmsis_os.h"
|
#include "cmsis_os.h"
|
||||||
|
|
||||||
/* Private includes ----------------------------------------------------------*/
|
/* Private includes ----------------------------------------------------------*/
|
||||||
/* USER CODE BEGIN Includes */
|
/* USER CODE BEGIN Includes */
|
||||||
|
#include "breadboard.h"
|
||||||
|
#include <stdbool.h>
|
||||||
/* USER CODE END Includes */
|
/* USER CODE END Includes */
|
||||||
|
|
||||||
/* Private typedef -----------------------------------------------------------*/
|
/* Private typedef -----------------------------------------------------------*/
|
||||||
@@ -61,13 +61,31 @@ static void MX_DMA2D_Init(void);
|
|||||||
static void MX_TIM1_Init(void);
|
static void MX_TIM1_Init(void);
|
||||||
void StartDefaultTask(void const * argument);
|
void StartDefaultTask(void const * argument);
|
||||||
|
|
||||||
|
void SetTrafficLights(TrafficSate s);
|
||||||
|
|
||||||
/* USER CODE BEGIN PFP */
|
/* USER CODE BEGIN PFP */
|
||||||
|
|
||||||
/* USER CODE END PFP */
|
/* USER CODE END PFP */
|
||||||
|
|
||||||
/* Private user code ---------------------------------------------------------*/
|
/* Private user code ---------------------------------------------------------*/
|
||||||
|
|
||||||
/* USER CODE BEGIN 0 */
|
/* USER CODE BEGIN 0 */
|
||||||
|
|
||||||
|
enum class TrafficState {
|
||||||
|
GREEN,
|
||||||
|
YELLOW,
|
||||||
|
RED
|
||||||
|
};
|
||||||
|
|
||||||
|
TrafficState currentState = TrafficState::GREEN;
|
||||||
|
uint32_t stateStartTime = 0; // HAL_GetTick() at the start of this state
|
||||||
|
bool buttonPressed = false;
|
||||||
|
bool pedestrianNextCycle = false;
|
||||||
|
|
||||||
|
const uint32_t DURATION_GREEN = 5000;
|
||||||
|
const uint32_t DURATION_YELLOW = 3000;
|
||||||
|
const uint32_t DURATION_RED = 5000;
|
||||||
|
|
||||||
/* USER CODE END 0 */
|
/* USER CODE END 0 */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -124,8 +142,8 @@ int main(void)
|
|||||||
|
|
||||||
/* Create the thread(s) */
|
/* Create the thread(s) */
|
||||||
/* definition and creation of defaultTask */
|
/* definition and creation of defaultTask */
|
||||||
osThreadDef(defaultTask, StartDefaultTask, osPriorityNormal, 0, 4096);
|
//osThreadDef(defaultTask, StartDefaultTask, osPriorityNormal, 0, 4096);
|
||||||
defaultTaskHandle = osThreadCreate(osThread(defaultTask), NULL);
|
//defaultTaskHandle = osThreadCreate(osThread(defaultTask), NULL);
|
||||||
|
|
||||||
/* USER CODE BEGIN RTOS_THREADS */
|
/* USER CODE BEGIN RTOS_THREADS */
|
||||||
/* add threads, ... */
|
/* add threads, ... */
|
||||||
@@ -140,6 +158,28 @@ int main(void)
|
|||||||
/* USER CODE BEGIN WHILE */
|
/* USER CODE BEGIN WHILE */
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
|
uint32_t now = HAL_GetTick();
|
||||||
|
uint32_t elapsed = now - stateStartTime;
|
||||||
|
|
||||||
|
switch(currentState)
|
||||||
|
{
|
||||||
|
case TrafficState::GREEN:
|
||||||
|
if (elapsed >= DURATION_GREEN) {
|
||||||
|
currentState = TrafficState::YELLOW;
|
||||||
|
stateStartTime = now;
|
||||||
|
buttonPressed = false; // reset the button-flag for the new cycle
|
||||||
|
} else if (buttonPressed) {
|
||||||
|
//idk
|
||||||
|
buttonPressed = true;
|
||||||
|
currentState = TrafficState::YELLOW;
|
||||||
|
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case TrafficState::YELLOW:
|
||||||
|
break;
|
||||||
|
case TrafficState::RED:
|
||||||
|
break;
|
||||||
|
}
|
||||||
/* USER CODE END WHILE */
|
/* USER CODE END WHILE */
|
||||||
|
|
||||||
/* USER CODE BEGIN 3 */
|
/* USER CODE BEGIN 3 */
|
||||||
@@ -345,6 +385,23 @@ static void MX_GPIO_Init(void)
|
|||||||
|
|
||||||
/* USER CODE BEGIN 4 */
|
/* USER CODE BEGIN 4 */
|
||||||
|
|
||||||
|
void HAL_GPIO_EXTI_CallBack(uint16_t GPIO_Pin)
|
||||||
|
{
|
||||||
|
static uint32_t lastInterruptTime = 0;
|
||||||
|
uint32_t now = HAL_GetTick();
|
||||||
|
if (now - lastInterruptTime < 100) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
lastInterruptTime = now;
|
||||||
|
|
||||||
|
bool buttonPressedThisCycle = false; // temporary, get rid of this
|
||||||
|
|
||||||
|
if (buttonPressed) { // buttonPressedHere?
|
||||||
|
buttonPressedThisCycle = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* USER CODE END 4 */
|
/* USER CODE END 4 */
|
||||||
|
|
||||||
/* USER CODE BEGIN Header_StartDefaultTask */
|
/* USER CODE BEGIN Header_StartDefaultTask */
|
||||||
@@ -0,0 +1,314 @@
|
|||||||
|
/* USER CODE BEGIN Header */
|
||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
* @file : main.c
|
||||||
|
* @brief : Main program body
|
||||||
|
******************************************************************************
|
||||||
|
* @attention
|
||||||
|
*
|
||||||
|
* Copyright (c) 2025 STMicroelectronics.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This software is licensed under terms that can be found in the LICENSE file
|
||||||
|
* in the root directory of this software component.
|
||||||
|
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||||
|
*
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
// Feeling sneaky.
|
||||||
|
extern "C" {
|
||||||
|
/* USER CODE END Header */
|
||||||
|
/* Includes ------------------------------------------------------------------*/
|
||||||
|
#include "main.h"
|
||||||
|
|
||||||
|
/* Private function prototypes -----------------------------------------------*/
|
||||||
|
void SystemClock_Config(void);
|
||||||
|
static void MX_GPIO_Init(void);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Private user code ---------------------------------------------------------*/
|
||||||
|
/* USER CODE BEGIN 0 */
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
enum class TrafficState { GREEN, YELLOW, RED };
|
||||||
|
void SetTrafficLights(TrafficState s);
|
||||||
|
|
||||||
|
TrafficState currentState = TrafficState::GREEN;
|
||||||
|
uint32_t stateStartTime = 0; //HAL_GetTick() at the start of this state
|
||||||
|
bool buttonPressedThisCycle = false;
|
||||||
|
bool pedestrianNextCycle = false;
|
||||||
|
bool pedestrianThisCycle = false;
|
||||||
|
|
||||||
|
const uint32_t DURATION_GREEN = 5000;
|
||||||
|
const uint32_t DURATION_YELLOW = 3000;
|
||||||
|
const uint32_t DURATION_RED_NOPED = 5000;
|
||||||
|
const uint32_t DURATION_RED_PED = 7000;
|
||||||
|
|
||||||
|
/* USER CODE END 0 */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief The application entry point.
|
||||||
|
* @retval int
|
||||||
|
*/
|
||||||
|
|
||||||
|
void SetTrafficLights(TrafficState s)
|
||||||
|
{
|
||||||
|
// reset all
|
||||||
|
HAL_GPIO_WritePin(GPIOD, Green_Pin, GPIO_PIN_RESET);
|
||||||
|
HAL_GPIO_WritePin(GPIOD, Yellow_Pin, GPIO_PIN_RESET);
|
||||||
|
HAL_GPIO_WritePin(GPIOD, Red_Pin, GPIO_PIN_SET);
|
||||||
|
|
||||||
|
switch (s)
|
||||||
|
{
|
||||||
|
case TrafficState::GREEN :
|
||||||
|
HAL_GPIO_WritePin(GPIOD, Green_Pin, GPIO_PIN_SET);
|
||||||
|
break;
|
||||||
|
case TrafficState::YELLOW :
|
||||||
|
HAL_GPIO_WritePin(GPIOD, Yellow_Pin, GPIO_PIN_SET);
|
||||||
|
break;
|
||||||
|
case TrafficState::RED:
|
||||||
|
HAL_GPIO_WritePin(GPIOD, Red_Pin, GPIO_PIN_SET);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
HAL_Init();
|
||||||
|
|
||||||
|
/* USER CODE BEGIN Init */
|
||||||
|
|
||||||
|
/* USER CODE END Init */
|
||||||
|
|
||||||
|
/* Configure the system clock */
|
||||||
|
SystemClock_Config();
|
||||||
|
MX_GPIO_Init();
|
||||||
|
|
||||||
|
stateStartTime = HAL_GetTick();
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
/* USER CODE END WHILE */
|
||||||
|
uint32_t now = HAL_GetTick();
|
||||||
|
uint32_t elapsed = now - stateStartTime;
|
||||||
|
|
||||||
|
switch(currentState)
|
||||||
|
{
|
||||||
|
case TrafficState::GREEN:
|
||||||
|
if (buttonPressedThisCycle)
|
||||||
|
pedestrianThisCycle = true;
|
||||||
|
|
||||||
|
/*
|
||||||
|
if (buttonPressedThisCycle)
|
||||||
|
{
|
||||||
|
currentState = TrafficState::YELLOW;
|
||||||
|
stateStartTime = now;
|
||||||
|
buttonPressedThisCycle = false;
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pedestrianNextCycle = false;
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
else if (elapsed >= DURATION_GREEN)
|
||||||
|
{
|
||||||
|
currentState = TrafficState::YELLOW;
|
||||||
|
stateStartTime = now;
|
||||||
|
buttonPressedThisCycle = false;
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case TrafficState::YELLOW:
|
||||||
|
if (buttonPressedThisCycle || pedestrianNextCycle)
|
||||||
|
pedestrianThisCycle = true;
|
||||||
|
|
||||||
|
if (elapsed >= DURATION_YELLOW)
|
||||||
|
{
|
||||||
|
currentState = TrafficState::RED;
|
||||||
|
stateStartTime = now;
|
||||||
|
buttonPressedThisCycle = false; //TODO add pressed pedestrian button in yellow
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
// If Ped Button was pressed during GREEN or YELLOW, we need to enable WHITE this cycle
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case TrafficState::RED:
|
||||||
|
if (pedestrianNextCycle)
|
||||||
|
{
|
||||||
|
HAL_GPIO_WritePin(GPIOD,White_Pin,GPIO_PIN_SET); // turn on Pedestrian LED
|
||||||
|
if (elapsed >= DURATION_RED_PED)
|
||||||
|
{
|
||||||
|
HAL_GPIO_WritePin(GPIOD,White_Pin,GPIO_PIN_RESET);
|
||||||
|
pedestrianNextCycle = false;
|
||||||
|
currentState = TrafficState::GREEN;
|
||||||
|
stateStartTime = now;
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
HAL_GPIO_WritePin(GPIOD,White_Pin,GPIO_PIN_RESET);
|
||||||
|
if(elapsed >= DURATION_RED_PED)
|
||||||
|
{
|
||||||
|
currentState = TrafficState::GREEN;
|
||||||
|
stateStartTime = now;
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/* USER CODE BEGIN 3 */
|
||||||
|
}
|
||||||
|
/* USER CODE END 3 */
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief System Clock Configuration
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void SystemClock_Config(void)
|
||||||
|
{
|
||||||
|
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
|
||||||
|
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
|
||||||
|
|
||||||
|
/** Configure the main internal regulator output voltage
|
||||||
|
*/
|
||||||
|
__HAL_RCC_PWR_CLK_ENABLE();
|
||||||
|
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE3);
|
||||||
|
|
||||||
|
/** Initializes the RCC Oscillators according to the specified parameters
|
||||||
|
* in the RCC_OscInitTypeDef structure.
|
||||||
|
*/
|
||||||
|
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
|
||||||
|
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
|
||||||
|
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
|
||||||
|
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
||||||
|
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
|
||||||
|
RCC_OscInitStruct.PLL.PLLM = 8;
|
||||||
|
RCC_OscInitStruct.PLL.PLLN = 50;
|
||||||
|
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4;
|
||||||
|
RCC_OscInitStruct.PLL.PLLQ = 7;
|
||||||
|
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Initializes the CPU, AHB and APB buses clocks
|
||||||
|
*/
|
||||||
|
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|
||||||
|
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
|
||||||
|
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
|
||||||
|
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
|
||||||
|
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV8;
|
||||||
|
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV4;
|
||||||
|
|
||||||
|
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief GPIO Initialization Function
|
||||||
|
* @param None
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
static void MX_GPIO_Init(void)
|
||||||
|
{
|
||||||
|
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||||
|
/* USER CODE BEGIN MX_GPIO_Init_1 */
|
||||||
|
|
||||||
|
/* USER CODE END MX_GPIO_Init_1 */
|
||||||
|
|
||||||
|
/* GPIO Ports Clock Enable */
|
||||||
|
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||||
|
__HAL_RCC_GPIOD_CLK_ENABLE();
|
||||||
|
|
||||||
|
/*Configure GPIO pin Output Level */
|
||||||
|
HAL_GPIO_WritePin(GPIOD, White_Pin|Red_Pin|Yellow_Pin|Green_Pin, GPIO_PIN_RESET);
|
||||||
|
|
||||||
|
/*Configure GPIO pin : PedButton_Pin */
|
||||||
|
GPIO_InitStruct.Pin = PedButton_Pin;
|
||||||
|
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
|
||||||
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
|
HAL_GPIO_Init(PedButton_GPIO_Port, &GPIO_InitStruct);
|
||||||
|
|
||||||
|
/*Configure GPIO pins : White_Pin Red_Pin Yellow_Pin Green_Pin */
|
||||||
|
GPIO_InitStruct.Pin = White_Pin|Red_Pin|Yellow_Pin|Green_Pin;
|
||||||
|
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||||
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||||
|
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
|
||||||
|
|
||||||
|
/* EXTI interrupt init*/
|
||||||
|
HAL_NVIC_SetPriority(EXTI15_10_IRQn, 15, 0);
|
||||||
|
HAL_NVIC_EnableIRQ(EXTI15_10_IRQn);
|
||||||
|
|
||||||
|
/* USER CODE BEGIN MX_GPIO_Init_2 */
|
||||||
|
|
||||||
|
/* USER CODE END MX_GPIO_Init_2 */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* USER CODE BEGIN 4 */
|
||||||
|
void HAL_GPIO_EXTI_CallBack()
|
||||||
|
{
|
||||||
|
static uint32_t lastInterruptTime = 0;
|
||||||
|
uint32_t now = HAL_GetTick();
|
||||||
|
if(now - lastInterruptTime < 100)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
lastInterruptTime = now;
|
||||||
|
|
||||||
|
if (PedButton_Pin)
|
||||||
|
{
|
||||||
|
buttonPressedThisCycle = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void HAL_GPIO_EXTI_IRQHandler()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/* USER CODE END 4 */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function is executed in case of error occurrence.
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void Error_Handler(void)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN Error_Handler_Debug */
|
||||||
|
/* User can add his own implementation to report the HAL error return state */
|
||||||
|
__disable_irq();
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
/* USER CODE END Error_Handler_Debug */
|
||||||
|
}
|
||||||
|
#ifdef USE_FULL_ASSERT
|
||||||
|
/**
|
||||||
|
* @brief Reports the name of the source file and the source line number
|
||||||
|
* where the assert_param error has occurred.
|
||||||
|
* @param file: pointer to the source file name
|
||||||
|
* @param line: assert_param error line source number
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void assert_failed(uint8_t *file, uint32_t line)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN 6 */
|
||||||
|
/* User can add his own implementation to report the file name and line number,
|
||||||
|
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
|
||||||
|
/* USER CODE END 6 */
|
||||||
|
}
|
||||||
|
#endif /* USE_FULL_ASSERT */
|
||||||
|
|
||||||
@@ -1,730 +0,0 @@
|
|||||||
/* USER CODE BEGIN Header */
|
|
||||||
/**
|
|
||||||
******************************************************************************
|
|
||||||
* @file : main.c
|
|
||||||
* @brief : Main program body
|
|
||||||
******************************************************************************
|
|
||||||
* @attention
|
|
||||||
*
|
|
||||||
* Copyright (c) 2025 STMicroelectronics.
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* This software is licensed under terms that can be found in the LICENSE file
|
|
||||||
* in the root directory of this software component.
|
|
||||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
|
||||||
*
|
|
||||||
******************************************************************************
|
|
||||||
*/
|
|
||||||
/* USER CODE END Header */
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
|
||||||
#include "main.h"
|
|
||||||
#include "cmsis_os.h"
|
|
||||||
#include "usb_host.h"
|
|
||||||
|
|
||||||
/* Private includes ----------------------------------------------------------*/
|
|
||||||
/* USER CODE BEGIN Includes */
|
|
||||||
#include "breadboard.h"
|
|
||||||
|
|
||||||
/* USER CODE END Includes */
|
|
||||||
|
|
||||||
/* Private typedef -----------------------------------------------------------*/
|
|
||||||
/* USER CODE BEGIN PTD */
|
|
||||||
|
|
||||||
/* USER CODE END PTD */
|
|
||||||
|
|
||||||
/* Private define ------------------------------------------------------------*/
|
|
||||||
/* USER CODE BEGIN PD */
|
|
||||||
|
|
||||||
/* USER CODE END PD */
|
|
||||||
|
|
||||||
/* Private macro -------------------------------------------------------------*/
|
|
||||||
/* USER CODE BEGIN PM */
|
|
||||||
|
|
||||||
/* USER CODE END PM */
|
|
||||||
|
|
||||||
/* Private variables ---------------------------------------------------------*/
|
|
||||||
CRC_HandleTypeDef hcrc;
|
|
||||||
|
|
||||||
DMA2D_HandleTypeDef hdma2d;
|
|
||||||
|
|
||||||
I2C_HandleTypeDef hi2c3;
|
|
||||||
|
|
||||||
LTDC_HandleTypeDef hltdc;
|
|
||||||
|
|
||||||
SPI_HandleTypeDef hspi5;
|
|
||||||
|
|
||||||
TIM_HandleTypeDef htim1;
|
|
||||||
|
|
||||||
UART_HandleTypeDef huart1;
|
|
||||||
|
|
||||||
SDRAM_HandleTypeDef hsdram1;
|
|
||||||
|
|
||||||
osThreadId defaultTaskHandle;
|
|
||||||
/* USER CODE BEGIN PV */
|
|
||||||
|
|
||||||
/* USER CODE END PV */
|
|
||||||
|
|
||||||
/* Private function prototypes -----------------------------------------------*/
|
|
||||||
void SystemClock_Config(void);
|
|
||||||
static void MX_GPIO_Init(void);
|
|
||||||
static void MX_CRC_Init(void);
|
|
||||||
static void MX_DMA2D_Init(void);
|
|
||||||
static void MX_FMC_Init(void);
|
|
||||||
static void MX_I2C3_Init(void);
|
|
||||||
static void MX_LTDC_Init(void);
|
|
||||||
static void MX_SPI5_Init(void);
|
|
||||||
static void MX_TIM1_Init(void);
|
|
||||||
static void MX_USART1_UART_Init(void);
|
|
||||||
void StartDefaultTask(void const * argument);
|
|
||||||
|
|
||||||
/* USER CODE BEGIN PFP */
|
|
||||||
|
|
||||||
/* USER CODE END PFP */
|
|
||||||
|
|
||||||
/* Private user code ---------------------------------------------------------*/
|
|
||||||
/* USER CODE BEGIN 0 */
|
|
||||||
|
|
||||||
/* USER CODE END 0 */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief The application entry point.
|
|
||||||
* @retval int
|
|
||||||
*/
|
|
||||||
int main(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* USER CODE BEGIN 1 */
|
|
||||||
|
|
||||||
/* USER CODE END 1 */
|
|
||||||
|
|
||||||
/* MCU Configuration--------------------------------------------------------*/
|
|
||||||
|
|
||||||
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
|
|
||||||
HAL_Init();
|
|
||||||
|
|
||||||
/* USER CODE BEGIN Init */
|
|
||||||
|
|
||||||
/* USER CODE END Init */
|
|
||||||
|
|
||||||
/* Configure the system clock */
|
|
||||||
SystemClock_Config();
|
|
||||||
|
|
||||||
/* USER CODE BEGIN SysInit */
|
|
||||||
|
|
||||||
/* USER CODE END SysInit */
|
|
||||||
|
|
||||||
/* Initialize all configured peripherals */
|
|
||||||
MX_GPIO_Init();
|
|
||||||
MX_CRC_Init();
|
|
||||||
MX_DMA2D_Init();
|
|
||||||
MX_FMC_Init();
|
|
||||||
MX_I2C3_Init();
|
|
||||||
MX_LTDC_Init();
|
|
||||||
MX_SPI5_Init();
|
|
||||||
MX_TIM1_Init();
|
|
||||||
MX_USART1_UART_Init();
|
|
||||||
/* USER CODE BEGIN 2 */
|
|
||||||
|
|
||||||
/* USER CODE END 2 */
|
|
||||||
|
|
||||||
/* USER CODE BEGIN RTOS_MUTEX */
|
|
||||||
/* add mutexes, ... */
|
|
||||||
/* USER CODE END RTOS_MUTEX */
|
|
||||||
|
|
||||||
/* USER CODE BEGIN RTOS_SEMAPHORES */
|
|
||||||
/* add semaphores, ... */
|
|
||||||
/* USER CODE END RTOS_SEMAPHORES */
|
|
||||||
|
|
||||||
/* USER CODE BEGIN RTOS_TIMERS */
|
|
||||||
/* start timers, add new ones, ... */
|
|
||||||
/* USER CODE END RTOS_TIMERS */
|
|
||||||
|
|
||||||
/* USER CODE BEGIN RTOS_QUEUES */
|
|
||||||
/* add queues, ... */
|
|
||||||
/* USER CODE END RTOS_QUEUES */
|
|
||||||
|
|
||||||
/* Create the thread(s) */
|
|
||||||
/* definition and creation of defaultTask */
|
|
||||||
//osThreadDef(defaultTask, StartDefaultTask, osPriorityNormal, 0, 4096);
|
|
||||||
//defaultTaskHandle = osThreadCreate(osThread(defaultTask), NULL);
|
|
||||||
|
|
||||||
/* USER CODE BEGIN RTOS_THREADS */
|
|
||||||
/* add threads, ... */
|
|
||||||
/* USER CODE END RTOS_THREADS */
|
|
||||||
|
|
||||||
/* Start scheduler */
|
|
||||||
//osKernelStart();
|
|
||||||
|
|
||||||
/* We should never get here as control is now taken by the scheduler */
|
|
||||||
|
|
||||||
/* Infinite loop */
|
|
||||||
/* USER CODE BEGIN WHILE */
|
|
||||||
while (1)
|
|
||||||
{
|
|
||||||
trafflight(2000, 10000);
|
|
||||||
/* USER CODE END WHILE */
|
|
||||||
|
|
||||||
/* USER CODE BEGIN 3 */
|
|
||||||
}
|
|
||||||
/* USER CODE END 3 */
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief System Clock Configuration
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
void SystemClock_Config(void)
|
|
||||||
{
|
|
||||||
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
|
|
||||||
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
|
|
||||||
|
|
||||||
/** Configure the main internal regulator output voltage
|
|
||||||
*/
|
|
||||||
__HAL_RCC_PWR_CLK_ENABLE();
|
|
||||||
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE3);
|
|
||||||
|
|
||||||
/** Initializes the RCC Oscillators according to the specified parameters
|
|
||||||
* in the RCC_OscInitTypeDef structure.
|
|
||||||
*/
|
|
||||||
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
|
|
||||||
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
|
|
||||||
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
|
||||||
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
|
|
||||||
RCC_OscInitStruct.PLL.PLLM = 4;
|
|
||||||
RCC_OscInitStruct.PLL.PLLN = 72;
|
|
||||||
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
|
|
||||||
RCC_OscInitStruct.PLL.PLLQ = 3;
|
|
||||||
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Initializes the CPU, AHB and APB buses clocks
|
|
||||||
*/
|
|
||||||
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|
|
||||||
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
|
|
||||||
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
|
|
||||||
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
|
|
||||||
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
|
|
||||||
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
|
|
||||||
|
|
||||||
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief CRC Initialization Function
|
|
||||||
* @param None
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
static void MX_CRC_Init(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* USER CODE BEGIN CRC_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE END CRC_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE BEGIN CRC_Init 1 */
|
|
||||||
|
|
||||||
/* USER CODE END CRC_Init 1 */
|
|
||||||
hcrc.Instance = CRC;
|
|
||||||
if (HAL_CRC_Init(&hcrc) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
/* USER CODE BEGIN CRC_Init 2 */
|
|
||||||
|
|
||||||
/* USER CODE END CRC_Init 2 */
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief DMA2D Initialization Function
|
|
||||||
* @param None
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
static void MX_DMA2D_Init(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* USER CODE BEGIN DMA2D_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE END DMA2D_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE BEGIN DMA2D_Init 1 */
|
|
||||||
|
|
||||||
/* USER CODE END DMA2D_Init 1 */
|
|
||||||
hdma2d.Instance = DMA2D;
|
|
||||||
hdma2d.Init.Mode = DMA2D_M2M;
|
|
||||||
hdma2d.Init.ColorMode = DMA2D_OUTPUT_ARGB8888;
|
|
||||||
hdma2d.Init.OutputOffset = 0;
|
|
||||||
hdma2d.LayerCfg[1].InputOffset = 0;
|
|
||||||
hdma2d.LayerCfg[1].InputColorMode = DMA2D_INPUT_ARGB8888;
|
|
||||||
hdma2d.LayerCfg[1].AlphaMode = DMA2D_NO_MODIF_ALPHA;
|
|
||||||
hdma2d.LayerCfg[1].InputAlpha = 0;
|
|
||||||
if (HAL_DMA2D_Init(&hdma2d) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
if (HAL_DMA2D_ConfigLayer(&hdma2d, 1) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
/* USER CODE BEGIN DMA2D_Init 2 */
|
|
||||||
|
|
||||||
/* USER CODE END DMA2D_Init 2 */
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief I2C3 Initialization Function
|
|
||||||
* @param None
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
static void MX_I2C3_Init(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* USER CODE BEGIN I2C3_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE END I2C3_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE BEGIN I2C3_Init 1 */
|
|
||||||
|
|
||||||
/* USER CODE END I2C3_Init 1 */
|
|
||||||
hi2c3.Instance = I2C3;
|
|
||||||
hi2c3.Init.ClockSpeed = 100000;
|
|
||||||
hi2c3.Init.DutyCycle = I2C_DUTYCYCLE_2;
|
|
||||||
hi2c3.Init.OwnAddress1 = 0;
|
|
||||||
hi2c3.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
|
|
||||||
hi2c3.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
|
|
||||||
hi2c3.Init.OwnAddress2 = 0;
|
|
||||||
hi2c3.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
|
|
||||||
hi2c3.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
|
|
||||||
if (HAL_I2C_Init(&hi2c3) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Configure Analogue filter
|
|
||||||
*/
|
|
||||||
if (HAL_I2CEx_ConfigAnalogFilter(&hi2c3, I2C_ANALOGFILTER_ENABLE) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Configure Digital filter
|
|
||||||
*/
|
|
||||||
if (HAL_I2CEx_ConfigDigitalFilter(&hi2c3, 0) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
/* USER CODE BEGIN I2C3_Init 2 */
|
|
||||||
|
|
||||||
/* USER CODE END I2C3_Init 2 */
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief LTDC Initialization Function
|
|
||||||
* @param None
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
static void MX_LTDC_Init(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* USER CODE BEGIN LTDC_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE END LTDC_Init 0 */
|
|
||||||
|
|
||||||
LTDC_LayerCfgTypeDef pLayerCfg = {0};
|
|
||||||
|
|
||||||
/* USER CODE BEGIN LTDC_Init 1 */
|
|
||||||
|
|
||||||
/* USER CODE END LTDC_Init 1 */
|
|
||||||
hltdc.Instance = LTDC;
|
|
||||||
hltdc.Init.HSPolarity = LTDC_HSPOLARITY_AL;
|
|
||||||
hltdc.Init.VSPolarity = LTDC_VSPOLARITY_AL;
|
|
||||||
hltdc.Init.DEPolarity = LTDC_DEPOLARITY_AL;
|
|
||||||
hltdc.Init.PCPolarity = LTDC_PCPOLARITY_IPC;
|
|
||||||
hltdc.Init.HorizontalSync = 9;
|
|
||||||
hltdc.Init.VerticalSync = 1;
|
|
||||||
hltdc.Init.AccumulatedHBP = 29;
|
|
||||||
hltdc.Init.AccumulatedVBP = 3;
|
|
||||||
hltdc.Init.AccumulatedActiveW = 269;
|
|
||||||
hltdc.Init.AccumulatedActiveH = 323;
|
|
||||||
hltdc.Init.TotalWidth = 279;
|
|
||||||
hltdc.Init.TotalHeigh = 327;
|
|
||||||
hltdc.Init.Backcolor.Blue = 0;
|
|
||||||
hltdc.Init.Backcolor.Green = 0;
|
|
||||||
hltdc.Init.Backcolor.Red = 0;
|
|
||||||
if (HAL_LTDC_Init(&hltdc) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
pLayerCfg.WindowX0 = 0;
|
|
||||||
pLayerCfg.WindowX1 = 240;
|
|
||||||
pLayerCfg.WindowY0 = 0;
|
|
||||||
pLayerCfg.WindowY1 = 320;
|
|
||||||
pLayerCfg.PixelFormat = LTDC_PIXEL_FORMAT_RGB565;
|
|
||||||
pLayerCfg.Alpha = 255;
|
|
||||||
pLayerCfg.Alpha0 = 0;
|
|
||||||
pLayerCfg.BlendingFactor1 = LTDC_BLENDING_FACTOR1_PAxCA;
|
|
||||||
pLayerCfg.BlendingFactor2 = LTDC_BLENDING_FACTOR2_PAxCA;
|
|
||||||
pLayerCfg.FBStartAdress = 0xD0000000;
|
|
||||||
pLayerCfg.ImageWidth = 240;
|
|
||||||
pLayerCfg.ImageHeight = 320;
|
|
||||||
pLayerCfg.Backcolor.Blue = 0;
|
|
||||||
pLayerCfg.Backcolor.Green = 0;
|
|
||||||
pLayerCfg.Backcolor.Red = 0;
|
|
||||||
if (HAL_LTDC_ConfigLayer(&hltdc, &pLayerCfg, 0) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
/* USER CODE BEGIN LTDC_Init 2 */
|
|
||||||
|
|
||||||
/* USER CODE END LTDC_Init 2 */
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief SPI5 Initialization Function
|
|
||||||
* @param None
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
static void MX_SPI5_Init(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* USER CODE BEGIN SPI5_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE END SPI5_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE BEGIN SPI5_Init 1 */
|
|
||||||
|
|
||||||
/* USER CODE END SPI5_Init 1 */
|
|
||||||
/* SPI5 parameter configuration*/
|
|
||||||
hspi5.Instance = SPI5;
|
|
||||||
hspi5.Init.Mode = SPI_MODE_MASTER;
|
|
||||||
hspi5.Init.Direction = SPI_DIRECTION_2LINES;
|
|
||||||
hspi5.Init.DataSize = SPI_DATASIZE_8BIT;
|
|
||||||
hspi5.Init.CLKPolarity = SPI_POLARITY_LOW;
|
|
||||||
hspi5.Init.CLKPhase = SPI_PHASE_1EDGE;
|
|
||||||
hspi5.Init.NSS = SPI_NSS_SOFT;
|
|
||||||
hspi5.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_16;
|
|
||||||
hspi5.Init.FirstBit = SPI_FIRSTBIT_MSB;
|
|
||||||
hspi5.Init.TIMode = SPI_TIMODE_DISABLE;
|
|
||||||
hspi5.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
|
|
||||||
hspi5.Init.CRCPolynomial = 10;
|
|
||||||
if (HAL_SPI_Init(&hspi5) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
/* USER CODE BEGIN SPI5_Init 2 */
|
|
||||||
|
|
||||||
/* USER CODE END SPI5_Init 2 */
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief TIM1 Initialization Function
|
|
||||||
* @param None
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
static void MX_TIM1_Init(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* USER CODE BEGIN TIM1_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE END TIM1_Init 0 */
|
|
||||||
|
|
||||||
TIM_ClockConfigTypeDef sClockSourceConfig = {0};
|
|
||||||
TIM_MasterConfigTypeDef sMasterConfig = {0};
|
|
||||||
|
|
||||||
/* USER CODE BEGIN TIM1_Init 1 */
|
|
||||||
|
|
||||||
/* USER CODE END TIM1_Init 1 */
|
|
||||||
htim1.Instance = TIM1;
|
|
||||||
htim1.Init.Prescaler = 0;
|
|
||||||
htim1.Init.CounterMode = TIM_COUNTERMODE_UP;
|
|
||||||
htim1.Init.Period = 65535;
|
|
||||||
htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
|
||||||
htim1.Init.RepetitionCounter = 0;
|
|
||||||
htim1.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
|
|
||||||
if (HAL_TIM_Base_Init(&htim1) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
|
|
||||||
if (HAL_TIM_ConfigClockSource(&htim1, &sClockSourceConfig) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
|
|
||||||
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
|
|
||||||
if (HAL_TIMEx_MasterConfigSynchronization(&htim1, &sMasterConfig) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
/* USER CODE BEGIN TIM1_Init 2 */
|
|
||||||
|
|
||||||
/* USER CODE END TIM1_Init 2 */
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief USART1 Initialization Function
|
|
||||||
* @param None
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
static void MX_USART1_UART_Init(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* USER CODE BEGIN USART1_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE END USART1_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE BEGIN USART1_Init 1 */
|
|
||||||
|
|
||||||
/* USER CODE END USART1_Init 1 */
|
|
||||||
huart1.Instance = USART1;
|
|
||||||
huart1.Init.BaudRate = 115200;
|
|
||||||
huart1.Init.WordLength = UART_WORDLENGTH_8B;
|
|
||||||
huart1.Init.StopBits = UART_STOPBITS_1;
|
|
||||||
huart1.Init.Parity = UART_PARITY_NONE;
|
|
||||||
huart1.Init.Mode = UART_MODE_TX_RX;
|
|
||||||
huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
|
|
||||||
huart1.Init.OverSampling = UART_OVERSAMPLING_16;
|
|
||||||
if (HAL_UART_Init(&huart1) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
/* USER CODE BEGIN USART1_Init 2 */
|
|
||||||
|
|
||||||
/* USER CODE END USART1_Init 2 */
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/* FMC initialization function */
|
|
||||||
static void MX_FMC_Init(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* USER CODE BEGIN FMC_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE END FMC_Init 0 */
|
|
||||||
|
|
||||||
FMC_SDRAM_TimingTypeDef SdramTiming = {0};
|
|
||||||
|
|
||||||
/* USER CODE BEGIN FMC_Init 1 */
|
|
||||||
|
|
||||||
/* USER CODE END FMC_Init 1 */
|
|
||||||
|
|
||||||
/** Perform the SDRAM1 memory initialization sequence
|
|
||||||
*/
|
|
||||||
hsdram1.Instance = FMC_SDRAM_DEVICE;
|
|
||||||
/* hsdram1.Init */
|
|
||||||
hsdram1.Init.SDBank = FMC_SDRAM_BANK2;
|
|
||||||
hsdram1.Init.ColumnBitsNumber = FMC_SDRAM_COLUMN_BITS_NUM_8;
|
|
||||||
hsdram1.Init.RowBitsNumber = FMC_SDRAM_ROW_BITS_NUM_12;
|
|
||||||
hsdram1.Init.MemoryDataWidth = FMC_SDRAM_MEM_BUS_WIDTH_16;
|
|
||||||
hsdram1.Init.InternalBankNumber = FMC_SDRAM_INTERN_BANKS_NUM_4;
|
|
||||||
hsdram1.Init.CASLatency = FMC_SDRAM_CAS_LATENCY_3;
|
|
||||||
hsdram1.Init.WriteProtection = FMC_SDRAM_WRITE_PROTECTION_DISABLE;
|
|
||||||
hsdram1.Init.SDClockPeriod = FMC_SDRAM_CLOCK_PERIOD_2;
|
|
||||||
hsdram1.Init.ReadBurst = FMC_SDRAM_RBURST_DISABLE;
|
|
||||||
hsdram1.Init.ReadPipeDelay = FMC_SDRAM_RPIPE_DELAY_1;
|
|
||||||
/* SdramTiming */
|
|
||||||
SdramTiming.LoadToActiveDelay = 2;
|
|
||||||
SdramTiming.ExitSelfRefreshDelay = 7;
|
|
||||||
SdramTiming.SelfRefreshTime = 4;
|
|
||||||
SdramTiming.RowCycleDelay = 7;
|
|
||||||
SdramTiming.WriteRecoveryTime = 3;
|
|
||||||
SdramTiming.RPDelay = 2;
|
|
||||||
SdramTiming.RCDDelay = 2;
|
|
||||||
|
|
||||||
if (HAL_SDRAM_Init(&hsdram1, &SdramTiming) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler( );
|
|
||||||
}
|
|
||||||
|
|
||||||
/* USER CODE BEGIN FMC_Init 2 */
|
|
||||||
|
|
||||||
/* USER CODE END FMC_Init 2 */
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief GPIO Initialization Function
|
|
||||||
* @param None
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
static void MX_GPIO_Init(void)
|
|
||||||
{
|
|
||||||
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
|
||||||
/* USER CODE BEGIN MX_GPIO_Init_1 */
|
|
||||||
|
|
||||||
/* USER CODE END MX_GPIO_Init_1 */
|
|
||||||
|
|
||||||
/* GPIO Ports Clock Enable */
|
|
||||||
__HAL_RCC_GPIOE_CLK_ENABLE();
|
|
||||||
__HAL_RCC_GPIOC_CLK_ENABLE();
|
|
||||||
__HAL_RCC_GPIOF_CLK_ENABLE();
|
|
||||||
__HAL_RCC_GPIOH_CLK_ENABLE();
|
|
||||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
|
||||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
|
||||||
__HAL_RCC_GPIOG_CLK_ENABLE();
|
|
||||||
__HAL_RCC_GPIOD_CLK_ENABLE();
|
|
||||||
|
|
||||||
/*Configure GPIO pin Output Level */
|
|
||||||
HAL_GPIO_WritePin(GPIOE, RedLight_Pin|YellowLight_Pin|GreenLight_Pin|WalkLight_Pin, GPIO_PIN_RESET);
|
|
||||||
|
|
||||||
/*Configure GPIO pin Output Level */
|
|
||||||
HAL_GPIO_WritePin(GPIOC, NCS_MEMS_SPI_Pin|CSX_Pin|OTG_FS_PSO_Pin, GPIO_PIN_RESET);
|
|
||||||
|
|
||||||
/*Configure GPIO pin Output Level */
|
|
||||||
HAL_GPIO_WritePin(ACP_RST_GPIO_Port, ACP_RST_Pin, GPIO_PIN_RESET);
|
|
||||||
|
|
||||||
/*Configure GPIO pin Output Level */
|
|
||||||
HAL_GPIO_WritePin(GPIOD, RDX_Pin|WRX_DCX_Pin, GPIO_PIN_RESET);
|
|
||||||
|
|
||||||
/*Configure GPIO pin Output Level */
|
|
||||||
HAL_GPIO_WritePin(GPIOG, LD3_Pin|LD4_Pin, GPIO_PIN_RESET);
|
|
||||||
|
|
||||||
/*Configure GPIO pins : RedLight_Pin YellowLight_Pin GreenLight_Pin WalkLight_Pin */
|
|
||||||
GPIO_InitStruct.Pin = RedLight_Pin|YellowLight_Pin|GreenLight_Pin|WalkLight_Pin;
|
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
||||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
|
||||||
HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
|
|
||||||
|
|
||||||
/*Configure GPIO pins : NCS_MEMS_SPI_Pin CSX_Pin OTG_FS_PSO_Pin */
|
|
||||||
GPIO_InitStruct.Pin = NCS_MEMS_SPI_Pin|CSX_Pin|OTG_FS_PSO_Pin;
|
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
||||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
|
||||||
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
|
|
||||||
|
|
||||||
/*Configure GPIO pins : B1_Pin MEMS_INT1_Pin MEMS_INT2_Pin TP_INT1_Pin */
|
|
||||||
GPIO_InitStruct.Pin = B1_Pin|MEMS_INT1_Pin|MEMS_INT2_Pin|TP_INT1_Pin;
|
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_EVT_RISING;
|
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
||||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
|
||||||
|
|
||||||
/*Configure GPIO pin : ACP_RST_Pin */
|
|
||||||
GPIO_InitStruct.Pin = ACP_RST_Pin;
|
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
||||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
|
||||||
HAL_GPIO_Init(ACP_RST_GPIO_Port, &GPIO_InitStruct);
|
|
||||||
|
|
||||||
/*Configure GPIO pin : OTG_FS_OC_Pin */
|
|
||||||
GPIO_InitStruct.Pin = OTG_FS_OC_Pin;
|
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_EVT_RISING;
|
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
||||||
HAL_GPIO_Init(OTG_FS_OC_GPIO_Port, &GPIO_InitStruct);
|
|
||||||
|
|
||||||
/*Configure GPIO pin : BOOT1_Pin */
|
|
||||||
GPIO_InitStruct.Pin = BOOT1_Pin;
|
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
||||||
HAL_GPIO_Init(BOOT1_GPIO_Port, &GPIO_InitStruct);
|
|
||||||
|
|
||||||
/*Configure GPIO pin : TE_Pin */
|
|
||||||
GPIO_InitStruct.Pin = TE_Pin;
|
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
||||||
HAL_GPIO_Init(TE_GPIO_Port, &GPIO_InitStruct);
|
|
||||||
|
|
||||||
/*Configure GPIO pins : RDX_Pin WRX_DCX_Pin */
|
|
||||||
GPIO_InitStruct.Pin = RDX_Pin|WRX_DCX_Pin;
|
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
||||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
|
||||||
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
|
|
||||||
|
|
||||||
/*Configure GPIO pins : LD3_Pin LD4_Pin */
|
|
||||||
GPIO_InitStruct.Pin = LD3_Pin|LD4_Pin;
|
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
||||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
|
||||||
HAL_GPIO_Init(GPIOG, &GPIO_InitStruct);
|
|
||||||
|
|
||||||
/* USER CODE BEGIN MX_GPIO_Init_2 */
|
|
||||||
|
|
||||||
/* USER CODE END MX_GPIO_Init_2 */
|
|
||||||
}
|
|
||||||
|
|
||||||
/* USER CODE BEGIN 4 */
|
|
||||||
|
|
||||||
/* USER CODE END 4 */
|
|
||||||
|
|
||||||
/* USER CODE BEGIN Header_StartDefaultTask */
|
|
||||||
/**
|
|
||||||
* @brief Function implementing the defaultTask thread.
|
|
||||||
* @param argument: Not used
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
/* USER CODE END Header_StartDefaultTask */
|
|
||||||
void StartDefaultTask(void const * argument)
|
|
||||||
{
|
|
||||||
/* init code for USB_HOST */
|
|
||||||
MX_USB_HOST_Init();
|
|
||||||
/* USER CODE BEGIN 5 */
|
|
||||||
/* Infinite loop */
|
|
||||||
for(;;)
|
|
||||||
{
|
|
||||||
osDelay(1);
|
|
||||||
}
|
|
||||||
/* USER CODE END 5 */
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Period elapsed callback in non blocking mode
|
|
||||||
* @note This function is called when TIM6 interrupt took place, inside
|
|
||||||
* HAL_TIM_IRQHandler(). It makes a direct call to HAL_IncTick() to increment
|
|
||||||
* a global variable "uwTick" used as application time base.
|
|
||||||
* @param htim : TIM handle
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
|
|
||||||
{
|
|
||||||
/* USER CODE BEGIN Callback 0 */
|
|
||||||
|
|
||||||
/* USER CODE END Callback 0 */
|
|
||||||
if (htim->Instance == TIM6)
|
|
||||||
{
|
|
||||||
HAL_IncTick();
|
|
||||||
}
|
|
||||||
/* USER CODE BEGIN Callback 1 */
|
|
||||||
|
|
||||||
/* USER CODE END Callback 1 */
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief This function is executed in case of error occurrence.
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
void Error_Handler(void)
|
|
||||||
{
|
|
||||||
/* USER CODE BEGIN Error_Handler_Debug */
|
|
||||||
/* User can add his own implementation to report the HAL error return state */
|
|
||||||
__disable_irq();
|
|
||||||
while (1)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
/* USER CODE END Error_Handler_Debug */
|
|
||||||
}
|
|
||||||
#ifdef USE_FULL_ASSERT
|
|
||||||
/**
|
|
||||||
* @brief Reports the name of the source file and the source line number
|
|
||||||
* where the assert_param error has occurred.
|
|
||||||
* @param file: pointer to the source file name
|
|
||||||
* @param line: assert_param error line source number
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
void assert_failed(uint8_t *file, uint32_t line)
|
|
||||||
{
|
|
||||||
/* USER CODE BEGIN 6 */
|
|
||||||
/* User can add his own implementation to report the file name and line number,
|
|
||||||
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
|
|
||||||
/* USER CODE END 6 */
|
|
||||||
}
|
|
||||||
#endif /* USE_FULL_ASSERT */
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
/*
|
|
||||||
* breadboard.c
|
|
||||||
*
|
|
||||||
* Created on: Sep 12, 2025
|
|
||||||
* Author: ja
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stdbool.h>
|
|
||||||
#include "main.h"
|
|
||||||
|
|
||||||
void
|
|
||||||
breadboard(int DELAY_MS)
|
|
||||||
{
|
|
||||||
bool Purple = (HAL_GPIO_ReadPin(BTN_PRPL_GPIO_Port, BTN_PRPL_Pin) == GPIO_PIN_SET); // PD5
|
|
||||||
bool Grey = (HAL_GPIO_ReadPin(BTN_GREY_GPIO_Port, BTN_GREY_Pin) == GPIO_PIN_SET); // PD7
|
|
||||||
|
|
||||||
if (Purple && Grey) { // inverted for ease of debug, assignment calls for (Purple && Grey)
|
|
||||||
HAL_GPIO_WritePin(LED_EXT_GPIO_Port, LED_EXT_Pin, GPIO_PIN_SET); // PB4
|
|
||||||
} else {
|
|
||||||
HAL_GPIO_WritePin(LED_EXT_GPIO_Port, LED_EXT_Pin, GPIO_PIN_RESET); // PB4
|
|
||||||
}
|
|
||||||
|
|
||||||
HAL_Delay(DELAY_MS); // milliseconds of delay after execution
|
|
||||||
|
|
||||||
/*
|
|
||||||
// Always flash:
|
|
||||||
HAL_GPIO_WritePin(GPIOB, LED_EXT_Pin, GPIO_PIN_SET); // PB4 ON
|
|
||||||
HAL_Delay(DELAY_MS);
|
|
||||||
HAL_GPIO_WritePin(GPIOB, LED_EXT_Pin, GPIO_PIN_RESET); // PB4 OFF
|
|
||||||
HAL_Delay(DELAY_MS);
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
@@ -1,85 +0,0 @@
|
|||||||
/*
|
|
||||||
* breadboard.c
|
|
||||||
*
|
|
||||||
* Created on: Sep 17, 2025
|
|
||||||
* Author: ja
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* #define RedLight_Pin GPIO_PIN_2
|
|
||||||
* #define RedLight_GPIO_Port GPIOE
|
|
||||||
*
|
|
||||||
* #define YellowLight_Pin GPIO_PIN_3
|
|
||||||
* #define YellowLight_GPIO_Port GPIOE
|
|
||||||
*
|
|
||||||
* #define GreenLight_Pin GPIO_PIN_4
|
|
||||||
* #define GreenLight_GPIO_Port GPIOE
|
|
||||||
*
|
|
||||||
* RedLight: PE2
|
|
||||||
* YellowLight: PE3
|
|
||||||
* GreenLight: PE4
|
|
||||||
* WalkLight: PE5
|
|
||||||
*
|
|
||||||
* Done: Traffic Light
|
|
||||||
* TODO: async? Walk Signal, Light Dimmer
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "main.h"
|
|
||||||
#include "breadboard.h"
|
|
||||||
|
|
||||||
#define R_Pin RedLight_Pin
|
|
||||||
#define Y_Pin YellowLight_Pin
|
|
||||||
#define G_Pin GreenLight_Pin
|
|
||||||
#define W_Pin WalkLight_Pin
|
|
||||||
|
|
||||||
#define R_Prt RedLight_GPIO_Port
|
|
||||||
#define Y_Prt YellowLight_GPIO_Port
|
|
||||||
#define G_Prt GreenLight_GPIO_Port
|
|
||||||
#define W_Prt WalkLight_GPIO_Port
|
|
||||||
|
|
||||||
uint32_t redlight_last;
|
|
||||||
uint32_t ylwlight_last;
|
|
||||||
uint32_t grnlight_last;
|
|
||||||
|
|
||||||
void
|
|
||||||
starttick(void)
|
|
||||||
{
|
|
||||||
trafftick_last = HAL_GetTick();
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
trafflight(int traffSPD)
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
HAL_GPIO_TogglePin(R_Prt, R_Pin);
|
|
||||||
HAL_Delay(traffSPD);
|
|
||||||
HAL_GPIO_TogglePin(R_Prt, R_Pin);
|
|
||||||
|
|
||||||
HAL_GPIO_TogglePin(Y_Prt, Y_Pin);
|
|
||||||
HAL_Delay(traffSPD);
|
|
||||||
HAL_GPIO_TogglePin(Y_Prt, Y_Pin);
|
|
||||||
|
|
||||||
HAL_GPIO_TogglePin(G_Prt, G_Pin);
|
|
||||||
HAL_Delay(traffSPD);
|
|
||||||
HAL_GPIO_TogglePin(G_Prt, G_Pin);
|
|
||||||
*/
|
|
||||||
|
|
||||||
uint32_t trafftick_curr = HAL_GetTick();
|
|
||||||
int ldelay2 = traffSPD * 2;
|
|
||||||
int ldelay3 = traffSPD * 3;
|
|
||||||
|
|
||||||
if ((trafftick_curr - redlight_last) >= traffSPD) {
|
|
||||||
redlight_last = trafftick_curr;
|
|
||||||
HAL_GPIO_TogglePin(R_Prt, R_Pin);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((trafftick_curr - ylwlight_last) >= ldelay2) {
|
|
||||||
ylwlight_last = trafftick_curr;
|
|
||||||
HAL_GPIO_TogglePin(Y_Prt, Y_Pin);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((trafftick_curr - trafftick_last) >= ldelay3) {
|
|
||||||
|
|
||||||
HAL_GPIO_TogglePin(G_Prt, G_Pin);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,730 +0,0 @@
|
|||||||
/* USER CODE BEGIN Header */
|
|
||||||
/**
|
|
||||||
******************************************************************************
|
|
||||||
* @file : main.c
|
|
||||||
* @brief : Main program body
|
|
||||||
******************************************************************************
|
|
||||||
* @attention
|
|
||||||
*
|
|
||||||
* Copyright (c) 2025 STMicroelectronics.
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* This software is licensed under terms that can be found in the LICENSE file
|
|
||||||
* in the root directory of this software component.
|
|
||||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
|
||||||
*
|
|
||||||
******************************************************************************
|
|
||||||
*/
|
|
||||||
/* USER CODE END Header */
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
|
||||||
#include "main.h"
|
|
||||||
#include "cmsis_os.h"
|
|
||||||
#include "usb_host.h"
|
|
||||||
|
|
||||||
/* Private includes ----------------------------------------------------------*/
|
|
||||||
/* USER CODE BEGIN Includes */
|
|
||||||
#include "breadboard.h"
|
|
||||||
|
|
||||||
/* USER CODE END Includes */
|
|
||||||
|
|
||||||
/* Private typedef -----------------------------------------------------------*/
|
|
||||||
/* USER CODE BEGIN PTD */
|
|
||||||
|
|
||||||
/* USER CODE END PTD */
|
|
||||||
|
|
||||||
/* Private define ------------------------------------------------------------*/
|
|
||||||
/* USER CODE BEGIN PD */
|
|
||||||
|
|
||||||
/* USER CODE END PD */
|
|
||||||
|
|
||||||
/* Private macro -------------------------------------------------------------*/
|
|
||||||
/* USER CODE BEGIN PM */
|
|
||||||
|
|
||||||
/* USER CODE END PM */
|
|
||||||
|
|
||||||
/* Private variables ---------------------------------------------------------*/
|
|
||||||
CRC_HandleTypeDef hcrc;
|
|
||||||
|
|
||||||
DMA2D_HandleTypeDef hdma2d;
|
|
||||||
|
|
||||||
I2C_HandleTypeDef hi2c3;
|
|
||||||
|
|
||||||
LTDC_HandleTypeDef hltdc;
|
|
||||||
|
|
||||||
SPI_HandleTypeDef hspi5;
|
|
||||||
|
|
||||||
TIM_HandleTypeDef htim1;
|
|
||||||
|
|
||||||
UART_HandleTypeDef huart1;
|
|
||||||
|
|
||||||
SDRAM_HandleTypeDef hsdram1;
|
|
||||||
|
|
||||||
osThreadId defaultTaskHandle;
|
|
||||||
/* USER CODE BEGIN PV */
|
|
||||||
|
|
||||||
/* USER CODE END PV */
|
|
||||||
|
|
||||||
/* Private function prototypes -----------------------------------------------*/
|
|
||||||
void SystemClock_Config(void);
|
|
||||||
static void MX_GPIO_Init(void);
|
|
||||||
static void MX_CRC_Init(void);
|
|
||||||
static void MX_DMA2D_Init(void);
|
|
||||||
static void MX_FMC_Init(void);
|
|
||||||
static void MX_I2C3_Init(void);
|
|
||||||
static void MX_LTDC_Init(void);
|
|
||||||
static void MX_SPI5_Init(void);
|
|
||||||
static void MX_TIM1_Init(void);
|
|
||||||
static void MX_USART1_UART_Init(void);
|
|
||||||
void StartDefaultTask(void const * argument);
|
|
||||||
|
|
||||||
/* USER CODE BEGIN PFP */
|
|
||||||
|
|
||||||
/* USER CODE END PFP */
|
|
||||||
|
|
||||||
/* Private user code ---------------------------------------------------------*/
|
|
||||||
/* USER CODE BEGIN 0 */
|
|
||||||
|
|
||||||
/* USER CODE END 0 */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief The application entry point.
|
|
||||||
* @retval int
|
|
||||||
*/
|
|
||||||
int main(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* USER CODE BEGIN 1 */
|
|
||||||
|
|
||||||
/* USER CODE END 1 */
|
|
||||||
|
|
||||||
/* MCU Configuration--------------------------------------------------------*/
|
|
||||||
|
|
||||||
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
|
|
||||||
HAL_Init();
|
|
||||||
|
|
||||||
/* USER CODE BEGIN Init */
|
|
||||||
|
|
||||||
/* USER CODE END Init */
|
|
||||||
|
|
||||||
/* Configure the system clock */
|
|
||||||
SystemClock_Config();
|
|
||||||
|
|
||||||
/* USER CODE BEGIN SysInit */
|
|
||||||
|
|
||||||
/* USER CODE END SysInit */
|
|
||||||
|
|
||||||
/* Initialize all configured peripherals */
|
|
||||||
MX_GPIO_Init();
|
|
||||||
MX_CRC_Init();
|
|
||||||
MX_DMA2D_Init();
|
|
||||||
MX_FMC_Init();
|
|
||||||
MX_I2C3_Init();
|
|
||||||
MX_LTDC_Init();
|
|
||||||
MX_SPI5_Init();
|
|
||||||
MX_TIM1_Init();
|
|
||||||
MX_USART1_UART_Init();
|
|
||||||
/* USER CODE BEGIN 2 */
|
|
||||||
|
|
||||||
/* USER CODE END 2 */
|
|
||||||
|
|
||||||
/* USER CODE BEGIN RTOS_MUTEX */
|
|
||||||
/* add mutexes, ... */
|
|
||||||
/* USER CODE END RTOS_MUTEX */
|
|
||||||
|
|
||||||
/* USER CODE BEGIN RTOS_SEMAPHORES */
|
|
||||||
/* add semaphores, ... */
|
|
||||||
/* USER CODE END RTOS_SEMAPHORES */
|
|
||||||
|
|
||||||
/* USER CODE BEGIN RTOS_TIMERS */
|
|
||||||
/* start timers, add new ones, ... */
|
|
||||||
/* USER CODE END RTOS_TIMERS */
|
|
||||||
|
|
||||||
/* USER CODE BEGIN RTOS_QUEUES */
|
|
||||||
/* add queues, ... */
|
|
||||||
/* USER CODE END RTOS_QUEUES */
|
|
||||||
|
|
||||||
/* Create the thread(s) */
|
|
||||||
/* definition and creation of defaultTask */
|
|
||||||
//osThreadDef(defaultTask, StartDefaultTask, osPriorityNormal, 0, 4096);
|
|
||||||
//defaultTaskHandle = osThreadCreate(osThread(defaultTask), NULL);
|
|
||||||
|
|
||||||
/* USER CODE BEGIN RTOS_THREADS */
|
|
||||||
/* add threads, ... */
|
|
||||||
/* USER CODE END RTOS_THREADS */
|
|
||||||
|
|
||||||
/* Start scheduler */
|
|
||||||
//osKernelStart();
|
|
||||||
|
|
||||||
/* We should never get here as control is now taken by the scheduler */
|
|
||||||
|
|
||||||
/* Infinite loop */
|
|
||||||
/* USER CODE BEGIN WHILE */
|
|
||||||
while (1)
|
|
||||||
{
|
|
||||||
trafflight(333);
|
|
||||||
/* USER CODE END WHILE */
|
|
||||||
|
|
||||||
/* USER CODE BEGIN 3 */
|
|
||||||
}
|
|
||||||
/* USER CODE END 3 */
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief System Clock Configuration
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
void SystemClock_Config(void)
|
|
||||||
{
|
|
||||||
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
|
|
||||||
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
|
|
||||||
|
|
||||||
/** Configure the main internal regulator output voltage
|
|
||||||
*/
|
|
||||||
__HAL_RCC_PWR_CLK_ENABLE();
|
|
||||||
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE3);
|
|
||||||
|
|
||||||
/** Initializes the RCC Oscillators according to the specified parameters
|
|
||||||
* in the RCC_OscInitTypeDef structure.
|
|
||||||
*/
|
|
||||||
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
|
|
||||||
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
|
|
||||||
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
|
||||||
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
|
|
||||||
RCC_OscInitStruct.PLL.PLLM = 4;
|
|
||||||
RCC_OscInitStruct.PLL.PLLN = 72;
|
|
||||||
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
|
|
||||||
RCC_OscInitStruct.PLL.PLLQ = 3;
|
|
||||||
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Initializes the CPU, AHB and APB buses clocks
|
|
||||||
*/
|
|
||||||
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|
|
||||||
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
|
|
||||||
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
|
|
||||||
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
|
|
||||||
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
|
|
||||||
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
|
|
||||||
|
|
||||||
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief CRC Initialization Function
|
|
||||||
* @param None
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
static void MX_CRC_Init(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* USER CODE BEGIN CRC_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE END CRC_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE BEGIN CRC_Init 1 */
|
|
||||||
|
|
||||||
/* USER CODE END CRC_Init 1 */
|
|
||||||
hcrc.Instance = CRC;
|
|
||||||
if (HAL_CRC_Init(&hcrc) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
/* USER CODE BEGIN CRC_Init 2 */
|
|
||||||
|
|
||||||
/* USER CODE END CRC_Init 2 */
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief DMA2D Initialization Function
|
|
||||||
* @param None
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
static void MX_DMA2D_Init(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* USER CODE BEGIN DMA2D_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE END DMA2D_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE BEGIN DMA2D_Init 1 */
|
|
||||||
|
|
||||||
/* USER CODE END DMA2D_Init 1 */
|
|
||||||
hdma2d.Instance = DMA2D;
|
|
||||||
hdma2d.Init.Mode = DMA2D_M2M;
|
|
||||||
hdma2d.Init.ColorMode = DMA2D_OUTPUT_ARGB8888;
|
|
||||||
hdma2d.Init.OutputOffset = 0;
|
|
||||||
hdma2d.LayerCfg[1].InputOffset = 0;
|
|
||||||
hdma2d.LayerCfg[1].InputColorMode = DMA2D_INPUT_ARGB8888;
|
|
||||||
hdma2d.LayerCfg[1].AlphaMode = DMA2D_NO_MODIF_ALPHA;
|
|
||||||
hdma2d.LayerCfg[1].InputAlpha = 0;
|
|
||||||
if (HAL_DMA2D_Init(&hdma2d) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
if (HAL_DMA2D_ConfigLayer(&hdma2d, 1) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
/* USER CODE BEGIN DMA2D_Init 2 */
|
|
||||||
|
|
||||||
/* USER CODE END DMA2D_Init 2 */
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief I2C3 Initialization Function
|
|
||||||
* @param None
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
static void MX_I2C3_Init(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* USER CODE BEGIN I2C3_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE END I2C3_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE BEGIN I2C3_Init 1 */
|
|
||||||
|
|
||||||
/* USER CODE END I2C3_Init 1 */
|
|
||||||
hi2c3.Instance = I2C3;
|
|
||||||
hi2c3.Init.ClockSpeed = 100000;
|
|
||||||
hi2c3.Init.DutyCycle = I2C_DUTYCYCLE_2;
|
|
||||||
hi2c3.Init.OwnAddress1 = 0;
|
|
||||||
hi2c3.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
|
|
||||||
hi2c3.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
|
|
||||||
hi2c3.Init.OwnAddress2 = 0;
|
|
||||||
hi2c3.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
|
|
||||||
hi2c3.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
|
|
||||||
if (HAL_I2C_Init(&hi2c3) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Configure Analogue filter
|
|
||||||
*/
|
|
||||||
if (HAL_I2CEx_ConfigAnalogFilter(&hi2c3, I2C_ANALOGFILTER_ENABLE) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Configure Digital filter
|
|
||||||
*/
|
|
||||||
if (HAL_I2CEx_ConfigDigitalFilter(&hi2c3, 0) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
/* USER CODE BEGIN I2C3_Init 2 */
|
|
||||||
|
|
||||||
/* USER CODE END I2C3_Init 2 */
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief LTDC Initialization Function
|
|
||||||
* @param None
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
static void MX_LTDC_Init(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* USER CODE BEGIN LTDC_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE END LTDC_Init 0 */
|
|
||||||
|
|
||||||
LTDC_LayerCfgTypeDef pLayerCfg = {0};
|
|
||||||
|
|
||||||
/* USER CODE BEGIN LTDC_Init 1 */
|
|
||||||
|
|
||||||
/* USER CODE END LTDC_Init 1 */
|
|
||||||
hltdc.Instance = LTDC;
|
|
||||||
hltdc.Init.HSPolarity = LTDC_HSPOLARITY_AL;
|
|
||||||
hltdc.Init.VSPolarity = LTDC_VSPOLARITY_AL;
|
|
||||||
hltdc.Init.DEPolarity = LTDC_DEPOLARITY_AL;
|
|
||||||
hltdc.Init.PCPolarity = LTDC_PCPOLARITY_IPC;
|
|
||||||
hltdc.Init.HorizontalSync = 9;
|
|
||||||
hltdc.Init.VerticalSync = 1;
|
|
||||||
hltdc.Init.AccumulatedHBP = 29;
|
|
||||||
hltdc.Init.AccumulatedVBP = 3;
|
|
||||||
hltdc.Init.AccumulatedActiveW = 269;
|
|
||||||
hltdc.Init.AccumulatedActiveH = 323;
|
|
||||||
hltdc.Init.TotalWidth = 279;
|
|
||||||
hltdc.Init.TotalHeigh = 327;
|
|
||||||
hltdc.Init.Backcolor.Blue = 0;
|
|
||||||
hltdc.Init.Backcolor.Green = 0;
|
|
||||||
hltdc.Init.Backcolor.Red = 0;
|
|
||||||
if (HAL_LTDC_Init(&hltdc) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
pLayerCfg.WindowX0 = 0;
|
|
||||||
pLayerCfg.WindowX1 = 240;
|
|
||||||
pLayerCfg.WindowY0 = 0;
|
|
||||||
pLayerCfg.WindowY1 = 320;
|
|
||||||
pLayerCfg.PixelFormat = LTDC_PIXEL_FORMAT_RGB565;
|
|
||||||
pLayerCfg.Alpha = 255;
|
|
||||||
pLayerCfg.Alpha0 = 0;
|
|
||||||
pLayerCfg.BlendingFactor1 = LTDC_BLENDING_FACTOR1_PAxCA;
|
|
||||||
pLayerCfg.BlendingFactor2 = LTDC_BLENDING_FACTOR2_PAxCA;
|
|
||||||
pLayerCfg.FBStartAdress = 0xD0000000;
|
|
||||||
pLayerCfg.ImageWidth = 240;
|
|
||||||
pLayerCfg.ImageHeight = 320;
|
|
||||||
pLayerCfg.Backcolor.Blue = 0;
|
|
||||||
pLayerCfg.Backcolor.Green = 0;
|
|
||||||
pLayerCfg.Backcolor.Red = 0;
|
|
||||||
if (HAL_LTDC_ConfigLayer(&hltdc, &pLayerCfg, 0) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
/* USER CODE BEGIN LTDC_Init 2 */
|
|
||||||
|
|
||||||
/* USER CODE END LTDC_Init 2 */
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief SPI5 Initialization Function
|
|
||||||
* @param None
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
static void MX_SPI5_Init(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* USER CODE BEGIN SPI5_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE END SPI5_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE BEGIN SPI5_Init 1 */
|
|
||||||
|
|
||||||
/* USER CODE END SPI5_Init 1 */
|
|
||||||
/* SPI5 parameter configuration*/
|
|
||||||
hspi5.Instance = SPI5;
|
|
||||||
hspi5.Init.Mode = SPI_MODE_MASTER;
|
|
||||||
hspi5.Init.Direction = SPI_DIRECTION_2LINES;
|
|
||||||
hspi5.Init.DataSize = SPI_DATASIZE_8BIT;
|
|
||||||
hspi5.Init.CLKPolarity = SPI_POLARITY_LOW;
|
|
||||||
hspi5.Init.CLKPhase = SPI_PHASE_1EDGE;
|
|
||||||
hspi5.Init.NSS = SPI_NSS_SOFT;
|
|
||||||
hspi5.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_16;
|
|
||||||
hspi5.Init.FirstBit = SPI_FIRSTBIT_MSB;
|
|
||||||
hspi5.Init.TIMode = SPI_TIMODE_DISABLE;
|
|
||||||
hspi5.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
|
|
||||||
hspi5.Init.CRCPolynomial = 10;
|
|
||||||
if (HAL_SPI_Init(&hspi5) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
/* USER CODE BEGIN SPI5_Init 2 */
|
|
||||||
|
|
||||||
/* USER CODE END SPI5_Init 2 */
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief TIM1 Initialization Function
|
|
||||||
* @param None
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
static void MX_TIM1_Init(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* USER CODE BEGIN TIM1_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE END TIM1_Init 0 */
|
|
||||||
|
|
||||||
TIM_ClockConfigTypeDef sClockSourceConfig = {0};
|
|
||||||
TIM_MasterConfigTypeDef sMasterConfig = {0};
|
|
||||||
|
|
||||||
/* USER CODE BEGIN TIM1_Init 1 */
|
|
||||||
|
|
||||||
/* USER CODE END TIM1_Init 1 */
|
|
||||||
htim1.Instance = TIM1;
|
|
||||||
htim1.Init.Prescaler = 0;
|
|
||||||
htim1.Init.CounterMode = TIM_COUNTERMODE_UP;
|
|
||||||
htim1.Init.Period = 65535;
|
|
||||||
htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
|
||||||
htim1.Init.RepetitionCounter = 0;
|
|
||||||
htim1.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
|
|
||||||
if (HAL_TIM_Base_Init(&htim1) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
|
|
||||||
if (HAL_TIM_ConfigClockSource(&htim1, &sClockSourceConfig) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
|
|
||||||
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
|
|
||||||
if (HAL_TIMEx_MasterConfigSynchronization(&htim1, &sMasterConfig) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
/* USER CODE BEGIN TIM1_Init 2 */
|
|
||||||
|
|
||||||
/* USER CODE END TIM1_Init 2 */
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief USART1 Initialization Function
|
|
||||||
* @param None
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
static void MX_USART1_UART_Init(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* USER CODE BEGIN USART1_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE END USART1_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE BEGIN USART1_Init 1 */
|
|
||||||
|
|
||||||
/* USER CODE END USART1_Init 1 */
|
|
||||||
huart1.Instance = USART1;
|
|
||||||
huart1.Init.BaudRate = 115200;
|
|
||||||
huart1.Init.WordLength = UART_WORDLENGTH_8B;
|
|
||||||
huart1.Init.StopBits = UART_STOPBITS_1;
|
|
||||||
huart1.Init.Parity = UART_PARITY_NONE;
|
|
||||||
huart1.Init.Mode = UART_MODE_TX_RX;
|
|
||||||
huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
|
|
||||||
huart1.Init.OverSampling = UART_OVERSAMPLING_16;
|
|
||||||
if (HAL_UART_Init(&huart1) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
/* USER CODE BEGIN USART1_Init 2 */
|
|
||||||
|
|
||||||
/* USER CODE END USART1_Init 2 */
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/* FMC initialization function */
|
|
||||||
static void MX_FMC_Init(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* USER CODE BEGIN FMC_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE END FMC_Init 0 */
|
|
||||||
|
|
||||||
FMC_SDRAM_TimingTypeDef SdramTiming = {0};
|
|
||||||
|
|
||||||
/* USER CODE BEGIN FMC_Init 1 */
|
|
||||||
|
|
||||||
/* USER CODE END FMC_Init 1 */
|
|
||||||
|
|
||||||
/** Perform the SDRAM1 memory initialization sequence
|
|
||||||
*/
|
|
||||||
hsdram1.Instance = FMC_SDRAM_DEVICE;
|
|
||||||
/* hsdram1.Init */
|
|
||||||
hsdram1.Init.SDBank = FMC_SDRAM_BANK2;
|
|
||||||
hsdram1.Init.ColumnBitsNumber = FMC_SDRAM_COLUMN_BITS_NUM_8;
|
|
||||||
hsdram1.Init.RowBitsNumber = FMC_SDRAM_ROW_BITS_NUM_12;
|
|
||||||
hsdram1.Init.MemoryDataWidth = FMC_SDRAM_MEM_BUS_WIDTH_16;
|
|
||||||
hsdram1.Init.InternalBankNumber = FMC_SDRAM_INTERN_BANKS_NUM_4;
|
|
||||||
hsdram1.Init.CASLatency = FMC_SDRAM_CAS_LATENCY_3;
|
|
||||||
hsdram1.Init.WriteProtection = FMC_SDRAM_WRITE_PROTECTION_DISABLE;
|
|
||||||
hsdram1.Init.SDClockPeriod = FMC_SDRAM_CLOCK_PERIOD_2;
|
|
||||||
hsdram1.Init.ReadBurst = FMC_SDRAM_RBURST_DISABLE;
|
|
||||||
hsdram1.Init.ReadPipeDelay = FMC_SDRAM_RPIPE_DELAY_1;
|
|
||||||
/* SdramTiming */
|
|
||||||
SdramTiming.LoadToActiveDelay = 2;
|
|
||||||
SdramTiming.ExitSelfRefreshDelay = 7;
|
|
||||||
SdramTiming.SelfRefreshTime = 4;
|
|
||||||
SdramTiming.RowCycleDelay = 7;
|
|
||||||
SdramTiming.WriteRecoveryTime = 3;
|
|
||||||
SdramTiming.RPDelay = 2;
|
|
||||||
SdramTiming.RCDDelay = 2;
|
|
||||||
|
|
||||||
if (HAL_SDRAM_Init(&hsdram1, &SdramTiming) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler( );
|
|
||||||
}
|
|
||||||
|
|
||||||
/* USER CODE BEGIN FMC_Init 2 */
|
|
||||||
|
|
||||||
/* USER CODE END FMC_Init 2 */
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief GPIO Initialization Function
|
|
||||||
* @param None
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
static void MX_GPIO_Init(void)
|
|
||||||
{
|
|
||||||
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
|
||||||
/* USER CODE BEGIN MX_GPIO_Init_1 */
|
|
||||||
|
|
||||||
/* USER CODE END MX_GPIO_Init_1 */
|
|
||||||
|
|
||||||
/* GPIO Ports Clock Enable */
|
|
||||||
__HAL_RCC_GPIOE_CLK_ENABLE();
|
|
||||||
__HAL_RCC_GPIOC_CLK_ENABLE();
|
|
||||||
__HAL_RCC_GPIOF_CLK_ENABLE();
|
|
||||||
__HAL_RCC_GPIOH_CLK_ENABLE();
|
|
||||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
|
||||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
|
||||||
__HAL_RCC_GPIOG_CLK_ENABLE();
|
|
||||||
__HAL_RCC_GPIOD_CLK_ENABLE();
|
|
||||||
|
|
||||||
/*Configure GPIO pin Output Level */
|
|
||||||
HAL_GPIO_WritePin(GPIOE, RedLight_Pin|YellowLight_Pin|GreenLight_Pin|WalkLight_Pin, GPIO_PIN_RESET);
|
|
||||||
|
|
||||||
/*Configure GPIO pin Output Level */
|
|
||||||
HAL_GPIO_WritePin(GPIOC, NCS_MEMS_SPI_Pin|CSX_Pin|OTG_FS_PSO_Pin, GPIO_PIN_RESET);
|
|
||||||
|
|
||||||
/*Configure GPIO pin Output Level */
|
|
||||||
HAL_GPIO_WritePin(ACP_RST_GPIO_Port, ACP_RST_Pin, GPIO_PIN_RESET);
|
|
||||||
|
|
||||||
/*Configure GPIO pin Output Level */
|
|
||||||
HAL_GPIO_WritePin(GPIOD, RDX_Pin|WRX_DCX_Pin, GPIO_PIN_RESET);
|
|
||||||
|
|
||||||
/*Configure GPIO pin Output Level */
|
|
||||||
HAL_GPIO_WritePin(GPIOG, LD3_Pin|LD4_Pin, GPIO_PIN_RESET);
|
|
||||||
|
|
||||||
/*Configure GPIO pins : RedLight_Pin YellowLight_Pin GreenLight_Pin WalkLight_Pin */
|
|
||||||
GPIO_InitStruct.Pin = RedLight_Pin|YellowLight_Pin|GreenLight_Pin|WalkLight_Pin;
|
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
||||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
|
||||||
HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
|
|
||||||
|
|
||||||
/*Configure GPIO pins : NCS_MEMS_SPI_Pin CSX_Pin OTG_FS_PSO_Pin */
|
|
||||||
GPIO_InitStruct.Pin = NCS_MEMS_SPI_Pin|CSX_Pin|OTG_FS_PSO_Pin;
|
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
||||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
|
||||||
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
|
|
||||||
|
|
||||||
/*Configure GPIO pins : B1_Pin MEMS_INT1_Pin MEMS_INT2_Pin TP_INT1_Pin */
|
|
||||||
GPIO_InitStruct.Pin = B1_Pin|MEMS_INT1_Pin|MEMS_INT2_Pin|TP_INT1_Pin;
|
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_EVT_RISING;
|
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
||||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
|
||||||
|
|
||||||
/*Configure GPIO pin : ACP_RST_Pin */
|
|
||||||
GPIO_InitStruct.Pin = ACP_RST_Pin;
|
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
||||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
|
||||||
HAL_GPIO_Init(ACP_RST_GPIO_Port, &GPIO_InitStruct);
|
|
||||||
|
|
||||||
/*Configure GPIO pin : OTG_FS_OC_Pin */
|
|
||||||
GPIO_InitStruct.Pin = OTG_FS_OC_Pin;
|
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_EVT_RISING;
|
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
||||||
HAL_GPIO_Init(OTG_FS_OC_GPIO_Port, &GPIO_InitStruct);
|
|
||||||
|
|
||||||
/*Configure GPIO pin : BOOT1_Pin */
|
|
||||||
GPIO_InitStruct.Pin = BOOT1_Pin;
|
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
||||||
HAL_GPIO_Init(BOOT1_GPIO_Port, &GPIO_InitStruct);
|
|
||||||
|
|
||||||
/*Configure GPIO pin : TE_Pin */
|
|
||||||
GPIO_InitStruct.Pin = TE_Pin;
|
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
||||||
HAL_GPIO_Init(TE_GPIO_Port, &GPIO_InitStruct);
|
|
||||||
|
|
||||||
/*Configure GPIO pins : RDX_Pin WRX_DCX_Pin */
|
|
||||||
GPIO_InitStruct.Pin = RDX_Pin|WRX_DCX_Pin;
|
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
||||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
|
||||||
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
|
|
||||||
|
|
||||||
/*Configure GPIO pins : LD3_Pin LD4_Pin */
|
|
||||||
GPIO_InitStruct.Pin = LD3_Pin|LD4_Pin;
|
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
||||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
|
||||||
HAL_GPIO_Init(GPIOG, &GPIO_InitStruct);
|
|
||||||
|
|
||||||
/* USER CODE BEGIN MX_GPIO_Init_2 */
|
|
||||||
|
|
||||||
/* USER CODE END MX_GPIO_Init_2 */
|
|
||||||
}
|
|
||||||
|
|
||||||
/* USER CODE BEGIN 4 */
|
|
||||||
|
|
||||||
/* USER CODE END 4 */
|
|
||||||
|
|
||||||
/* USER CODE BEGIN Header_StartDefaultTask */
|
|
||||||
/**
|
|
||||||
* @brief Function implementing the defaultTask thread.
|
|
||||||
* @param argument: Not used
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
/* USER CODE END Header_StartDefaultTask */
|
|
||||||
void StartDefaultTask(void const * argument)
|
|
||||||
{
|
|
||||||
/* init code for USB_HOST */
|
|
||||||
MX_USB_HOST_Init();
|
|
||||||
/* USER CODE BEGIN 5 */
|
|
||||||
/* Infinite loop */
|
|
||||||
for(;;)
|
|
||||||
{
|
|
||||||
osDelay(1);
|
|
||||||
}
|
|
||||||
/* USER CODE END 5 */
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Period elapsed callback in non blocking mode
|
|
||||||
* @note This function is called when TIM6 interrupt took place, inside
|
|
||||||
* HAL_TIM_IRQHandler(). It makes a direct call to HAL_IncTick() to increment
|
|
||||||
* a global variable "uwTick" used as application time base.
|
|
||||||
* @param htim : TIM handle
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
|
|
||||||
{
|
|
||||||
/* USER CODE BEGIN Callback 0 */
|
|
||||||
|
|
||||||
/* USER CODE END Callback 0 */
|
|
||||||
if (htim->Instance == TIM6)
|
|
||||||
{
|
|
||||||
HAL_IncTick();
|
|
||||||
}
|
|
||||||
/* USER CODE BEGIN Callback 1 */
|
|
||||||
|
|
||||||
/* USER CODE END Callback 1 */
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief This function is executed in case of error occurrence.
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
void Error_Handler(void)
|
|
||||||
{
|
|
||||||
/* USER CODE BEGIN Error_Handler_Debug */
|
|
||||||
/* User can add his own implementation to report the HAL error return state */
|
|
||||||
__disable_irq();
|
|
||||||
while (1)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
/* USER CODE END Error_Handler_Debug */
|
|
||||||
}
|
|
||||||
#ifdef USE_FULL_ASSERT
|
|
||||||
/**
|
|
||||||
* @brief Reports the name of the source file and the source line number
|
|
||||||
* where the assert_param error has occurred.
|
|
||||||
* @param file: pointer to the source file name
|
|
||||||
* @param line: assert_param error line source number
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
void assert_failed(uint8_t *file, uint32_t line)
|
|
||||||
{
|
|
||||||
/* USER CODE BEGIN 6 */
|
|
||||||
/* User can add his own implementation to report the file name and line number,
|
|
||||||
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
|
|
||||||
/* USER CODE END 6 */
|
|
||||||
}
|
|
||||||
#endif /* USE_FULL_ASSERT */
|
|
||||||
@@ -1,72 +0,0 @@
|
|||||||
/*
|
|
||||||
* breadboard.c
|
|
||||||
*
|
|
||||||
* Created on: Sep 17, 2025
|
|
||||||
* Author: ja
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* #define RedLight_Pin GPIO_PIN_2
|
|
||||||
* #define RedLight_GPIO_Port GPIOE
|
|
||||||
*
|
|
||||||
* #define YellowLight_Pin GPIO_PIN_3
|
|
||||||
* #define YellowLight_GPIO_Port GPIOE
|
|
||||||
*
|
|
||||||
* #define GreenLight_Pin GPIO_PIN_4
|
|
||||||
* #define GreenLight_GPIO_Port GPIOE
|
|
||||||
*
|
|
||||||
* RedLight: PE2
|
|
||||||
* YellowLight: PE3
|
|
||||||
* GreenLight: PE4
|
|
||||||
* WalkLight: PE5
|
|
||||||
*
|
|
||||||
* Done: Traffic Light
|
|
||||||
* TODO: async? Walk Signal, Light Dimmer
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "main.h"
|
|
||||||
#include "breadboard.h"
|
|
||||||
|
|
||||||
#define R_Pin RedLight_Pin
|
|
||||||
#define Y_Pin YellowLight_Pin
|
|
||||||
#define G_Pin GreenLight_Pin
|
|
||||||
#define W_Pin WalkLight_Pin
|
|
||||||
|
|
||||||
#define R_Prt RedLight_GPIO_Port
|
|
||||||
#define Y_Prt YellowLight_GPIO_Port
|
|
||||||
#define G_Prt GreenLight_GPIO_Port
|
|
||||||
#define W_Prt WalkLight_GPIO_Port
|
|
||||||
|
|
||||||
uint32_t trafftick_last;
|
|
||||||
|
|
||||||
uint8_t trafflight_i = 0;
|
|
||||||
|
|
||||||
void
|
|
||||||
starttick(void)
|
|
||||||
{
|
|
||||||
trafftick_last = HAL_GetTick();
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
trafflight(int traffSPD)
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
HAL_GPIO_TogglePin(R_Prt, R_Pin);
|
|
||||||
HAL_Delay(traffSPD);
|
|
||||||
HAL_GPIO_TogglePin(R_Prt, R_Pin);
|
|
||||||
|
|
||||||
HAL_GPIO_TogglePin(Y_Prt, Y_Pin);
|
|
||||||
HAL_Delay(traffSPD);
|
|
||||||
HAL_GPIO_TogglePin(Y_Prt, Y_Pin);
|
|
||||||
|
|
||||||
HAL_GPIO_TogglePin(G_Prt, G_Pin);
|
|
||||||
HAL_Delay(traffSPD);
|
|
||||||
HAL_GPIO_TogglePin(G_Prt, G_Pin);
|
|
||||||
*/
|
|
||||||
|
|
||||||
uint32_t trafftick_curr = HAL_GetTick();
|
|
||||||
|
|
||||||
if ((trafftick_curr - trafftick_last) >= traffSPD) {
|
|
||||||
switch (trafflight_i)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,334 @@
|
|||||||
|
/* USER CODE BEGIN Header */
|
||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
* @file : main.c
|
||||||
|
* @brief : Main program body
|
||||||
|
******************************************************************************
|
||||||
|
* @attention
|
||||||
|
*
|
||||||
|
* Copyright (c) 2025 STMicroelectronics.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This software is licensed under terms that can be found in the LICENSE file
|
||||||
|
* in the root directory of this software component.
|
||||||
|
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||||
|
*
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
// Feeling sneaky.
|
||||||
|
extern "C" {
|
||||||
|
/* USER CODE END Header */
|
||||||
|
/* Includes ------------------------------------------------------------------*/
|
||||||
|
#include "main.h"
|
||||||
|
|
||||||
|
/* Private function prototypes -----------------------------------------------*/
|
||||||
|
void SystemClock_Config(void);
|
||||||
|
static void MX_GPIO_Init(void);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Private user code ---------------------------------------------------------*/
|
||||||
|
/* USER CODE BEGIN 0 */
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
enum class TrafficState { GREEN, YELLOW, RED };
|
||||||
|
void SetTrafficLights(TrafficState s);
|
||||||
|
|
||||||
|
TrafficState currentState = TrafficState::GREEN;
|
||||||
|
uint32_t stateStartTime = 0; //HAL_GetTick() at the start of this state
|
||||||
|
bool buttonPressedThisCycle = false;
|
||||||
|
bool pedestrianNextCycle = false;
|
||||||
|
bool pedestrianThisCycle = false;
|
||||||
|
|
||||||
|
const uint32_t DURATION_GREEN = 5000;
|
||||||
|
const uint32_t DURATION_YELLOW = 3000;
|
||||||
|
const uint32_t DURATION_RED_NOPED = 5000;
|
||||||
|
const uint32_t DURATION_RED_PED = 7000;
|
||||||
|
|
||||||
|
/* USER CODE END 0 */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief The application entry point.
|
||||||
|
* @retval int
|
||||||
|
*/
|
||||||
|
|
||||||
|
void SetTrafficLights(TrafficState s)
|
||||||
|
{
|
||||||
|
// reset all
|
||||||
|
HAL_GPIO_WritePin(GPIOD, Green_Pin, GPIO_PIN_RESET);
|
||||||
|
HAL_GPIO_WritePin(GPIOD, Yellow_Pin, GPIO_PIN_RESET);
|
||||||
|
HAL_GPIO_WritePin(GPIOD, Red_Pin, GPIO_PIN_SET);
|
||||||
|
|
||||||
|
switch (s)
|
||||||
|
{
|
||||||
|
case TrafficState::GREEN :
|
||||||
|
HAL_GPIO_WritePin(GPIOD, Green_Pin, GPIO_PIN_SET);
|
||||||
|
break;
|
||||||
|
case TrafficState::YELLOW :
|
||||||
|
HAL_GPIO_WritePin(GPIOD, Yellow_Pin, GPIO_PIN_SET);
|
||||||
|
break;
|
||||||
|
case TrafficState::RED:
|
||||||
|
HAL_GPIO_WritePin(GPIOD, Red_Pin, GPIO_PIN_SET);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
HAL_Init();
|
||||||
|
|
||||||
|
/* USER CODE BEGIN Init */
|
||||||
|
|
||||||
|
/* USER CODE END Init */
|
||||||
|
|
||||||
|
/* Configure the system clock */
|
||||||
|
SystemClock_Config();
|
||||||
|
MX_GPIO_Init();
|
||||||
|
|
||||||
|
stateStartTime = HAL_GetTick();
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
/* USER CODE END WHILE */
|
||||||
|
uint32_t now = HAL_GetTick();
|
||||||
|
uint32_t elapsed = now - stateStartTime;
|
||||||
|
|
||||||
|
switch(currentState)
|
||||||
|
{
|
||||||
|
case TrafficState::GREEN:
|
||||||
|
if (buttonPressedThisCycle)
|
||||||
|
pedestrianThisCycle = true;
|
||||||
|
|
||||||
|
/*
|
||||||
|
if (buttonPressedThisCycle)
|
||||||
|
{
|
||||||
|
currentState = TrafficState::YELLOW;
|
||||||
|
stateStartTime = now;
|
||||||
|
buttonPressedThisCycle = false;
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pedestrianNextCycle = false;
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
else if (elapsed >= DURATION_GREEN)
|
||||||
|
{
|
||||||
|
currentState = TrafficState::YELLOW;
|
||||||
|
stateStartTime = now;
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case TrafficState::YELLOW:
|
||||||
|
if (buttonPressedThisCycle || pedestrianNextCycle)
|
||||||
|
pedestrianThisCycle = true;
|
||||||
|
|
||||||
|
if (elapsed >= DURATION_YELLOW)
|
||||||
|
{
|
||||||
|
currentState = TrafficState::RED;
|
||||||
|
stateStartTime = now;
|
||||||
|
buttonPressedThisCycle = false; //TODO add pressed pedestrian button in yellow
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
// If Ped Button was pressed during GREEN or YELLOW, we need to enable WHITE this cycle
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case TrafficState::RED:
|
||||||
|
/*
|
||||||
|
if (pedestrianNextCycle)
|
||||||
|
{
|
||||||
|
HAL_GPIO_WritePin(GPIOD,White_Pin,GPIO_PIN_SET); // turn on Pedestrian LED
|
||||||
|
if (elapsed >= DURATION_RED_PED)
|
||||||
|
{
|
||||||
|
HAL_GPIO_WritePin(GPIOD,White_Pin,GPIO_PIN_RESET);
|
||||||
|
pedestrianNextCycle = false;
|
||||||
|
currentState = TrafficState::GREEN;
|
||||||
|
stateStartTime = now;
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
HAL_GPIO_WritePin(GPIOD,White_Pin,GPIO_PIN_RESET);
|
||||||
|
if(elapsed >= DURATION_RED_PED)
|
||||||
|
{
|
||||||
|
currentState = TrafficState::GREEN;
|
||||||
|
stateStartTime = now;
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (buttonPressedThisCycle)
|
||||||
|
pedestrianNextCycle = true;
|
||||||
|
|
||||||
|
if (pedestrianThisCycle) {
|
||||||
|
HAL_GPIO_WritePin(White_GPIO_Port, White_Pin, GPIO_PIN_RESET);
|
||||||
|
pedestrianThisCycle = false;
|
||||||
|
pedestrianNextcycle = false;
|
||||||
|
currentState = TrafficState::GREEN;
|
||||||
|
stateStartTime = now;
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
buttonPressedThisCycle = false;
|
||||||
|
} else {
|
||||||
|
HAL_GPIO_WritePin(White_GPIO_Port, White_Pin, GPIO_PIN_RESET);
|
||||||
|
if (elapsed >= DURATION_RED_NOPED)
|
||||||
|
{
|
||||||
|
currentState = TrafficState::GREEN;
|
||||||
|
stateStartTime = now;
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
buttonPressedThisCycle = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/* USER CODE BEGIN 3 */
|
||||||
|
}
|
||||||
|
/* USER CODE END 3 */
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief System Clock Configuration
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
|
||||||
|
void SystemClock_Config(void)
|
||||||
|
{
|
||||||
|
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
|
||||||
|
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
|
||||||
|
|
||||||
|
/** Configure the main internal regulator output voltage
|
||||||
|
*/
|
||||||
|
__HAL_RCC_PWR_CLK_ENABLE();
|
||||||
|
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE3);
|
||||||
|
|
||||||
|
/** Initializes the RCC Oscillators according to the specified parameters
|
||||||
|
* in the RCC_OscInitTypeDef structure.
|
||||||
|
*/
|
||||||
|
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
|
||||||
|
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
|
||||||
|
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
|
||||||
|
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
||||||
|
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
|
||||||
|
RCC_OscInitStruct.PLL.PLLM = 8;
|
||||||
|
RCC_OscInitStruct.PLL.PLLN = 50;
|
||||||
|
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4;
|
||||||
|
RCC_OscInitStruct.PLL.PLLQ = 7;
|
||||||
|
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Initializes the CPU, AHB and APB buses clocks
|
||||||
|
*/
|
||||||
|
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|
||||||
|
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
|
||||||
|
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
|
||||||
|
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
|
||||||
|
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV8;
|
||||||
|
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV4;
|
||||||
|
|
||||||
|
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief GPIO Initialization Function
|
||||||
|
* @param None
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
static void MX_GPIO_Init(void)
|
||||||
|
{
|
||||||
|
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||||
|
/* USER CODE BEGIN MX_GPIO_Init_1 */
|
||||||
|
|
||||||
|
/* USER CODE END MX_GPIO_Init_1 */
|
||||||
|
|
||||||
|
/* GPIO Ports Clock Enable */
|
||||||
|
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||||
|
__HAL_RCC_GPIOD_CLK_ENABLE();
|
||||||
|
|
||||||
|
/*Configure GPIO pin Output Level */
|
||||||
|
HAL_GPIO_WritePin(GPIOD, White_Pin|Red_Pin|Yellow_Pin|Green_Pin, GPIO_PIN_RESET);
|
||||||
|
|
||||||
|
/*Configure GPIO pin : PedButton_Pin */
|
||||||
|
GPIO_InitStruct.Pin = PedButton_Pin;
|
||||||
|
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
|
||||||
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
|
HAL_GPIO_Init(PedButton_GPIO_Port, &GPIO_InitStruct);
|
||||||
|
|
||||||
|
/*Configure GPIO pins : White_Pin Red_Pin Yellow_Pin Green_Pin */
|
||||||
|
GPIO_InitStruct.Pin = White_Pin|Red_Pin|Yellow_Pin|Green_Pin;
|
||||||
|
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||||
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||||
|
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
|
||||||
|
|
||||||
|
/* EXTI interrupt init*/
|
||||||
|
HAL_NVIC_SetPriority(EXTI15_10_IRQn, 15, 0);
|
||||||
|
HAL_NVIC_EnableIRQ(EXTI15_10_IRQn);
|
||||||
|
|
||||||
|
/* USER CODE BEGIN MX_GPIO_Init_2 */
|
||||||
|
|
||||||
|
/* USER CODE END MX_GPIO_Init_2 */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* USER CODE BEGIN 4 */
|
||||||
|
void HAL_GPIO_EXTI_CallBack()
|
||||||
|
{
|
||||||
|
static uint32_t lastInterruptTime = 0;
|
||||||
|
uint32_t now = HAL_GetTick();
|
||||||
|
if(now - lastInterruptTime < 100)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
lastInterruptTime = now;
|
||||||
|
|
||||||
|
if (PedButton_Pin)
|
||||||
|
{
|
||||||
|
buttonPressedThisCycle = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void HAL_GPIO_EXTI_IRQHandler()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/* USER CODE END 4 */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function is executed in case of error occurrence.
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void Error_Handler(void)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN Error_Handler_Debug */
|
||||||
|
/* User can add his own implementation to report the HAL error return state */
|
||||||
|
__disable_irq();
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
/* USER CODE END Error_Handler_Debug */
|
||||||
|
}
|
||||||
|
#ifdef USE_FULL_ASSERT
|
||||||
|
/**
|
||||||
|
* @brief Reports the name of the source file and the source line number
|
||||||
|
* where the assert_param error has occurred.
|
||||||
|
* @param file: pointer to the source file name
|
||||||
|
* @param line: assert_param error line source number
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void assert_failed(uint8_t *file, uint32_t line)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN 6 */
|
||||||
|
/* User can add his own implementation to report the file name and line number,
|
||||||
|
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
|
||||||
|
/* USER CODE END 6 */
|
||||||
|
}
|
||||||
|
#endif /* USE_FULL_ASSERT */
|
||||||
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
/*
|
|
||||||
* breadboard.cpp
|
|
||||||
*
|
|
||||||
* Created on: Sep 22, 2025
|
|
||||||
* Author: ja
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "../Inc/breadboad.hpp"
|
|
||||||
|
|
||||||
@@ -1,101 +0,0 @@
|
|||||||
/*
|
|
||||||
* breadboard.c
|
|
||||||
*
|
|
||||||
* Created on: Sep 17, 2025
|
|
||||||
* Author: ja
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* #define RedLight_Pin GPIO_PIN_2
|
|
||||||
* #define RedLight_GPIO_Port GPIOE
|
|
||||||
*
|
|
||||||
* #define YellowLight_Pin GPIO_PIN_3
|
|
||||||
* #define YellowLight_GPIO_Port GPIOE
|
|
||||||
*
|
|
||||||
* #define GreenLight_Pin GPIO_PIN_4
|
|
||||||
* #define GreenLight_GPIO_Port GPIOE
|
|
||||||
*
|
|
||||||
* RedLight: PE2
|
|
||||||
* YellowLight: PE3
|
|
||||||
* GreenLight: PE4
|
|
||||||
* WalkLight: PE5
|
|
||||||
*
|
|
||||||
* Done: Traffic Light
|
|
||||||
* TODO: async? Walk Signal, Light Dimmer
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "main.h"
|
|
||||||
#include "breadboard.h"
|
|
||||||
|
|
||||||
#define R_Pin RedLight_Pin
|
|
||||||
#define Y_Pin YellowLight_Pin
|
|
||||||
#define G_Pin GreenLight_Pin
|
|
||||||
#define W_Pin WalkLight_Pin
|
|
||||||
|
|
||||||
#define R_Prt RedLight_GPIO_Port
|
|
||||||
#define Y_Prt YellowLight_GPIO_Port
|
|
||||||
#define G_Prt GreenLight_GPIO_Port
|
|
||||||
#define W_Prt WalkLight_GPIO_Port
|
|
||||||
|
|
||||||
uint32_t trafftick_last;
|
|
||||||
uint32_t walktick_last;
|
|
||||||
|
|
||||||
uint8_t trafflight_i = 0;
|
|
||||||
|
|
||||||
void
|
|
||||||
starttick(void)
|
|
||||||
{
|
|
||||||
trafftick_last = HAL_GetTick();
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
trafflight(int traffSPD)
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
HAL_GPIO_TogglePin(R_Prt, R_Pin);
|
|
||||||
HAL_Delay(traffSPD);
|
|
||||||
HAL_GPIO_TogglePin(R_Prt, R_Pin);
|
|
||||||
|
|
||||||
HAL_GPIO_TogglePin(Y_Prt, Y_Pin);
|
|
||||||
HAL_Delay(traffSPD);
|
|
||||||
HAL_GPIO_TogglePin(Y_Prt, Y_Pin);
|
|
||||||
|
|
||||||
HAL_GPIO_TogglePin(G_Prt, G_Pin);
|
|
||||||
HAL_Delay(traffSPD);
|
|
||||||
HAL_GPIO_TogglePin(G_Prt, G_Pin);
|
|
||||||
*/
|
|
||||||
|
|
||||||
uint32_t trafftick_curr = HAL_GetTick();
|
|
||||||
|
|
||||||
if ((trafftick_curr - trafftick_last) >= traffSPD) {
|
|
||||||
HAL_GPIO_WritePin(
|
|
||||||
R_Prt, R_Pin &&
|
|
||||||
Y_Prt, Y_Pin &&
|
|
||||||
G_Prt, G_Pin,
|
|
||||||
GPIO_PIN_RESET
|
|
||||||
);
|
|
||||||
HAL_GPIO_WritePin(R_Prt, R_Pin, GPIO_PIN_RESET);
|
|
||||||
HAL_GPIO_WritePin(Y_Prt, Y_Pin, GPIO_PIN_RESET);
|
|
||||||
HAL_GPIO_WritePin(G_Prt, G_Pin, GPIO_PIN_RESET);
|
|
||||||
|
|
||||||
switch (trafflight_i) {
|
|
||||||
case 0:
|
|
||||||
HAL_GPIO_WritePin(R_Prt, R_Pin);
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
HAL_GPIO_WritePin(Y_Prt, Y_Pin);
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
HAL_GPIO_WritePin(G_Prt, G_Pin);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
trafflight_i = (trafflight_i + 1) % 3;
|
|
||||||
trafftick_last = trafftick_curr;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((trafftick_curr - walktick_last) >= walkSPD) {
|
|
||||||
HAL_GPIO_TogglePin(W_Prt, W_Pin);
|
|
||||||
walktick_last = trafftick_curr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
/*
|
|
||||||
* breadboard.h
|
|
||||||
*
|
|
||||||
* Created on: Sep 20, 2025
|
|
||||||
* Author: ja
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef INC_BREADBOARD_H_
|
|
||||||
#define INC_BREADBOARD_H_
|
|
||||||
|
|
||||||
void starttick(void);
|
|
||||||
|
|
||||||
void trafflight(int);
|
|
||||||
|
|
||||||
#endif /* INC_BREADBOARD_H_ */
|
|
||||||
@@ -1,91 +0,0 @@
|
|||||||
/*
|
|
||||||
* breadboard.c
|
|
||||||
*
|
|
||||||
* Created on: Sep 17, 2025
|
|
||||||
* Author: ja
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* #define RedLight_Pin GPIO_PIN_2
|
|
||||||
* #define RedLight_GPIO_Port GPIOE
|
|
||||||
*
|
|
||||||
* #define YellowLight_Pin GPIO_PIN_3
|
|
||||||
* #define YellowLight_GPIO_Port GPIOE
|
|
||||||
*
|
|
||||||
* #define GreenLight_Pin GPIO_PIN_4
|
|
||||||
* #define GreenLight_GPIO_Port GPIOE
|
|
||||||
*
|
|
||||||
* RedLight: PE2
|
|
||||||
* YellowLight: PE3
|
|
||||||
* GreenLight: PE4
|
|
||||||
* WalkLight: PE5
|
|
||||||
*
|
|
||||||
* Done: Traffic Light
|
|
||||||
* TODO: Light Dimmer
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "main.h"
|
|
||||||
#include "breadboard.h"
|
|
||||||
|
|
||||||
#define R_Pin RedLight_Pin
|
|
||||||
#define Y_Pin YellowLight_Pin
|
|
||||||
#define G_Pin GreenLight_Pin
|
|
||||||
#define W_Pin WalkLight_Pin
|
|
||||||
|
|
||||||
#define R_Prt RedLight_GPIO_Port
|
|
||||||
#define Y_Prt YellowLight_GPIO_Port
|
|
||||||
#define G_Prt GreenLight_GPIO_Port
|
|
||||||
#define W_Prt WalkLight_GPIO_Port
|
|
||||||
|
|
||||||
uint32_t trafftick_last;
|
|
||||||
uint32_t walktick_last;
|
|
||||||
|
|
||||||
uint8_t trafflight_index = 0;
|
|
||||||
|
|
||||||
void
|
|
||||||
starttick(void)
|
|
||||||
{
|
|
||||||
trafftick_last = HAL_GetTick();
|
|
||||||
walktick_last = HAL_GetTick();
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
trafflight(int traffSPD, int walkSPD)
|
|
||||||
{
|
|
||||||
uint32_t trafftick_curr = HAL_GetTick();
|
|
||||||
|
|
||||||
if ((trafftick_curr - trafftick_last) >= traffSPD) {
|
|
||||||
HAL_GPIO_WritePin(R_Prt, R_Pin, GPIO_PIN_RESET);
|
|
||||||
HAL_GPIO_WritePin(Y_Prt, Y_Pin, GPIO_PIN_RESET);
|
|
||||||
HAL_GPIO_WritePin(G_Prt, G_Pin, GPIO_PIN_RESET);
|
|
||||||
|
|
||||||
switch (trafflight_index) {
|
|
||||||
case 0:
|
|
||||||
HAL_GPIO_WritePin(R_Prt, R_Pin, GPIO_PIN_SET);
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
HAL_GPIO_WritePin(Y_Prt, Y_Pin, GPIO_PIN_SET);
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
HAL_GPIO_WritePin(G_Prt, G_Pin, GPIO_PIN_SET);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 0:
|
|
||||||
HAL_GPIO_WritePin(G_Prt, G_Pin, GPIO_PIN_SET);
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
HAL_GPIO_WritePin(Y_Prt, Y_Pin, GPIO_PIN_SET);
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
HAL_GPIO_WritePin(R_Prt, R_Pin, GPIO_PIN_SET);
|
|
||||||
}
|
|
||||||
|
|
||||||
trafflight_index = (trafflight_index + 1) % 3;
|
|
||||||
trafftick_last = trafftick_curr;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((trafftick_curr - walktick_last) >= walkSPD) {
|
|
||||||
HAL_GPIO_TogglePin(W_Prt, W_Pin);
|
|
||||||
walktick_last = trafftick_curr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
/*
|
|
||||||
* breadboard.cpp
|
|
||||||
*
|
|
||||||
* Created on: Sep 22, 2025
|
|
||||||
* Author: ja
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "breadboard.h"
|
|
||||||
|
|
||||||
void SetTrafficLights(TrafficState s)
|
|
||||||
{
|
|
||||||
HAL_GPIO_WritePin(Green_Port)
|
|
||||||
}
|
|
||||||
@@ -1,89 +0,0 @@
|
|||||||
/*
|
|
||||||
* breadboard.c
|
|
||||||
*
|
|
||||||
* Created on: Sep 17, 2025
|
|
||||||
* Author: ja
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* #define RedLight_Pin GPIO_PIN_2
|
|
||||||
* #define RedLight_GPIO_Port GPIOE
|
|
||||||
*
|
|
||||||
* #define YellowLight_Pin GPIO_PIN_3
|
|
||||||
* #define YellowLight_GPIO_Port GPIOE
|
|
||||||
*
|
|
||||||
* #define GreenLight_Pin GPIO_PIN_4
|
|
||||||
* #define GreenLight_GPIO_Port GPIOE
|
|
||||||
*
|
|
||||||
* RedLight: PE2
|
|
||||||
* YellowLight: PE3
|
|
||||||
* GreenLight: PE4
|
|
||||||
* WalkLight: PE5
|
|
||||||
*
|
|
||||||
* Done: Traffic Light
|
|
||||||
* TODO: async? Walk Signal, Light Dimmer
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "main.h"
|
|
||||||
#include "breadboard.h"
|
|
||||||
|
|
||||||
#define R_Pin RedLight_Pin
|
|
||||||
#define Y_Pin YellowLight_Pin
|
|
||||||
#define G_Pin GreenLight_Pin
|
|
||||||
#define W_Pin WalkLight_Pin
|
|
||||||
|
|
||||||
#define R_Prt RedLight_GPIO_Port
|
|
||||||
#define Y_Prt YellowLight_GPIO_Port
|
|
||||||
#define G_Prt GreenLight_GPIO_Port
|
|
||||||
#define W_Prt WalkLight_GPIO_Port
|
|
||||||
|
|
||||||
uint32_t trafftick_last;
|
|
||||||
|
|
||||||
uint8_t trafflight_i = 0;
|
|
||||||
|
|
||||||
void
|
|
||||||
starttick(void)
|
|
||||||
{
|
|
||||||
trafftick_last = HAL_GetTick();
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
trafflight(int traffSPD)
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
HAL_GPIO_TogglePin(R_Prt, R_Pin);
|
|
||||||
HAL_Delay(traffSPD);
|
|
||||||
HAL_GPIO_TogglePin(R_Prt, R_Pin);
|
|
||||||
|
|
||||||
HAL_GPIO_TogglePin(Y_Prt, Y_Pin);
|
|
||||||
HAL_Delay(traffSPD);
|
|
||||||
HAL_GPIO_TogglePin(Y_Prt, Y_Pin);
|
|
||||||
|
|
||||||
HAL_GPIO_TogglePin(G_Prt, G_Pin);
|
|
||||||
HAL_Delay(traffSPD);
|
|
||||||
HAL_GPIO_TogglePin(G_Prt, G_Pin);
|
|
||||||
*/
|
|
||||||
|
|
||||||
uint32_t trafftick_curr = HAL_GetTick();
|
|
||||||
|
|
||||||
if ((trafftick_curr - trafftick_last) >= traffSPD) {
|
|
||||||
HAL_GPIO_WritePin(
|
|
||||||
R_Prt, R_Pin |
|
|
||||||
Y_Prt, Y_Pin |
|
|
||||||
G_Prt, G_Pin,
|
|
||||||
GPIO_PIN_RESET
|
|
||||||
);
|
|
||||||
|
|
||||||
switch (trafflight_i) {
|
|
||||||
case 0:
|
|
||||||
HAL_GPIO_WritePin(R_Prt, R_Pin);
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
HAL_GPIO_WritePin(Y_Prt, Y_Pin);
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
HAL_GPIO_WritePin(G_Prt, G_Pin);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,494 @@
|
|||||||
|
/* USER CODE BEGIN Header */
|
||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
* @file : main.c
|
||||||
|
* @brief : Main program body
|
||||||
|
******************************************************************************
|
||||||
|
* @attention
|
||||||
|
*
|
||||||
|
* Copyright (c) 2025 STMicroelectronics.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This software is licensed under terms that can be found in the LICENSE file
|
||||||
|
* in the root directory of this software component.
|
||||||
|
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||||
|
*
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
/* USER CODE END Header */
|
||||||
|
/* Includes ------------------------------------------------------------------*/
|
||||||
|
#include "main.h"
|
||||||
|
#include "cmsis_os.h"
|
||||||
|
|
||||||
|
/* Private includes ----------------------------------------------------------*/
|
||||||
|
/* USER CODE BEGIN Includes */
|
||||||
|
#include "breadboard.h"
|
||||||
|
#include <stdbool.h>
|
||||||
|
/* USER CODE END Includes */
|
||||||
|
|
||||||
|
/* Private typedef -----------------------------------------------------------*/
|
||||||
|
/* USER CODE BEGIN PTD */
|
||||||
|
|
||||||
|
/* USER CODE END PTD */
|
||||||
|
|
||||||
|
/* Private define ------------------------------------------------------------*/
|
||||||
|
/* USER CODE BEGIN PD */
|
||||||
|
|
||||||
|
/* USER CODE END PD */
|
||||||
|
|
||||||
|
/* Private macro -------------------------------------------------------------*/
|
||||||
|
/* USER CODE BEGIN PM */
|
||||||
|
|
||||||
|
/* USER CODE END PM */
|
||||||
|
|
||||||
|
/* Private variables ---------------------------------------------------------*/
|
||||||
|
CRC_HandleTypeDef hcrc;
|
||||||
|
|
||||||
|
DMA2D_HandleTypeDef hdma2d;
|
||||||
|
|
||||||
|
TIM_HandleTypeDef htim1;
|
||||||
|
|
||||||
|
osThreadId defaultTaskHandle;
|
||||||
|
/* USER CODE BEGIN PV */
|
||||||
|
|
||||||
|
/* USER CODE END PV */
|
||||||
|
|
||||||
|
/* Private function prototypes -----------------------------------------------*/
|
||||||
|
void SystemClock_Config(void);
|
||||||
|
static void MX_GPIO_Init(void);
|
||||||
|
static void MX_CRC_Init(void);
|
||||||
|
static void MX_DMA2D_Init(void);
|
||||||
|
static void MX_TIM1_Init(void);
|
||||||
|
void StartDefaultTask(void const * argument);
|
||||||
|
|
||||||
|
void SetTrafficLights(TrafficSate s);
|
||||||
|
|
||||||
|
/* USER CODE BEGIN PFP */
|
||||||
|
|
||||||
|
/* USER CODE END PFP */
|
||||||
|
|
||||||
|
/* Private user code ---------------------------------------------------------*/
|
||||||
|
|
||||||
|
/* USER CODE BEGIN 0 */
|
||||||
|
|
||||||
|
enum class TrafficState {
|
||||||
|
GREEN,
|
||||||
|
YELLOW,
|
||||||
|
RED
|
||||||
|
};
|
||||||
|
|
||||||
|
TrafficState currentState = TrafficState::GREEN;
|
||||||
|
uint32_t stateStartTime = 0; // HAL_GetTick() at the start of this state
|
||||||
|
bool buttonPressed = false;
|
||||||
|
bool pedestrianNextCycle = false;
|
||||||
|
|
||||||
|
const uint32_t DURATION_GREEN = 5000;
|
||||||
|
const uint32_t DURATION_YELLOW = 3000;
|
||||||
|
const uint32_t DURATION_RED = 5000;
|
||||||
|
const uint32_t DURATION_RED_PED = 7000;
|
||||||
|
|
||||||
|
/* USER CODE END 0 */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief The application entry point.
|
||||||
|
* @retval int
|
||||||
|
*/
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* USER CODE BEGIN 1 */
|
||||||
|
|
||||||
|
/* USER CODE END 1 */
|
||||||
|
|
||||||
|
/* MCU Configuration--------------------------------------------------------*/
|
||||||
|
|
||||||
|
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
|
||||||
|
HAL_Init();
|
||||||
|
|
||||||
|
/* USER CODE BEGIN Init */
|
||||||
|
|
||||||
|
/* USER CODE END Init */
|
||||||
|
|
||||||
|
/* Configure the system clock */
|
||||||
|
SystemClock_Config();
|
||||||
|
|
||||||
|
/* USER CODE BEGIN SysInit */
|
||||||
|
|
||||||
|
stateStartTime = HAL_GetTick();
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
|
||||||
|
/* USER CODE END SysInit */
|
||||||
|
|
||||||
|
/* Initialize all configured peripherals */
|
||||||
|
MX_GPIO_Init();
|
||||||
|
MX_CRC_Init();
|
||||||
|
MX_DMA2D_Init();
|
||||||
|
MX_TIM1_Init();
|
||||||
|
/* USER CODE BEGIN 2 */
|
||||||
|
|
||||||
|
/* USER CODE END 2 */
|
||||||
|
|
||||||
|
/* USER CODE BEGIN RTOS_MUTEX */
|
||||||
|
/* add mutexes, ... */
|
||||||
|
/* USER CODE END RTOS_MUTEX */
|
||||||
|
|
||||||
|
/* USER CODE BEGIN RTOS_SEMAPHORES */
|
||||||
|
/* add semaphores, ... */
|
||||||
|
/* USER CODE END RTOS_SEMAPHORES */
|
||||||
|
|
||||||
|
/* USER CODE BEGIN RTOS_TIMERS */
|
||||||
|
/* start timers, add new ones, ... */
|
||||||
|
/* USER CODE END RTOS_TIMERS */
|
||||||
|
|
||||||
|
/* USER CODE BEGIN RTOS_QUEUES */
|
||||||
|
/* add queues, ... */
|
||||||
|
/* USER CODE END RTOS_QUEUES */
|
||||||
|
|
||||||
|
/* Create the thread(s) */
|
||||||
|
/* definition and creation of defaultTask */
|
||||||
|
//osThreadDef(defaultTask, StartDefaultTask, osPriorityNormal, 0, 4096);
|
||||||
|
//defaultTaskHandle = osThreadCreate(osThread(defaultTask), NULL);
|
||||||
|
|
||||||
|
/* USER CODE BEGIN RTOS_THREADS */
|
||||||
|
/* add threads, ... */
|
||||||
|
/* USER CODE END RTOS_THREADS */
|
||||||
|
|
||||||
|
/* Start scheduler */
|
||||||
|
osKernelStart();
|
||||||
|
|
||||||
|
/* We should never get here as control is now taken by the scheduler */
|
||||||
|
|
||||||
|
/* Infinite loop */
|
||||||
|
/* USER CODE BEGIN WHILE */
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
uint32_t now = HAL_GetTick();
|
||||||
|
uint32_t elapsed = now - stateStartTime;
|
||||||
|
|
||||||
|
/*
|
||||||
|
switch(currentState)
|
||||||
|
{
|
||||||
|
case TrafficState::GREEN:
|
||||||
|
if (elapsed >= DURATION_GREEN) {
|
||||||
|
currentState = TrafficState::YELLOW;
|
||||||
|
stateStartTime = now;
|
||||||
|
buttonPressed = false; // reset the button-flag for the new cycle
|
||||||
|
} else if (buttonPressed) {
|
||||||
|
//idk
|
||||||
|
buttonPressed = true;
|
||||||
|
currentState = TrafficState::YELLOW;
|
||||||
|
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case TrafficState::YELLOW:
|
||||||
|
break;
|
||||||
|
case TrafficState::RED:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
switch(currentState)
|
||||||
|
{
|
||||||
|
case TrafficState::GREEN:
|
||||||
|
if (butonPressedThisCycle)
|
||||||
|
{
|
||||||
|
currentState = TrafficState::YELLOW;
|
||||||
|
stateStartTime = now;
|
||||||
|
buttonPressedThisCycle = false;
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* USER CODE END WHILE */
|
||||||
|
|
||||||
|
/* USER CODE BEGIN 3 */
|
||||||
|
}
|
||||||
|
/* USER CODE END 3 */
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief System Clock Configuration
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void SystemClock_Config(void)
|
||||||
|
{
|
||||||
|
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
|
||||||
|
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
|
||||||
|
|
||||||
|
/** Configure the main internal regulator output voltage
|
||||||
|
*/
|
||||||
|
__HAL_RCC_PWR_CLK_ENABLE();
|
||||||
|
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE3);
|
||||||
|
|
||||||
|
/** Initializes the RCC Oscillators according to the specified parameters
|
||||||
|
* in the RCC_OscInitTypeDef structure.
|
||||||
|
*/
|
||||||
|
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
|
||||||
|
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
|
||||||
|
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
|
||||||
|
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
||||||
|
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
|
||||||
|
RCC_OscInitStruct.PLL.PLLM = 8;
|
||||||
|
RCC_OscInitStruct.PLL.PLLN = 72;
|
||||||
|
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
|
||||||
|
RCC_OscInitStruct.PLL.PLLQ = 3;
|
||||||
|
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Initializes the CPU, AHB and APB buses clocks
|
||||||
|
*/
|
||||||
|
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|
||||||
|
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
|
||||||
|
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
|
||||||
|
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
|
||||||
|
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
|
||||||
|
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
|
||||||
|
|
||||||
|
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief CRC Initialization Function
|
||||||
|
* @param None
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
static void MX_CRC_Init(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* USER CODE BEGIN CRC_Init 0 */
|
||||||
|
|
||||||
|
/* USER CODE END CRC_Init 0 */
|
||||||
|
|
||||||
|
/* USER CODE BEGIN CRC_Init 1 */
|
||||||
|
|
||||||
|
/* USER CODE END CRC_Init 1 */
|
||||||
|
hcrc.Instance = CRC;
|
||||||
|
if (HAL_CRC_Init(&hcrc) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
/* USER CODE BEGIN CRC_Init 2 */
|
||||||
|
|
||||||
|
/* USER CODE END CRC_Init 2 */
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief DMA2D Initialization Function
|
||||||
|
* @param None
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
static void MX_DMA2D_Init(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* USER CODE BEGIN DMA2D_Init 0 */
|
||||||
|
|
||||||
|
/* USER CODE END DMA2D_Init 0 */
|
||||||
|
|
||||||
|
/* USER CODE BEGIN DMA2D_Init 1 */
|
||||||
|
|
||||||
|
/* USER CODE END DMA2D_Init 1 */
|
||||||
|
hdma2d.Instance = DMA2D;
|
||||||
|
hdma2d.Init.Mode = DMA2D_M2M;
|
||||||
|
hdma2d.Init.ColorMode = DMA2D_OUTPUT_ARGB8888;
|
||||||
|
hdma2d.Init.OutputOffset = 0;
|
||||||
|
hdma2d.LayerCfg[1].InputOffset = 0;
|
||||||
|
hdma2d.LayerCfg[1].InputColorMode = DMA2D_INPUT_ARGB8888;
|
||||||
|
hdma2d.LayerCfg[1].AlphaMode = DMA2D_NO_MODIF_ALPHA;
|
||||||
|
hdma2d.LayerCfg[1].InputAlpha = 0;
|
||||||
|
if (HAL_DMA2D_Init(&hdma2d) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
if (HAL_DMA2D_ConfigLayer(&hdma2d, 1) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
/* USER CODE BEGIN DMA2D_Init 2 */
|
||||||
|
|
||||||
|
/* USER CODE END DMA2D_Init 2 */
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief TIM1 Initialization Function
|
||||||
|
* @param None
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
static void MX_TIM1_Init(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* USER CODE BEGIN TIM1_Init 0 */
|
||||||
|
|
||||||
|
/* USER CODE END TIM1_Init 0 */
|
||||||
|
|
||||||
|
TIM_ClockConfigTypeDef sClockSourceConfig = {0};
|
||||||
|
TIM_MasterConfigTypeDef sMasterConfig = {0};
|
||||||
|
|
||||||
|
/* USER CODE BEGIN TIM1_Init 1 */
|
||||||
|
|
||||||
|
/* USER CODE END TIM1_Init 1 */
|
||||||
|
htim1.Instance = TIM1;
|
||||||
|
htim1.Init.Prescaler = 0;
|
||||||
|
htim1.Init.CounterMode = TIM_COUNTERMODE_UP;
|
||||||
|
htim1.Init.Period = 65535;
|
||||||
|
htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
||||||
|
htim1.Init.RepetitionCounter = 0;
|
||||||
|
htim1.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
|
||||||
|
if (HAL_TIM_Base_Init(&htim1) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
|
||||||
|
if (HAL_TIM_ConfigClockSource(&htim1, &sClockSourceConfig) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
|
||||||
|
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
|
||||||
|
if (HAL_TIMEx_MasterConfigSynchronization(&htim1, &sMasterConfig) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
/* USER CODE BEGIN TIM1_Init 2 */
|
||||||
|
|
||||||
|
/* USER CODE END TIM1_Init 2 */
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief GPIO Initialization Function
|
||||||
|
* @param None
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
static void MX_GPIO_Init(void)
|
||||||
|
{
|
||||||
|
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||||
|
/* USER CODE BEGIN MX_GPIO_Init_1 */
|
||||||
|
|
||||||
|
/* USER CODE END MX_GPIO_Init_1 */
|
||||||
|
|
||||||
|
/* GPIO Ports Clock Enable */
|
||||||
|
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||||
|
__HAL_RCC_GPIOD_CLK_ENABLE();
|
||||||
|
|
||||||
|
/*Configure GPIO pin Output Level */
|
||||||
|
HAL_GPIO_WritePin(GPIOD, White_Pin|Red_Pin|Yellow_Pin|Green_Pin, GPIO_PIN_RESET);
|
||||||
|
|
||||||
|
/*Configure GPIO pin : PedButton_Pin */
|
||||||
|
GPIO_InitStruct.Pin = PedButton_Pin;
|
||||||
|
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
|
||||||
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
|
HAL_GPIO_Init(PedButton_GPIO_Port, &GPIO_InitStruct);
|
||||||
|
|
||||||
|
/*Configure GPIO pins : White_Pin Red_Pin Yellow_Pin Green_Pin */
|
||||||
|
GPIO_InitStruct.Pin = White_Pin|Red_Pin|Yellow_Pin|Green_Pin;
|
||||||
|
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||||
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||||
|
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
|
||||||
|
|
||||||
|
/* EXTI interrupt init*/
|
||||||
|
HAL_NVIC_SetPriority(EXTI15_10_IRQn, 15, 0);
|
||||||
|
HAL_NVIC_EnableIRQ(EXTI15_10_IRQn);
|
||||||
|
|
||||||
|
/* USER CODE BEGIN MX_GPIO_Init_2 */
|
||||||
|
|
||||||
|
/* USER CODE END MX_GPIO_Init_2 */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* USER CODE BEGIN 4 */
|
||||||
|
|
||||||
|
void HAL_GPIO_EXTI_CallBack(uint16_t GPIO_Pin)
|
||||||
|
{
|
||||||
|
static uint32_t lastInterruptTime = 0;
|
||||||
|
uint32_t now = HAL_GetTick();
|
||||||
|
if (now - lastInterruptTime < 100) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
lastInterruptTime = now;
|
||||||
|
|
||||||
|
bool buttonPressedThisCycle = false; // temporary, get rid of this
|
||||||
|
|
||||||
|
if (buttonPressed) { // buttonPressedHere?
|
||||||
|
buttonPressedThisCycle = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* USER CODE END 4 */
|
||||||
|
|
||||||
|
/* USER CODE BEGIN Header_StartDefaultTask */
|
||||||
|
/**
|
||||||
|
* @brief Function implementing the defaultTask thread.
|
||||||
|
* @param argument: Not used
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
/* USER CODE END Header_StartDefaultTask */
|
||||||
|
void StartDefaultTask(void const * argument)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN 5 */
|
||||||
|
/* Infinite loop */
|
||||||
|
for(;;)
|
||||||
|
{
|
||||||
|
osDelay(1);
|
||||||
|
}
|
||||||
|
/* USER CODE END 5 */
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Period elapsed callback in non blocking mode
|
||||||
|
* @note This function is called when TIM6 interrupt took place, inside
|
||||||
|
* HAL_TIM_IRQHandler(). It makes a direct call to HAL_IncTick() to increment
|
||||||
|
* a global variable "uwTick" used as application time base.
|
||||||
|
* @param htim : TIM handle
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN Callback 0 */
|
||||||
|
|
||||||
|
/* USER CODE END Callback 0 */
|
||||||
|
if (htim->Instance == TIM6)
|
||||||
|
{
|
||||||
|
HAL_IncTick();
|
||||||
|
}
|
||||||
|
/* USER CODE BEGIN Callback 1 */
|
||||||
|
|
||||||
|
/* USER CODE END Callback 1 */
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function is executed in case of error occurrence.
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void Error_Handler(void)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN Error_Handler_Debug */
|
||||||
|
/* User can add his own implementation to report the HAL error return state */
|
||||||
|
__disable_irq();
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
/* USER CODE END Error_Handler_Debug */
|
||||||
|
}
|
||||||
|
#ifdef USE_FULL_ASSERT
|
||||||
|
/**
|
||||||
|
* @brief Reports the name of the source file and the source line number
|
||||||
|
* where the assert_param error has occurred.
|
||||||
|
* @param file: pointer to the source file name
|
||||||
|
* @param line: assert_param error line source number
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void assert_failed(uint8_t *file, uint32_t line)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN 6 */
|
||||||
|
/* User can add his own implementation to report the file name and line number,
|
||||||
|
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
|
||||||
|
/* USER CODE END 6 */
|
||||||
|
}
|
||||||
|
#endif /* USE_FULL_ASSERT */
|
||||||
@@ -0,0 +1,322 @@
|
|||||||
|
/* USER CODE BEGIN Header */
|
||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
* @file : main.c
|
||||||
|
* @brief : Main program body
|
||||||
|
******************************************************************************
|
||||||
|
* @attention
|
||||||
|
*
|
||||||
|
* Copyright (c) 2025 STMicroelectronics.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This software is licensed under terms that can be found in the LICENSE file
|
||||||
|
* in the root directory of this software component.
|
||||||
|
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||||
|
*
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
// Feeling sneaky.
|
||||||
|
extern "C" {
|
||||||
|
/* USER CODE END Header */
|
||||||
|
/* Includes ------------------------------------------------------------------*/
|
||||||
|
#include "main.h"
|
||||||
|
|
||||||
|
/* Private function prototypes -----------------------------------------------*/
|
||||||
|
void SystemClock_Config(void);
|
||||||
|
static void MX_GPIO_Init(void);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Private user code ---------------------------------------------------------*/
|
||||||
|
/* USER CODE BEGIN 0 */
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
enum class TrafficState { GREEN, YELLOW, RED };
|
||||||
|
void SetTrafficLights(TrafficState s);
|
||||||
|
|
||||||
|
TrafficState currentState = TrafficState::GREEN;
|
||||||
|
uint32_t stateStartTime = 0; //HAL_GetTick() at the start of this state
|
||||||
|
bool buttonPressedThisCycle = false;
|
||||||
|
bool pedestrianNextCycle = false;
|
||||||
|
bool pedestrianThisCycle = false;
|
||||||
|
|
||||||
|
const uint32_t DURATION_GREEN = 5000;
|
||||||
|
const uint32_t DURATION_YELLOW = 3000;
|
||||||
|
const uint32_t DURATION_RED_NOPED = 5000;
|
||||||
|
const uint32_t DURATION_RED_PED = 7000;
|
||||||
|
|
||||||
|
/* USER CODE END 0 */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief The application entry point.
|
||||||
|
* @retval int
|
||||||
|
*/
|
||||||
|
|
||||||
|
void SetTrafficLights(TrafficState s)
|
||||||
|
{
|
||||||
|
// reset all
|
||||||
|
HAL_GPIO_WritePin(GPIOD, Green_Pin, GPIO_PIN_RESET);
|
||||||
|
HAL_GPIO_WritePin(GPIOD, Yellow_Pin, GPIO_PIN_RESET);
|
||||||
|
HAL_GPIO_WritePin(GPIOD, Red_Pin, GPIO_PIN_SET);
|
||||||
|
|
||||||
|
switch (s)
|
||||||
|
{
|
||||||
|
case TrafficState::GREEN :
|
||||||
|
HAL_GPIO_WritePin(GPIOD, Green_Pin, GPIO_PIN_SET);
|
||||||
|
break;
|
||||||
|
case TrafficState::YELLOW :
|
||||||
|
HAL_GPIO_WritePin(GPIOD, Yellow_Pin, GPIO_PIN_SET);
|
||||||
|
break;
|
||||||
|
case TrafficState::RED:
|
||||||
|
HAL_GPIO_WritePin(GPIOD, Red_Pin, GPIO_PIN_SET);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
HAL_Init();
|
||||||
|
|
||||||
|
/* USER CODE BEGIN Init */
|
||||||
|
|
||||||
|
/* USER CODE END Init */
|
||||||
|
|
||||||
|
/* Configure the system clock */
|
||||||
|
SystemClock_Config();
|
||||||
|
MX_GPIO_Init();
|
||||||
|
|
||||||
|
stateStartTime = HAL_GetTick();
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
/* USER CODE END WHILE */
|
||||||
|
uint32_t now = HAL_GetTick();
|
||||||
|
uint32_t elapsed = now - stateStartTime;
|
||||||
|
|
||||||
|
switch(currentState)
|
||||||
|
{
|
||||||
|
case TrafficState::GREEN:
|
||||||
|
if (buttonPressedThisCycle)
|
||||||
|
pedestrianThisCycle = true;
|
||||||
|
|
||||||
|
/*
|
||||||
|
if (buttonPressedThisCycle)
|
||||||
|
{
|
||||||
|
currentState = TrafficState::YELLOW;
|
||||||
|
stateStartTime = now;
|
||||||
|
buttonPressedThisCycle = false;
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pedestrianNextCycle = false;
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
else if (elapsed >= DURATION_GREEN)
|
||||||
|
{
|
||||||
|
currentState = TrafficState::YELLOW;
|
||||||
|
stateStartTime = now;
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case TrafficState::YELLOW:
|
||||||
|
if (buttonPressedThisCycle || pedestrianNextCycle)
|
||||||
|
pedestrianThisCycle = true;
|
||||||
|
|
||||||
|
if (elapsed >= DURATION_YELLOW)
|
||||||
|
{
|
||||||
|
currentState = TrafficState::RED;
|
||||||
|
stateStartTime = now;
|
||||||
|
buttonPressedThisCycle = false; //TODO add pressed pedestrian button in yellow
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
// If Ped Button was pressed during GREEN or YELLOW, we need to enable WHITE this cycle
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case TrafficState::RED:
|
||||||
|
/*
|
||||||
|
if (pedestrianNextCycle)
|
||||||
|
{
|
||||||
|
HAL_GPIO_WritePin(GPIOD,White_Pin,GPIO_PIN_SET); // turn on Pedestrian LED
|
||||||
|
if (elapsed >= DURATION_RED_PED)
|
||||||
|
{
|
||||||
|
HAL_GPIO_WritePin(GPIOD,White_Pin,GPIO_PIN_RESET);
|
||||||
|
pedestrianNextCycle = false;
|
||||||
|
currentState = TrafficState::GREEN;
|
||||||
|
stateStartTime = now;
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
HAL_GPIO_WritePin(GPIOD,White_Pin,GPIO_PIN_RESET);
|
||||||
|
if(elapsed >= DURATION_RED_PED)
|
||||||
|
{
|
||||||
|
currentState = TrafficState::GREEN;
|
||||||
|
stateStartTime = now;
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (buttonPressedThisCycle)
|
||||||
|
pedestrianNextCycle = true;
|
||||||
|
|
||||||
|
if (pedestrianThisCycle) {
|
||||||
|
HAL_GPIO_WritePin(White)
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/* USER CODE BEGIN 3 */
|
||||||
|
}
|
||||||
|
/* USER CODE END 3 */
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief System Clock Configuration
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void SystemClock_Config(void)
|
||||||
|
{
|
||||||
|
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
|
||||||
|
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
|
||||||
|
|
||||||
|
/** Configure the main internal regulator output voltage
|
||||||
|
*/
|
||||||
|
__HAL_RCC_PWR_CLK_ENABLE();
|
||||||
|
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE3);
|
||||||
|
|
||||||
|
/** Initializes the RCC Oscillators according to the specified parameters
|
||||||
|
* in the RCC_OscInitTypeDef structure.
|
||||||
|
*/
|
||||||
|
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
|
||||||
|
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
|
||||||
|
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
|
||||||
|
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
||||||
|
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
|
||||||
|
RCC_OscInitStruct.PLL.PLLM = 8;
|
||||||
|
RCC_OscInitStruct.PLL.PLLN = 50;
|
||||||
|
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4;
|
||||||
|
RCC_OscInitStruct.PLL.PLLQ = 7;
|
||||||
|
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Initializes the CPU, AHB and APB buses clocks
|
||||||
|
*/
|
||||||
|
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|
||||||
|
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
|
||||||
|
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
|
||||||
|
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
|
||||||
|
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV8;
|
||||||
|
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV4;
|
||||||
|
|
||||||
|
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief GPIO Initialization Function
|
||||||
|
* @param None
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
static void MX_GPIO_Init(void)
|
||||||
|
{
|
||||||
|
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||||
|
/* USER CODE BEGIN MX_GPIO_Init_1 */
|
||||||
|
|
||||||
|
/* USER CODE END MX_GPIO_Init_1 */
|
||||||
|
|
||||||
|
/* GPIO Ports Clock Enable */
|
||||||
|
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||||
|
__HAL_RCC_GPIOD_CLK_ENABLE();
|
||||||
|
|
||||||
|
/*Configure GPIO pin Output Level */
|
||||||
|
HAL_GPIO_WritePin(GPIOD, White_Pin|Red_Pin|Yellow_Pin|Green_Pin, GPIO_PIN_RESET);
|
||||||
|
|
||||||
|
/*Configure GPIO pin : PedButton_Pin */
|
||||||
|
GPIO_InitStruct.Pin = PedButton_Pin;
|
||||||
|
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
|
||||||
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
|
HAL_GPIO_Init(PedButton_GPIO_Port, &GPIO_InitStruct);
|
||||||
|
|
||||||
|
/*Configure GPIO pins : White_Pin Red_Pin Yellow_Pin Green_Pin */
|
||||||
|
GPIO_InitStruct.Pin = White_Pin|Red_Pin|Yellow_Pin|Green_Pin;
|
||||||
|
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||||
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||||
|
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
|
||||||
|
|
||||||
|
/* EXTI interrupt init*/
|
||||||
|
HAL_NVIC_SetPriority(EXTI15_10_IRQn, 15, 0);
|
||||||
|
HAL_NVIC_EnableIRQ(EXTI15_10_IRQn);
|
||||||
|
|
||||||
|
/* USER CODE BEGIN MX_GPIO_Init_2 */
|
||||||
|
|
||||||
|
/* USER CODE END MX_GPIO_Init_2 */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* USER CODE BEGIN 4 */
|
||||||
|
void HAL_GPIO_EXTI_CallBack()
|
||||||
|
{
|
||||||
|
static uint32_t lastInterruptTime = 0;
|
||||||
|
uint32_t now = HAL_GetTick();
|
||||||
|
if(now - lastInterruptTime < 100)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
lastInterruptTime = now;
|
||||||
|
|
||||||
|
if (PedButton_Pin)
|
||||||
|
{
|
||||||
|
buttonPressedThisCycle = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void HAL_GPIO_EXTI_IRQHandler()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/* USER CODE END 4 */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function is executed in case of error occurrence.
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void Error_Handler(void)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN Error_Handler_Debug */
|
||||||
|
/* User can add his own implementation to report the HAL error return state */
|
||||||
|
__disable_irq();
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
/* USER CODE END Error_Handler_Debug */
|
||||||
|
}
|
||||||
|
#ifdef USE_FULL_ASSERT
|
||||||
|
/**
|
||||||
|
* @brief Reports the name of the source file and the source line number
|
||||||
|
* where the assert_param error has occurred.
|
||||||
|
* @param file: pointer to the source file name
|
||||||
|
* @param line: assert_param error line source number
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void assert_failed(uint8_t *file, uint32_t line)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN 6 */
|
||||||
|
/* User can add his own implementation to report the file name and line number,
|
||||||
|
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
|
||||||
|
/* USER CODE END 6 */
|
||||||
|
}
|
||||||
|
#endif /* USE_FULL_ASSERT */
|
||||||
|
|
||||||
@@ -0,0 +1,322 @@
|
|||||||
|
/* USER CODE BEGIN Header */
|
||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
* @file : main.c
|
||||||
|
* @brief : Main program body
|
||||||
|
******************************************************************************
|
||||||
|
* @attention
|
||||||
|
*
|
||||||
|
* Copyright (c) 2025 STMicroelectronics.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This software is licensed under terms that can be found in the LICENSE file
|
||||||
|
* in the root directory of this software component.
|
||||||
|
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||||
|
*
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
// Feeling sneaky.
|
||||||
|
extern "C" {
|
||||||
|
/* USER CODE END Header */
|
||||||
|
/* Includes ------------------------------------------------------------------*/
|
||||||
|
#include "main.h"
|
||||||
|
|
||||||
|
/* Private function prototypes -----------------------------------------------*/
|
||||||
|
void SystemClock_Config(void);
|
||||||
|
static void MX_GPIO_Init(void);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Private user code ---------------------------------------------------------*/
|
||||||
|
/* USER CODE BEGIN 0 */
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
enum class TrafficState { GREEN, YELLOW, RED };
|
||||||
|
void SetTrafficLights(TrafficState s);
|
||||||
|
|
||||||
|
TrafficState currentState = TrafficState::GREEN;
|
||||||
|
uint32_t stateStartTime = 0; //HAL_GetTick() at the start of this state
|
||||||
|
bool buttonPressedThisCycle = false;
|
||||||
|
bool pedestrianNextCycle = false;
|
||||||
|
bool pedestrianThisCycle = false;
|
||||||
|
|
||||||
|
const uint32_t DURATION_GREEN = 5000;
|
||||||
|
const uint32_t DURATION_YELLOW = 3000;
|
||||||
|
const uint32_t DURATION_RED_NOPED = 5000;
|
||||||
|
const uint32_t DURATION_RED_PED = 7000;
|
||||||
|
|
||||||
|
/* USER CODE END 0 */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief The application entry point.
|
||||||
|
* @retval int
|
||||||
|
*/
|
||||||
|
|
||||||
|
void SetTrafficLights(TrafficState s)
|
||||||
|
{
|
||||||
|
// reset all
|
||||||
|
HAL_GPIO_WritePin(GPIOD, Green_Pin, GPIO_PIN_RESET);
|
||||||
|
HAL_GPIO_WritePin(GPIOD, Yellow_Pin, GPIO_PIN_RESET);
|
||||||
|
HAL_GPIO_WritePin(GPIOD, Red_Pin, GPIO_PIN_SET);
|
||||||
|
|
||||||
|
switch (s)
|
||||||
|
{
|
||||||
|
case TrafficState::GREEN :
|
||||||
|
HAL_GPIO_WritePin(GPIOD, Green_Pin, GPIO_PIN_SET);
|
||||||
|
break;
|
||||||
|
case TrafficState::YELLOW :
|
||||||
|
HAL_GPIO_WritePin(GPIOD, Yellow_Pin, GPIO_PIN_SET);
|
||||||
|
break;
|
||||||
|
case TrafficState::RED:
|
||||||
|
HAL_GPIO_WritePin(GPIOD, Red_Pin, GPIO_PIN_SET);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
HAL_Init();
|
||||||
|
|
||||||
|
/* USER CODE BEGIN Init */
|
||||||
|
|
||||||
|
/* USER CODE END Init */
|
||||||
|
|
||||||
|
/* Configure the system clock */
|
||||||
|
SystemClock_Config();
|
||||||
|
MX_GPIO_Init();
|
||||||
|
|
||||||
|
stateStartTime = HAL_GetTick();
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
/* USER CODE END WHILE */
|
||||||
|
uint32_t now = HAL_GetTick();
|
||||||
|
uint32_t elapsed = now - stateStartTime;
|
||||||
|
|
||||||
|
switch(currentState)
|
||||||
|
{
|
||||||
|
case TrafficState::GREEN:
|
||||||
|
if (buttonPressedThisCycle)
|
||||||
|
pedestrianThisCycle = true;
|
||||||
|
|
||||||
|
/*
|
||||||
|
if (buttonPressedThisCycle)
|
||||||
|
{
|
||||||
|
currentState = TrafficState::YELLOW;
|
||||||
|
stateStartTime = now;
|
||||||
|
buttonPressedThisCycle = false;
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pedestrianNextCycle = false;
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
else if (elapsed >= DURATION_GREEN)
|
||||||
|
{
|
||||||
|
currentState = TrafficState::YELLOW;
|
||||||
|
stateStartTime = now;
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case TrafficState::YELLOW:
|
||||||
|
if (buttonPressedThisCycle || pedestrianNextCycle)
|
||||||
|
pedestrianThisCycle = true;
|
||||||
|
|
||||||
|
if (elapsed >= DURATION_YELLOW)
|
||||||
|
{
|
||||||
|
currentState = TrafficState::RED;
|
||||||
|
stateStartTime = now;
|
||||||
|
buttonPressedThisCycle = false; //TODO add pressed pedestrian button in yellow
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
// If Ped Button was pressed during GREEN or YELLOW, we need to enable WHITE this cycle
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case TrafficState::RED:
|
||||||
|
/*
|
||||||
|
if (pedestrianNextCycle)
|
||||||
|
{
|
||||||
|
HAL_GPIO_WritePin(GPIOD,White_Pin,GPIO_PIN_SET); // turn on Pedestrian LED
|
||||||
|
if (elapsed >= DURATION_RED_PED)
|
||||||
|
{
|
||||||
|
HAL_GPIO_WritePin(GPIOD,White_Pin,GPIO_PIN_RESET);
|
||||||
|
pedestrianNextCycle = false;
|
||||||
|
currentState = TrafficState::GREEN;
|
||||||
|
stateStartTime = now;
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
HAL_GPIO_WritePin(GPIOD,White_Pin,GPIO_PIN_RESET);
|
||||||
|
if(elapsed >= DURATION_RED_PED)
|
||||||
|
{
|
||||||
|
currentState = TrafficState::GREEN;
|
||||||
|
stateStartTime = now;
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (buttonPressedThisCycle)
|
||||||
|
pedestrianNextCycle = true;
|
||||||
|
|
||||||
|
if (pedestrianThisCycle) {
|
||||||
|
HAL_GPIO_WritePin()
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/* USER CODE BEGIN 3 */
|
||||||
|
}
|
||||||
|
/* USER CODE END 3 */
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief System Clock Configuration
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void SystemClock_Config(void)
|
||||||
|
{
|
||||||
|
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
|
||||||
|
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
|
||||||
|
|
||||||
|
/** Configure the main internal regulator output voltage
|
||||||
|
*/
|
||||||
|
__HAL_RCC_PWR_CLK_ENABLE();
|
||||||
|
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE3);
|
||||||
|
|
||||||
|
/** Initializes the RCC Oscillators according to the specified parameters
|
||||||
|
* in the RCC_OscInitTypeDef structure.
|
||||||
|
*/
|
||||||
|
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
|
||||||
|
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
|
||||||
|
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
|
||||||
|
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
||||||
|
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
|
||||||
|
RCC_OscInitStruct.PLL.PLLM = 8;
|
||||||
|
RCC_OscInitStruct.PLL.PLLN = 50;
|
||||||
|
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4;
|
||||||
|
RCC_OscInitStruct.PLL.PLLQ = 7;
|
||||||
|
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Initializes the CPU, AHB and APB buses clocks
|
||||||
|
*/
|
||||||
|
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|
||||||
|
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
|
||||||
|
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
|
||||||
|
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
|
||||||
|
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV8;
|
||||||
|
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV4;
|
||||||
|
|
||||||
|
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief GPIO Initialization Function
|
||||||
|
* @param None
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
static void MX_GPIO_Init(void)
|
||||||
|
{
|
||||||
|
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||||
|
/* USER CODE BEGIN MX_GPIO_Init_1 */
|
||||||
|
|
||||||
|
/* USER CODE END MX_GPIO_Init_1 */
|
||||||
|
|
||||||
|
/* GPIO Ports Clock Enable */
|
||||||
|
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||||
|
__HAL_RCC_GPIOD_CLK_ENABLE();
|
||||||
|
|
||||||
|
/*Configure GPIO pin Output Level */
|
||||||
|
HAL_GPIO_WritePin(GPIOD, White_Pin|Red_Pin|Yellow_Pin|Green_Pin, GPIO_PIN_RESET);
|
||||||
|
|
||||||
|
/*Configure GPIO pin : PedButton_Pin */
|
||||||
|
GPIO_InitStruct.Pin = PedButton_Pin;
|
||||||
|
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
|
||||||
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
|
HAL_GPIO_Init(PedButton_GPIO_Port, &GPIO_InitStruct);
|
||||||
|
|
||||||
|
/*Configure GPIO pins : White_Pin Red_Pin Yellow_Pin Green_Pin */
|
||||||
|
GPIO_InitStruct.Pin = White_Pin|Red_Pin|Yellow_Pin|Green_Pin;
|
||||||
|
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||||
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||||
|
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
|
||||||
|
|
||||||
|
/* EXTI interrupt init*/
|
||||||
|
HAL_NVIC_SetPriority(EXTI15_10_IRQn, 15, 0);
|
||||||
|
HAL_NVIC_EnableIRQ(EXTI15_10_IRQn);
|
||||||
|
|
||||||
|
/* USER CODE BEGIN MX_GPIO_Init_2 */
|
||||||
|
|
||||||
|
/* USER CODE END MX_GPIO_Init_2 */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* USER CODE BEGIN 4 */
|
||||||
|
void HAL_GPIO_EXTI_CallBack()
|
||||||
|
{
|
||||||
|
static uint32_t lastInterruptTime = 0;
|
||||||
|
uint32_t now = HAL_GetTick();
|
||||||
|
if(now - lastInterruptTime < 100)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
lastInterruptTime = now;
|
||||||
|
|
||||||
|
if (PedButton_Pin)
|
||||||
|
{
|
||||||
|
buttonPressedThisCycle = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void HAL_GPIO_EXTI_IRQHandler()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/* USER CODE END 4 */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function is executed in case of error occurrence.
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void Error_Handler(void)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN Error_Handler_Debug */
|
||||||
|
/* User can add his own implementation to report the HAL error return state */
|
||||||
|
__disable_irq();
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
/* USER CODE END Error_Handler_Debug */
|
||||||
|
}
|
||||||
|
#ifdef USE_FULL_ASSERT
|
||||||
|
/**
|
||||||
|
* @brief Reports the name of the source file and the source line number
|
||||||
|
* where the assert_param error has occurred.
|
||||||
|
* @param file: pointer to the source file name
|
||||||
|
* @param line: assert_param error line source number
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void assert_failed(uint8_t *file, uint32_t line)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN 6 */
|
||||||
|
/* User can add his own implementation to report the file name and line number,
|
||||||
|
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
|
||||||
|
/* USER CODE END 6 */
|
||||||
|
}
|
||||||
|
#endif /* USE_FULL_ASSERT */
|
||||||
|
|
||||||
@@ -0,0 +1,529 @@
|
|||||||
|
/* USER CODE BEGIN Header */
|
||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
* @file : main.c
|
||||||
|
* @brief : Main program body
|
||||||
|
******************************************************************************
|
||||||
|
* @attention
|
||||||
|
*
|
||||||
|
* Copyright (c) 2025 STMicroelectronics.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This software is licensed under terms that can be found in the LICENSE file
|
||||||
|
* in the root directory of this software component.
|
||||||
|
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||||
|
*
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
/* USER CODE END Header */
|
||||||
|
/* Includes ------------------------------------------------------------------*/
|
||||||
|
#include "main.h"
|
||||||
|
#include "cmsis_os.h"
|
||||||
|
|
||||||
|
/* Private includes ----------------------------------------------------------*/
|
||||||
|
/* USER CODE BEGIN Includes */
|
||||||
|
#include "breadboard.h"
|
||||||
|
#include <stdbool.h>
|
||||||
|
/* USER CODE END Includes */
|
||||||
|
|
||||||
|
/* Private typedef -----------------------------------------------------------*/
|
||||||
|
/* USER CODE BEGIN PTD */
|
||||||
|
|
||||||
|
/* USER CODE END PTD */
|
||||||
|
|
||||||
|
/* Private define ------------------------------------------------------------*/
|
||||||
|
/* USER CODE BEGIN PD */
|
||||||
|
|
||||||
|
/* USER CODE END PD */
|
||||||
|
|
||||||
|
/* Private macro -------------------------------------------------------------*/
|
||||||
|
/* USER CODE BEGIN PM */
|
||||||
|
|
||||||
|
/* USER CODE END PM */
|
||||||
|
|
||||||
|
/* Private variables ---------------------------------------------------------*/
|
||||||
|
CRC_HandleTypeDef hcrc;
|
||||||
|
|
||||||
|
DMA2D_HandleTypeDef hdma2d;
|
||||||
|
|
||||||
|
TIM_HandleTypeDef htim1;
|
||||||
|
|
||||||
|
osThreadId defaultTaskHandle;
|
||||||
|
/* USER CODE BEGIN PV */
|
||||||
|
|
||||||
|
/* USER CODE END PV */
|
||||||
|
|
||||||
|
/* Private function prototypes -----------------------------------------------*/
|
||||||
|
void SystemClock_Config(void);
|
||||||
|
static void MX_GPIO_Init(void);
|
||||||
|
static void MX_CRC_Init(void);
|
||||||
|
static void MX_DMA2D_Init(void);
|
||||||
|
static void MX_TIM1_Init(void);
|
||||||
|
void StartDefaultTask(void const * argument);
|
||||||
|
|
||||||
|
void SetTrafficLights(TrafficSate s);
|
||||||
|
|
||||||
|
/* USER CODE BEGIN PFP */
|
||||||
|
|
||||||
|
/* USER CODE END PFP */
|
||||||
|
|
||||||
|
/* Private user code ---------------------------------------------------------*/
|
||||||
|
|
||||||
|
/* USER CODE BEGIN 0 */
|
||||||
|
|
||||||
|
enum class TrafficState {
|
||||||
|
GREEN,
|
||||||
|
YELLOW,
|
||||||
|
RED
|
||||||
|
};
|
||||||
|
|
||||||
|
TrafficState currentState = TrafficState::GREEN;
|
||||||
|
uint32_t stateStartTime = 0; // HAL_GetTick() at the start of this state
|
||||||
|
bool buttonPressed = false;
|
||||||
|
bool pedestrianNextCycle = false;
|
||||||
|
|
||||||
|
const uint32_t DURATION_GREEN = 5000;
|
||||||
|
const uint32_t DURATION_YELLOW = 3000;
|
||||||
|
const uint32_t DURATION_RED = 5000;
|
||||||
|
const uint32_t DURATION_RED_PED = 7000;
|
||||||
|
|
||||||
|
/* USER CODE END 0 */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief The application entry point.
|
||||||
|
* @retval int
|
||||||
|
*/
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* USER CODE BEGIN 1 */
|
||||||
|
|
||||||
|
/* USER CODE END 1 */
|
||||||
|
|
||||||
|
/* MCU Configuration--------------------------------------------------------*/
|
||||||
|
|
||||||
|
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
|
||||||
|
HAL_Init();
|
||||||
|
|
||||||
|
/* USER CODE BEGIN Init */
|
||||||
|
|
||||||
|
/* USER CODE END Init */
|
||||||
|
|
||||||
|
/* Configure the system clock */
|
||||||
|
SystemClock_Config();
|
||||||
|
|
||||||
|
/* USER CODE BEGIN SysInit */
|
||||||
|
|
||||||
|
stateStartTime = HAL_GetTick();
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
|
||||||
|
/* USER CODE END SysInit */
|
||||||
|
|
||||||
|
/* Initialize all configured peripherals */
|
||||||
|
MX_GPIO_Init();
|
||||||
|
MX_CRC_Init();
|
||||||
|
MX_DMA2D_Init();
|
||||||
|
MX_TIM1_Init();
|
||||||
|
/* USER CODE BEGIN 2 */
|
||||||
|
|
||||||
|
/* USER CODE END 2 */
|
||||||
|
|
||||||
|
/* USER CODE BEGIN RTOS_MUTEX */
|
||||||
|
/* add mutexes, ... */
|
||||||
|
/* USER CODE END RTOS_MUTEX */
|
||||||
|
|
||||||
|
/* USER CODE BEGIN RTOS_SEMAPHORES */
|
||||||
|
/* add semaphores, ... */
|
||||||
|
/* USER CODE END RTOS_SEMAPHORES */
|
||||||
|
|
||||||
|
/* USER CODE BEGIN RTOS_TIMERS */
|
||||||
|
/* start timers, add new ones, ... */
|
||||||
|
/* USER CODE END RTOS_TIMERS */
|
||||||
|
|
||||||
|
/* USER CODE BEGIN RTOS_QUEUES */
|
||||||
|
/* add queues, ... */
|
||||||
|
/* USER CODE END RTOS_QUEUES */
|
||||||
|
|
||||||
|
/* Create the thread(s) */
|
||||||
|
/* definition and creation of defaultTask */
|
||||||
|
//osThreadDef(defaultTask, StartDefaultTask, osPriorityNormal, 0, 4096);
|
||||||
|
//defaultTaskHandle = osThreadCreate(osThread(defaultTask), NULL);
|
||||||
|
|
||||||
|
/* USER CODE BEGIN RTOS_THREADS */
|
||||||
|
/* add threads, ... */
|
||||||
|
/* USER CODE END RTOS_THREADS */
|
||||||
|
|
||||||
|
/* Start scheduler */
|
||||||
|
osKernelStart();
|
||||||
|
|
||||||
|
/* We should never get here as control is now taken by the scheduler */
|
||||||
|
|
||||||
|
/* Infinite loop */
|
||||||
|
/* USER CODE BEGIN WHILE */
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
uint32_t now = HAL_GetTick();
|
||||||
|
uint32_t elapsed = now - stateStartTime;
|
||||||
|
|
||||||
|
/*
|
||||||
|
switch(currentState)
|
||||||
|
{
|
||||||
|
case TrafficState::GREEN:
|
||||||
|
if (elapsed >= DURATION_GREEN) {
|
||||||
|
currentState = TrafficState::YELLOW;
|
||||||
|
stateStartTime = now;
|
||||||
|
buttonPressed = false; // reset the button-flag for the new cycle
|
||||||
|
} else if (buttonPressed) {
|
||||||
|
//idk
|
||||||
|
buttonPressed = true;
|
||||||
|
currentState = TrafficState::YELLOW;
|
||||||
|
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case TrafficState::YELLOW:
|
||||||
|
break;
|
||||||
|
case TrafficState::RED:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
switch(currentState)
|
||||||
|
{
|
||||||
|
case TrafficState::GREEN:
|
||||||
|
if (butonPressedThisCycle)
|
||||||
|
{
|
||||||
|
currentState = TrafficState::YELLOW;
|
||||||
|
stateStartTime = now;
|
||||||
|
buttonPressedThisCycle = false;
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
} else if (elapsed >= DURATION_GREEN)
|
||||||
|
{
|
||||||
|
buttonPressedThisCycle = true;
|
||||||
|
currentState = TrafficState::YELLOW;
|
||||||
|
stateStartTime = now;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case TrafficState::YELLOW:
|
||||||
|
if (elapsed >= DURATION_YELLOW)
|
||||||
|
{
|
||||||
|
currentState = TrafficState::RED;
|
||||||
|
stateStartTime = now;
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
// if ped button was pressed during GREEN or YELLOW,
|
||||||
|
// we need to enable WHITE ...
|
||||||
|
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case TrafficState::RED:
|
||||||
|
if (pedestrianNextCycle)
|
||||||
|
{
|
||||||
|
HAL_GPIO_WritePin(White_GPIO_Port, White_Pin, GPIO_PIN_SET);
|
||||||
|
if (elapsed >= DURATION_RED_PED)
|
||||||
|
{
|
||||||
|
HAL_GPIO_WritePin(White_GPIO_Port, White_Pin, GPIO_PIN_RESET);
|
||||||
|
pedestrianNextCycle = false;
|
||||||
|
currentState = TrafficState::GREEN;
|
||||||
|
stateStartTime = now;
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/* USER CODE END WHILE */
|
||||||
|
|
||||||
|
/* USER CODE BEGIN 3 */
|
||||||
|
}
|
||||||
|
/* USER CODE END 3 */
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief System Clock Configuration
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void SystemClock_Config(void)
|
||||||
|
{
|
||||||
|
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
|
||||||
|
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
|
||||||
|
|
||||||
|
/** Configure the main internal regulator output voltage
|
||||||
|
*/
|
||||||
|
__HAL_RCC_PWR_CLK_ENABLE();
|
||||||
|
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE3);
|
||||||
|
|
||||||
|
/** Initializes the RCC Oscillators according to the specified parameters
|
||||||
|
* in the RCC_OscInitTypeDef structure.
|
||||||
|
*/
|
||||||
|
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
|
||||||
|
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
|
||||||
|
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
|
||||||
|
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
||||||
|
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
|
||||||
|
RCC_OscInitStruct.PLL.PLLM = 8;
|
||||||
|
RCC_OscInitStruct.PLL.PLLN = 72;
|
||||||
|
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
|
||||||
|
RCC_OscInitStruct.PLL.PLLQ = 3;
|
||||||
|
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Initializes the CPU, AHB and APB buses clocks
|
||||||
|
*/
|
||||||
|
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|
||||||
|
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
|
||||||
|
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
|
||||||
|
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
|
||||||
|
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
|
||||||
|
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
|
||||||
|
|
||||||
|
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief CRC Initialization Function
|
||||||
|
* @param None
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
static void MX_CRC_Init(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* USER CODE BEGIN CRC_Init 0 */
|
||||||
|
|
||||||
|
/* USER CODE END CRC_Init 0 */
|
||||||
|
|
||||||
|
/* USER CODE BEGIN CRC_Init 1 */
|
||||||
|
|
||||||
|
/* USER CODE END CRC_Init 1 */
|
||||||
|
hcrc.Instance = CRC;
|
||||||
|
if (HAL_CRC_Init(&hcrc) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
/* USER CODE BEGIN CRC_Init 2 */
|
||||||
|
|
||||||
|
/* USER CODE END CRC_Init 2 */
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief DMA2D Initialization Function
|
||||||
|
* @param None
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
static void MX_DMA2D_Init(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* USER CODE BEGIN DMA2D_Init 0 */
|
||||||
|
|
||||||
|
/* USER CODE END DMA2D_Init 0 */
|
||||||
|
|
||||||
|
/* USER CODE BEGIN DMA2D_Init 1 */
|
||||||
|
|
||||||
|
/* USER CODE END DMA2D_Init 1 */
|
||||||
|
hdma2d.Instance = DMA2D;
|
||||||
|
hdma2d.Init.Mode = DMA2D_M2M;
|
||||||
|
hdma2d.Init.ColorMode = DMA2D_OUTPUT_ARGB8888;
|
||||||
|
hdma2d.Init.OutputOffset = 0;
|
||||||
|
hdma2d.LayerCfg[1].InputOffset = 0;
|
||||||
|
hdma2d.LayerCfg[1].InputColorMode = DMA2D_INPUT_ARGB8888;
|
||||||
|
hdma2d.LayerCfg[1].AlphaMode = DMA2D_NO_MODIF_ALPHA;
|
||||||
|
hdma2d.LayerCfg[1].InputAlpha = 0;
|
||||||
|
if (HAL_DMA2D_Init(&hdma2d) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
if (HAL_DMA2D_ConfigLayer(&hdma2d, 1) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
/* USER CODE BEGIN DMA2D_Init 2 */
|
||||||
|
|
||||||
|
/* USER CODE END DMA2D_Init 2 */
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief TIM1 Initialization Function
|
||||||
|
* @param None
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
static void MX_TIM1_Init(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* USER CODE BEGIN TIM1_Init 0 */
|
||||||
|
|
||||||
|
/* USER CODE END TIM1_Init 0 */
|
||||||
|
|
||||||
|
TIM_ClockConfigTypeDef sClockSourceConfig = {0};
|
||||||
|
TIM_MasterConfigTypeDef sMasterConfig = {0};
|
||||||
|
|
||||||
|
/* USER CODE BEGIN TIM1_Init 1 */
|
||||||
|
|
||||||
|
/* USER CODE END TIM1_Init 1 */
|
||||||
|
htim1.Instance = TIM1;
|
||||||
|
htim1.Init.Prescaler = 0;
|
||||||
|
htim1.Init.CounterMode = TIM_COUNTERMODE_UP;
|
||||||
|
htim1.Init.Period = 65535;
|
||||||
|
htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
||||||
|
htim1.Init.RepetitionCounter = 0;
|
||||||
|
htim1.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
|
||||||
|
if (HAL_TIM_Base_Init(&htim1) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
|
||||||
|
if (HAL_TIM_ConfigClockSource(&htim1, &sClockSourceConfig) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
|
||||||
|
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
|
||||||
|
if (HAL_TIMEx_MasterConfigSynchronization(&htim1, &sMasterConfig) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
/* USER CODE BEGIN TIM1_Init 2 */
|
||||||
|
|
||||||
|
/* USER CODE END TIM1_Init 2 */
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief GPIO Initialization Function
|
||||||
|
* @param None
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
static void MX_GPIO_Init(void)
|
||||||
|
{
|
||||||
|
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||||
|
/* USER CODE BEGIN MX_GPIO_Init_1 */
|
||||||
|
|
||||||
|
/* USER CODE END MX_GPIO_Init_1 */
|
||||||
|
|
||||||
|
/* GPIO Ports Clock Enable */
|
||||||
|
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||||
|
__HAL_RCC_GPIOD_CLK_ENABLE();
|
||||||
|
|
||||||
|
/*Configure GPIO pin Output Level */
|
||||||
|
HAL_GPIO_WritePin(GPIOD, White_Pin|Red_Pin|Yellow_Pin|Green_Pin, GPIO_PIN_RESET);
|
||||||
|
|
||||||
|
/*Configure GPIO pin : PedButton_Pin */
|
||||||
|
GPIO_InitStruct.Pin = PedButton_Pin;
|
||||||
|
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
|
||||||
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
|
HAL_GPIO_Init(PedButton_GPIO_Port, &GPIO_InitStruct);
|
||||||
|
|
||||||
|
/*Configure GPIO pins : White_Pin Red_Pin Yellow_Pin Green_Pin */
|
||||||
|
GPIO_InitStruct.Pin = White_Pin|Red_Pin|Yellow_Pin|Green_Pin;
|
||||||
|
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||||
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||||
|
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
|
||||||
|
|
||||||
|
/* EXTI interrupt init*/
|
||||||
|
HAL_NVIC_SetPriority(EXTI15_10_IRQn, 15, 0);
|
||||||
|
HAL_NVIC_EnableIRQ(EXTI15_10_IRQn);
|
||||||
|
|
||||||
|
/* USER CODE BEGIN MX_GPIO_Init_2 */
|
||||||
|
|
||||||
|
/* USER CODE END MX_GPIO_Init_2 */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* USER CODE BEGIN 4 */
|
||||||
|
|
||||||
|
void HAL_GPIO_EXTI_CallBack(uint16_t GPIO_Pin)
|
||||||
|
{
|
||||||
|
static uint32_t lastInterruptTime = 0;
|
||||||
|
uint32_t now = HAL_GetTick();
|
||||||
|
if (now - lastInterruptTime < 100) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
lastInterruptTime = now;
|
||||||
|
|
||||||
|
bool buttonPressedThisCycle = false; // temporary, get rid of this
|
||||||
|
|
||||||
|
if (buttonPressed) { // buttonPressedHere?
|
||||||
|
buttonPressedThisCycle = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* USER CODE END 4 */
|
||||||
|
|
||||||
|
/* USER CODE BEGIN Header_StartDefaultTask */
|
||||||
|
/**
|
||||||
|
* @brief Function implementing the defaultTask thread.
|
||||||
|
* @param argument: Not used
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
/* USER CODE END Header_StartDefaultTask */
|
||||||
|
void StartDefaultTask(void const * argument)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN 5 */
|
||||||
|
/* Infinite loop */
|
||||||
|
for(;;)
|
||||||
|
{
|
||||||
|
osDelay(1);
|
||||||
|
}
|
||||||
|
/* USER CODE END 5 */
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Period elapsed callback in non blocking mode
|
||||||
|
* @note This function is called when TIM6 interrupt took place, inside
|
||||||
|
* HAL_TIM_IRQHandler(). It makes a direct call to HAL_IncTick() to increment
|
||||||
|
* a global variable "uwTick" used as application time base.
|
||||||
|
* @param htim : TIM handle
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN Callback 0 */
|
||||||
|
|
||||||
|
/* USER CODE END Callback 0 */
|
||||||
|
if (htim->Instance == TIM6)
|
||||||
|
{
|
||||||
|
HAL_IncTick();
|
||||||
|
}
|
||||||
|
/* USER CODE BEGIN Callback 1 */
|
||||||
|
|
||||||
|
/* USER CODE END Callback 1 */
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function is executed in case of error occurrence.
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void Error_Handler(void)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN Error_Handler_Debug */
|
||||||
|
/* User can add his own implementation to report the HAL error return state */
|
||||||
|
__disable_irq();
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
/* USER CODE END Error_Handler_Debug */
|
||||||
|
}
|
||||||
|
#ifdef USE_FULL_ASSERT
|
||||||
|
/**
|
||||||
|
* @brief Reports the name of the source file and the source line number
|
||||||
|
* where the assert_param error has occurred.
|
||||||
|
* @param file: pointer to the source file name
|
||||||
|
* @param line: assert_param error line source number
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void assert_failed(uint8_t *file, uint32_t line)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN 6 */
|
||||||
|
/* User can add his own implementation to report the file name and line number,
|
||||||
|
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
|
||||||
|
/* USER CODE END 6 */
|
||||||
|
}
|
||||||
|
#endif /* USE_FULL_ASSERT */
|
||||||
@@ -0,0 +1,340 @@
|
|||||||
|
/* USER CODE BEGIN Header */
|
||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
* @file : main.c
|
||||||
|
* @brief : Main program body
|
||||||
|
******************************************************************************
|
||||||
|
* @attention
|
||||||
|
*
|
||||||
|
* Copyright (c) 2025 STMicroelectronics.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This software is licensed under terms that can be found in the LICENSE file
|
||||||
|
* in the root directory of this software component.
|
||||||
|
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||||
|
*
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
// Feeling sneaky.
|
||||||
|
extern "C" {
|
||||||
|
/* USER CODE END Header */
|
||||||
|
/* Includes ------------------------------------------------------------------*/
|
||||||
|
#include "main.h"
|
||||||
|
|
||||||
|
/* Private function prototypes -----------------------------------------------*/
|
||||||
|
void SystemClock_Config(void);
|
||||||
|
static void MX_GPIO_Init(void);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Private user code ---------------------------------------------------------*/
|
||||||
|
/* USER CODE BEGIN 0 */
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
enum class TrafficState { GREEN, YELLOW, RED };
|
||||||
|
void SetTrafficLights(TrafficState s);
|
||||||
|
|
||||||
|
TrafficState currentState = TrafficState::GREEN;
|
||||||
|
uint32_t stateStartTime = 0; //HAL_GetTick() at the start of this state
|
||||||
|
bool buttonPressedThisCycle = false;
|
||||||
|
bool pedestrianNextCycle = false;
|
||||||
|
bool pedestrianThisCycle = false;
|
||||||
|
|
||||||
|
const uint32_t DURATION_GREEN = 5000;
|
||||||
|
const uint32_t DURATION_YELLOW = 3000;
|
||||||
|
const uint32_t DURATION_RED_NOPED = 5000;
|
||||||
|
const uint32_t DURATION_RED_PED = 7000;
|
||||||
|
|
||||||
|
/* USER CODE END 0 */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief The application entry point.
|
||||||
|
* @retval int
|
||||||
|
*/
|
||||||
|
|
||||||
|
void SetTrafficLights(TrafficState s)
|
||||||
|
{
|
||||||
|
// reset all
|
||||||
|
HAL_GPIO_WritePin(GPIOD, Green_Pin, GPIO_PIN_RESET);
|
||||||
|
HAL_GPIO_WritePin(GPIOD, Yellow_Pin, GPIO_PIN_RESET);
|
||||||
|
HAL_GPIO_WritePin(GPIOD, Red_Pin, GPIO_PIN_SET);
|
||||||
|
|
||||||
|
switch (s)
|
||||||
|
{
|
||||||
|
case TrafficState::GREEN :
|
||||||
|
HAL_GPIO_WritePin(GPIOD, Green_Pin, GPIO_PIN_SET);
|
||||||
|
break;
|
||||||
|
case TrafficState::YELLOW :
|
||||||
|
HAL_GPIO_WritePin(GPIOD, Yellow_Pin, GPIO_PIN_SET);
|
||||||
|
break;
|
||||||
|
case TrafficState::RED:
|
||||||
|
HAL_GPIO_WritePin(GPIOD, Red_Pin, GPIO_PIN_SET);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
HAL_Init();
|
||||||
|
|
||||||
|
/* USER CODE BEGIN Init */
|
||||||
|
|
||||||
|
/* USER CODE END Init */
|
||||||
|
|
||||||
|
/* Configure the system clock */
|
||||||
|
SystemClock_Config();
|
||||||
|
MX_GPIO_Init();
|
||||||
|
|
||||||
|
stateStartTime = HAL_GetTick();
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
/* USER CODE END WHILE */
|
||||||
|
uint32_t now = HAL_GetTick();
|
||||||
|
uint32_t elapsed = now - stateStartTime;
|
||||||
|
|
||||||
|
switch(currentState)
|
||||||
|
{
|
||||||
|
case TrafficState::GREEN:
|
||||||
|
if (buttonPressedThisCycle)
|
||||||
|
pedestrianThisCycle = true;
|
||||||
|
|
||||||
|
/*
|
||||||
|
if (buttonPressedThisCycle)
|
||||||
|
{
|
||||||
|
currentState = TrafficState::YELLOW;
|
||||||
|
stateStartTime = now;
|
||||||
|
buttonPressedThisCycle = false;
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pedestrianNextCycle = false;
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
else if (elapsed >= DURATION_GREEN)
|
||||||
|
{
|
||||||
|
currentState = TrafficState::YELLOW;
|
||||||
|
stateStartTime = now;
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case TrafficState::YELLOW:
|
||||||
|
if (buttonPressedThisCycle || pedestrianNextCycle)
|
||||||
|
pedestrianThisCycle = true;
|
||||||
|
|
||||||
|
if (elapsed >= DURATION_YELLOW)
|
||||||
|
{
|
||||||
|
currentState = TrafficState::RED;
|
||||||
|
stateStartTime = now;
|
||||||
|
buttonPressedThisCycle = false; //TODO add pressed pedestrian button in yellow
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
// If Ped Button was pressed during GREEN or YELLOW, we need to enable WHITE this cycle
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case TrafficState::RED:
|
||||||
|
/*
|
||||||
|
if (pedestrianNextCycle)
|
||||||
|
{
|
||||||
|
HAL_GPIO_WritePin(GPIOD,White_Pin,GPIO_PIN_SET); // turn on Pedestrian LED
|
||||||
|
if (elapsed >= DURATION_RED_PED)
|
||||||
|
{
|
||||||
|
HAL_GPIO_WritePin(GPIOD,White_Pin,GPIO_PIN_RESET);
|
||||||
|
pedestrianNextCycle = false;
|
||||||
|
currentState = TrafficState::GREEN;
|
||||||
|
stateStartTime = now;
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
HAL_GPIO_WritePin(GPIOD,White_Pin,GPIO_PIN_RESET);
|
||||||
|
if(elapsed >= DURATION_RED_PED)
|
||||||
|
{
|
||||||
|
currentState = TrafficState::GREEN;
|
||||||
|
stateStartTime = now;
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (buttonPressedThisCycle)
|
||||||
|
pedestrianNextCycle = true;
|
||||||
|
|
||||||
|
if (pedestrianThisCycle) {
|
||||||
|
HAL_GPIO_WritePin(White_GPIO_Port, White_Pin, GPIO_PIN_RESET);
|
||||||
|
pedestrianThisCycle = false;
|
||||||
|
pedestrianNextcycle = false;
|
||||||
|
currentState = TrafficState::GREEN;
|
||||||
|
stateStartTime = now;
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
buttonPressedThisCycle = false;
|
||||||
|
} else {
|
||||||
|
HAL_GPIO_WritePin(White_GPIO_Port, White_Pin, GPIO_PIN_RESET);
|
||||||
|
if (elapsed >= DURATION_RED_NOPED)
|
||||||
|
{
|
||||||
|
currentState = TrafficState::GREEN;
|
||||||
|
stateStartTime = now;
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
buttonPressedThisCycle = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/* USER CODE BEGIN 3 */
|
||||||
|
}
|
||||||
|
/* USER CODE END 3 */
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief System Clock Configuration
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
|
||||||
|
void SystemClock_Config(void)
|
||||||
|
{
|
||||||
|
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
|
||||||
|
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
|
||||||
|
|
||||||
|
/** Configure the main internal regulator output voltage
|
||||||
|
*/
|
||||||
|
__HAL_RCC_PWR_CLK_ENABLE();
|
||||||
|
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE3);
|
||||||
|
|
||||||
|
/** Initializes the RCC Oscillators according to the specified parameters
|
||||||
|
* in the RCC_OscInitTypeDef structure.
|
||||||
|
*/
|
||||||
|
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
|
||||||
|
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
|
||||||
|
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
|
||||||
|
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
||||||
|
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
|
||||||
|
RCC_OscInitStruct.PLL.PLLM = 8;
|
||||||
|
RCC_OscInitStruct.PLL.PLLN = 50;
|
||||||
|
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4;
|
||||||
|
RCC_OscInitStruct.PLL.PLLQ = 7;
|
||||||
|
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Initializes the CPU, AHB and APB buses clocks
|
||||||
|
*/
|
||||||
|
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|
||||||
|
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
|
||||||
|
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
|
||||||
|
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
|
||||||
|
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV8;
|
||||||
|
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV4;
|
||||||
|
|
||||||
|
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief GPIO Initialization Function
|
||||||
|
* @param None
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
static void MX_GPIO_Init(void)
|
||||||
|
{
|
||||||
|
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||||
|
/* USER CODE BEGIN MX_GPIO_Init_1 */
|
||||||
|
|
||||||
|
/* USER CODE END MX_GPIO_Init_1 */
|
||||||
|
|
||||||
|
/* GPIO Ports Clock Enable */
|
||||||
|
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||||
|
__HAL_RCC_GPIOD_CLK_ENABLE();
|
||||||
|
|
||||||
|
/*Configure GPIO pin Output Level */
|
||||||
|
HAL_GPIO_WritePin(GPIOD, White_Pin|Red_Pin|Yellow_Pin|Green_Pin, GPIO_PIN_RESET);
|
||||||
|
|
||||||
|
/*Configure GPIO pin : PedButton_Pin */
|
||||||
|
GPIO_InitStruct.Pin = PedButton_Pin;
|
||||||
|
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
|
||||||
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
|
HAL_GPIO_Init(PedButton_GPIO_Port, &GPIO_InitStruct);
|
||||||
|
|
||||||
|
/*Configure GPIO pins : White_Pin Red_Pin Yellow_Pin Green_Pin */
|
||||||
|
GPIO_InitStruct.Pin = White_Pin|Red_Pin|Yellow_Pin|Green_Pin;
|
||||||
|
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||||
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||||
|
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
|
||||||
|
|
||||||
|
/* EXTI interrupt init*/
|
||||||
|
HAL_NVIC_SetPriority(EXTI15_10_IRQn, 15, 0);
|
||||||
|
HAL_NVIC_EnableIRQ(EXTI15_10_IRQn);
|
||||||
|
|
||||||
|
/* USER CODE BEGIN MX_GPIO_Init_2 */
|
||||||
|
|
||||||
|
/* USER CODE END MX_GPIO_Init_2 */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* USER CODE BEGIN 4 */
|
||||||
|
|
||||||
|
extern "C" void EXTI15_10_IRQHandler()
|
||||||
|
{
|
||||||
|
HAL_GPIO_EXTI_IRQHandler(PedButton_Pin);
|
||||||
|
}
|
||||||
|
|
||||||
|
void HAL_GPIO_EXTI_CallBack(uint16_t GPIO_Pin)
|
||||||
|
{
|
||||||
|
static uint32_t lastInterruptTime = 0;
|
||||||
|
uint32_t now = HAL_GetTick();
|
||||||
|
|
||||||
|
// software debounce
|
||||||
|
if (now - lastInterruptTime < 100)
|
||||||
|
return;
|
||||||
|
|
||||||
|
lastInterruptTime = now;
|
||||||
|
|
||||||
|
if (GPIO_Pin == PedButton_Pin)
|
||||||
|
buttonPressedThisCycle = true;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void HAL_GPIO_EXTI_IRQHandler()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/* USER CODE END 4 */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function is executed in case of error occurrence.
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void Error_Handler(void)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN Error_Handler_Debug */
|
||||||
|
/* User can add his own implementation to report the HAL error return state */
|
||||||
|
__disable_irq();
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
/* USER CODE END Error_Handler_Debug */
|
||||||
|
}
|
||||||
|
#ifdef USE_FULL_ASSERT
|
||||||
|
/**
|
||||||
|
* @brief Reports the name of the source file and the source line number
|
||||||
|
* where the assert_param error has occurred.
|
||||||
|
* @param file: pointer to the source file name
|
||||||
|
* @param line: assert_param error line source number
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void assert_failed(uint8_t *file, uint32_t line)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN 6 */
|
||||||
|
/* User can add his own implementation to report the file name and line number,
|
||||||
|
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
|
||||||
|
/* USER CODE END 6 */
|
||||||
|
}
|
||||||
|
#endif /* USE_FULL_ASSERT */
|
||||||
|
|
||||||
@@ -0,0 +1,320 @@
|
|||||||
|
/* USER CODE BEGIN Header */
|
||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
* @file : main.c
|
||||||
|
* @brief : Main program body
|
||||||
|
******************************************************************************
|
||||||
|
* @attention
|
||||||
|
*
|
||||||
|
* Copyright (c) 2025 STMicroelectronics.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This software is licensed under terms that can be found in the LICENSE file
|
||||||
|
* in the root directory of this software component.
|
||||||
|
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||||
|
*
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
// Feeling sneaky.
|
||||||
|
extern "C" {
|
||||||
|
/* USER CODE END Header */
|
||||||
|
/* Includes ------------------------------------------------------------------*/
|
||||||
|
#include "main.h"
|
||||||
|
|
||||||
|
/* Private function prototypes -----------------------------------------------*/
|
||||||
|
void SystemClock_Config(void);
|
||||||
|
static void MX_GPIO_Init(void);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Private user code ---------------------------------------------------------*/
|
||||||
|
/* USER CODE BEGIN 0 */
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
enum class TrafficState { GREEN, YELLOW, RED };
|
||||||
|
void SetTrafficLights(TrafficState s);
|
||||||
|
|
||||||
|
TrafficState currentState = TrafficState::GREEN;
|
||||||
|
uint32_t stateStartTime = 0; //HAL_GetTick() at the start of this state
|
||||||
|
bool buttonPressedThisCycle = false;
|
||||||
|
bool pedestrianNextCycle = false;
|
||||||
|
bool pedestrianThisCycle = false;
|
||||||
|
|
||||||
|
const uint32_t DURATION_GREEN = 5000;
|
||||||
|
const uint32_t DURATION_YELLOW = 3000;
|
||||||
|
const uint32_t DURATION_RED_NOPED = 5000;
|
||||||
|
const uint32_t DURATION_RED_PED = 7000;
|
||||||
|
|
||||||
|
/* USER CODE END 0 */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief The application entry point.
|
||||||
|
* @retval int
|
||||||
|
*/
|
||||||
|
|
||||||
|
void SetTrafficLights(TrafficState s)
|
||||||
|
{
|
||||||
|
// reset all
|
||||||
|
HAL_GPIO_WritePin(GPIOD, Green_Pin, GPIO_PIN_RESET);
|
||||||
|
HAL_GPIO_WritePin(GPIOD, Yellow_Pin, GPIO_PIN_RESET);
|
||||||
|
HAL_GPIO_WritePin(GPIOD, Red_Pin, GPIO_PIN_SET);
|
||||||
|
|
||||||
|
switch (s)
|
||||||
|
{
|
||||||
|
case TrafficState::GREEN :
|
||||||
|
HAL_GPIO_WritePin(GPIOD, Green_Pin, GPIO_PIN_SET);
|
||||||
|
break;
|
||||||
|
case TrafficState::YELLOW :
|
||||||
|
HAL_GPIO_WritePin(GPIOD, Yellow_Pin, GPIO_PIN_SET);
|
||||||
|
break;
|
||||||
|
case TrafficState::RED:
|
||||||
|
HAL_GPIO_WritePin(GPIOD, Red_Pin, GPIO_PIN_SET);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
HAL_Init();
|
||||||
|
|
||||||
|
/* USER CODE BEGIN Init */
|
||||||
|
|
||||||
|
/* USER CODE END Init */
|
||||||
|
|
||||||
|
/* Configure the system clock */
|
||||||
|
SystemClock_Config();
|
||||||
|
MX_GPIO_Init();
|
||||||
|
|
||||||
|
stateStartTime = HAL_GetTick();
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
/* USER CODE END WHILE */
|
||||||
|
uint32_t now = HAL_GetTick();
|
||||||
|
uint32_t elapsed = now - stateStartTime;
|
||||||
|
|
||||||
|
switch(currentState)
|
||||||
|
{
|
||||||
|
case TrafficState::GREEN:
|
||||||
|
if (buttonPressedThisCycle)
|
||||||
|
pedestrianThisCycle = true;
|
||||||
|
|
||||||
|
/*
|
||||||
|
if (buttonPressedThisCycle)
|
||||||
|
{
|
||||||
|
currentState = TrafficState::YELLOW;
|
||||||
|
stateStartTime = now;
|
||||||
|
buttonPressedThisCycle = false;
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pedestrianNextCycle = false;
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
else if (elapsed >= DURATION_GREEN)
|
||||||
|
{
|
||||||
|
currentState = TrafficState::YELLOW;
|
||||||
|
stateStartTime = now;
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case TrafficState::YELLOW:
|
||||||
|
if (buttonPressedThisCycle || pedestrianNextCycle)
|
||||||
|
pedestrianThisCycle = true;
|
||||||
|
|
||||||
|
if (elapsed >= DURATION_YELLOW)
|
||||||
|
{
|
||||||
|
currentState = TrafficState::RED;
|
||||||
|
stateStartTime = now;
|
||||||
|
buttonPressedThisCycle = false; //TODO add pressed pedestrian button in yellow
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
// If Ped Button was pressed during GREEN or YELLOW, we need to enable WHITE this cycle
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case TrafficState::RED:
|
||||||
|
/*
|
||||||
|
if (pedestrianNextCycle)
|
||||||
|
{
|
||||||
|
HAL_GPIO_WritePin(GPIOD,White_Pin,GPIO_PIN_SET); // turn on Pedestrian LED
|
||||||
|
if (elapsed >= DURATION_RED_PED)
|
||||||
|
{
|
||||||
|
HAL_GPIO_WritePin(GPIOD,White_Pin,GPIO_PIN_RESET);
|
||||||
|
pedestrianNextCycle = false;
|
||||||
|
currentState = TrafficState::GREEN;
|
||||||
|
stateStartTime = now;
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
HAL_GPIO_WritePin(GPIOD,White_Pin,GPIO_PIN_RESET);
|
||||||
|
if(elapsed >= DURATION_RED_PED)
|
||||||
|
{
|
||||||
|
currentState = TrafficState::GREEN;
|
||||||
|
stateStartTime = now;
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (buttonPressedThisCycle)
|
||||||
|
{
|
||||||
|
pedestrianNextCycle = true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/* USER CODE BEGIN 3 */
|
||||||
|
}
|
||||||
|
/* USER CODE END 3 */
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief System Clock Configuration
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void SystemClock_Config(void)
|
||||||
|
{
|
||||||
|
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
|
||||||
|
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
|
||||||
|
|
||||||
|
/** Configure the main internal regulator output voltage
|
||||||
|
*/
|
||||||
|
__HAL_RCC_PWR_CLK_ENABLE();
|
||||||
|
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE3);
|
||||||
|
|
||||||
|
/** Initializes the RCC Oscillators according to the specified parameters
|
||||||
|
* in the RCC_OscInitTypeDef structure.
|
||||||
|
*/
|
||||||
|
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
|
||||||
|
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
|
||||||
|
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
|
||||||
|
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
||||||
|
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
|
||||||
|
RCC_OscInitStruct.PLL.PLLM = 8;
|
||||||
|
RCC_OscInitStruct.PLL.PLLN = 50;
|
||||||
|
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4;
|
||||||
|
RCC_OscInitStruct.PLL.PLLQ = 7;
|
||||||
|
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Initializes the CPU, AHB and APB buses clocks
|
||||||
|
*/
|
||||||
|
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|
||||||
|
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
|
||||||
|
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
|
||||||
|
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
|
||||||
|
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV8;
|
||||||
|
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV4;
|
||||||
|
|
||||||
|
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief GPIO Initialization Function
|
||||||
|
* @param None
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
static void MX_GPIO_Init(void)
|
||||||
|
{
|
||||||
|
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||||
|
/* USER CODE BEGIN MX_GPIO_Init_1 */
|
||||||
|
|
||||||
|
/* USER CODE END MX_GPIO_Init_1 */
|
||||||
|
|
||||||
|
/* GPIO Ports Clock Enable */
|
||||||
|
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||||
|
__HAL_RCC_GPIOD_CLK_ENABLE();
|
||||||
|
|
||||||
|
/*Configure GPIO pin Output Level */
|
||||||
|
HAL_GPIO_WritePin(GPIOD, White_Pin|Red_Pin|Yellow_Pin|Green_Pin, GPIO_PIN_RESET);
|
||||||
|
|
||||||
|
/*Configure GPIO pin : PedButton_Pin */
|
||||||
|
GPIO_InitStruct.Pin = PedButton_Pin;
|
||||||
|
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
|
||||||
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
|
HAL_GPIO_Init(PedButton_GPIO_Port, &GPIO_InitStruct);
|
||||||
|
|
||||||
|
/*Configure GPIO pins : White_Pin Red_Pin Yellow_Pin Green_Pin */
|
||||||
|
GPIO_InitStruct.Pin = White_Pin|Red_Pin|Yellow_Pin|Green_Pin;
|
||||||
|
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||||
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||||
|
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
|
||||||
|
|
||||||
|
/* EXTI interrupt init*/
|
||||||
|
HAL_NVIC_SetPriority(EXTI15_10_IRQn, 15, 0);
|
||||||
|
HAL_NVIC_EnableIRQ(EXTI15_10_IRQn);
|
||||||
|
|
||||||
|
/* USER CODE BEGIN MX_GPIO_Init_2 */
|
||||||
|
|
||||||
|
/* USER CODE END MX_GPIO_Init_2 */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* USER CODE BEGIN 4 */
|
||||||
|
void HAL_GPIO_EXTI_CallBack()
|
||||||
|
{
|
||||||
|
static uint32_t lastInterruptTime = 0;
|
||||||
|
uint32_t now = HAL_GetTick();
|
||||||
|
if(now - lastInterruptTime < 100)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
lastInterruptTime = now;
|
||||||
|
|
||||||
|
if (PedButton_Pin)
|
||||||
|
{
|
||||||
|
buttonPressedThisCycle = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void HAL_GPIO_EXTI_IRQHandler()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/* USER CODE END 4 */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function is executed in case of error occurrence.
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void Error_Handler(void)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN Error_Handler_Debug */
|
||||||
|
/* User can add his own implementation to report the HAL error return state */
|
||||||
|
__disable_irq();
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
/* USER CODE END Error_Handler_Debug */
|
||||||
|
}
|
||||||
|
#ifdef USE_FULL_ASSERT
|
||||||
|
/**
|
||||||
|
* @brief Reports the name of the source file and the source line number
|
||||||
|
* where the assert_param error has occurred.
|
||||||
|
* @param file: pointer to the source file name
|
||||||
|
* @param line: assert_param error line source number
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void assert_failed(uint8_t *file, uint32_t line)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN 6 */
|
||||||
|
/* User can add his own implementation to report the file name and line number,
|
||||||
|
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
|
||||||
|
/* USER CODE END 6 */
|
||||||
|
}
|
||||||
|
#endif /* USE_FULL_ASSERT */
|
||||||
|
|
||||||
@@ -1,74 +0,0 @@
|
|||||||
/*
|
|
||||||
* breadboard.c
|
|
||||||
*
|
|
||||||
* Created on: Sep 17, 2025
|
|
||||||
* Author: ja
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* #define RedLight_Pin GPIO_PIN_2
|
|
||||||
* #define RedLight_GPIO_Port GPIOE
|
|
||||||
*
|
|
||||||
* #define YellowLight_Pin GPIO_PIN_3
|
|
||||||
* #define YellowLight_GPIO_Port GPIOE
|
|
||||||
*
|
|
||||||
* #define GreenLight_Pin GPIO_PIN_4
|
|
||||||
* #define GreenLight_GPIO_Port GPIOE
|
|
||||||
*
|
|
||||||
* RedLight: PE2
|
|
||||||
* YellowLight: PE3
|
|
||||||
* GreenLight: PE4
|
|
||||||
* WalkLight: PE5
|
|
||||||
*
|
|
||||||
* Done: Traffic Light
|
|
||||||
* TODO: async? Walk Signal, Light Dimmer
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "main.h"
|
|
||||||
#include "breadboard.h"
|
|
||||||
|
|
||||||
#define R_Pin RedLight_Pin
|
|
||||||
#define Y_Pin YellowLight_Pin
|
|
||||||
#define G_Pin GreenLight_Pin
|
|
||||||
#define W_Pin WalkLight_Pin
|
|
||||||
|
|
||||||
#define R_Prt RedLight_GPIO_Port
|
|
||||||
#define Y_Prt YellowLight_GPIO_Port
|
|
||||||
#define G_Prt GreenLight_GPIO_Port
|
|
||||||
#define W_Prt WalkLight_GPIO_Port
|
|
||||||
|
|
||||||
uint32_t redlight_last;
|
|
||||||
uint32_t ylwlight_last;
|
|
||||||
uint32_t grnlight_last;
|
|
||||||
|
|
||||||
void
|
|
||||||
starttick(void)
|
|
||||||
{
|
|
||||||
redlight_last = HAL_GetTick();
|
|
||||||
ylwlight_last = HAL_GetTick();
|
|
||||||
grnlight_last = HAL_GetTick();
|
|
||||||
|
|
||||||
trafflight_last = HAL_GetTick();
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
trafflight(int traffSPD)
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
HAL_GPIO_TogglePin(R_Prt, R_Pin);
|
|
||||||
HAL_Delay(traffSPD);
|
|
||||||
HAL_GPIO_TogglePin(R_Prt, R_Pin);
|
|
||||||
|
|
||||||
HAL_GPIO_TogglePin(Y_Prt, Y_Pin);
|
|
||||||
HAL_Delay(traffSPD);
|
|
||||||
HAL_GPIO_TogglePin(Y_Prt, Y_Pin);
|
|
||||||
|
|
||||||
HAL_GPIO_TogglePin(G_Prt, G_Pin);
|
|
||||||
HAL_Delay(traffSPD);
|
|
||||||
HAL_GPIO_TogglePin(G_Prt, G_Pin);
|
|
||||||
*/
|
|
||||||
|
|
||||||
uint32_t trafftick_curr = HAL_GetTick();
|
|
||||||
|
|
||||||
if (trafftick_curr)
|
|
||||||
}
|
|
||||||
@@ -1,730 +0,0 @@
|
|||||||
/* USER CODE BEGIN Header */
|
|
||||||
/**
|
|
||||||
******************************************************************************
|
|
||||||
* @file : main.c
|
|
||||||
* @brief : Main program body
|
|
||||||
******************************************************************************
|
|
||||||
* @attention
|
|
||||||
*
|
|
||||||
* Copyright (c) 2025 STMicroelectronics.
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* This software is licensed under terms that can be found in the LICENSE file
|
|
||||||
* in the root directory of this software component.
|
|
||||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
|
||||||
*
|
|
||||||
******************************************************************************
|
|
||||||
*/
|
|
||||||
/* USER CODE END Header */
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
|
||||||
#include "main.h"
|
|
||||||
#include "cmsis_os.h"
|
|
||||||
#include "usb_host.h"
|
|
||||||
|
|
||||||
/* Private includes ----------------------------------------------------------*/
|
|
||||||
/* USER CODE BEGIN Includes */
|
|
||||||
#include "breadboard.h"
|
|
||||||
|
|
||||||
/* USER CODE END Includes */
|
|
||||||
|
|
||||||
/* Private typedef -----------------------------------------------------------*/
|
|
||||||
/* USER CODE BEGIN PTD */
|
|
||||||
|
|
||||||
/* USER CODE END PTD */
|
|
||||||
|
|
||||||
/* Private define ------------------------------------------------------------*/
|
|
||||||
/* USER CODE BEGIN PD */
|
|
||||||
|
|
||||||
/* USER CODE END PD */
|
|
||||||
|
|
||||||
/* Private macro -------------------------------------------------------------*/
|
|
||||||
/* USER CODE BEGIN PM */
|
|
||||||
|
|
||||||
/* USER CODE END PM */
|
|
||||||
|
|
||||||
/* Private variables ---------------------------------------------------------*/
|
|
||||||
CRC_HandleTypeDef hcrc;
|
|
||||||
|
|
||||||
DMA2D_HandleTypeDef hdma2d;
|
|
||||||
|
|
||||||
I2C_HandleTypeDef hi2c3;
|
|
||||||
|
|
||||||
LTDC_HandleTypeDef hltdc;
|
|
||||||
|
|
||||||
SPI_HandleTypeDef hspi5;
|
|
||||||
|
|
||||||
TIM_HandleTypeDef htim1;
|
|
||||||
|
|
||||||
UART_HandleTypeDef huart1;
|
|
||||||
|
|
||||||
SDRAM_HandleTypeDef hsdram1;
|
|
||||||
|
|
||||||
osThreadId defaultTaskHandle;
|
|
||||||
/* USER CODE BEGIN PV */
|
|
||||||
|
|
||||||
/* USER CODE END PV */
|
|
||||||
|
|
||||||
/* Private function prototypes -----------------------------------------------*/
|
|
||||||
void SystemClock_Config(void);
|
|
||||||
static void MX_GPIO_Init(void);
|
|
||||||
static void MX_CRC_Init(void);
|
|
||||||
static void MX_DMA2D_Init(void);
|
|
||||||
static void MX_FMC_Init(void);
|
|
||||||
static void MX_I2C3_Init(void);
|
|
||||||
static void MX_LTDC_Init(void);
|
|
||||||
static void MX_SPI5_Init(void);
|
|
||||||
static void MX_TIM1_Init(void);
|
|
||||||
static void MX_USART1_UART_Init(void);
|
|
||||||
void StartDefaultTask(void const * argument);
|
|
||||||
|
|
||||||
/* USER CODE BEGIN PFP */
|
|
||||||
|
|
||||||
/* USER CODE END PFP */
|
|
||||||
|
|
||||||
/* Private user code ---------------------------------------------------------*/
|
|
||||||
/* USER CODE BEGIN 0 */
|
|
||||||
|
|
||||||
/* USER CODE END 0 */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief The application entry point.
|
|
||||||
* @retval int
|
|
||||||
*/
|
|
||||||
int main(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* USER CODE BEGIN 1 */
|
|
||||||
|
|
||||||
/* USER CODE END 1 */
|
|
||||||
|
|
||||||
/* MCU Configuration--------------------------------------------------------*/
|
|
||||||
|
|
||||||
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
|
|
||||||
HAL_Init();
|
|
||||||
|
|
||||||
/* USER CODE BEGIN Init */
|
|
||||||
|
|
||||||
/* USER CODE END Init */
|
|
||||||
|
|
||||||
/* Configure the system clock */
|
|
||||||
SystemClock_Config();
|
|
||||||
|
|
||||||
/* USER CODE BEGIN SysInit */
|
|
||||||
|
|
||||||
/* USER CODE END SysInit */
|
|
||||||
|
|
||||||
/* Initialize all configured peripherals */
|
|
||||||
MX_GPIO_Init();
|
|
||||||
MX_CRC_Init();
|
|
||||||
MX_DMA2D_Init();
|
|
||||||
MX_FMC_Init();
|
|
||||||
MX_I2C3_Init();
|
|
||||||
MX_LTDC_Init();
|
|
||||||
MX_SPI5_Init();
|
|
||||||
MX_TIM1_Init();
|
|
||||||
MX_USART1_UART_Init();
|
|
||||||
/* USER CODE BEGIN 2 */
|
|
||||||
|
|
||||||
/* USER CODE END 2 */
|
|
||||||
|
|
||||||
/* USER CODE BEGIN RTOS_MUTEX */
|
|
||||||
/* add mutexes, ... */
|
|
||||||
/* USER CODE END RTOS_MUTEX */
|
|
||||||
|
|
||||||
/* USER CODE BEGIN RTOS_SEMAPHORES */
|
|
||||||
/* add semaphores, ... */
|
|
||||||
/* USER CODE END RTOS_SEMAPHORES */
|
|
||||||
|
|
||||||
/* USER CODE BEGIN RTOS_TIMERS */
|
|
||||||
/* start timers, add new ones, ... */
|
|
||||||
/* USER CODE END RTOS_TIMERS */
|
|
||||||
|
|
||||||
/* USER CODE BEGIN RTOS_QUEUES */
|
|
||||||
/* add queues, ... */
|
|
||||||
/* USER CODE END RTOS_QUEUES */
|
|
||||||
|
|
||||||
/* Create the thread(s) */
|
|
||||||
/* definition and creation of defaultTask */
|
|
||||||
//osThreadDef(defaultTask, StartDefaultTask, osPriorityNormal, 0, 4096);
|
|
||||||
//defaultTaskHandle = osThreadCreate(osThread(defaultTask), NULL);
|
|
||||||
|
|
||||||
/* USER CODE BEGIN RTOS_THREADS */
|
|
||||||
/* add threads, ... */
|
|
||||||
/* USER CODE END RTOS_THREADS */
|
|
||||||
|
|
||||||
/* Start scheduler */
|
|
||||||
//osKernelStart();
|
|
||||||
|
|
||||||
/* We should never get here as control is now taken by the scheduler */
|
|
||||||
|
|
||||||
/* Infinite loop */
|
|
||||||
/* USER CODE BEGIN WHILE */
|
|
||||||
while (1)
|
|
||||||
{
|
|
||||||
trafflight(2*1000, 10*1000);
|
|
||||||
/* USER CODE END WHILE */
|
|
||||||
|
|
||||||
/* USER CODE BEGIN 3 */
|
|
||||||
}
|
|
||||||
/* USER CODE END 3 */
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief System Clock Configuration
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
void SystemClock_Config(void)
|
|
||||||
{
|
|
||||||
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
|
|
||||||
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
|
|
||||||
|
|
||||||
/** Configure the main internal regulator output voltage
|
|
||||||
*/
|
|
||||||
__HAL_RCC_PWR_CLK_ENABLE();
|
|
||||||
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE3);
|
|
||||||
|
|
||||||
/** Initializes the RCC Oscillators according to the specified parameters
|
|
||||||
* in the RCC_OscInitTypeDef structure.
|
|
||||||
*/
|
|
||||||
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
|
|
||||||
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
|
|
||||||
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
|
||||||
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
|
|
||||||
RCC_OscInitStruct.PLL.PLLM = 4;
|
|
||||||
RCC_OscInitStruct.PLL.PLLN = 72;
|
|
||||||
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
|
|
||||||
RCC_OscInitStruct.PLL.PLLQ = 3;
|
|
||||||
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Initializes the CPU, AHB and APB buses clocks
|
|
||||||
*/
|
|
||||||
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|
|
||||||
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
|
|
||||||
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
|
|
||||||
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
|
|
||||||
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
|
|
||||||
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
|
|
||||||
|
|
||||||
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief CRC Initialization Function
|
|
||||||
* @param None
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
static void MX_CRC_Init(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* USER CODE BEGIN CRC_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE END CRC_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE BEGIN CRC_Init 1 */
|
|
||||||
|
|
||||||
/* USER CODE END CRC_Init 1 */
|
|
||||||
hcrc.Instance = CRC;
|
|
||||||
if (HAL_CRC_Init(&hcrc) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
/* USER CODE BEGIN CRC_Init 2 */
|
|
||||||
|
|
||||||
/* USER CODE END CRC_Init 2 */
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief DMA2D Initialization Function
|
|
||||||
* @param None
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
static void MX_DMA2D_Init(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* USER CODE BEGIN DMA2D_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE END DMA2D_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE BEGIN DMA2D_Init 1 */
|
|
||||||
|
|
||||||
/* USER CODE END DMA2D_Init 1 */
|
|
||||||
hdma2d.Instance = DMA2D;
|
|
||||||
hdma2d.Init.Mode = DMA2D_M2M;
|
|
||||||
hdma2d.Init.ColorMode = DMA2D_OUTPUT_ARGB8888;
|
|
||||||
hdma2d.Init.OutputOffset = 0;
|
|
||||||
hdma2d.LayerCfg[1].InputOffset = 0;
|
|
||||||
hdma2d.LayerCfg[1].InputColorMode = DMA2D_INPUT_ARGB8888;
|
|
||||||
hdma2d.LayerCfg[1].AlphaMode = DMA2D_NO_MODIF_ALPHA;
|
|
||||||
hdma2d.LayerCfg[1].InputAlpha = 0;
|
|
||||||
if (HAL_DMA2D_Init(&hdma2d) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
if (HAL_DMA2D_ConfigLayer(&hdma2d, 1) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
/* USER CODE BEGIN DMA2D_Init 2 */
|
|
||||||
|
|
||||||
/* USER CODE END DMA2D_Init 2 */
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief I2C3 Initialization Function
|
|
||||||
* @param None
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
static void MX_I2C3_Init(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* USER CODE BEGIN I2C3_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE END I2C3_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE BEGIN I2C3_Init 1 */
|
|
||||||
|
|
||||||
/* USER CODE END I2C3_Init 1 */
|
|
||||||
hi2c3.Instance = I2C3;
|
|
||||||
hi2c3.Init.ClockSpeed = 100000;
|
|
||||||
hi2c3.Init.DutyCycle = I2C_DUTYCYCLE_2;
|
|
||||||
hi2c3.Init.OwnAddress1 = 0;
|
|
||||||
hi2c3.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
|
|
||||||
hi2c3.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
|
|
||||||
hi2c3.Init.OwnAddress2 = 0;
|
|
||||||
hi2c3.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
|
|
||||||
hi2c3.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
|
|
||||||
if (HAL_I2C_Init(&hi2c3) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Configure Analogue filter
|
|
||||||
*/
|
|
||||||
if (HAL_I2CEx_ConfigAnalogFilter(&hi2c3, I2C_ANALOGFILTER_ENABLE) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Configure Digital filter
|
|
||||||
*/
|
|
||||||
if (HAL_I2CEx_ConfigDigitalFilter(&hi2c3, 0) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
/* USER CODE BEGIN I2C3_Init 2 */
|
|
||||||
|
|
||||||
/* USER CODE END I2C3_Init 2 */
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief LTDC Initialization Function
|
|
||||||
* @param None
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
static void MX_LTDC_Init(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* USER CODE BEGIN LTDC_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE END LTDC_Init 0 */
|
|
||||||
|
|
||||||
LTDC_LayerCfgTypeDef pLayerCfg = {0};
|
|
||||||
|
|
||||||
/* USER CODE BEGIN LTDC_Init 1 */
|
|
||||||
|
|
||||||
/* USER CODE END LTDC_Init 1 */
|
|
||||||
hltdc.Instance = LTDC;
|
|
||||||
hltdc.Init.HSPolarity = LTDC_HSPOLARITY_AL;
|
|
||||||
hltdc.Init.VSPolarity = LTDC_VSPOLARITY_AL;
|
|
||||||
hltdc.Init.DEPolarity = LTDC_DEPOLARITY_AL;
|
|
||||||
hltdc.Init.PCPolarity = LTDC_PCPOLARITY_IPC;
|
|
||||||
hltdc.Init.HorizontalSync = 9;
|
|
||||||
hltdc.Init.VerticalSync = 1;
|
|
||||||
hltdc.Init.AccumulatedHBP = 29;
|
|
||||||
hltdc.Init.AccumulatedVBP = 3;
|
|
||||||
hltdc.Init.AccumulatedActiveW = 269;
|
|
||||||
hltdc.Init.AccumulatedActiveH = 323;
|
|
||||||
hltdc.Init.TotalWidth = 279;
|
|
||||||
hltdc.Init.TotalHeigh = 327;
|
|
||||||
hltdc.Init.Backcolor.Blue = 0;
|
|
||||||
hltdc.Init.Backcolor.Green = 0;
|
|
||||||
hltdc.Init.Backcolor.Red = 0;
|
|
||||||
if (HAL_LTDC_Init(&hltdc) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
pLayerCfg.WindowX0 = 0;
|
|
||||||
pLayerCfg.WindowX1 = 240;
|
|
||||||
pLayerCfg.WindowY0 = 0;
|
|
||||||
pLayerCfg.WindowY1 = 320;
|
|
||||||
pLayerCfg.PixelFormat = LTDC_PIXEL_FORMAT_RGB565;
|
|
||||||
pLayerCfg.Alpha = 255;
|
|
||||||
pLayerCfg.Alpha0 = 0;
|
|
||||||
pLayerCfg.BlendingFactor1 = LTDC_BLENDING_FACTOR1_PAxCA;
|
|
||||||
pLayerCfg.BlendingFactor2 = LTDC_BLENDING_FACTOR2_PAxCA;
|
|
||||||
pLayerCfg.FBStartAdress = 0xD0000000;
|
|
||||||
pLayerCfg.ImageWidth = 240;
|
|
||||||
pLayerCfg.ImageHeight = 320;
|
|
||||||
pLayerCfg.Backcolor.Blue = 0;
|
|
||||||
pLayerCfg.Backcolor.Green = 0;
|
|
||||||
pLayerCfg.Backcolor.Red = 0;
|
|
||||||
if (HAL_LTDC_ConfigLayer(&hltdc, &pLayerCfg, 0) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
/* USER CODE BEGIN LTDC_Init 2 */
|
|
||||||
|
|
||||||
/* USER CODE END LTDC_Init 2 */
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief SPI5 Initialization Function
|
|
||||||
* @param None
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
static void MX_SPI5_Init(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* USER CODE BEGIN SPI5_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE END SPI5_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE BEGIN SPI5_Init 1 */
|
|
||||||
|
|
||||||
/* USER CODE END SPI5_Init 1 */
|
|
||||||
/* SPI5 parameter configuration*/
|
|
||||||
hspi5.Instance = SPI5;
|
|
||||||
hspi5.Init.Mode = SPI_MODE_MASTER;
|
|
||||||
hspi5.Init.Direction = SPI_DIRECTION_2LINES;
|
|
||||||
hspi5.Init.DataSize = SPI_DATASIZE_8BIT;
|
|
||||||
hspi5.Init.CLKPolarity = SPI_POLARITY_LOW;
|
|
||||||
hspi5.Init.CLKPhase = SPI_PHASE_1EDGE;
|
|
||||||
hspi5.Init.NSS = SPI_NSS_SOFT;
|
|
||||||
hspi5.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_16;
|
|
||||||
hspi5.Init.FirstBit = SPI_FIRSTBIT_MSB;
|
|
||||||
hspi5.Init.TIMode = SPI_TIMODE_DISABLE;
|
|
||||||
hspi5.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
|
|
||||||
hspi5.Init.CRCPolynomial = 10;
|
|
||||||
if (HAL_SPI_Init(&hspi5) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
/* USER CODE BEGIN SPI5_Init 2 */
|
|
||||||
|
|
||||||
/* USER CODE END SPI5_Init 2 */
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief TIM1 Initialization Function
|
|
||||||
* @param None
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
static void MX_TIM1_Init(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* USER CODE BEGIN TIM1_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE END TIM1_Init 0 */
|
|
||||||
|
|
||||||
TIM_ClockConfigTypeDef sClockSourceConfig = {0};
|
|
||||||
TIM_MasterConfigTypeDef sMasterConfig = {0};
|
|
||||||
|
|
||||||
/* USER CODE BEGIN TIM1_Init 1 */
|
|
||||||
|
|
||||||
/* USER CODE END TIM1_Init 1 */
|
|
||||||
htim1.Instance = TIM1;
|
|
||||||
htim1.Init.Prescaler = 0;
|
|
||||||
htim1.Init.CounterMode = TIM_COUNTERMODE_UP;
|
|
||||||
htim1.Init.Period = 65535;
|
|
||||||
htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
|
||||||
htim1.Init.RepetitionCounter = 0;
|
|
||||||
htim1.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
|
|
||||||
if (HAL_TIM_Base_Init(&htim1) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
|
|
||||||
if (HAL_TIM_ConfigClockSource(&htim1, &sClockSourceConfig) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
|
|
||||||
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
|
|
||||||
if (HAL_TIMEx_MasterConfigSynchronization(&htim1, &sMasterConfig) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
/* USER CODE BEGIN TIM1_Init 2 */
|
|
||||||
|
|
||||||
/* USER CODE END TIM1_Init 2 */
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief USART1 Initialization Function
|
|
||||||
* @param None
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
static void MX_USART1_UART_Init(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* USER CODE BEGIN USART1_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE END USART1_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE BEGIN USART1_Init 1 */
|
|
||||||
|
|
||||||
/* USER CODE END USART1_Init 1 */
|
|
||||||
huart1.Instance = USART1;
|
|
||||||
huart1.Init.BaudRate = 115200;
|
|
||||||
huart1.Init.WordLength = UART_WORDLENGTH_8B;
|
|
||||||
huart1.Init.StopBits = UART_STOPBITS_1;
|
|
||||||
huart1.Init.Parity = UART_PARITY_NONE;
|
|
||||||
huart1.Init.Mode = UART_MODE_TX_RX;
|
|
||||||
huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
|
|
||||||
huart1.Init.OverSampling = UART_OVERSAMPLING_16;
|
|
||||||
if (HAL_UART_Init(&huart1) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
/* USER CODE BEGIN USART1_Init 2 */
|
|
||||||
|
|
||||||
/* USER CODE END USART1_Init 2 */
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/* FMC initialization function */
|
|
||||||
static void MX_FMC_Init(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* USER CODE BEGIN FMC_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE END FMC_Init 0 */
|
|
||||||
|
|
||||||
FMC_SDRAM_TimingTypeDef SdramTiming = {0};
|
|
||||||
|
|
||||||
/* USER CODE BEGIN FMC_Init 1 */
|
|
||||||
|
|
||||||
/* USER CODE END FMC_Init 1 */
|
|
||||||
|
|
||||||
/** Perform the SDRAM1 memory initialization sequence
|
|
||||||
*/
|
|
||||||
hsdram1.Instance = FMC_SDRAM_DEVICE;
|
|
||||||
/* hsdram1.Init */
|
|
||||||
hsdram1.Init.SDBank = FMC_SDRAM_BANK2;
|
|
||||||
hsdram1.Init.ColumnBitsNumber = FMC_SDRAM_COLUMN_BITS_NUM_8;
|
|
||||||
hsdram1.Init.RowBitsNumber = FMC_SDRAM_ROW_BITS_NUM_12;
|
|
||||||
hsdram1.Init.MemoryDataWidth = FMC_SDRAM_MEM_BUS_WIDTH_16;
|
|
||||||
hsdram1.Init.InternalBankNumber = FMC_SDRAM_INTERN_BANKS_NUM_4;
|
|
||||||
hsdram1.Init.CASLatency = FMC_SDRAM_CAS_LATENCY_3;
|
|
||||||
hsdram1.Init.WriteProtection = FMC_SDRAM_WRITE_PROTECTION_DISABLE;
|
|
||||||
hsdram1.Init.SDClockPeriod = FMC_SDRAM_CLOCK_PERIOD_2;
|
|
||||||
hsdram1.Init.ReadBurst = FMC_SDRAM_RBURST_DISABLE;
|
|
||||||
hsdram1.Init.ReadPipeDelay = FMC_SDRAM_RPIPE_DELAY_1;
|
|
||||||
/* SdramTiming */
|
|
||||||
SdramTiming.LoadToActiveDelay = 2;
|
|
||||||
SdramTiming.ExitSelfRefreshDelay = 7;
|
|
||||||
SdramTiming.SelfRefreshTime = 4;
|
|
||||||
SdramTiming.RowCycleDelay = 7;
|
|
||||||
SdramTiming.WriteRecoveryTime = 3;
|
|
||||||
SdramTiming.RPDelay = 2;
|
|
||||||
SdramTiming.RCDDelay = 2;
|
|
||||||
|
|
||||||
if (HAL_SDRAM_Init(&hsdram1, &SdramTiming) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler( );
|
|
||||||
}
|
|
||||||
|
|
||||||
/* USER CODE BEGIN FMC_Init 2 */
|
|
||||||
|
|
||||||
/* USER CODE END FMC_Init 2 */
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief GPIO Initialization Function
|
|
||||||
* @param None
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
static void MX_GPIO_Init(void)
|
|
||||||
{
|
|
||||||
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
|
||||||
/* USER CODE BEGIN MX_GPIO_Init_1 */
|
|
||||||
|
|
||||||
/* USER CODE END MX_GPIO_Init_1 */
|
|
||||||
|
|
||||||
/* GPIO Ports Clock Enable */
|
|
||||||
__HAL_RCC_GPIOE_CLK_ENABLE();
|
|
||||||
__HAL_RCC_GPIOC_CLK_ENABLE();
|
|
||||||
__HAL_RCC_GPIOF_CLK_ENABLE();
|
|
||||||
__HAL_RCC_GPIOH_CLK_ENABLE();
|
|
||||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
|
||||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
|
||||||
__HAL_RCC_GPIOG_CLK_ENABLE();
|
|
||||||
__HAL_RCC_GPIOD_CLK_ENABLE();
|
|
||||||
|
|
||||||
/*Configure GPIO pin Output Level */
|
|
||||||
HAL_GPIO_WritePin(GPIOE, RedLight_Pin|YellowLight_Pin|GreenLight_Pin|WalkLight_Pin, GPIO_PIN_RESET);
|
|
||||||
|
|
||||||
/*Configure GPIO pin Output Level */
|
|
||||||
HAL_GPIO_WritePin(GPIOC, NCS_MEMS_SPI_Pin|CSX_Pin|OTG_FS_PSO_Pin, GPIO_PIN_RESET);
|
|
||||||
|
|
||||||
/*Configure GPIO pin Output Level */
|
|
||||||
HAL_GPIO_WritePin(ACP_RST_GPIO_Port, ACP_RST_Pin, GPIO_PIN_RESET);
|
|
||||||
|
|
||||||
/*Configure GPIO pin Output Level */
|
|
||||||
HAL_GPIO_WritePin(GPIOD, RDX_Pin|WRX_DCX_Pin, GPIO_PIN_RESET);
|
|
||||||
|
|
||||||
/*Configure GPIO pin Output Level */
|
|
||||||
HAL_GPIO_WritePin(GPIOG, LD3_Pin|LD4_Pin, GPIO_PIN_RESET);
|
|
||||||
|
|
||||||
/*Configure GPIO pins : RedLight_Pin YellowLight_Pin GreenLight_Pin WalkLight_Pin */
|
|
||||||
GPIO_InitStruct.Pin = RedLight_Pin|YellowLight_Pin|GreenLight_Pin|WalkLight_Pin;
|
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
||||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
|
||||||
HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
|
|
||||||
|
|
||||||
/*Configure GPIO pins : NCS_MEMS_SPI_Pin CSX_Pin OTG_FS_PSO_Pin */
|
|
||||||
GPIO_InitStruct.Pin = NCS_MEMS_SPI_Pin|CSX_Pin|OTG_FS_PSO_Pin;
|
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
||||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
|
||||||
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
|
|
||||||
|
|
||||||
/*Configure GPIO pins : B1_Pin MEMS_INT1_Pin MEMS_INT2_Pin TP_INT1_Pin */
|
|
||||||
GPIO_InitStruct.Pin = B1_Pin|MEMS_INT1_Pin|MEMS_INT2_Pin|TP_INT1_Pin;
|
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_EVT_RISING;
|
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
||||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
|
||||||
|
|
||||||
/*Configure GPIO pin : ACP_RST_Pin */
|
|
||||||
GPIO_InitStruct.Pin = ACP_RST_Pin;
|
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
||||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
|
||||||
HAL_GPIO_Init(ACP_RST_GPIO_Port, &GPIO_InitStruct);
|
|
||||||
|
|
||||||
/*Configure GPIO pin : OTG_FS_OC_Pin */
|
|
||||||
GPIO_InitStruct.Pin = OTG_FS_OC_Pin;
|
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_EVT_RISING;
|
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
||||||
HAL_GPIO_Init(OTG_FS_OC_GPIO_Port, &GPIO_InitStruct);
|
|
||||||
|
|
||||||
/*Configure GPIO pin : BOOT1_Pin */
|
|
||||||
GPIO_InitStruct.Pin = BOOT1_Pin;
|
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
||||||
HAL_GPIO_Init(BOOT1_GPIO_Port, &GPIO_InitStruct);
|
|
||||||
|
|
||||||
/*Configure GPIO pin : TE_Pin */
|
|
||||||
GPIO_InitStruct.Pin = TE_Pin;
|
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
||||||
HAL_GPIO_Init(TE_GPIO_Port, &GPIO_InitStruct);
|
|
||||||
|
|
||||||
/*Configure GPIO pins : RDX_Pin WRX_DCX_Pin */
|
|
||||||
GPIO_InitStruct.Pin = RDX_Pin|WRX_DCX_Pin;
|
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
||||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
|
||||||
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
|
|
||||||
|
|
||||||
/*Configure GPIO pins : LD3_Pin LD4_Pin */
|
|
||||||
GPIO_InitStruct.Pin = LD3_Pin|LD4_Pin;
|
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
||||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
|
||||||
HAL_GPIO_Init(GPIOG, &GPIO_InitStruct);
|
|
||||||
|
|
||||||
/* USER CODE BEGIN MX_GPIO_Init_2 */
|
|
||||||
|
|
||||||
/* USER CODE END MX_GPIO_Init_2 */
|
|
||||||
}
|
|
||||||
|
|
||||||
/* USER CODE BEGIN 4 */
|
|
||||||
|
|
||||||
/* USER CODE END 4 */
|
|
||||||
|
|
||||||
/* USER CODE BEGIN Header_StartDefaultTask */
|
|
||||||
/**
|
|
||||||
* @brief Function implementing the defaultTask thread.
|
|
||||||
* @param argument: Not used
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
/* USER CODE END Header_StartDefaultTask */
|
|
||||||
void StartDefaultTask(void const * argument)
|
|
||||||
{
|
|
||||||
/* init code for USB_HOST */
|
|
||||||
MX_USB_HOST_Init();
|
|
||||||
/* USER CODE BEGIN 5 */
|
|
||||||
/* Infinite loop */
|
|
||||||
for(;;)
|
|
||||||
{
|
|
||||||
osDelay(1);
|
|
||||||
}
|
|
||||||
/* USER CODE END 5 */
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Period elapsed callback in non blocking mode
|
|
||||||
* @note This function is called when TIM6 interrupt took place, inside
|
|
||||||
* HAL_TIM_IRQHandler(). It makes a direct call to HAL_IncTick() to increment
|
|
||||||
* a global variable "uwTick" used as application time base.
|
|
||||||
* @param htim : TIM handle
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
|
|
||||||
{
|
|
||||||
/* USER CODE BEGIN Callback 0 */
|
|
||||||
|
|
||||||
/* USER CODE END Callback 0 */
|
|
||||||
if (htim->Instance == TIM6)
|
|
||||||
{
|
|
||||||
HAL_IncTick();
|
|
||||||
}
|
|
||||||
/* USER CODE BEGIN Callback 1 */
|
|
||||||
|
|
||||||
/* USER CODE END Callback 1 */
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief This function is executed in case of error occurrence.
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
void Error_Handler(void)
|
|
||||||
{
|
|
||||||
/* USER CODE BEGIN Error_Handler_Debug */
|
|
||||||
/* User can add his own implementation to report the HAL error return state */
|
|
||||||
__disable_irq();
|
|
||||||
while (1)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
/* USER CODE END Error_Handler_Debug */
|
|
||||||
}
|
|
||||||
#ifdef USE_FULL_ASSERT
|
|
||||||
/**
|
|
||||||
* @brief Reports the name of the source file and the source line number
|
|
||||||
* where the assert_param error has occurred.
|
|
||||||
* @param file: pointer to the source file name
|
|
||||||
* @param line: assert_param error line source number
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
void assert_failed(uint8_t *file, uint32_t line)
|
|
||||||
{
|
|
||||||
/* USER CODE BEGIN 6 */
|
|
||||||
/* User can add his own implementation to report the file name and line number,
|
|
||||||
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
|
|
||||||
/* USER CODE END 6 */
|
|
||||||
}
|
|
||||||
#endif /* USE_FULL_ASSERT */
|
|
||||||
@@ -1,100 +0,0 @@
|
|||||||
/*
|
|
||||||
* breadboard.c
|
|
||||||
*
|
|
||||||
* Created on: Sep 17, 2025
|
|
||||||
* Author: ja
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* #define RedLight_Pin GPIO_PIN_2
|
|
||||||
* #define RedLight_GPIO_Port GPIOE
|
|
||||||
*
|
|
||||||
* #define YellowLight_Pin GPIO_PIN_3
|
|
||||||
* #define YellowLight_GPIO_Port GPIOE
|
|
||||||
*
|
|
||||||
* #define GreenLight_Pin GPIO_PIN_4
|
|
||||||
* #define GreenLight_GPIO_Port GPIOE
|
|
||||||
*
|
|
||||||
* RedLight: PE2
|
|
||||||
* YellowLight: PE3
|
|
||||||
* GreenLight: PE4
|
|
||||||
* WalkLight: PE5
|
|
||||||
*
|
|
||||||
* Done: Traffic Light
|
|
||||||
* TODO: async? Walk Signal, Light Dimmer
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "main.h"
|
|
||||||
#include "breadboard.h"
|
|
||||||
|
|
||||||
#define R_Pin RedLight_Pin
|
|
||||||
#define Y_Pin YellowLight_Pin
|
|
||||||
#define G_Pin GreenLight_Pin
|
|
||||||
#define W_Pin WalkLight_Pin
|
|
||||||
|
|
||||||
#define R_Prt RedLight_GPIO_Port
|
|
||||||
#define Y_Prt YellowLight_GPIO_Port
|
|
||||||
#define G_Prt GreenLight_GPIO_Port
|
|
||||||
#define W_Prt WalkLight_GPIO_Port
|
|
||||||
|
|
||||||
uint32_t trafftick_last;
|
|
||||||
uint32_t walktick_last;
|
|
||||||
|
|
||||||
uint8_t trafflight_i = 0;
|
|
||||||
|
|
||||||
void
|
|
||||||
starttick(void)
|
|
||||||
{
|
|
||||||
trafftick_last = HAL_GetTick();
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
trafflight(int traffSPD)
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
HAL_GPIO_TogglePin(R_Prt, R_Pin);
|
|
||||||
HAL_Delay(traffSPD);
|
|
||||||
HAL_GPIO_TogglePin(R_Prt, R_Pin);
|
|
||||||
|
|
||||||
HAL_GPIO_TogglePin(Y_Prt, Y_Pin);
|
|
||||||
HAL_Delay(traffSPD);
|
|
||||||
HAL_GPIO_TogglePin(Y_Prt, Y_Pin);
|
|
||||||
|
|
||||||
HAL_GPIO_TogglePin(G_Prt, G_Pin);
|
|
||||||
HAL_Delay(traffSPD);
|
|
||||||
HAL_GPIO_TogglePin(G_Prt, G_Pin);
|
|
||||||
*/
|
|
||||||
|
|
||||||
uint32_t trafftick_curr = HAL_GetTick();
|
|
||||||
|
|
||||||
if ((trafftick_curr - trafftick_last) >= traffSPD) {
|
|
||||||
HAL_GPIO_WritePin(
|
|
||||||
R_Prt, R_Pin &&
|
|
||||||
Y_Prt, Y_Pin &&
|
|
||||||
G_Prt, G_Pin,
|
|
||||||
GPIO_PIN_RESET
|
|
||||||
);
|
|
||||||
HAL_GPIO_WritePin(R_Prt, R_Pin, GPIO_PIN_RESET);
|
|
||||||
HAL_GPIO_WritePin(Y_Prt, Y_Pin, GPIO_PIN_RESET);
|
|
||||||
|
|
||||||
switch (trafflight_i) {
|
|
||||||
case 0:
|
|
||||||
HAL_GPIO_WritePin(R_Prt, R_Pin);
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
HAL_GPIO_WritePin(Y_Prt, Y_Pin);
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
HAL_GPIO_WritePin(G_Prt, G_Pin);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
trafflight_i = (trafflight_i + 1) % 3;
|
|
||||||
trafftick_last = trafftick_curr;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((trafftick_curr - walktick_last) >= walkSPD) {
|
|
||||||
HAL_GPIO_TogglePin(W_Prt, W_Pin);
|
|
||||||
walktick_last = trafftick_curr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
/*
|
|
||||||
* breadboard.hpp
|
|
||||||
*
|
|
||||||
* Created on: Sep 22, 2025
|
|
||||||
* Author: ja
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef INC_BREADBOARD_HPP_
|
|
||||||
#define INC_BREADBOARD_HPP_
|
|
||||||
|
|
||||||
|
|
||||||
void breadboard(void);
|
|
||||||
|
|
||||||
|
|
||||||
#endif /* INC_BREADBOARD_HPP_ */
|
|
||||||
@@ -22,7 +22,8 @@
|
|||||||
|
|
||||||
/* Private includes ----------------------------------------------------------*/
|
/* Private includes ----------------------------------------------------------*/
|
||||||
/* USER CODE BEGIN Includes */
|
/* USER CODE BEGIN Includes */
|
||||||
|
#include "breadboard.h"
|
||||||
|
#include <stdbool.h>
|
||||||
/* USER CODE END Includes */
|
/* USER CODE END Includes */
|
||||||
|
|
||||||
/* Private typedef -----------------------------------------------------------*/
|
/* Private typedef -----------------------------------------------------------*/
|
||||||
@@ -60,13 +61,32 @@ static void MX_DMA2D_Init(void);
|
|||||||
static void MX_TIM1_Init(void);
|
static void MX_TIM1_Init(void);
|
||||||
void StartDefaultTask(void const * argument);
|
void StartDefaultTask(void const * argument);
|
||||||
|
|
||||||
|
void SetTrafficLights(TrafficSate s);
|
||||||
|
|
||||||
/* USER CODE BEGIN PFP */
|
/* USER CODE BEGIN PFP */
|
||||||
|
|
||||||
/* USER CODE END PFP */
|
/* USER CODE END PFP */
|
||||||
|
|
||||||
/* Private user code ---------------------------------------------------------*/
|
/* Private user code ---------------------------------------------------------*/
|
||||||
|
|
||||||
/* USER CODE BEGIN 0 */
|
/* USER CODE BEGIN 0 */
|
||||||
|
|
||||||
|
enum class TrafficState {
|
||||||
|
GREEN,
|
||||||
|
YELLOW,
|
||||||
|
RED
|
||||||
|
};
|
||||||
|
|
||||||
|
TrafficState currentState = TrafficState::GREEN;
|
||||||
|
uint32_t stateStartTime = 0; // HAL_GetTick() at the start of this state
|
||||||
|
bool buttonPressed = false;
|
||||||
|
bool pedestrianNextCycle = false;
|
||||||
|
|
||||||
|
const uint32_t DURATION_GREEN = 5000;
|
||||||
|
const uint32_t DURATION_YELLOW = 3000;
|
||||||
|
const uint32_t DURATION_RED = 5000;
|
||||||
|
const uint32_t DURATION_RED_PED = 7000;
|
||||||
|
|
||||||
/* USER CODE END 0 */
|
/* USER CODE END 0 */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -123,8 +143,8 @@ int main(void)
|
|||||||
|
|
||||||
/* Create the thread(s) */
|
/* Create the thread(s) */
|
||||||
/* definition and creation of defaultTask */
|
/* definition and creation of defaultTask */
|
||||||
osThreadDef(defaultTask, StartDefaultTask, osPriorityNormal, 0, 4096);
|
//osThreadDef(defaultTask, StartDefaultTask, osPriorityNormal, 0, 4096);
|
||||||
defaultTaskHandle = osThreadCreate(osThread(defaultTask), NULL);
|
//defaultTaskHandle = osThreadCreate(osThread(defaultTask), NULL);
|
||||||
|
|
||||||
/* USER CODE BEGIN RTOS_THREADS */
|
/* USER CODE BEGIN RTOS_THREADS */
|
||||||
/* add threads, ... */
|
/* add threads, ... */
|
||||||
@@ -139,6 +159,28 @@ int main(void)
|
|||||||
/* USER CODE BEGIN WHILE */
|
/* USER CODE BEGIN WHILE */
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
|
uint32_t now = HAL_GetTick();
|
||||||
|
uint32_t elapsed = now - stateStartTime;
|
||||||
|
|
||||||
|
switch(currentState)
|
||||||
|
{
|
||||||
|
case TrafficState::GREEN:
|
||||||
|
if (elapsed >= DURATION_GREEN) {
|
||||||
|
currentState = TrafficState::YELLOW;
|
||||||
|
stateStartTime = now;
|
||||||
|
buttonPressed = false; // reset the button-flag for the new cycle
|
||||||
|
} else if (buttonPressed) {
|
||||||
|
//idk
|
||||||
|
buttonPressed = true;
|
||||||
|
currentState = TrafficState::YELLOW;
|
||||||
|
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case TrafficState::YELLOW:
|
||||||
|
break;
|
||||||
|
case TrafficState::RED:
|
||||||
|
break;
|
||||||
|
}
|
||||||
/* USER CODE END WHILE */
|
/* USER CODE END WHILE */
|
||||||
|
|
||||||
/* USER CODE BEGIN 3 */
|
/* USER CODE BEGIN 3 */
|
||||||
@@ -344,6 +386,23 @@ static void MX_GPIO_Init(void)
|
|||||||
|
|
||||||
/* USER CODE BEGIN 4 */
|
/* USER CODE BEGIN 4 */
|
||||||
|
|
||||||
|
void HAL_GPIO_EXTI_CallBack(uint16_t GPIO_Pin)
|
||||||
|
{
|
||||||
|
static uint32_t lastInterruptTime = 0;
|
||||||
|
uint32_t now = HAL_GetTick();
|
||||||
|
if (now - lastInterruptTime < 100) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
lastInterruptTime = now;
|
||||||
|
|
||||||
|
bool buttonPressedThisCycle = false; // temporary, get rid of this
|
||||||
|
|
||||||
|
if (buttonPressed) { // buttonPressedHere?
|
||||||
|
buttonPressedThisCycle = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* USER CODE END 4 */
|
/* USER CODE END 4 */
|
||||||
|
|
||||||
/* USER CODE BEGIN Header_StartDefaultTask */
|
/* USER CODE BEGIN Header_StartDefaultTask */
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
/*
|
|
||||||
* breadboard.hpp
|
|
||||||
*
|
|
||||||
* Created on: Sep 22, 2025
|
|
||||||
* Author: ja
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef INC_BREADBOARD_HPP_
|
|
||||||
#define INC_BREADBOARD_HPP_
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif /* INC_BREADBOARD_HPP_ */
|
|
||||||
@@ -1,728 +0,0 @@
|
|||||||
/* USER CODE BEGIN Header */
|
|
||||||
/**
|
|
||||||
******************************************************************************
|
|
||||||
* @file : main.c
|
|
||||||
* @brief : Main program body
|
|
||||||
******************************************************************************
|
|
||||||
* @attention
|
|
||||||
*
|
|
||||||
* Copyright (c) 2025 STMicroelectronics.
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* This software is licensed under terms that can be found in the LICENSE file
|
|
||||||
* in the root directory of this software component.
|
|
||||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
|
||||||
*
|
|
||||||
******************************************************************************
|
|
||||||
*/
|
|
||||||
/* USER CODE END Header */
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
|
||||||
#include "main.h"
|
|
||||||
#include "cmsis_os.h"
|
|
||||||
#include "usb_host.h"
|
|
||||||
|
|
||||||
/* Private includes ----------------------------------------------------------*/
|
|
||||||
/* USER CODE BEGIN Includes */
|
|
||||||
|
|
||||||
/* USER CODE END Includes */
|
|
||||||
|
|
||||||
/* Private typedef -----------------------------------------------------------*/
|
|
||||||
/* USER CODE BEGIN PTD */
|
|
||||||
|
|
||||||
/* USER CODE END PTD */
|
|
||||||
|
|
||||||
/* Private define ------------------------------------------------------------*/
|
|
||||||
/* USER CODE BEGIN PD */
|
|
||||||
|
|
||||||
/* USER CODE END PD */
|
|
||||||
|
|
||||||
/* Private macro -------------------------------------------------------------*/
|
|
||||||
/* USER CODE BEGIN PM */
|
|
||||||
|
|
||||||
/* USER CODE END PM */
|
|
||||||
|
|
||||||
/* Private variables ---------------------------------------------------------*/
|
|
||||||
CRC_HandleTypeDef hcrc;
|
|
||||||
|
|
||||||
DMA2D_HandleTypeDef hdma2d;
|
|
||||||
|
|
||||||
I2C_HandleTypeDef hi2c3;
|
|
||||||
|
|
||||||
LTDC_HandleTypeDef hltdc;
|
|
||||||
|
|
||||||
SPI_HandleTypeDef hspi5;
|
|
||||||
|
|
||||||
TIM_HandleTypeDef htim1;
|
|
||||||
|
|
||||||
UART_HandleTypeDef huart1;
|
|
||||||
|
|
||||||
SDRAM_HandleTypeDef hsdram1;
|
|
||||||
|
|
||||||
osThreadId defaultTaskHandle;
|
|
||||||
/* USER CODE BEGIN PV */
|
|
||||||
|
|
||||||
/* USER CODE END PV */
|
|
||||||
|
|
||||||
/* Private function prototypes -----------------------------------------------*/
|
|
||||||
void SystemClock_Config(void);
|
|
||||||
static void MX_GPIO_Init(void);
|
|
||||||
static void MX_CRC_Init(void);
|
|
||||||
static void MX_DMA2D_Init(void);
|
|
||||||
static void MX_FMC_Init(void);
|
|
||||||
static void MX_I2C3_Init(void);
|
|
||||||
static void MX_LTDC_Init(void);
|
|
||||||
static void MX_SPI5_Init(void);
|
|
||||||
static void MX_TIM1_Init(void);
|
|
||||||
static void MX_USART1_UART_Init(void);
|
|
||||||
void StartDefaultTask(void const * argument);
|
|
||||||
|
|
||||||
/* USER CODE BEGIN PFP */
|
|
||||||
|
|
||||||
/* USER CODE END PFP */
|
|
||||||
|
|
||||||
/* Private user code ---------------------------------------------------------*/
|
|
||||||
/* USER CODE BEGIN 0 */
|
|
||||||
|
|
||||||
/* USER CODE END 0 */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief The application entry point.
|
|
||||||
* @retval int
|
|
||||||
*/
|
|
||||||
int main(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* USER CODE BEGIN 1 */
|
|
||||||
|
|
||||||
/* USER CODE END 1 */
|
|
||||||
|
|
||||||
/* MCU Configuration--------------------------------------------------------*/
|
|
||||||
|
|
||||||
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
|
|
||||||
HAL_Init();
|
|
||||||
|
|
||||||
/* USER CODE BEGIN Init */
|
|
||||||
|
|
||||||
/* USER CODE END Init */
|
|
||||||
|
|
||||||
/* Configure the system clock */
|
|
||||||
SystemClock_Config();
|
|
||||||
|
|
||||||
/* USER CODE BEGIN SysInit */
|
|
||||||
|
|
||||||
/* USER CODE END SysInit */
|
|
||||||
|
|
||||||
/* Initialize all configured peripherals */
|
|
||||||
MX_GPIO_Init();
|
|
||||||
MX_CRC_Init();
|
|
||||||
MX_DMA2D_Init();
|
|
||||||
MX_FMC_Init();
|
|
||||||
MX_I2C3_Init();
|
|
||||||
MX_LTDC_Init();
|
|
||||||
MX_SPI5_Init();
|
|
||||||
MX_TIM1_Init();
|
|
||||||
MX_USART1_UART_Init();
|
|
||||||
/* USER CODE BEGIN 2 */
|
|
||||||
|
|
||||||
/* USER CODE END 2 */
|
|
||||||
|
|
||||||
/* USER CODE BEGIN RTOS_MUTEX */
|
|
||||||
/* add mutexes, ... */
|
|
||||||
/* USER CODE END RTOS_MUTEX */
|
|
||||||
|
|
||||||
/* USER CODE BEGIN RTOS_SEMAPHORES */
|
|
||||||
/* add semaphores, ... */
|
|
||||||
/* USER CODE END RTOS_SEMAPHORES */
|
|
||||||
|
|
||||||
/* USER CODE BEGIN RTOS_TIMERS */
|
|
||||||
/* start timers, add new ones, ... */
|
|
||||||
/* USER CODE END RTOS_TIMERS */
|
|
||||||
|
|
||||||
/* USER CODE BEGIN RTOS_QUEUES */
|
|
||||||
/* add queues, ... */
|
|
||||||
/* USER CODE END RTOS_QUEUES */
|
|
||||||
|
|
||||||
/* Create the thread(s) */
|
|
||||||
/* definition and creation of defaultTask */
|
|
||||||
osThreadDef(defaultTask, StartDefaultTask, osPriorityNormal, 0, 4096);
|
|
||||||
defaultTaskHandle = osThreadCreate(osThread(defaultTask), NULL);
|
|
||||||
|
|
||||||
/* USER CODE BEGIN RTOS_THREADS */
|
|
||||||
/* add threads, ... */
|
|
||||||
/* USER CODE END RTOS_THREADS */
|
|
||||||
|
|
||||||
/* Start scheduler */
|
|
||||||
osKernelStart();
|
|
||||||
|
|
||||||
/* We should never get here as control is now taken by the scheduler */
|
|
||||||
|
|
||||||
/* Infinite loop */
|
|
||||||
/* USER CODE BEGIN WHILE */
|
|
||||||
while (1)
|
|
||||||
{
|
|
||||||
/* USER CODE END WHILE */
|
|
||||||
|
|
||||||
/* USER CODE BEGIN 3 */
|
|
||||||
}
|
|
||||||
/* USER CODE END 3 */
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief System Clock Configuration
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
void SystemClock_Config(void)
|
|
||||||
{
|
|
||||||
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
|
|
||||||
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
|
|
||||||
|
|
||||||
/** Configure the main internal regulator output voltage
|
|
||||||
*/
|
|
||||||
__HAL_RCC_PWR_CLK_ENABLE();
|
|
||||||
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE3);
|
|
||||||
|
|
||||||
/** Initializes the RCC Oscillators according to the specified parameters
|
|
||||||
* in the RCC_OscInitTypeDef structure.
|
|
||||||
*/
|
|
||||||
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
|
|
||||||
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
|
|
||||||
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
|
||||||
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
|
|
||||||
RCC_OscInitStruct.PLL.PLLM = 4;
|
|
||||||
RCC_OscInitStruct.PLL.PLLN = 72;
|
|
||||||
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
|
|
||||||
RCC_OscInitStruct.PLL.PLLQ = 3;
|
|
||||||
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Initializes the CPU, AHB and APB buses clocks
|
|
||||||
*/
|
|
||||||
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|
|
||||||
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
|
|
||||||
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
|
|
||||||
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
|
|
||||||
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
|
|
||||||
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
|
|
||||||
|
|
||||||
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief CRC Initialization Function
|
|
||||||
* @param None
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
static void MX_CRC_Init(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* USER CODE BEGIN CRC_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE END CRC_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE BEGIN CRC_Init 1 */
|
|
||||||
|
|
||||||
/* USER CODE END CRC_Init 1 */
|
|
||||||
hcrc.Instance = CRC;
|
|
||||||
if (HAL_CRC_Init(&hcrc) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
/* USER CODE BEGIN CRC_Init 2 */
|
|
||||||
|
|
||||||
/* USER CODE END CRC_Init 2 */
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief DMA2D Initialization Function
|
|
||||||
* @param None
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
static void MX_DMA2D_Init(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* USER CODE BEGIN DMA2D_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE END DMA2D_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE BEGIN DMA2D_Init 1 */
|
|
||||||
|
|
||||||
/* USER CODE END DMA2D_Init 1 */
|
|
||||||
hdma2d.Instance = DMA2D;
|
|
||||||
hdma2d.Init.Mode = DMA2D_M2M;
|
|
||||||
hdma2d.Init.ColorMode = DMA2D_OUTPUT_ARGB8888;
|
|
||||||
hdma2d.Init.OutputOffset = 0;
|
|
||||||
hdma2d.LayerCfg[1].InputOffset = 0;
|
|
||||||
hdma2d.LayerCfg[1].InputColorMode = DMA2D_INPUT_ARGB8888;
|
|
||||||
hdma2d.LayerCfg[1].AlphaMode = DMA2D_NO_MODIF_ALPHA;
|
|
||||||
hdma2d.LayerCfg[1].InputAlpha = 0;
|
|
||||||
if (HAL_DMA2D_Init(&hdma2d) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
if (HAL_DMA2D_ConfigLayer(&hdma2d, 1) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
/* USER CODE BEGIN DMA2D_Init 2 */
|
|
||||||
|
|
||||||
/* USER CODE END DMA2D_Init 2 */
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief I2C3 Initialization Function
|
|
||||||
* @param None
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
static void MX_I2C3_Init(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* USER CODE BEGIN I2C3_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE END I2C3_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE BEGIN I2C3_Init 1 */
|
|
||||||
|
|
||||||
/* USER CODE END I2C3_Init 1 */
|
|
||||||
hi2c3.Instance = I2C3;
|
|
||||||
hi2c3.Init.ClockSpeed = 100000;
|
|
||||||
hi2c3.Init.DutyCycle = I2C_DUTYCYCLE_2;
|
|
||||||
hi2c3.Init.OwnAddress1 = 0;
|
|
||||||
hi2c3.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
|
|
||||||
hi2c3.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
|
|
||||||
hi2c3.Init.OwnAddress2 = 0;
|
|
||||||
hi2c3.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
|
|
||||||
hi2c3.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
|
|
||||||
if (HAL_I2C_Init(&hi2c3) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Configure Analogue filter
|
|
||||||
*/
|
|
||||||
if (HAL_I2CEx_ConfigAnalogFilter(&hi2c3, I2C_ANALOGFILTER_ENABLE) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Configure Digital filter
|
|
||||||
*/
|
|
||||||
if (HAL_I2CEx_ConfigDigitalFilter(&hi2c3, 0) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
/* USER CODE BEGIN I2C3_Init 2 */
|
|
||||||
|
|
||||||
/* USER CODE END I2C3_Init 2 */
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief LTDC Initialization Function
|
|
||||||
* @param None
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
static void MX_LTDC_Init(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* USER CODE BEGIN LTDC_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE END LTDC_Init 0 */
|
|
||||||
|
|
||||||
LTDC_LayerCfgTypeDef pLayerCfg = {0};
|
|
||||||
|
|
||||||
/* USER CODE BEGIN LTDC_Init 1 */
|
|
||||||
|
|
||||||
/* USER CODE END LTDC_Init 1 */
|
|
||||||
hltdc.Instance = LTDC;
|
|
||||||
hltdc.Init.HSPolarity = LTDC_HSPOLARITY_AL;
|
|
||||||
hltdc.Init.VSPolarity = LTDC_VSPOLARITY_AL;
|
|
||||||
hltdc.Init.DEPolarity = LTDC_DEPOLARITY_AL;
|
|
||||||
hltdc.Init.PCPolarity = LTDC_PCPOLARITY_IPC;
|
|
||||||
hltdc.Init.HorizontalSync = 9;
|
|
||||||
hltdc.Init.VerticalSync = 1;
|
|
||||||
hltdc.Init.AccumulatedHBP = 29;
|
|
||||||
hltdc.Init.AccumulatedVBP = 3;
|
|
||||||
hltdc.Init.AccumulatedActiveW = 269;
|
|
||||||
hltdc.Init.AccumulatedActiveH = 323;
|
|
||||||
hltdc.Init.TotalWidth = 279;
|
|
||||||
hltdc.Init.TotalHeigh = 327;
|
|
||||||
hltdc.Init.Backcolor.Blue = 0;
|
|
||||||
hltdc.Init.Backcolor.Green = 0;
|
|
||||||
hltdc.Init.Backcolor.Red = 0;
|
|
||||||
if (HAL_LTDC_Init(&hltdc) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
pLayerCfg.WindowX0 = 0;
|
|
||||||
pLayerCfg.WindowX1 = 240;
|
|
||||||
pLayerCfg.WindowY0 = 0;
|
|
||||||
pLayerCfg.WindowY1 = 320;
|
|
||||||
pLayerCfg.PixelFormat = LTDC_PIXEL_FORMAT_RGB565;
|
|
||||||
pLayerCfg.Alpha = 255;
|
|
||||||
pLayerCfg.Alpha0 = 0;
|
|
||||||
pLayerCfg.BlendingFactor1 = LTDC_BLENDING_FACTOR1_PAxCA;
|
|
||||||
pLayerCfg.BlendingFactor2 = LTDC_BLENDING_FACTOR2_PAxCA;
|
|
||||||
pLayerCfg.FBStartAdress = 0xD0000000;
|
|
||||||
pLayerCfg.ImageWidth = 240;
|
|
||||||
pLayerCfg.ImageHeight = 320;
|
|
||||||
pLayerCfg.Backcolor.Blue = 0;
|
|
||||||
pLayerCfg.Backcolor.Green = 0;
|
|
||||||
pLayerCfg.Backcolor.Red = 0;
|
|
||||||
if (HAL_LTDC_ConfigLayer(&hltdc, &pLayerCfg, 0) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
/* USER CODE BEGIN LTDC_Init 2 */
|
|
||||||
|
|
||||||
/* USER CODE END LTDC_Init 2 */
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief SPI5 Initialization Function
|
|
||||||
* @param None
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
static void MX_SPI5_Init(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* USER CODE BEGIN SPI5_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE END SPI5_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE BEGIN SPI5_Init 1 */
|
|
||||||
|
|
||||||
/* USER CODE END SPI5_Init 1 */
|
|
||||||
/* SPI5 parameter configuration*/
|
|
||||||
hspi5.Instance = SPI5;
|
|
||||||
hspi5.Init.Mode = SPI_MODE_MASTER;
|
|
||||||
hspi5.Init.Direction = SPI_DIRECTION_2LINES;
|
|
||||||
hspi5.Init.DataSize = SPI_DATASIZE_8BIT;
|
|
||||||
hspi5.Init.CLKPolarity = SPI_POLARITY_LOW;
|
|
||||||
hspi5.Init.CLKPhase = SPI_PHASE_1EDGE;
|
|
||||||
hspi5.Init.NSS = SPI_NSS_SOFT;
|
|
||||||
hspi5.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_16;
|
|
||||||
hspi5.Init.FirstBit = SPI_FIRSTBIT_MSB;
|
|
||||||
hspi5.Init.TIMode = SPI_TIMODE_DISABLE;
|
|
||||||
hspi5.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
|
|
||||||
hspi5.Init.CRCPolynomial = 10;
|
|
||||||
if (HAL_SPI_Init(&hspi5) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
/* USER CODE BEGIN SPI5_Init 2 */
|
|
||||||
|
|
||||||
/* USER CODE END SPI5_Init 2 */
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief TIM1 Initialization Function
|
|
||||||
* @param None
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
static void MX_TIM1_Init(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* USER CODE BEGIN TIM1_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE END TIM1_Init 0 */
|
|
||||||
|
|
||||||
TIM_ClockConfigTypeDef sClockSourceConfig = {0};
|
|
||||||
TIM_MasterConfigTypeDef sMasterConfig = {0};
|
|
||||||
|
|
||||||
/* USER CODE BEGIN TIM1_Init 1 */
|
|
||||||
|
|
||||||
/* USER CODE END TIM1_Init 1 */
|
|
||||||
htim1.Instance = TIM1;
|
|
||||||
htim1.Init.Prescaler = 0;
|
|
||||||
htim1.Init.CounterMode = TIM_COUNTERMODE_UP;
|
|
||||||
htim1.Init.Period = 65535;
|
|
||||||
htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
|
||||||
htim1.Init.RepetitionCounter = 0;
|
|
||||||
htim1.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
|
|
||||||
if (HAL_TIM_Base_Init(&htim1) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
|
|
||||||
if (HAL_TIM_ConfigClockSource(&htim1, &sClockSourceConfig) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
|
|
||||||
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
|
|
||||||
if (HAL_TIMEx_MasterConfigSynchronization(&htim1, &sMasterConfig) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
/* USER CODE BEGIN TIM1_Init 2 */
|
|
||||||
|
|
||||||
/* USER CODE END TIM1_Init 2 */
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief USART1 Initialization Function
|
|
||||||
* @param None
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
static void MX_USART1_UART_Init(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* USER CODE BEGIN USART1_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE END USART1_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE BEGIN USART1_Init 1 */
|
|
||||||
|
|
||||||
/* USER CODE END USART1_Init 1 */
|
|
||||||
huart1.Instance = USART1;
|
|
||||||
huart1.Init.BaudRate = 115200;
|
|
||||||
huart1.Init.WordLength = UART_WORDLENGTH_8B;
|
|
||||||
huart1.Init.StopBits = UART_STOPBITS_1;
|
|
||||||
huart1.Init.Parity = UART_PARITY_NONE;
|
|
||||||
huart1.Init.Mode = UART_MODE_TX_RX;
|
|
||||||
huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
|
|
||||||
huart1.Init.OverSampling = UART_OVERSAMPLING_16;
|
|
||||||
if (HAL_UART_Init(&huart1) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
/* USER CODE BEGIN USART1_Init 2 */
|
|
||||||
|
|
||||||
/* USER CODE END USART1_Init 2 */
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/* FMC initialization function */
|
|
||||||
static void MX_FMC_Init(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* USER CODE BEGIN FMC_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE END FMC_Init 0 */
|
|
||||||
|
|
||||||
FMC_SDRAM_TimingTypeDef SdramTiming = {0};
|
|
||||||
|
|
||||||
/* USER CODE BEGIN FMC_Init 1 */
|
|
||||||
|
|
||||||
/* USER CODE END FMC_Init 1 */
|
|
||||||
|
|
||||||
/** Perform the SDRAM1 memory initialization sequence
|
|
||||||
*/
|
|
||||||
hsdram1.Instance = FMC_SDRAM_DEVICE;
|
|
||||||
/* hsdram1.Init */
|
|
||||||
hsdram1.Init.SDBank = FMC_SDRAM_BANK2;
|
|
||||||
hsdram1.Init.ColumnBitsNumber = FMC_SDRAM_COLUMN_BITS_NUM_8;
|
|
||||||
hsdram1.Init.RowBitsNumber = FMC_SDRAM_ROW_BITS_NUM_12;
|
|
||||||
hsdram1.Init.MemoryDataWidth = FMC_SDRAM_MEM_BUS_WIDTH_16;
|
|
||||||
hsdram1.Init.InternalBankNumber = FMC_SDRAM_INTERN_BANKS_NUM_4;
|
|
||||||
hsdram1.Init.CASLatency = FMC_SDRAM_CAS_LATENCY_3;
|
|
||||||
hsdram1.Init.WriteProtection = FMC_SDRAM_WRITE_PROTECTION_DISABLE;
|
|
||||||
hsdram1.Init.SDClockPeriod = FMC_SDRAM_CLOCK_PERIOD_2;
|
|
||||||
hsdram1.Init.ReadBurst = FMC_SDRAM_RBURST_DISABLE;
|
|
||||||
hsdram1.Init.ReadPipeDelay = FMC_SDRAM_RPIPE_DELAY_1;
|
|
||||||
/* SdramTiming */
|
|
||||||
SdramTiming.LoadToActiveDelay = 2;
|
|
||||||
SdramTiming.ExitSelfRefreshDelay = 7;
|
|
||||||
SdramTiming.SelfRefreshTime = 4;
|
|
||||||
SdramTiming.RowCycleDelay = 7;
|
|
||||||
SdramTiming.WriteRecoveryTime = 3;
|
|
||||||
SdramTiming.RPDelay = 2;
|
|
||||||
SdramTiming.RCDDelay = 2;
|
|
||||||
|
|
||||||
if (HAL_SDRAM_Init(&hsdram1, &SdramTiming) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler( );
|
|
||||||
}
|
|
||||||
|
|
||||||
/* USER CODE BEGIN FMC_Init 2 */
|
|
||||||
|
|
||||||
/* USER CODE END FMC_Init 2 */
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief GPIO Initialization Function
|
|
||||||
* @param None
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
static void MX_GPIO_Init(void)
|
|
||||||
{
|
|
||||||
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
|
||||||
/* USER CODE BEGIN MX_GPIO_Init_1 */
|
|
||||||
|
|
||||||
/* USER CODE END MX_GPIO_Init_1 */
|
|
||||||
|
|
||||||
/* GPIO Ports Clock Enable */
|
|
||||||
__HAL_RCC_GPIOE_CLK_ENABLE();
|
|
||||||
__HAL_RCC_GPIOC_CLK_ENABLE();
|
|
||||||
__HAL_RCC_GPIOF_CLK_ENABLE();
|
|
||||||
__HAL_RCC_GPIOH_CLK_ENABLE();
|
|
||||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
|
||||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
|
||||||
__HAL_RCC_GPIOG_CLK_ENABLE();
|
|
||||||
__HAL_RCC_GPIOD_CLK_ENABLE();
|
|
||||||
|
|
||||||
/*Configure GPIO pin Output Level */
|
|
||||||
HAL_GPIO_WritePin(GPIOE, RedLight_Pin|YellowLight_Pin|GreenLight_Pin, GPIO_PIN_RESET);
|
|
||||||
|
|
||||||
/*Configure GPIO pin Output Level */
|
|
||||||
HAL_GPIO_WritePin(GPIOC, NCS_MEMS_SPI_Pin|CSX_Pin|OTG_FS_PSO_Pin, GPIO_PIN_RESET);
|
|
||||||
|
|
||||||
/*Configure GPIO pin Output Level */
|
|
||||||
HAL_GPIO_WritePin(ACP_RST_GPIO_Port, ACP_RST_Pin, GPIO_PIN_RESET);
|
|
||||||
|
|
||||||
/*Configure GPIO pin Output Level */
|
|
||||||
HAL_GPIO_WritePin(GPIOD, RDX_Pin|WRX_DCX_Pin, GPIO_PIN_RESET);
|
|
||||||
|
|
||||||
/*Configure GPIO pin Output Level */
|
|
||||||
HAL_GPIO_WritePin(GPIOG, LD3_Pin|LD4_Pin, GPIO_PIN_RESET);
|
|
||||||
|
|
||||||
/*Configure GPIO pins : RedLight_Pin YellowLight_Pin GreenLight_Pin */
|
|
||||||
GPIO_InitStruct.Pin = RedLight_Pin|YellowLight_Pin|GreenLight_Pin;
|
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
||||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
|
||||||
HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
|
|
||||||
|
|
||||||
/*Configure GPIO pins : NCS_MEMS_SPI_Pin CSX_Pin OTG_FS_PSO_Pin */
|
|
||||||
GPIO_InitStruct.Pin = NCS_MEMS_SPI_Pin|CSX_Pin|OTG_FS_PSO_Pin;
|
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
||||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
|
||||||
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
|
|
||||||
|
|
||||||
/*Configure GPIO pins : B1_Pin MEMS_INT1_Pin MEMS_INT2_Pin TP_INT1_Pin */
|
|
||||||
GPIO_InitStruct.Pin = B1_Pin|MEMS_INT1_Pin|MEMS_INT2_Pin|TP_INT1_Pin;
|
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_EVT_RISING;
|
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
||||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
|
||||||
|
|
||||||
/*Configure GPIO pin : ACP_RST_Pin */
|
|
||||||
GPIO_InitStruct.Pin = ACP_RST_Pin;
|
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
||||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
|
||||||
HAL_GPIO_Init(ACP_RST_GPIO_Port, &GPIO_InitStruct);
|
|
||||||
|
|
||||||
/*Configure GPIO pin : OTG_FS_OC_Pin */
|
|
||||||
GPIO_InitStruct.Pin = OTG_FS_OC_Pin;
|
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_EVT_RISING;
|
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
||||||
HAL_GPIO_Init(OTG_FS_OC_GPIO_Port, &GPIO_InitStruct);
|
|
||||||
|
|
||||||
/*Configure GPIO pin : BOOT1_Pin */
|
|
||||||
GPIO_InitStruct.Pin = BOOT1_Pin;
|
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
||||||
HAL_GPIO_Init(BOOT1_GPIO_Port, &GPIO_InitStruct);
|
|
||||||
|
|
||||||
/*Configure GPIO pin : TE_Pin */
|
|
||||||
GPIO_InitStruct.Pin = TE_Pin;
|
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
||||||
HAL_GPIO_Init(TE_GPIO_Port, &GPIO_InitStruct);
|
|
||||||
|
|
||||||
/*Configure GPIO pins : RDX_Pin WRX_DCX_Pin */
|
|
||||||
GPIO_InitStruct.Pin = RDX_Pin|WRX_DCX_Pin;
|
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
||||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
|
||||||
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
|
|
||||||
|
|
||||||
/*Configure GPIO pins : LD3_Pin LD4_Pin */
|
|
||||||
GPIO_InitStruct.Pin = LD3_Pin|LD4_Pin;
|
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
||||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
|
||||||
HAL_GPIO_Init(GPIOG, &GPIO_InitStruct);
|
|
||||||
|
|
||||||
/* USER CODE BEGIN MX_GPIO_Init_2 */
|
|
||||||
|
|
||||||
/* USER CODE END MX_GPIO_Init_2 */
|
|
||||||
}
|
|
||||||
|
|
||||||
/* USER CODE BEGIN 4 */
|
|
||||||
|
|
||||||
/* USER CODE END 4 */
|
|
||||||
|
|
||||||
/* USER CODE BEGIN Header_StartDefaultTask */
|
|
||||||
/**
|
|
||||||
* @brief Function implementing the defaultTask thread.
|
|
||||||
* @param argument: Not used
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
/* USER CODE END Header_StartDefaultTask */
|
|
||||||
void StartDefaultTask(void const * argument)
|
|
||||||
{
|
|
||||||
/* init code for USB_HOST */
|
|
||||||
MX_USB_HOST_Init();
|
|
||||||
/* USER CODE BEGIN 5 */
|
|
||||||
/* Infinite loop */
|
|
||||||
for(;;)
|
|
||||||
{
|
|
||||||
osDelay(1);
|
|
||||||
}
|
|
||||||
/* USER CODE END 5 */
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Period elapsed callback in non blocking mode
|
|
||||||
* @note This function is called when TIM6 interrupt took place, inside
|
|
||||||
* HAL_TIM_IRQHandler(). It makes a direct call to HAL_IncTick() to increment
|
|
||||||
* a global variable "uwTick" used as application time base.
|
|
||||||
* @param htim : TIM handle
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
|
|
||||||
{
|
|
||||||
/* USER CODE BEGIN Callback 0 */
|
|
||||||
|
|
||||||
/* USER CODE END Callback 0 */
|
|
||||||
if (htim->Instance == TIM6)
|
|
||||||
{
|
|
||||||
HAL_IncTick();
|
|
||||||
}
|
|
||||||
/* USER CODE BEGIN Callback 1 */
|
|
||||||
|
|
||||||
/* USER CODE END Callback 1 */
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief This function is executed in case of error occurrence.
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
void Error_Handler(void)
|
|
||||||
{
|
|
||||||
/* USER CODE BEGIN Error_Handler_Debug */
|
|
||||||
/* User can add his own implementation to report the HAL error return state */
|
|
||||||
__disable_irq();
|
|
||||||
while (1)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
/* USER CODE END Error_Handler_Debug */
|
|
||||||
}
|
|
||||||
#ifdef USE_FULL_ASSERT
|
|
||||||
/**
|
|
||||||
* @brief Reports the name of the source file and the source line number
|
|
||||||
* where the assert_param error has occurred.
|
|
||||||
* @param file: pointer to the source file name
|
|
||||||
* @param line: assert_param error line source number
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
void assert_failed(uint8_t *file, uint32_t line)
|
|
||||||
{
|
|
||||||
/* USER CODE BEGIN 6 */
|
|
||||||
/* User can add his own implementation to report the file name and line number,
|
|
||||||
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
|
|
||||||
/* USER CODE END 6 */
|
|
||||||
}
|
|
||||||
#endif /* USE_FULL_ASSERT */
|
|
||||||
@@ -1,68 +0,0 @@
|
|||||||
/*
|
|
||||||
* breadboard.c
|
|
||||||
*
|
|
||||||
* Created on: Sep 17, 2025
|
|
||||||
* Author: ja
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* #define RedLight_Pin GPIO_PIN_2
|
|
||||||
* #define RedLight_GPIO_Port GPIOE
|
|
||||||
*
|
|
||||||
* #define YellowLight_Pin GPIO_PIN_3
|
|
||||||
* #define YellowLight_GPIO_Port GPIOE
|
|
||||||
*
|
|
||||||
* #define GreenLight_Pin GPIO_PIN_4
|
|
||||||
* #define GreenLight_GPIO_Port GPIOE
|
|
||||||
*
|
|
||||||
* RedLight: PE2
|
|
||||||
* YellowLight: PE3
|
|
||||||
* GreenLight: PE4
|
|
||||||
* WalkLight: PE5
|
|
||||||
*
|
|
||||||
* Done: Traffic Light
|
|
||||||
* TODO: async? Walk Signal, Light Dimmer
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "main.h"
|
|
||||||
#include "breadboard.h"
|
|
||||||
|
|
||||||
#define R_Pin RedLight_Pin
|
|
||||||
#define Y_Pin YellowLight_Pin
|
|
||||||
#define G_Pin GreenLight_Pin
|
|
||||||
#define W_Pin WalkLight_Pin
|
|
||||||
|
|
||||||
#define R_Prt RedLight_GPIO_Port
|
|
||||||
#define Y_Prt YellowLight_GPIO_Port
|
|
||||||
#define G_Prt GreenLight_GPIO_Port
|
|
||||||
#define W_Prt WalkLight_GPIO_Port
|
|
||||||
|
|
||||||
uint32_t trafftick_last;
|
|
||||||
|
|
||||||
void
|
|
||||||
starttick(void)
|
|
||||||
{
|
|
||||||
trafftick_last = HAL_GetTick();
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
trafflight(int traffSPD)
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
HAL_GPIO_TogglePin(R_Prt, R_Pin);
|
|
||||||
HAL_Delay(traffSPD);
|
|
||||||
HAL_GPIO_TogglePin(R_Prt, R_Pin);
|
|
||||||
|
|
||||||
HAL_GPIO_TogglePin(Y_Prt, Y_Pin);
|
|
||||||
HAL_Delay(traffSPD);
|
|
||||||
HAL_GPIO_TogglePin(Y_Prt, Y_Pin);
|
|
||||||
|
|
||||||
HAL_GPIO_TogglePin(G_Prt, G_Pin);
|
|
||||||
HAL_Delay(traffSPD);
|
|
||||||
HAL_GPIO_TogglePin(G_Prt, G_Pin);
|
|
||||||
*/
|
|
||||||
|
|
||||||
uint32_t trafftick_curr = HAL_GetTick();
|
|
||||||
|
|
||||||
if ((trafftick_curr - trafftick_last))
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,513 @@
|
|||||||
|
/* USER CODE BEGIN Header */
|
||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
* @file : main.c
|
||||||
|
* @brief : Main program body
|
||||||
|
******************************************************************************
|
||||||
|
* @attention
|
||||||
|
*
|
||||||
|
* Copyright (c) 2025 STMicroelectronics.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This software is licensed under terms that can be found in the LICENSE file
|
||||||
|
* in the root directory of this software component.
|
||||||
|
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||||
|
*
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
/* USER CODE END Header */
|
||||||
|
/* Includes ------------------------------------------------------------------*/
|
||||||
|
#include "main.h"
|
||||||
|
#include "cmsis_os.h"
|
||||||
|
|
||||||
|
/* Private includes ----------------------------------------------------------*/
|
||||||
|
/* USER CODE BEGIN Includes */
|
||||||
|
#include "breadboard.h"
|
||||||
|
#include <stdbool.h>
|
||||||
|
/* USER CODE END Includes */
|
||||||
|
|
||||||
|
/* Private typedef -----------------------------------------------------------*/
|
||||||
|
/* USER CODE BEGIN PTD */
|
||||||
|
|
||||||
|
/* USER CODE END PTD */
|
||||||
|
|
||||||
|
/* Private define ------------------------------------------------------------*/
|
||||||
|
/* USER CODE BEGIN PD */
|
||||||
|
|
||||||
|
/* USER CODE END PD */
|
||||||
|
|
||||||
|
/* Private macro -------------------------------------------------------------*/
|
||||||
|
/* USER CODE BEGIN PM */
|
||||||
|
|
||||||
|
/* USER CODE END PM */
|
||||||
|
|
||||||
|
/* Private variables ---------------------------------------------------------*/
|
||||||
|
CRC_HandleTypeDef hcrc;
|
||||||
|
|
||||||
|
DMA2D_HandleTypeDef hdma2d;
|
||||||
|
|
||||||
|
TIM_HandleTypeDef htim1;
|
||||||
|
|
||||||
|
osThreadId defaultTaskHandle;
|
||||||
|
/* USER CODE BEGIN PV */
|
||||||
|
|
||||||
|
/* USER CODE END PV */
|
||||||
|
|
||||||
|
/* Private function prototypes -----------------------------------------------*/
|
||||||
|
void SystemClock_Config(void);
|
||||||
|
static void MX_GPIO_Init(void);
|
||||||
|
static void MX_CRC_Init(void);
|
||||||
|
static void MX_DMA2D_Init(void);
|
||||||
|
static void MX_TIM1_Init(void);
|
||||||
|
void StartDefaultTask(void const * argument);
|
||||||
|
|
||||||
|
void SetTrafficLights(TrafficSate s);
|
||||||
|
|
||||||
|
/* USER CODE BEGIN PFP */
|
||||||
|
|
||||||
|
/* USER CODE END PFP */
|
||||||
|
|
||||||
|
/* Private user code ---------------------------------------------------------*/
|
||||||
|
|
||||||
|
/* USER CODE BEGIN 0 */
|
||||||
|
|
||||||
|
enum class TrafficState {
|
||||||
|
GREEN,
|
||||||
|
YELLOW,
|
||||||
|
RED
|
||||||
|
};
|
||||||
|
|
||||||
|
TrafficState currentState = TrafficState::GREEN;
|
||||||
|
uint32_t stateStartTime = 0; // HAL_GetTick() at the start of this state
|
||||||
|
bool buttonPressed = false;
|
||||||
|
bool pedestrianNextCycle = false;
|
||||||
|
|
||||||
|
const uint32_t DURATION_GREEN = 5000;
|
||||||
|
const uint32_t DURATION_YELLOW = 3000;
|
||||||
|
const uint32_t DURATION_RED = 5000;
|
||||||
|
const uint32_t DURATION_RED_PED = 7000;
|
||||||
|
|
||||||
|
/* USER CODE END 0 */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief The application entry point.
|
||||||
|
* @retval int
|
||||||
|
*/
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* USER CODE BEGIN 1 */
|
||||||
|
|
||||||
|
/* USER CODE END 1 */
|
||||||
|
|
||||||
|
/* MCU Configuration--------------------------------------------------------*/
|
||||||
|
|
||||||
|
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
|
||||||
|
HAL_Init();
|
||||||
|
|
||||||
|
/* USER CODE BEGIN Init */
|
||||||
|
|
||||||
|
/* USER CODE END Init */
|
||||||
|
|
||||||
|
/* Configure the system clock */
|
||||||
|
SystemClock_Config();
|
||||||
|
|
||||||
|
/* USER CODE BEGIN SysInit */
|
||||||
|
|
||||||
|
stateStartTime = HAL_GetTick();
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
|
||||||
|
/* USER CODE END SysInit */
|
||||||
|
|
||||||
|
/* Initialize all configured peripherals */
|
||||||
|
MX_GPIO_Init();
|
||||||
|
MX_CRC_Init();
|
||||||
|
MX_DMA2D_Init();
|
||||||
|
MX_TIM1_Init();
|
||||||
|
/* USER CODE BEGIN 2 */
|
||||||
|
|
||||||
|
/* USER CODE END 2 */
|
||||||
|
|
||||||
|
/* USER CODE BEGIN RTOS_MUTEX */
|
||||||
|
/* add mutexes, ... */
|
||||||
|
/* USER CODE END RTOS_MUTEX */
|
||||||
|
|
||||||
|
/* USER CODE BEGIN RTOS_SEMAPHORES */
|
||||||
|
/* add semaphores, ... */
|
||||||
|
/* USER CODE END RTOS_SEMAPHORES */
|
||||||
|
|
||||||
|
/* USER CODE BEGIN RTOS_TIMERS */
|
||||||
|
/* start timers, add new ones, ... */
|
||||||
|
/* USER CODE END RTOS_TIMERS */
|
||||||
|
|
||||||
|
/* USER CODE BEGIN RTOS_QUEUES */
|
||||||
|
/* add queues, ... */
|
||||||
|
/* USER CODE END RTOS_QUEUES */
|
||||||
|
|
||||||
|
/* Create the thread(s) */
|
||||||
|
/* definition and creation of defaultTask */
|
||||||
|
//osThreadDef(defaultTask, StartDefaultTask, osPriorityNormal, 0, 4096);
|
||||||
|
//defaultTaskHandle = osThreadCreate(osThread(defaultTask), NULL);
|
||||||
|
|
||||||
|
/* USER CODE BEGIN RTOS_THREADS */
|
||||||
|
/* add threads, ... */
|
||||||
|
/* USER CODE END RTOS_THREADS */
|
||||||
|
|
||||||
|
/* Start scheduler */
|
||||||
|
osKernelStart();
|
||||||
|
|
||||||
|
/* We should never get here as control is now taken by the scheduler */
|
||||||
|
|
||||||
|
/* Infinite loop */
|
||||||
|
/* USER CODE BEGIN WHILE */
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
uint32_t now = HAL_GetTick();
|
||||||
|
uint32_t elapsed = now - stateStartTime;
|
||||||
|
|
||||||
|
/*
|
||||||
|
switch(currentState)
|
||||||
|
{
|
||||||
|
case TrafficState::GREEN:
|
||||||
|
if (elapsed >= DURATION_GREEN) {
|
||||||
|
currentState = TrafficState::YELLOW;
|
||||||
|
stateStartTime = now;
|
||||||
|
buttonPressed = false; // reset the button-flag for the new cycle
|
||||||
|
} else if (buttonPressed) {
|
||||||
|
//idk
|
||||||
|
buttonPressed = true;
|
||||||
|
currentState = TrafficState::YELLOW;
|
||||||
|
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case TrafficState::YELLOW:
|
||||||
|
break;
|
||||||
|
case TrafficState::RED:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
switch(currentState)
|
||||||
|
{
|
||||||
|
case TrafficState::GREEN:
|
||||||
|
if (butonPressedThisCycle)
|
||||||
|
{
|
||||||
|
currentState = TrafficState::YELLOW;
|
||||||
|
stateStartTime = now;
|
||||||
|
buttonPressedThisCycle = false;
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
} else if (elapsed >= DURATION_GREEN)
|
||||||
|
{
|
||||||
|
buttonPressedThisCycle = true;
|
||||||
|
currentState = TrafficState::YELLOW;
|
||||||
|
stateStartTime = now;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case TrafficState::YELLOW:
|
||||||
|
if (elapsed >= DURATION_YELLOW)
|
||||||
|
{
|
||||||
|
currentState = TrafficState::RED;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case TrafficState::RED:
|
||||||
|
//
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/* USER CODE END WHILE */
|
||||||
|
|
||||||
|
/* USER CODE BEGIN 3 */
|
||||||
|
}
|
||||||
|
/* USER CODE END 3 */
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief System Clock Configuration
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void SystemClock_Config(void)
|
||||||
|
{
|
||||||
|
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
|
||||||
|
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
|
||||||
|
|
||||||
|
/** Configure the main internal regulator output voltage
|
||||||
|
*/
|
||||||
|
__HAL_RCC_PWR_CLK_ENABLE();
|
||||||
|
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE3);
|
||||||
|
|
||||||
|
/** Initializes the RCC Oscillators according to the specified parameters
|
||||||
|
* in the RCC_OscInitTypeDef structure.
|
||||||
|
*/
|
||||||
|
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
|
||||||
|
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
|
||||||
|
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
|
||||||
|
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
||||||
|
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
|
||||||
|
RCC_OscInitStruct.PLL.PLLM = 8;
|
||||||
|
RCC_OscInitStruct.PLL.PLLN = 72;
|
||||||
|
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
|
||||||
|
RCC_OscInitStruct.PLL.PLLQ = 3;
|
||||||
|
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Initializes the CPU, AHB and APB buses clocks
|
||||||
|
*/
|
||||||
|
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|
||||||
|
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
|
||||||
|
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
|
||||||
|
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
|
||||||
|
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
|
||||||
|
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
|
||||||
|
|
||||||
|
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief CRC Initialization Function
|
||||||
|
* @param None
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
static void MX_CRC_Init(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* USER CODE BEGIN CRC_Init 0 */
|
||||||
|
|
||||||
|
/* USER CODE END CRC_Init 0 */
|
||||||
|
|
||||||
|
/* USER CODE BEGIN CRC_Init 1 */
|
||||||
|
|
||||||
|
/* USER CODE END CRC_Init 1 */
|
||||||
|
hcrc.Instance = CRC;
|
||||||
|
if (HAL_CRC_Init(&hcrc) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
/* USER CODE BEGIN CRC_Init 2 */
|
||||||
|
|
||||||
|
/* USER CODE END CRC_Init 2 */
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief DMA2D Initialization Function
|
||||||
|
* @param None
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
static void MX_DMA2D_Init(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* USER CODE BEGIN DMA2D_Init 0 */
|
||||||
|
|
||||||
|
/* USER CODE END DMA2D_Init 0 */
|
||||||
|
|
||||||
|
/* USER CODE BEGIN DMA2D_Init 1 */
|
||||||
|
|
||||||
|
/* USER CODE END DMA2D_Init 1 */
|
||||||
|
hdma2d.Instance = DMA2D;
|
||||||
|
hdma2d.Init.Mode = DMA2D_M2M;
|
||||||
|
hdma2d.Init.ColorMode = DMA2D_OUTPUT_ARGB8888;
|
||||||
|
hdma2d.Init.OutputOffset = 0;
|
||||||
|
hdma2d.LayerCfg[1].InputOffset = 0;
|
||||||
|
hdma2d.LayerCfg[1].InputColorMode = DMA2D_INPUT_ARGB8888;
|
||||||
|
hdma2d.LayerCfg[1].AlphaMode = DMA2D_NO_MODIF_ALPHA;
|
||||||
|
hdma2d.LayerCfg[1].InputAlpha = 0;
|
||||||
|
if (HAL_DMA2D_Init(&hdma2d) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
if (HAL_DMA2D_ConfigLayer(&hdma2d, 1) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
/* USER CODE BEGIN DMA2D_Init 2 */
|
||||||
|
|
||||||
|
/* USER CODE END DMA2D_Init 2 */
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief TIM1 Initialization Function
|
||||||
|
* @param None
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
static void MX_TIM1_Init(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* USER CODE BEGIN TIM1_Init 0 */
|
||||||
|
|
||||||
|
/* USER CODE END TIM1_Init 0 */
|
||||||
|
|
||||||
|
TIM_ClockConfigTypeDef sClockSourceConfig = {0};
|
||||||
|
TIM_MasterConfigTypeDef sMasterConfig = {0};
|
||||||
|
|
||||||
|
/* USER CODE BEGIN TIM1_Init 1 */
|
||||||
|
|
||||||
|
/* USER CODE END TIM1_Init 1 */
|
||||||
|
htim1.Instance = TIM1;
|
||||||
|
htim1.Init.Prescaler = 0;
|
||||||
|
htim1.Init.CounterMode = TIM_COUNTERMODE_UP;
|
||||||
|
htim1.Init.Period = 65535;
|
||||||
|
htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
||||||
|
htim1.Init.RepetitionCounter = 0;
|
||||||
|
htim1.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
|
||||||
|
if (HAL_TIM_Base_Init(&htim1) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
|
||||||
|
if (HAL_TIM_ConfigClockSource(&htim1, &sClockSourceConfig) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
|
||||||
|
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
|
||||||
|
if (HAL_TIMEx_MasterConfigSynchronization(&htim1, &sMasterConfig) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
/* USER CODE BEGIN TIM1_Init 2 */
|
||||||
|
|
||||||
|
/* USER CODE END TIM1_Init 2 */
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief GPIO Initialization Function
|
||||||
|
* @param None
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
static void MX_GPIO_Init(void)
|
||||||
|
{
|
||||||
|
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||||
|
/* USER CODE BEGIN MX_GPIO_Init_1 */
|
||||||
|
|
||||||
|
/* USER CODE END MX_GPIO_Init_1 */
|
||||||
|
|
||||||
|
/* GPIO Ports Clock Enable */
|
||||||
|
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||||
|
__HAL_RCC_GPIOD_CLK_ENABLE();
|
||||||
|
|
||||||
|
/*Configure GPIO pin Output Level */
|
||||||
|
HAL_GPIO_WritePin(GPIOD, White_Pin|Red_Pin|Yellow_Pin|Green_Pin, GPIO_PIN_RESET);
|
||||||
|
|
||||||
|
/*Configure GPIO pin : PedButton_Pin */
|
||||||
|
GPIO_InitStruct.Pin = PedButton_Pin;
|
||||||
|
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
|
||||||
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
|
HAL_GPIO_Init(PedButton_GPIO_Port, &GPIO_InitStruct);
|
||||||
|
|
||||||
|
/*Configure GPIO pins : White_Pin Red_Pin Yellow_Pin Green_Pin */
|
||||||
|
GPIO_InitStruct.Pin = White_Pin|Red_Pin|Yellow_Pin|Green_Pin;
|
||||||
|
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||||
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||||
|
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
|
||||||
|
|
||||||
|
/* EXTI interrupt init*/
|
||||||
|
HAL_NVIC_SetPriority(EXTI15_10_IRQn, 15, 0);
|
||||||
|
HAL_NVIC_EnableIRQ(EXTI15_10_IRQn);
|
||||||
|
|
||||||
|
/* USER CODE BEGIN MX_GPIO_Init_2 */
|
||||||
|
|
||||||
|
/* USER CODE END MX_GPIO_Init_2 */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* USER CODE BEGIN 4 */
|
||||||
|
|
||||||
|
void HAL_GPIO_EXTI_CallBack(uint16_t GPIO_Pin)
|
||||||
|
{
|
||||||
|
static uint32_t lastInterruptTime = 0;
|
||||||
|
uint32_t now = HAL_GetTick();
|
||||||
|
if (now - lastInterruptTime < 100) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
lastInterruptTime = now;
|
||||||
|
|
||||||
|
bool buttonPressedThisCycle = false; // temporary, get rid of this
|
||||||
|
|
||||||
|
if (buttonPressed) { // buttonPressedHere?
|
||||||
|
buttonPressedThisCycle = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* USER CODE END 4 */
|
||||||
|
|
||||||
|
/* USER CODE BEGIN Header_StartDefaultTask */
|
||||||
|
/**
|
||||||
|
* @brief Function implementing the defaultTask thread.
|
||||||
|
* @param argument: Not used
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
/* USER CODE END Header_StartDefaultTask */
|
||||||
|
void StartDefaultTask(void const * argument)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN 5 */
|
||||||
|
/* Infinite loop */
|
||||||
|
for(;;)
|
||||||
|
{
|
||||||
|
osDelay(1);
|
||||||
|
}
|
||||||
|
/* USER CODE END 5 */
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Period elapsed callback in non blocking mode
|
||||||
|
* @note This function is called when TIM6 interrupt took place, inside
|
||||||
|
* HAL_TIM_IRQHandler(). It makes a direct call to HAL_IncTick() to increment
|
||||||
|
* a global variable "uwTick" used as application time base.
|
||||||
|
* @param htim : TIM handle
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN Callback 0 */
|
||||||
|
|
||||||
|
/* USER CODE END Callback 0 */
|
||||||
|
if (htim->Instance == TIM6)
|
||||||
|
{
|
||||||
|
HAL_IncTick();
|
||||||
|
}
|
||||||
|
/* USER CODE BEGIN Callback 1 */
|
||||||
|
|
||||||
|
/* USER CODE END Callback 1 */
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function is executed in case of error occurrence.
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void Error_Handler(void)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN Error_Handler_Debug */
|
||||||
|
/* User can add his own implementation to report the HAL error return state */
|
||||||
|
__disable_irq();
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
/* USER CODE END Error_Handler_Debug */
|
||||||
|
}
|
||||||
|
#ifdef USE_FULL_ASSERT
|
||||||
|
/**
|
||||||
|
* @brief Reports the name of the source file and the source line number
|
||||||
|
* where the assert_param error has occurred.
|
||||||
|
* @param file: pointer to the source file name
|
||||||
|
* @param line: assert_param error line source number
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void assert_failed(uint8_t *file, uint32_t line)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN 6 */
|
||||||
|
/* User can add his own implementation to report the file name and line number,
|
||||||
|
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
|
||||||
|
/* USER CODE END 6 */
|
||||||
|
}
|
||||||
|
#endif /* USE_FULL_ASSERT */
|
||||||
@@ -1,88 +0,0 @@
|
|||||||
/*
|
|
||||||
* breadboard.c
|
|
||||||
*
|
|
||||||
* Created on: Sep 17, 2025
|
|
||||||
* Author: ja
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* #define RedLight_Pin GPIO_PIN_2
|
|
||||||
* #define RedLight_GPIO_Port GPIOE
|
|
||||||
*
|
|
||||||
* #define YellowLight_Pin GPIO_PIN_3
|
|
||||||
* #define YellowLight_GPIO_Port GPIOE
|
|
||||||
*
|
|
||||||
* #define GreenLight_Pin GPIO_PIN_4
|
|
||||||
* #define GreenLight_GPIO_Port GPIOE
|
|
||||||
*
|
|
||||||
* RedLight: PE2
|
|
||||||
* YellowLight: PE3
|
|
||||||
* GreenLight: PE4
|
|
||||||
* WalkLight: PE5
|
|
||||||
*
|
|
||||||
* Done: Traffic Light
|
|
||||||
* TODO: async? Walk Signal, Light Dimmer
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "main.h"
|
|
||||||
#include "breadboard.h"
|
|
||||||
|
|
||||||
#define R_Pin RedLight_Pin
|
|
||||||
#define Y_Pin YellowLight_Pin
|
|
||||||
#define G_Pin GreenLight_Pin
|
|
||||||
#define W_Pin WalkLight_Pin
|
|
||||||
|
|
||||||
#define R_Prt RedLight_GPIO_Port
|
|
||||||
#define Y_Prt YellowLight_GPIO_Port
|
|
||||||
#define G_Prt GreenLight_GPIO_Port
|
|
||||||
#define W_Prt WalkLight_GPIO_Port
|
|
||||||
|
|
||||||
uint32_t trafftick_last;
|
|
||||||
|
|
||||||
uint8_t trafflight_i = 0;
|
|
||||||
|
|
||||||
void
|
|
||||||
starttick(void)
|
|
||||||
{
|
|
||||||
trafftick_last = HAL_GetTick();
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
trafflight(int traffSPD)
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
HAL_GPIO_TogglePin(R_Prt, R_Pin);
|
|
||||||
HAL_Delay(traffSPD);
|
|
||||||
HAL_GPIO_TogglePin(R_Prt, R_Pin);
|
|
||||||
|
|
||||||
HAL_GPIO_TogglePin(Y_Prt, Y_Pin);
|
|
||||||
HAL_Delay(traffSPD);
|
|
||||||
HAL_GPIO_TogglePin(Y_Prt, Y_Pin);
|
|
||||||
|
|
||||||
HAL_GPIO_TogglePin(G_Prt, G_Pin);
|
|
||||||
HAL_Delay(traffSPD);
|
|
||||||
HAL_GPIO_TogglePin(G_Prt, G_Pin);
|
|
||||||
*/
|
|
||||||
|
|
||||||
uint32_t trafftick_curr = HAL_GetTick();
|
|
||||||
|
|
||||||
if ((trafftick_curr - trafftick_last) >= traffSPD) {
|
|
||||||
HAL_GPIO_WritePin(
|
|
||||||
R_Prt, R_Pin |
|
|
||||||
Y_Prt, Y_Pin |
|
|
||||||
G_Prt, G_Pin,
|
|
||||||
GPIO_PIN_RESET
|
|
||||||
);
|
|
||||||
|
|
||||||
switch (trafflight_i) {
|
|
||||||
case 0:
|
|
||||||
HAL_GPIO_WritePin(R_Prt, R_Pin);
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
HAL_GPIO_WritePin(Y_Prt, Y_Pin);
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
HAL_GPIO_WritePin(G_Prt, G_Pin);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,532 @@
|
|||||||
|
/* USER CODE BEGIN Header */
|
||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
* @file : main.c
|
||||||
|
* @brief : Main program body
|
||||||
|
******************************************************************************
|
||||||
|
* @attention
|
||||||
|
*
|
||||||
|
* Copyright (c) 2025 STMicroelectronics.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This software is licensed under terms that can be found in the LICENSE file
|
||||||
|
* in the root directory of this software component.
|
||||||
|
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||||
|
*
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
/* USER CODE END Header */
|
||||||
|
/* Includes ------------------------------------------------------------------*/
|
||||||
|
#include "main.h"
|
||||||
|
#include "cmsis_os.h"
|
||||||
|
|
||||||
|
/* Private includes ----------------------------------------------------------*/
|
||||||
|
/* USER CODE BEGIN Includes */
|
||||||
|
#include "breadboard.h"
|
||||||
|
#include <stdbool.h>
|
||||||
|
/* USER CODE END Includes */
|
||||||
|
|
||||||
|
/* Private typedef -----------------------------------------------------------*/
|
||||||
|
/* USER CODE BEGIN PTD */
|
||||||
|
|
||||||
|
/* USER CODE END PTD */
|
||||||
|
|
||||||
|
/* Private define ------------------------------------------------------------*/
|
||||||
|
/* USER CODE BEGIN PD */
|
||||||
|
|
||||||
|
/* USER CODE END PD */
|
||||||
|
|
||||||
|
/* Private macro -------------------------------------------------------------*/
|
||||||
|
/* USER CODE BEGIN PM */
|
||||||
|
|
||||||
|
/* USER CODE END PM */
|
||||||
|
|
||||||
|
/* Private variables ---------------------------------------------------------*/
|
||||||
|
CRC_HandleTypeDef hcrc;
|
||||||
|
|
||||||
|
DMA2D_HandleTypeDef hdma2d;
|
||||||
|
|
||||||
|
TIM_HandleTypeDef htim1;
|
||||||
|
|
||||||
|
osThreadId defaultTaskHandle;
|
||||||
|
/* USER CODE BEGIN PV */
|
||||||
|
|
||||||
|
/* USER CODE END PV */
|
||||||
|
|
||||||
|
/* Private function prototypes -----------------------------------------------*/
|
||||||
|
void SystemClock_Config(void);
|
||||||
|
static void MX_GPIO_Init(void);
|
||||||
|
static void MX_CRC_Init(void);
|
||||||
|
static void MX_DMA2D_Init(void);
|
||||||
|
static void MX_TIM1_Init(void);
|
||||||
|
void StartDefaultTask(void const * argument);
|
||||||
|
|
||||||
|
void SetTrafficLights(TrafficSate s);
|
||||||
|
|
||||||
|
/* USER CODE BEGIN PFP */
|
||||||
|
|
||||||
|
/* USER CODE END PFP */
|
||||||
|
|
||||||
|
/* Private user code ---------------------------------------------------------*/
|
||||||
|
|
||||||
|
/* USER CODE BEGIN 0 */
|
||||||
|
|
||||||
|
enum class TrafficState {
|
||||||
|
GREEN,
|
||||||
|
YELLOW,
|
||||||
|
RED
|
||||||
|
};
|
||||||
|
|
||||||
|
TrafficState currentState = TrafficState::GREEN;
|
||||||
|
uint32_t stateStartTime = 0; // HAL_GetTick() at the start of this state
|
||||||
|
bool buttonPressed = false;
|
||||||
|
bool pedestrianNextCycle = false;
|
||||||
|
|
||||||
|
const uint32_t DURATION_GREEN = 5000;
|
||||||
|
const uint32_t DURATION_YELLOW = 3000;
|
||||||
|
const uint32_t DURATION_RED = 5000;
|
||||||
|
const uint32_t DURATION_RED_PED = 7000;
|
||||||
|
|
||||||
|
/* USER CODE END 0 */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief The application entry point.
|
||||||
|
* @retval int
|
||||||
|
*/
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* USER CODE BEGIN 1 */
|
||||||
|
|
||||||
|
/* USER CODE END 1 */
|
||||||
|
|
||||||
|
/* MCU Configuration--------------------------------------------------------*/
|
||||||
|
|
||||||
|
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
|
||||||
|
HAL_Init();
|
||||||
|
|
||||||
|
/* USER CODE BEGIN Init */
|
||||||
|
|
||||||
|
/* USER CODE END Init */
|
||||||
|
|
||||||
|
/* Configure the system clock */
|
||||||
|
SystemClock_Config();
|
||||||
|
|
||||||
|
/* USER CODE BEGIN SysInit */
|
||||||
|
|
||||||
|
stateStartTime = HAL_GetTick();
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
|
||||||
|
/* USER CODE END SysInit */
|
||||||
|
|
||||||
|
/* Initialize all configured peripherals */
|
||||||
|
MX_GPIO_Init();
|
||||||
|
MX_CRC_Init();
|
||||||
|
MX_DMA2D_Init();
|
||||||
|
MX_TIM1_Init();
|
||||||
|
/* USER CODE BEGIN 2 */
|
||||||
|
|
||||||
|
/* USER CODE END 2 */
|
||||||
|
|
||||||
|
/* USER CODE BEGIN RTOS_MUTEX */
|
||||||
|
/* add mutexes, ... */
|
||||||
|
/* USER CODE END RTOS_MUTEX */
|
||||||
|
|
||||||
|
/* USER CODE BEGIN RTOS_SEMAPHORES */
|
||||||
|
/* add semaphores, ... */
|
||||||
|
/* USER CODE END RTOS_SEMAPHORES */
|
||||||
|
|
||||||
|
/* USER CODE BEGIN RTOS_TIMERS */
|
||||||
|
/* start timers, add new ones, ... */
|
||||||
|
/* USER CODE END RTOS_TIMERS */
|
||||||
|
|
||||||
|
/* USER CODE BEGIN RTOS_QUEUES */
|
||||||
|
/* add queues, ... */
|
||||||
|
/* USER CODE END RTOS_QUEUES */
|
||||||
|
|
||||||
|
/* Create the thread(s) */
|
||||||
|
/* definition and creation of defaultTask */
|
||||||
|
//osThreadDef(defaultTask, StartDefaultTask, osPriorityNormal, 0, 4096);
|
||||||
|
//defaultTaskHandle = osThreadCreate(osThread(defaultTask), NULL);
|
||||||
|
|
||||||
|
/* USER CODE BEGIN RTOS_THREADS */
|
||||||
|
/* add threads, ... */
|
||||||
|
/* USER CODE END RTOS_THREADS */
|
||||||
|
|
||||||
|
/* Start scheduler */
|
||||||
|
osKernelStart();
|
||||||
|
|
||||||
|
/* We should never get here as control is now taken by the scheduler */
|
||||||
|
|
||||||
|
/* Infinite loop */
|
||||||
|
/* USER CODE BEGIN WHILE */
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
uint32_t now = HAL_GetTick();
|
||||||
|
uint32_t elapsed = now - stateStartTime;
|
||||||
|
|
||||||
|
/*
|
||||||
|
switch(currentState)
|
||||||
|
{
|
||||||
|
case TrafficState::GREEN:
|
||||||
|
if (elapsed >= DURATION_GREEN) {
|
||||||
|
currentState = TrafficState::YELLOW;
|
||||||
|
stateStartTime = now;
|
||||||
|
buttonPressed = false; // reset the button-flag for the new cycle
|
||||||
|
} else if (buttonPressed) {
|
||||||
|
//idk
|
||||||
|
buttonPressed = true;
|
||||||
|
currentState = TrafficState::YELLOW;
|
||||||
|
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case TrafficState::YELLOW:
|
||||||
|
break;
|
||||||
|
case TrafficState::RED:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
switch(currentState)
|
||||||
|
{
|
||||||
|
case TrafficState::GREEN:
|
||||||
|
if (butonPressedThisCycle)
|
||||||
|
{
|
||||||
|
currentState = TrafficState::YELLOW;
|
||||||
|
stateStartTime = now;
|
||||||
|
buttonPressedThisCycle = false;
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
} else if (elapsed >= DURATION_GREEN)
|
||||||
|
{
|
||||||
|
buttonPressedThisCycle = true;
|
||||||
|
currentState = TrafficState::YELLOW;
|
||||||
|
stateStartTime = now;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case TrafficState::YELLOW:
|
||||||
|
if (elapsed >= DURATION_YELLOW)
|
||||||
|
{
|
||||||
|
currentState = TrafficState::RED;
|
||||||
|
stateStartTime = now;
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
// if ped button was pressed during GREEN or YELLOW,
|
||||||
|
// we need to enable WHITE ...
|
||||||
|
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case TrafficState::RED:
|
||||||
|
if (pedestrianNextCycle)
|
||||||
|
{
|
||||||
|
HAL_GPIO_WritePin(White_GPIO_Port, White_Pin, GPIO_PIN_SET);
|
||||||
|
if (elapsed >= DURATION_RED_PED)
|
||||||
|
{
|
||||||
|
HAL_GPIO_WritePin(White_GPIO_Port, White_Pin, GPIO_PIN_RESET);
|
||||||
|
pedestrianNextCycle = false;
|
||||||
|
currentState = TrafficState::GREEN;
|
||||||
|
stateStartTime = now;
|
||||||
|
SetTrafficLights(currentState);
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
HAL_GPIO_WritePin(White_GPIO_Port, White_Pin, GPIO_Pin_RESET);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/* USER CODE END WHILE */
|
||||||
|
|
||||||
|
/* USER CODE BEGIN 3 */
|
||||||
|
}
|
||||||
|
/* USER CODE END 3 */
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief System Clock Configuration
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void SystemClock_Config(void)
|
||||||
|
{
|
||||||
|
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
|
||||||
|
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
|
||||||
|
|
||||||
|
/** Configure the main internal regulator output voltage
|
||||||
|
*/
|
||||||
|
__HAL_RCC_PWR_CLK_ENABLE();
|
||||||
|
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE3);
|
||||||
|
|
||||||
|
/** Initializes the RCC Oscillators according to the specified parameters
|
||||||
|
* in the RCC_OscInitTypeDef structure.
|
||||||
|
*/
|
||||||
|
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
|
||||||
|
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
|
||||||
|
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
|
||||||
|
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
||||||
|
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
|
||||||
|
RCC_OscInitStruct.PLL.PLLM = 8;
|
||||||
|
RCC_OscInitStruct.PLL.PLLN = 72;
|
||||||
|
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
|
||||||
|
RCC_OscInitStruct.PLL.PLLQ = 3;
|
||||||
|
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Initializes the CPU, AHB and APB buses clocks
|
||||||
|
*/
|
||||||
|
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|
||||||
|
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
|
||||||
|
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
|
||||||
|
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
|
||||||
|
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
|
||||||
|
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
|
||||||
|
|
||||||
|
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief CRC Initialization Function
|
||||||
|
* @param None
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
static void MX_CRC_Init(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* USER CODE BEGIN CRC_Init 0 */
|
||||||
|
|
||||||
|
/* USER CODE END CRC_Init 0 */
|
||||||
|
|
||||||
|
/* USER CODE BEGIN CRC_Init 1 */
|
||||||
|
|
||||||
|
/* USER CODE END CRC_Init 1 */
|
||||||
|
hcrc.Instance = CRC;
|
||||||
|
if (HAL_CRC_Init(&hcrc) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
/* USER CODE BEGIN CRC_Init 2 */
|
||||||
|
|
||||||
|
/* USER CODE END CRC_Init 2 */
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief DMA2D Initialization Function
|
||||||
|
* @param None
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
static void MX_DMA2D_Init(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* USER CODE BEGIN DMA2D_Init 0 */
|
||||||
|
|
||||||
|
/* USER CODE END DMA2D_Init 0 */
|
||||||
|
|
||||||
|
/* USER CODE BEGIN DMA2D_Init 1 */
|
||||||
|
|
||||||
|
/* USER CODE END DMA2D_Init 1 */
|
||||||
|
hdma2d.Instance = DMA2D;
|
||||||
|
hdma2d.Init.Mode = DMA2D_M2M;
|
||||||
|
hdma2d.Init.ColorMode = DMA2D_OUTPUT_ARGB8888;
|
||||||
|
hdma2d.Init.OutputOffset = 0;
|
||||||
|
hdma2d.LayerCfg[1].InputOffset = 0;
|
||||||
|
hdma2d.LayerCfg[1].InputColorMode = DMA2D_INPUT_ARGB8888;
|
||||||
|
hdma2d.LayerCfg[1].AlphaMode = DMA2D_NO_MODIF_ALPHA;
|
||||||
|
hdma2d.LayerCfg[1].InputAlpha = 0;
|
||||||
|
if (HAL_DMA2D_Init(&hdma2d) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
if (HAL_DMA2D_ConfigLayer(&hdma2d, 1) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
/* USER CODE BEGIN DMA2D_Init 2 */
|
||||||
|
|
||||||
|
/* USER CODE END DMA2D_Init 2 */
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief TIM1 Initialization Function
|
||||||
|
* @param None
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
static void MX_TIM1_Init(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* USER CODE BEGIN TIM1_Init 0 */
|
||||||
|
|
||||||
|
/* USER CODE END TIM1_Init 0 */
|
||||||
|
|
||||||
|
TIM_ClockConfigTypeDef sClockSourceConfig = {0};
|
||||||
|
TIM_MasterConfigTypeDef sMasterConfig = {0};
|
||||||
|
|
||||||
|
/* USER CODE BEGIN TIM1_Init 1 */
|
||||||
|
|
||||||
|
/* USER CODE END TIM1_Init 1 */
|
||||||
|
htim1.Instance = TIM1;
|
||||||
|
htim1.Init.Prescaler = 0;
|
||||||
|
htim1.Init.CounterMode = TIM_COUNTERMODE_UP;
|
||||||
|
htim1.Init.Period = 65535;
|
||||||
|
htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
||||||
|
htim1.Init.RepetitionCounter = 0;
|
||||||
|
htim1.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
|
||||||
|
if (HAL_TIM_Base_Init(&htim1) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
|
||||||
|
if (HAL_TIM_ConfigClockSource(&htim1, &sClockSourceConfig) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
|
||||||
|
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
|
||||||
|
if (HAL_TIMEx_MasterConfigSynchronization(&htim1, &sMasterConfig) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
/* USER CODE BEGIN TIM1_Init 2 */
|
||||||
|
|
||||||
|
/* USER CODE END TIM1_Init 2 */
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief GPIO Initialization Function
|
||||||
|
* @param None
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
static void MX_GPIO_Init(void)
|
||||||
|
{
|
||||||
|
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||||
|
/* USER CODE BEGIN MX_GPIO_Init_1 */
|
||||||
|
|
||||||
|
/* USER CODE END MX_GPIO_Init_1 */
|
||||||
|
|
||||||
|
/* GPIO Ports Clock Enable */
|
||||||
|
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||||
|
__HAL_RCC_GPIOD_CLK_ENABLE();
|
||||||
|
|
||||||
|
/*Configure GPIO pin Output Level */
|
||||||
|
HAL_GPIO_WritePin(GPIOD, White_Pin|Red_Pin|Yellow_Pin|Green_Pin, GPIO_PIN_RESET);
|
||||||
|
|
||||||
|
/*Configure GPIO pin : PedButton_Pin */
|
||||||
|
GPIO_InitStruct.Pin = PedButton_Pin;
|
||||||
|
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
|
||||||
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
|
HAL_GPIO_Init(PedButton_GPIO_Port, &GPIO_InitStruct);
|
||||||
|
|
||||||
|
/*Configure GPIO pins : White_Pin Red_Pin Yellow_Pin Green_Pin */
|
||||||
|
GPIO_InitStruct.Pin = White_Pin|Red_Pin|Yellow_Pin|Green_Pin;
|
||||||
|
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||||
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||||
|
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
|
||||||
|
|
||||||
|
/* EXTI interrupt init*/
|
||||||
|
HAL_NVIC_SetPriority(EXTI15_10_IRQn, 15, 0);
|
||||||
|
HAL_NVIC_EnableIRQ(EXTI15_10_IRQn);
|
||||||
|
|
||||||
|
/* USER CODE BEGIN MX_GPIO_Init_2 */
|
||||||
|
|
||||||
|
/* USER CODE END MX_GPIO_Init_2 */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* USER CODE BEGIN 4 */
|
||||||
|
|
||||||
|
void HAL_GPIO_EXTI_CallBack(uint16_t GPIO_Pin)
|
||||||
|
{
|
||||||
|
static uint32_t lastInterruptTime = 0;
|
||||||
|
uint32_t now = HAL_GetTick();
|
||||||
|
if (now - lastInterruptTime < 100) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
lastInterruptTime = now;
|
||||||
|
|
||||||
|
bool buttonPressedThisCycle = false; // temporary, get rid of this
|
||||||
|
|
||||||
|
if (buttonPressed) { // buttonPressedHere?
|
||||||
|
buttonPressedThisCycle = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* USER CODE END 4 */
|
||||||
|
|
||||||
|
/* USER CODE BEGIN Header_StartDefaultTask */
|
||||||
|
/**
|
||||||
|
* @brief Function implementing the defaultTask thread.
|
||||||
|
* @param argument: Not used
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
/* USER CODE END Header_StartDefaultTask */
|
||||||
|
void StartDefaultTask(void const * argument)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN 5 */
|
||||||
|
/* Infinite loop */
|
||||||
|
for(;;)
|
||||||
|
{
|
||||||
|
osDelay(1);
|
||||||
|
}
|
||||||
|
/* USER CODE END 5 */
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Period elapsed callback in non blocking mode
|
||||||
|
* @note This function is called when TIM6 interrupt took place, inside
|
||||||
|
* HAL_TIM_IRQHandler(). It makes a direct call to HAL_IncTick() to increment
|
||||||
|
* a global variable "uwTick" used as application time base.
|
||||||
|
* @param htim : TIM handle
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN Callback 0 */
|
||||||
|
|
||||||
|
/* USER CODE END Callback 0 */
|
||||||
|
if (htim->Instance == TIM6)
|
||||||
|
{
|
||||||
|
HAL_IncTick();
|
||||||
|
}
|
||||||
|
/* USER CODE BEGIN Callback 1 */
|
||||||
|
|
||||||
|
/* USER CODE END Callback 1 */
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function is executed in case of error occurrence.
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void Error_Handler(void)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN Error_Handler_Debug */
|
||||||
|
/* User can add his own implementation to report the HAL error return state */
|
||||||
|
__disable_irq();
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
/* USER CODE END Error_Handler_Debug */
|
||||||
|
}
|
||||||
|
#ifdef USE_FULL_ASSERT
|
||||||
|
/**
|
||||||
|
* @brief Reports the name of the source file and the source line number
|
||||||
|
* where the assert_param error has occurred.
|
||||||
|
* @param file: pointer to the source file name
|
||||||
|
* @param line: assert_param error line source number
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void assert_failed(uint8_t *file, uint32_t line)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN 6 */
|
||||||
|
/* User can add his own implementation to report the file name and line number,
|
||||||
|
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
|
||||||
|
/* USER CODE END 6 */
|
||||||
|
}
|
||||||
|
#endif /* USE_FULL_ASSERT */
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user