Now let's look at how we can do that flashing part a little bit better. One way is to to a perl telnet script.
First we need to make sure that you have installed perl telnet.
sudo apt-get install libnet-telnet-perl
Then we put this little script in the dir.
Filename: do_flash.pl
#!/usr/bin/perl use Net::Telnet; $numArgs = $#ARGV + 1; if($numArgs != 1){ die( "Usage ./do_flash.pl [main.bin] \n"); } $file = $ARGV[0]; $ip = "127.0.0.1"; $port = 4444; $telnet = new Net::Telnet ( Port => $port, Timeout=>10, Errmode=>'die', Prompt =>'/>/'); $telnet->open($ip); print $telnet->cmd('reset halt'); print $telnet->cmd('flash probe 0'); print $telnet->cmd('stm32x mass_erase 0'); print $telnet->cmd('flash write_bank 0 '.$file.' 0'); print $telnet->cmd('reset halt'); print $telnet->cmd('exit'); print "\n";
And add this to the Makefile.
flash: all ./do_flash.pl main.bin
So it looks a little bit like this.
Filename: Makefile
CC = arm-none-eabi-gcc LD = arm-none-eabi-ld -v AR = arm-none-eabi-ar AS = arm-none-eabi-as CP = arm-none-eabi-objcopy OD = arm-none-eabi-objdump CFLAGS = -I./ -c -fno-common -O0 -g -mcpu=cortex-m3 -mthumb AFLAGS = -ahls -mcpu=cortex-m3 -mthumb LFLAGS = -Tstm32.ld -nostartfiles CPFLAGS = -Obinary ODFLAGS = -S all: main.bin clean: -rm main.lst main.o main.elf main.lst main.bin startup_stm32f10x.lst startup_stm32f10x.o main.bin: main.elf @ echo "...copying" $(CP) $(CPFLAGS) main.elf main.bin $(OD) $(ODFLAGS) main.elf > main.lst main.elf: main.o startup_stm32f10x.o stm32.ld @ echo "..linking" $(LD) $(LFLAGS) -o main.elf main.o startup_stm32f10x.o main.o: main.c @ echo ".compiling" $(CC) $(CFLAGS) main.c startup_stm32f10x.o: startup_stm32f10x.s @ echo ".assembling" $(AS) $(AFLAGS) -o startup_stm32f10x.o startup_stm32f10x.s > startup_stm32f10x.lst flash: all ./do_flash.pl main.bin
Now we can build and flash in one step by just type.
make flashFatal error: Uncaught Error: Call to a member function link_ext() on null in /customers/9/b/5/fun-tech.se/httpd.www/stm32/class.page.php:62 Stack trace: #0 /customers/9/b/5/fun-tech.se/httpd.www/stm32/PerlTelnet/index.php(65): page->getFoot() #1 {main} thrown in /customers/9/b/5/fun-tech.se/httpd.www/stm32/class.page.php on line 62