Servers by jDrones

Porting to stm32F407ve 512kB Flash, 192+4kB SRAM


(Alex) #1

Hello All!

I am trying to port latest ArduPilot to this board: STM32F407VET6
This is not exactly a Copter board, but I have it. It has mini-USB, microSD card slot, and Flash chip on board.
*Edit: Here’s EasyEDA link to schematics https://easyeda.com/rossos/stm32f407vet6-ebay-board-stm32f4xx

I have watched the video at http://ardupilot.org/dev/docs/porting.html and learned about the migration of the project to ChibiOS and its simplification regarding porting to new hardware.
I’ve made a hwdef.dat file for the board here: stm32F4ve/hwdef.dat

The plan was to also use stm32f103 for FMU_IO in the long run, however for now I want to focus on the main board. GY-91 mpu9250+bmp280 board is to be primarily used. Also “NEO-M8N Ublox GPS Module w/Compass +GPS for APM2.8 APM2.6 Pixhawk”.
I have tried to retain the fmu_v3 pinout as much as was possible.
However this board has build in Flash chip on SPI3, which is one of the major deviations so far.
Also, I am confused regarding the PPM/SBUS input pin, I lean towards PC7 which is also USART6_RX but that was giving me errors.

The main challenge I am facing right now is that this board has only 512kb of memory, and my successful compile ends up being 988024.
During compilation of 506 steps/files I have noticed that it compiles a lot of things I wouldn’t necessary need.
My question is: is it possible to disable modules/features to lower the size to ~500kb?

Thank you in advance.

Best regard,
Rossos


(Amilcar Lucas) #2

take a look at the config.h file. there are a lot of features that you can disable there.


(Alex) #3

Thank you for your suggestion.
I have disabled all except Magnetometer support.
The compiled size is down to 784536.


(peterbarker) #4

Fitting into 512kB has been done. But not in a way (now) suitable for
master.

It’s based on stubbing out entire (ordinarily critical) files:

Peter


(Alex) #5

I have added those STUB_OUT lines as well as all the “define xyz disable” lines to my hwdef.dat file.
./waf clean
./waf configure --board stm32F4ve
./waf copter
and the result is again 784536.

while compiling it still went for 506 files, it did compile all those excluded directories as far as I can see.


(peterbarker) #6

Sorry, I wasn’t clear.

Those hwdef.dat lines I pointed to you only activate code present in
several patches only in the branch the lines are present in.

Sadly, the patches aren’t really collected anywhere at the moment…


(Alex) #7

Progress so far:
Following this https://github.com/tridge/ardupilot/commit/50759630a5dad72572858bdf472c920340ab6f7b#diff-77dfacb08e10fa18c7afcfedd33face1 I have edited the chibios_hwdef.py file.
Copied the files from https://github.com/tridge/ardupilot/tree/skyviper2018/libraries/AP_Stub

My fork with modifications currently compares to master like this https://github.com/ArduPilot/ardupilot/compare/master...RossosHEX:master

The build succeeds

Target          Text    Data  BSS     Total 
--------------------------------------------
bin/arducopter  654316   864  130284  785464

Build commands will be stored in build/stm32F4ve/compile_commands.json
'copter' finished successfully (1m37.174s)

However it doesn’t look like my edits work.

So far every time it compiles, it compiles everything, including modules/libraries like Airspeed, and all the Sensors variations I am not planning to use.
Does it include everything it compiles into the build file?
Or does it compile everything and selectively picks things it needs for the build file?


(Alex) #8

Progress Update:

I switched my focus onto another board.
STM32F407VG (basically the same chip as in F4Discovery?)
It has 1024k
Although getting a smaller footprint with eliminating modules still interest me.

I’ve pushed all changes to github under: https://github.com/RossosHEX/ardupilot/tree/master/libraries/AP_HAL_ChibiOS/hwdef/stm32f407vg
Also included all the support files.

I have also compiled the Bootloader file. Successfully flashed the board in DFU mode as described in Step 4 of porting guide: http://ardupilot.org/dev/docs/porting.html#step-4-upload-an-ardupilot-compatible-bootloader-to-the-board

The firmware also successfully compiles and uploads onto the board.

Upload info

Checking for env.py
env added MAIN_STACK=0x400
env added FLASH_RESERVE_START_KB=64
env added CHIBIOS_BUILD_FLAGS=USE_FATFS=no MCU=cortex-m4 ENV_UDEFS=-DCHPRINTF_USE_FLOAT=1 CHIBIOS_PLATFORM_MK=os/hal/ports/STM32/STM32F4xx/platform.mk CHIBIOS_STARTUP_MK=os/common/startup/ARMCMx/compilers/GCC/mk/startup_stm32f4xx.mk
env appended CPU_FLAGS=[’-mcpu=cortex-m4’, ‘-mfpu=fpv4-sp-d16’, ‘-mfloat-abi=hard’, ‘-u_printf_float’]
env added IOMCU_FW=0
env added PROCESS_STACK=0x2000
[504/507] Linking build/stm32f407vg/bin/arducopter
[505/507] Generating bin/arducopter.bin
[506/507] Generating bin/arducopter.apj
[507/507] Uploading build/stm32f407vg/bin/arducopter.apj
Loaded firmware for 3,0, size: 822788 bytes, waiting for the bootloader…
If the board does not respond within 1-2 seconds, unplug and re-plug the USB connector.
Found board 3,0 bootloader rev 5 on /dev/serial/by-id/usb-ArduPilot_stm32f407vg-BL_31003D001851363135353537-if00
ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff type: ÿÿÿÿ
idtype: =FF
vid: ffffffff
pid: ffffffff
coa: //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////8=

sn: 003d00313136511837353535
chip: 10076413
family: STM32F40x
revision: 1
flash 983040

Erase : [====================] 100.0%
Program: [====================] 100.0%
Verify : [====================] 100.0%
Rebooting.

Attempting reboot on /dev/serial/by-id/usb-ArduPilot_stm32f407vg_31003D001851363135353537-if00 with baudrate=57600…
If the board does not respond, unplug and re-plug the USB connector.

Waf: Leaving directory `/home/X/Y/Z/ardupilot/ardupilot-rossoshex/build/stm32f407vg’

BUILD SUMMARY
Build directory: /home/X/Y/Z/ardupilot/ardupilot-rossoshex/build/stm32f407vg
Target Text Data BSS Total

bin/arducopter 821964 812 130332 953108

Build commands will be stored in build/stm32f407vg/compile_commands.json
‘copter’ finished successfully (23.521s)

Thus far I have only connected GY-91 module, which is mpu9250+BMP280 with common SPI bus and different CS pins.

Wire connections

Yes I have connected the VIN and GND to the board and yes the module gets power.

Pinouts
VIN: Voltage Supply Pin
3V3: 3.3v Regulator output
GND: 0V Power Supply
SCL: I2C Clock / SPI Clock
SDA: I2C Data or SPI Data Input
SDO/SAO: SPI Data output / I2C Slave Address configuration pin
NCS: Chip Select for SPI mode only for MPU-9250
CSB: Chip Select for BMP280

&

PA5 SPI1_SCK SPI1
PA6 SPI1_MISO SPI1
PA7 SPI1_MOSI SPI1

in hwdef.dat definitions.

Mission Planner does ‘connect’ to the board, but swiftly fails with MAVLink communication.
Mission Planner does not get any GYRO/Accel/Baro readings from the module.
This is what happens in the command line:

Command line output

bps 21 loss 1 left 108 mem 32.3046875 mav2 True sign False mav1 0 mav2 1 signed 0
INFO MissionPlanner.MAVLinkInterface - 1/8/2019 10:37:53 PM 6 ArduCopter V3.7.0-dev (4a6dc0bc)
INFO MissionPlanner.MAVLinkInterface - 1/8/2019 10:37:53 PM 6 ChibiOS: 35ad8a79
INFO MissionPlanner.MAVLinkInterface - 1/8/2019 10:37:53 PM 6 stm32f407vg 003D0031 31365118 37353535
INFO MissionPlanner.MAVLinkInterface - 1/8/2019 10:37:53 PM 6 Frame: UNKNOWN
HUD resize 356 263
HUD 7 hz drawtime 19 gl True
HUD resize 356 261
INFO MissionPlanner.MAVLinkInterface - 1/8/2019 10:37:53 PM 6 Initialising APM
HUD resize 356 267
HUD resize 356 263
HUD resize 356 261
Sensor failure: Baro: unable to initialise driverINFO MissionPlanner.MAVLinkInterface -
Sensor failSensor failure: Baro: unable to initialise driver
INFO MissionPlanner.MAVLinkInterface -
Sensor failSensor failure: Baro: unable to initialise driver

INFO MissionPlanner.MAVLinkInterface - 1/8/2019 10:37:53 PM 3 Check BRD_TYPE: Baro: unable to initialise driver
HUD resize 356 267
HUD 3 hz drawtime 37 gl True
HUD resize 356 261
HUD resize 356 259
HUD resize 356 267
HUD resize 356 265
bps 265 loss 1 left 0 mem 43.34375 mav2 True sign False mav1 0 mav2 7 signed 0
bps 21 loss 1 left 0 mem 36.2587890625 mav2 True sign False mav1 0 mav2 1 signed 0
HUD 6 hz drawtime 24 gl True
bps 21 loss 1 left 0 mem 43.2353515625 mav2 True sign False mav1 0 mav2 1 signed 0
HUD 1 hz drawtime 6 gl True
Sensor failure: Baro: unable to initialise driverINFO MissionPlanner.MAVLinkInterface -
Sensor failure: Baro: unable to initialise driver
INFO MissionPlanner.MAVLinkInterface -
Sensor failure: Baro: unable to initialise driver

INFO MissionPlanner.MAVLinkInterface - 1/8/2019 10:37:56 PM 3 Check BRD_TYPE: Baro: unable to initialise driver
bps 83 loss 1 left 0 mem 32.2998046875 mav2 True sign False mav1 0 mav2 2 signed 0
INFO MissionPlanner.MAVLinkInterface - Get param 1 by 1 - got 0 of 1
HUD 1 hz drawtime 3 gl True
bps 21 loss 1 left 0 mem 35.037109375 mav2 True sign False mav1 0 mav2 1 signed 0
INFO MissionPlanner.MAVLinkInterface - 1/8/2019 10:37:58 PM 6 Initialising APM
INFO MissionPlanner.MAVLinkInterface - Get param 1 by 1 - got 0 of 1
HUD 1 hz drawtime 2 gl True
INFO MissionPlanner.MAVLinkInterface - Get param 1 by 1 - got 0 of 1
bps 50 loss 1 left 0 mem 46.5380859375 mav2 True sign False mav1 0 mav2 2 signed 0
INFO MissionPlanner.MAVLinkInterface - Get param 1 by 1 - got 0 of 1
HUD 1 hz drawtime 2 gl True
Sensor failure: Baro: unable to initialise driverINFO MissionPlanner.MAVLinkInterface -
Sensor failure: Baro: unable to initialise driver
INFO MissionPlanner.MAVLinkInterface -
Sensor failure: Baro: unable to initialise driver

Any insight is much appreciated.


(Alex) #9

So um… I did an oopsy. Could have been the fact that it’s late at night.
Anyhow,

Instead of plugging the wires to PA5/PA6/PA7 on the board I plugged them to PA3/PA4/PA5.

Now everything seems to be working. I get Accel/Gyro/Magnet and Baro readings in MissionPlanner.

Could be unrelated but I also removed I2C definitions for now.