2025-03-17 3:58 PM
Hi, I am following a course about USB bare metal, up until now I had no problems but the moment it started touching USB stuff the compiler started to give me errors, I think it's mostly that it does not recognize some definitions like USB_OTG_GlobalTypeDef even though it is in the stm32f407xx header file from the official CMSIS from ST.
Note that all this code is bare metal (mostly).
This is the full build log:
19:42:59 **** Incremental Build of configuration Debug for project USB_COURSE ****
make -j12 all
arm-none-eabi-gcc "../Src/usbd_driver.c" -mcpu=cortex-m4 -std=gnu11 -g3 -DDEBUG -DSTM32 -DSTM32F407G_DISC1 -DSTM32F4 -DSTM32F407VGTx -DSTM32F407xx -c -I../Inc -I"C:/Users/nicoc/Desktop/archivos/codigo/STM/USB_COURSE/Inc/CMSIS/Include" -I"C:/Users/nicoc/Desktop/archivos/codigo/STM/USB_COURSE/Inc/CMSIS/Device/ST/STM32F4xx/Include" -O0 -ffunction-sections -fdata-sections -Wall -fstack-usage -fcyclomatic-complexity -MMD -MP -MF"Src/usbd_driver.d" -MT"Src/usbd_driver.o" --specs=nano.specs -mfpu=fpv4-sp-d16 -mfloat-abi=hard -mthumb -o "Src/usbd_driver.o"
In file included from C:/Users/nicoc/Desktop/archivos/codigo/STM/USB_COURSE/Inc/CMSIS/Device/ST/STM32F4xx/Include/stm32f4xx.h:132,
from ../Inc/usbd_driver.h:11,
from ../Src/usbd_driver.c:1:
C:/Users/nicoc/Desktop/archivos/codigo/STM/USB_COURSE/Inc/CMSIS/Device/ST/STM32F4xx/Include/stm32f407xx.h:1144:31: error: expected identifier or '(' before 'USB_OTG_GlobalTypeDef'
1144 | #define USB_OTG_FS ((USB_OTG_GlobalTypeDef *) USB_OTG_FS_PERIPH_BASE)
| ^~~~~~~~~~~~~~~~~~~~~
../Src/usbd_driver.c:4:1: note: in expansion of macro 'USB_OTG_FS'
4 | USB_OTG_FS;
| ^~~~~~~~~~
C:/Users/nicoc/Desktop/archivos/codigo/STM/USB_COURSE/Inc/CMSIS/Device/ST/STM32F4xx/Include/stm32f407xx.h:1036:46: error: expected ')' before numeric constant
1036 | #define USB_OTG_FS_PERIPH_BASE 0x50000000UL
| ^~~~~~~~~~~~
C:/Users/nicoc/Desktop/archivos/codigo/STM/USB_COURSE/Inc/CMSIS/Device/ST/STM32F4xx/Include/stm32f407xx.h:1144:56: note: in expansion of macro 'USB_OTG_FS_PERIPH_BASE'
1144 | #define USB_OTG_FS ((USB_OTG_GlobalTypeDef *) USB_OTG_FS_PERIPH_BASE)
| ^~~~~~~~~~~~~~~~~~~~~~
../Src/usbd_driver.c:4:1: note: in expansion of macro 'USB_OTG_FS'
4 | USB_OTG_FS;
| ^~~~~~~~~~
make: *** [Src/subdir.mk:34: Src/usbd_driver.o] Error 1
"make -j12 all" terminated with exit code 2. Build might be incomplete.
Any errors you may find (in this post or in the code) you can point it out to me.
Solved! Go to Solution.
2025-03-17 4:24 PM - edited 2025-03-17 4:25 PM
Here is your usbd_driver.c file:
#include <usbd_driver.h>
USB_OTG_FS;
This is not valid code. What are you trying to achieve here? At the top level scope you can create global variables or define functions.
Nothing wrong with how USB_OTG_FS is defined, but it doesn't make this valid code here. Expand out the defines.
2025-03-17 4:24 PM - edited 2025-03-17 4:25 PM
Here is your usbd_driver.c file:
#include <usbd_driver.h>
USB_OTG_FS;
This is not valid code. What are you trying to achieve here? At the top level scope you can create global variables or define functions.
Nothing wrong with how USB_OTG_FS is defined, but it doesn't make this valid code here. Expand out the defines.
2025-03-17 5:00 PM
Now that I see it a feel dumb for making such a newbie mistake, I did not remember that one cannot access/modify something outside the scope of a function. Sorry for making such a time-wasting post.