Stm32f407vg stm32f4discovery: Difference between revisions
No edit summary |
m (Fixed baudrate, was 115200 but is 19200) |
||
(11 intermediate revisions by 5 users not shown) | |||
Line 1: | Line 1: | ||
This is a cheap self contained [http://www.st.com/web/catalog/tools/PF252419 discovery board] with a powerful processor, and a Linux-friendly [http://www.st.com/web/catalog/tools/PF219866 ST-LINK/V2] programmer/in circuit debugger. | |||
The board is equipped with | |||
* | * A [http://www.st.com/web/catalog/mmc/FM141/SC1169/SS1577/LN11/PF252140 STM32F407VG] microcontroller with a 168MHz ARM Cortex-M4F core, 1024KB Flash, 192KB RAM, 4KB battery-backed RAM in LQFP100 package. | ||
* A LIS302DL accelerometer, MP45DT02 mems microphone, CS43L22 audio DAC, 4 user LEDs, user button, reset button, a second USB connector as the microcontroller supports USB. | |||
[[File:Stm32f4discovery.jpg|frameless]] | |||
== Configuring the kernel == | |||
The minimum configuration required is to edit the [[Makefile.inc|miosix/config/Makefile.inc]] file to uncomment the ''OPT_BOARD := stm32f407vg_stm32f4discovery'' line. If you had compiled the kernel before, it is recommended to do a ''make clean'' (or in the Netbeans IDE, to click on the "Clean project" button) to avoid leaving object files around. After, do a ''make'' to compile. | |||
In addition, this board has a couple of board-specific options in the Makefile.inc file. For convenience, the relevant part of that configuration file is reported here so as to be easily located within the file | In addition, this board has a couple of board-specific options in the Makefile.inc file. For convenience, the relevant part of that configuration file is reported here so as to be easily located within the file | ||
Line 49: | Line 33: | ||
</source> | </source> | ||
As can be seen, | As can be seen, there are two options for this board: LINKER_SCRIPT and SRAM_BOOT. The comments explain in detail the meaning of there options, so it isn't necessary to further explain them. | ||
After modifying configuration files it is recommended to do a make clean; make (or in the Netbeans IDE, to click on the "Clean and build project" button) to be sure that changes are applied. | |||
== Loading code == | |||
As explained before, there are more than one linker script for this board, and the selected linker script affects the way code should be loaded on the board. | |||
===stm32_1m+192k_rom.ld=== | |||
This is the default linker script, and puts the code in FLASH, so you need to program the microcontroller's FLASH every time you change your code, but code will run faster and won't be lost at each reboot. | |||
A simple way to load code in FLASH is to use the [https://github.com/fpoussin/QStlink2 QStlink2] tool. Also, if you have a brand new board and QStlink fails you may take a look at [[ST-LINK utility update|this page]] | |||
===stm32_1m+192k_ram.ld=== | |||
This linker script is very useful for debugging code on this board, as it locates everything (code, stack, heap) in the microcontroller's RAM. It has the disadvantage that the loaded code is lost upon reboot (being in a volatile memory), but for debugging, it is not an issue. | |||
== Reading printf output == | |||
The board has no serial to USB adapter onboard, so you need to use an external one, connected to USART3, in detail PB10 (TXD) and PB11 (RXD). The choice of USART3 was done due to the fact that USART1 pins are not free on this board. | |||
On Linux you can use screen. Open a terminal and type ''screen /dev/ttyUSB0 19200'' (Note that to quit from screen you need to type "Ctrl-C, \"). You'll need to change /dev/ttyUSB0 with your serial port device name. | |||
On windows you can use HyperTerminal, you need to configure it to use the required baud rate, no flow control, and select the correct COM port device name. | |||
== In Circuit Debugging == | |||
Before you begin you should note that the Miosix kernel will put the CPU to a low power state when no thread is running. This low power state will usually confuse debuggers and make them lose sync with the CPU. To avoid this you need to edit the [[miosix_settings.h|miosix/config/miosix_settings.h]] file and uncomment ''#define JTAG_DISABLE_SLEEP'' line. This will prevent the kernel from putting the CPU in its low power state making debugging possible. | |||
Before you begin you should note that the Miosix kernel will put the CPU to a | Also, to be able to precisely single-step your code you need to disable compiler optimizations as gdb is incapable of reliably debug an optimized code. The option is in the miosix/config/Makefile.inc file and is the ''OPT_OPTIMIZATION := -O0'' that should be uncommented while the other lines related to the same option should be commented out. | ||
This will prevent the kernel from putting the CPU in its low power state making debugging possible. | |||
Also, to be able to precisely single-step your code you need to | |||
After modifying configuration files it is | After modifying configuration files it is recommended to do a ''make clean; make'' (or in the Netbeans IDE, to click on the "Clean and build project" button) to be sure that changes are applied. | ||
Since the board has an on board SWD in circuit debugger, simply | Since the board has an on board SWD in circuit debugger, simply plugging the USB cable is all you need from an hardware point of view. | ||
On the software side, you need to | On the software side, you need to open two shells. In one do a | ||
<source lang="BASH"> | |||
sudo openocd -f miosix/arch/cortexM4_stm32f4/stm32f407vg_stm32f4discovery/stm32f4discovery.cfg | |||
</source> | |||
This will | This will start the OpenOCD program that will connect to the board and listen for GDB connections. | ||
In the second shell type the following commands | In the second shell type the following commands | ||
<source lang="BASH"> | |||
arm-miosix-eabi-gdb main.elf | |||
target remote :3333 | |||
monitor soft_reset_halt | |||
break main | |||
continue | |||
</source> | |||
The first command will | The first command will start the gdb debugger. The following commands are typed into the gdb console, and tell it to connect to OpenOCD, and reset the board and stop the program at the beginning of main() | ||
To load the program to be debugged, you can either do a make program before and then start debugging, or you can directly write the FLASH memory from within gdb with this command | To load the program to be debugged, you can either do a make program before and then start debugging, or you can directly write the FLASH memory from within gdb with this command | ||
=== (Optional) Configuring the Netbeans IDE | <source lang="BASH"> | ||
monitor flash write_image erase main.bin 0x08000000 | |||
</source> | |||
From there on, have a look at [[Quick_start]] for debugger commands. | |||
== (Optional) Configuring the Netbeans IDE == | |||
To have a fully working code completion that can also resolve the board-specific symbols, right click on the project, go to Set Configuration and select the right board. | To have a fully working code completion that can also resolve the board-specific symbols, right click on the project, go to Set Configuration and select the right board. | ||
=== | [[File: Netbeans-config.png]] | ||
== SD Card == | |||
This board lacks an SD connector, so the filesystem support does not work out of the box (upon boot the kernel will say that filesystem mounting failed). However, it is possible to connect one to specific GPIO pins. | |||
The SD or microSD connector VCC and GND pins need to be connected to 3V and GND pins on the board. Add a 100nF capacitor between VCC and GND, as close as possible to the SD connector. This will be useful to overcome current absorption peaks from the SD card. | |||
Then connect the following GPIOs to the SD connector. | |||
{| class="wikitable" | |||
|- | |||
! SD !! STM32 !! Optional | |||
|- | |||
| CLK || PC12 || | |||
|- | |||
| CMD || PD2 || | |||
|- | |||
| D0 || PC8 || | |||
|- | |||
| D1 || PC9 || Y | |||
|- | |||
| D2 || PC10 || Y | |||
|- | |||
| D3 || PC11 || Y | |||
|} | |||
Each connection needs a pullup resistor between ~47Kohm and 100Kohm. | |||
To increase read/write speed it is possible to connect the optional GPIOs thereby communicating with the SD in 4-bit mode. | |||
Note that by default in this board the SD driver uses 1 bit mode. To enable 4-bit mode you need to edit the ''miosix/config/arch/cortexM4_stm32f4/stm32f407vg_stm32f4discovery/board_settings.h'' and comment out the ''#define SD_ONE_BIT_DATABUS'' line. | |||
Also note that filesystem support is enabled by default, so the pins marked as not optional are used by the filesystem driver. If you do not want to connect an SD card, and want to use those GPIOs, you should disable the filesystem support in [[miosix_settings.h|miosix/config/miosix_settings.h]]. | |||
== Resource == | |||
stm32f4discovery [http://www.st.com/st-web-ui/static/active/en/resource/technical/document/user_manual/DM00039084.pdf Datasheet] | |||
[[Category:Boards]] | |||
Latest revision as of 00:03, 28 February 2017
This is a cheap self contained discovery board with a powerful processor, and a Linux-friendly ST-LINK/V2 programmer/in circuit debugger. The board is equipped with
- A STM32F407VG microcontroller with a 168MHz ARM Cortex-M4F core, 1024KB Flash, 192KB RAM, 4KB battery-backed RAM in LQFP100 package.
- A LIS302DL accelerometer, MP45DT02 mems microphone, CS43L22 audio DAC, 4 user LEDs, user button, reset button, a second USB connector as the microcontroller supports USB.
Configuring the kernel
The minimum configuration required is to edit the miosix/config/Makefile.inc file to uncomment the OPT_BOARD := stm32f407vg_stm32f4discovery line. If you had compiled the kernel before, it is recommended to do a make clean (or in the Netbeans IDE, to click on the "Clean project" button) to avoid leaving object files around. After, do a make to compile.
In addition, this board has a couple of board-specific options in the Makefile.inc file. For convenience, the relevant part of that configuration file is reported here so as to be easily located within the file
##---------------------------------------------------------------------------
## stm32f407vg_stm32f4discovery
##
ifeq ($(OPT_BOARD),stm32f407vg_stm32f4discovery)
## Linker script type, there are two options
## 1) Code in FLASH, stack + heap in internal RAM (file *_rom.ld)
## 2) Code + stack + heap in internal RAM (file *_ram.ld)
LINKER_SCRIPT_PATH := arch/cortexM4_stm32f4/stm32f407vg_stm32f4discovery/
LINKER_SCRIPT := $(LINKER_SCRIPT_PATH)stm32_1m+192k_rom.ld
#LINKER_SCRIPT := $(LINKER_SCRIPT_PATH)stm32_1m+192k_ram.ld
## This causes the interrupt vector table to be relocated in SRAM, must be
## uncommented when using the ram linker script
#SRAM_BOOT := -DVECT_TAB_SRAM
endif
As can be seen, there are two options for this board: LINKER_SCRIPT and SRAM_BOOT. The comments explain in detail the meaning of there options, so it isn't necessary to further explain them.
After modifying configuration files it is recommended to do a make clean; make (or in the Netbeans IDE, to click on the "Clean and build project" button) to be sure that changes are applied.
Loading code
As explained before, there are more than one linker script for this board, and the selected linker script affects the way code should be loaded on the board.
stm32_1m+192k_rom.ld
This is the default linker script, and puts the code in FLASH, so you need to program the microcontroller's FLASH every time you change your code, but code will run faster and won't be lost at each reboot.
A simple way to load code in FLASH is to use the QStlink2 tool. Also, if you have a brand new board and QStlink fails you may take a look at this page
stm32_1m+192k_ram.ld
This linker script is very useful for debugging code on this board, as it locates everything (code, stack, heap) in the microcontroller's RAM. It has the disadvantage that the loaded code is lost upon reboot (being in a volatile memory), but for debugging, it is not an issue.
Reading printf output
The board has no serial to USB adapter onboard, so you need to use an external one, connected to USART3, in detail PB10 (TXD) and PB11 (RXD). The choice of USART3 was done due to the fact that USART1 pins are not free on this board.
On Linux you can use screen. Open a terminal and type screen /dev/ttyUSB0 19200 (Note that to quit from screen you need to type "Ctrl-C, \"). You'll need to change /dev/ttyUSB0 with your serial port device name.
On windows you can use HyperTerminal, you need to configure it to use the required baud rate, no flow control, and select the correct COM port device name.
In Circuit Debugging
Before you begin you should note that the Miosix kernel will put the CPU to a low power state when no thread is running. This low power state will usually confuse debuggers and make them lose sync with the CPU. To avoid this you need to edit the miosix/config/miosix_settings.h file and uncomment #define JTAG_DISABLE_SLEEP line. This will prevent the kernel from putting the CPU in its low power state making debugging possible. Also, to be able to precisely single-step your code you need to disable compiler optimizations as gdb is incapable of reliably debug an optimized code. The option is in the miosix/config/Makefile.inc file and is the OPT_OPTIMIZATION := -O0 that should be uncommented while the other lines related to the same option should be commented out.
After modifying configuration files it is recommended to do a make clean; make (or in the Netbeans IDE, to click on the "Clean and build project" button) to be sure that changes are applied.
Since the board has an on board SWD in circuit debugger, simply plugging the USB cable is all you need from an hardware point of view. On the software side, you need to open two shells. In one do a
sudo openocd -f miosix/arch/cortexM4_stm32f4/stm32f407vg_stm32f4discovery/stm32f4discovery.cfg
This will start the OpenOCD program that will connect to the board and listen for GDB connections.
In the second shell type the following commands
arm-miosix-eabi-gdb main.elf
target remote :3333
monitor soft_reset_halt
break main
continue
The first command will start the gdb debugger. The following commands are typed into the gdb console, and tell it to connect to OpenOCD, and reset the board and stop the program at the beginning of main() To load the program to be debugged, you can either do a make program before and then start debugging, or you can directly write the FLASH memory from within gdb with this command
monitor flash write_image erase main.bin 0x08000000
From there on, have a look at Quick_start for debugger commands.
(Optional) Configuring the Netbeans IDE
To have a fully working code completion that can also resolve the board-specific symbols, right click on the project, go to Set Configuration and select the right board.
SD Card
This board lacks an SD connector, so the filesystem support does not work out of the box (upon boot the kernel will say that filesystem mounting failed). However, it is possible to connect one to specific GPIO pins.
The SD or microSD connector VCC and GND pins need to be connected to 3V and GND pins on the board. Add a 100nF capacitor between VCC and GND, as close as possible to the SD connector. This will be useful to overcome current absorption peaks from the SD card.
Then connect the following GPIOs to the SD connector.
SD | STM32 | Optional |
---|---|---|
CLK | PC12 | |
CMD | PD2 | |
D0 | PC8 | |
D1 | PC9 | Y |
D2 | PC10 | Y |
D3 | PC11 | Y |
Each connection needs a pullup resistor between ~47Kohm and 100Kohm.
To increase read/write speed it is possible to connect the optional GPIOs thereby communicating with the SD in 4-bit mode. Note that by default in this board the SD driver uses 1 bit mode. To enable 4-bit mode you need to edit the miosix/config/arch/cortexM4_stm32f4/stm32f407vg_stm32f4discovery/board_settings.h and comment out the #define SD_ONE_BIT_DATABUS line.
Also note that filesystem support is enabled by default, so the pins marked as not optional are used by the filesystem driver. If you do not want to connect an SD card, and want to use those GPIOs, you should disable the filesystem support in miosix/config/miosix_settings.h.
Resource
stm32f4discovery Datasheet