Stm32f207ig stm3220g-eval: Difference between revisions

From Miosix Wiki
Jump to navigation Jump to search
(Created page with "This board has an STM32F207IG, a Cortex-M3 running at 120MHz with 1MB of FLASH and 128KB of RAM, plus 2MB of external SRAM. In addtion, the board has some nice peripherals inc...")
 
(Fix details related to connecting to the serial port.)
 
Line 79: Line 79:
== Reading printf output ==
== Reading printf output ==


The board support package of this board simply redirects printf to the serial port USART3. The board has an RS232 connector, so you'll simply need to connect it to your computer via a serial cable, or use an USB to serial adapter.
The board support package of this board simply redirects printf to the serial port USART3. The board has an RS232 connector, so you'll simply need to connect it to your computer via a serial cable, or use an USB to serial adapter connected to pins PC10 (USART3 TX) and PC11 (USART3 RX), which are exposed on pins 36 (PC10) and 35 (PC11) of CN4.
The serial port baudrate is set to 19200baud, 8N1.
The serial port baudrate is set to 19200baud, 8N1.




On Linux you can use screen. Open a terminal and type ''screen /dev/ttyUSB0 115200'' (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 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.
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.

Latest revision as of 20:21, 31 March 2023

This board has an STM32F207IG, a Cortex-M3 running at 120MHz with 1MB of FLASH and 128KB of RAM, plus 2MB of external SRAM. In addtion, the board has some nice peripherals including an USB port and a 320x240 LCD display. Also, there is a microSD socket allowing filesystem support. Due to GPIO conflicts between the USART and SDIO the SD card works in 1-bit mode instead of 4-bit, thus write speed is limited in this board.

To develop for this board you'll need an USB to serial adapter to be able to deploy your code to the board through its serial bootloader as well as to be able to see debug messages as printf is redirected to the serial port on this board. Optionally, you'll need a JTAG in circuit debugger compatible with OpenOCD and Linux, an ARM-USB-OCD was tested succesfully.

Stm3220g-eval.jpg

Configuring the kernel

The minimum configuration required is to edit the miosix/config/Makefile.inc file to uncomment the OPT_BOARD := stm32f207ig_stm3220g-eval 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

##---------------------------------------------------------------------------
## stm32f207ig_stm3220g-eval
##
ifeq ($(OPT_BOARD),stm32f207ig_stm3220g-eval)

  ## Linker script type, there are three options
  ## 1) Code in FLASH, stack + heap in internal RAM (file *_rom.ld)
  ##    the most common choice, available for all microcontrollers
  ## 2) Code in FLASH stack in internal RAM heap in external RAM (file
  ##    *_xram.ld) useful for hardware like STM3220G-EVAL when big heap is
  ##    needed. The microcontroller must have an external memory interface.
  ## 3) Code + stack + heap in external RAM, (file *_all_in_xram.ld)
  ##    useful for debugging code in hardware like STM3220G-EVAL. Code runs
  ##    *very* slow compared to FLASH. Works only with a booloader that
  ##    forwards interrrupts @ 0x64000000 (see miosix/bootloaders for one).
  ##    The microcontroller must have an external memory interface.
  ## Warning! enable external ram if you use a linker script that requires it
  ## (see the XRAM flag below)
  LINKER_SCRIPT_PATH := arch/cortexM3_stm32f2/stm32f207ig_stm3220g-eval/
  #LINKER_SCRIPT := $(LINKER_SCRIPT_PATH)stm32_1m+128k_rom.ld
  #LINKER_SCRIPT := $(LINKER_SCRIPT_PATH)stm32_1m+128k_xram.ld
  LINKER_SCRIPT := $(LINKER_SCRIPT_PATH)stm32_1m+128k_all_in_xram.ld
  
  ## Enable/disable initialization of external RAM at boot. Three options:
  ## __ENABLE_XRAM : If you want the heap in xram (with an appropriate linker
  ## script selected above)
  ## __ENABLE_XRAM and __CODE_IN_XRAM : Debug mode with code + stack + heap
  ## in xram (with an appropriate linker script selected above)
  ## none selected : don't use xram (with an appropriate linker script
  ## selected above)
  #XRAM := -D__ENABLE_XRAM
  XRAM := -D__ENABLE_XRAM -D__CODE_IN_XRAM
  
endif

As can be seen, there are two options for this board: LINKER_SCRIPT and XRAM. 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+128k_all_in_xram.ld

This is the default linker script, it is very useful for debugging code on this board, as it locates everything (code, stack, heap) in the external RAM. It has the disadvantage that the loaded code is lost upon reboot (being in a volatile memory) and that code will run ~10 times slower due to external RAM access timings, but for debugging, these are not issues.

To be able to use this linker script you need to program a bootloader into the microcontroller's FLASH memory that allows code loading to the external RAM as well as forwarding interrupts there. This bootloader is in the miosix/_tools/bootloaders/stm32/uc_loader_stm3220g-eval directory, and information on how to install it can be found in the miosix/_doc/textdoc/stm32-bootloader.txt file. For programming the bootloader the stm32flash tool can be used.

stm32_1m+128k_rom.ld and stm32_1m+128k_xram.ld

These linker scripts put 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 stm32flash tool. After having installed it on your system, all you need to do is to connect a serial cable between the USART1 connector on the board and your PC. USB to serial adapters work well if you don't have a serial port. Then, flip up the boot0 switch on your board, and hit the Reset key. On the PC side, you'll need to run the

stm32flash -w main.hex -v /dev/ttyUSB0

Of course, replace /dev/ttyUSB0 with your serial port device name. After that, flip down the boot0 switch and hit again Reset. The code you have loaded should start.

Reading printf output

The board support package of this board simply redirects printf to the serial port USART3. The board has an RS232 connector, so you'll simply need to connect it to your computer via a serial cable, or use an USB to serial adapter connected to pins PC10 (USART3 TX) and PC11 (USART3 RX), which are exposed on pins 36 (PC10) and 35 (PC11) of CN4. The serial port baudrate is set to 19200baud, 8N1.


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

In-circuit debugging requires an USB to JTAG adapter. Ther recomended one is the ARM-USB-OCD. If you use a different one, you may need to modify the miosix/arch/arm7_lpc2000/lpc2138_miosix_board/lpc2138_armusbocd.cfg to adapt it to your JTAG tool.

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.

On the software side, you need to open two shells. In one do a

sudo openocd -f miosix/arch/cortexM3_stm32f2/stm32f207ig_stm3220g-eval/stm3220g_eval.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
load
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, reset the board and stop at the beginning of main() Please not that the load command implies that you are using the stm32_512k+64k_all_in_xram.ld linker script, and will instruct gdb to load your code in RAM. If you are using another linker script that loads code in FLASH you'll need to replace this command with a

monitor flash write_image erase main.bin 0x08000000

that will program the FLASH memory.

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.

Netbeans-config.png