Change Log: - GaloisInc/betaflight GitHub Wiki
Nik Cosmetic Touches
- Modified riscv_flash_k210.ld,
- modified address for the EEPROM config, added a PROVIDE() for the __config_start and __config_end
- moved the pg_registry after .finit_array
- MAIXBIT/target.h
- changed the TARGET_BOARD_IDENTIFIER to "MAIX"
- changed the USBD_PRODUCT_STRING to "MAIX"
- removed block comments
- added USE_RISCV_K210 for the RISCV PG entry
- MAIXBIT/target.mk
- removed the commented target_src since it is already in the target_mcu.mk -MAIXBIT/target.c
- added a little blink led function that gets called in main for demo purposes
- src/config/config_eeprom.c
- uncommented and added the crc start and end values in the correct order
- modified the print in the writeSettingsToEEPROM function
- size in KB , CRC Check value added, reg->address was direfferanced
- src/config/config_streamer.c
- config_streamer_init , added an if clause for RISCV, and if true initializes the flash, gets the device id
- config_streamer_finish , added a RISCV_K210 clause since our device neither flushes nor locks
- k210_unt_tests
- Added a new folder and a source file with tests for flash testing
- created two functions that run the tests for config and for flash in the test runner
Nik
- Merged code between Rubens code and capstone port
- modified source.mk, added a RISCV section for COMMON_SRC
- in the same block added a clause for if TEST if not test add main.c else dont because the unit tests have their own main.c
- target_mcu.mk , added capstone_print.c in target_src
- k210 unit test folder, in Makefile removed commented blocks, removed vpath calls , removed src directories that were not used
Ruben
- Renamed riscv_flash_k210_128k.ld to riscv_flash_k210.ld
- Renamed make/mcu/MAIXBIT.mk to make/mcu/RISCV_K210.mk
- Replaced references of MAIXBIT to RISCV_K210 (but not in all cases was this required)
- Replaced references of MAIXBIT_TARGETS to RISCV_K210_TARGETS
- runner.sh will pull kflash if missing
- code cleanup
Ruben
- Fixed flash write logic - it will now write config file to flash correctly and when board resets, it will find config and not write again
- Removed FLASH and FLASH_CONFIG ref in the ld file
- Fixed the correct CRC check value
- changed EEPROM_SIZE from 1MB to 4kB
Pending
- runner.sh - pull kflash from git if missing on host
- Continue to merge
- Uncommented more BT code
Ruben
- Fixed riscv_k210_entry_user.c - since BT main.c has no input arguments
- merged Makefile from riscv_blink_led
- merged mcu/MAIXBIT.mk from riscv_blink_led
- Fixed bug in runner.sh - BIN_FILE was not being defined correctly
Pending
- runner.sh - pull kflash from git if missing on host
- Uncommented more BT code
Ruben
- Commented initial flash and spi test in main.c. It had same address as config so it would erase sector at every boot up. Will change flash address and uncomment it in next push
- Uncommented more BT code
- Cleaned up debug verbose
- Improved runner.sh - it will automatically git bin filename, pull kendryte-toolchain if missing on host, install minicom if missing on host
Pending
- change flash address and uncomment it in next push in main.c to test flash
- runner.sh - pull kflash from git if missing on host
- Uncommented more BT code
Ruben
I pulled from Eric's branch and started dev. I have a ton of prints and my code is a bit not clean but I am moving along. I have been able to initialize spi and our flash dev using kendryte's api.
NOTE: I am not using bus_spi.h nor flash.h.. these implemenations are stm related
- I am configuring our spi, you will see that in init.c (about line 442) the function configureSPIAndQuadSPI (also in init.c) is calling spi_init which initializes our spi dev with our api riscv_k210_spi.h
- I setup our flash dev by calling flash_init from init.c (about line 456) - flash_init is in drivers/flash_riscv_k210.h
- I'm able to initEEPROM
- There is some cases where the bus_spi.c is getting called but it's not impacting our spi
I lefted off at config_streamer.c - about line 361 inside function write_word. This is where it's trying to write the config file back to flash.
if you see output prints (write_word:./src/main/config/config_streamer.c:361) - it loops several times trying to write to flash but I haven't implemented this section. it will go all the way but error when trying to read the info back from flash (since I haven't finished)
I included a simple bash script to automate the make, flash, and running minicom.
located betaflight/tools/runner.sh
pre-req
- run as sudo since kflash and minicom require it
- have kflash installed (just pull git, I didn't test with apt install kflash)
- have minicom already installed
- place runner.sh, betaflight, kflash in same dir or you can update the var section inside the script to work with your path
-
src/main/main.c --uncommented everything
-
make/mcu/MAIXBIT.mk --fixed the INCLUDE_DIRS to point to the .h files for bsp/include, drivers/include, and added
$(ROOT)/src/main/target/$ (TARGET) (to make target.h visible) --added DEVICE_FLAGS to point to RISCV_K210 --added TARGET_FLAGS to point to MAIXBIT --fixed MCU_FLASH_SIZE to reflect correct size..it was 128 bytes before but it should be 16384 bytes which is 16MB -
added logic for RISCV_K210 section in src/main/platform.h --this will include the API header files (list is still incomplete) --it defines MAIXBIT
-
uncommented all files in src/main/config
-
removed directory lib/main/MAIXBIT since it was missing files and the correct directory with all files was already there lib/main/RISCV_K210
-
renamed file lib/main/RISCV_K210/bsp/include/platform.h to platform_k210.h
-
added to file lib/main/RISCV_K210/bsp/include/platform_k210.h
--#define RISCVK210
-Nik
-
Added a PG in src/pg
- flash_riscv_k210.c
- flash_riscv_k210.h - struct that contains pins and other useful stuff
-
Forked of the Kendryte's demo for flash to begin making the drivers for flashing
- Nik
system.h
-
need to adjust setting to accommodate riscvk210 - potentially need custom riscvk210 system file
-
drivers/bus_spi.c Line 119
Add a spi device
bus_spi.c line 56 needs to be configured with the correct values
-
settings.c - Need to add potentially RISCV stuff
-
config.h:59:33: error: 'TARGET_BOARD_IDENTIFIER'
Notes: The above is related to the whole PG definded in config.h
PG_DECLARE(pilotConfig_t, pilotConfig);
-
io_def_generated.h:1319:4: warning: #warning "No pins are defined
-
system.h:84:34: error: unknown type name 'IRQn_Type'
-
void registerExtiCallbackHandler(IRQn_Type irqn, extiCallbackHandlerFunc *fn
Eric - (PG config storage changes) - Compiler errors fixed, Linker errors fixed, executable builds!
-
target.h
- Line 32: Defined SPI1 variable using address from STM32F1 board (placeholder value)
-
drivers/bus_spi.c
- Line 24: Included stdio.h lib
- Line 44: Added printf to check return value from spiDeviceByInstance()
- Line 295: Added dummy function definition for spiInitDevice()
-
source.mk
- Uncommented in COMMON_SRC:
- drivers/bus_spi_pinconfig.c
- drivers/bus_spi_config.c
- drivers/io.c
- pg/flash.c
- Uncommented in COMMON_SRC:
-
drivers/io.c
- Line 171: Added 'MAIXBIT' to if statement (to resolve # error "Unknown target type")
- Line 431: Added 'MAIXBIT' and dummy IOConfigGPIO() function to if statement
Eric - (PG config storage changes) - Getting compiler errors
-
drivers/flash.c
- Line 94: Commented spiPreinitRegister();
- Line 123: Commented IOConfigGPIO();
-
drivers/bus_spi_impl.h
- Line 30: Defined MAX_SPI_PIN_SEL for Maixbit board
-
drivers/bus_spi.c
- Line 242: Modified arguement of spiBusSetDivisor from: (busDevice_t *bus, uint16_t divisor) to: (busDevice_t *bus, SPIClockDivider_e divisor) to match function prototype in bus_spi.h.
Eric - (PG config storage changes)
-
target.h
- Line 31: Added #define USE_QUADSPI
- Line 32: Added #define FLASH_QUADSPI_INSTANCE SPI3
- Line 33: Added #define FLASH_CS_PIN G2
-
source.mk
- Added drivers/bus_quadspi.c to COMMON_SRC
-
drivers/flash.c
- Line 195: Added printf statement
- Line 207: Added printf statement
-
init.c
- Line 436: Added printf statement
Eric - (PG config storage changes - Program enters init() through main.c now)
-
riscv_flash_k210_128k.ld
- Line 160: Moved .pg_registry, .pg_resetdata sections below .fini_arrray section
-
main.c
- Line 36: Removed print loop
- Line 38: Uncommented init() call
Eric - (PG config storage changes - Program executes on board now)
-
main.c
- Line 24: Added #include <unistd.h>
- Line 36: Added print loop to demonstrate execution has made it to init.c
- Line 40: Commented init() call
-
riscv_flash_k210_128k.ld
- Line 69: Commented .pg_registry section
- Line 76: Commented .pg_resetdata section
Eric - (PG config storage changes - Program builds now)
-
source.mk
- Uncommented in COMMON_SRC:
- rx/rx.c
- config/feature.c
- fc/board_info.c
- pg/board.c
- build/version.c
- Uncommented in COMMON_SRC:
-
init.c
- Line 186: Uncommented declaration of variable systemState
-
src/main/target/MAIXBIT/target.c
- Line 22: Added #include <stdio.h>
- Line 23: Added #include <stdlib.h>
- Line 25: Added #include "drivers/system.h"
- Line 27: Defined function failureMode
Eric - (PG config storage changes)
-
source.mk
- Uncommented in COMMON_SRC:
- sensors/initialisation.c
- sensors/gyro.c
- drivers/flash.c
- config/config_eeprom.c
- config/config_streamer.c
- common/crc.c
- Uncommented in COMMON_SRC:
-
flash.c
- Line 343: Changed function's argument to flashPartitionType_e type (changed from 'uint8_t index' to match prototype's argument in flash.h)
-
init.c
- Line 432: Commented failureMode function call
- Line 433: Added printf statement to show if flash init failed
-
init.c
- Commented sections of file irreleveant to CONFIG_IN_EXTERNAL_FLASH flag
-
target.h
- Line 20: Added #include <stdint.h>
-
config.c
- Commented most of the file, except for functions needed for compilation
Eric - (PG config storage changes)
-
source.mk
- Commented:
- #config/config.c \
- #config/config_eeprom.c \
- #config/config_streamer.c\
- #drivers/flash.c \
- Commented:
-
target.h
- Line 30: Added #define SERIAL_PORT_COUNT statement.
- Line 105: Added typedef declarations needed for config storage compilation.
-
src/main/drivers/timer.h
- Line 40: Added 'defined(RISCV_K210)' to the if statement.
-
init.c
-
Commented most of the file (except for parts needed for config storage compilation - #ifdef CONFIG_IN_EXTERNAL_FLASH and #ifdef USE_FLASH_CHIP
-
Line 26: Added #include <stdio.h> for printf statement.
-
-
riscv_flash_k210_128k.ld
- Line 68: Added .pg_registry and .pg_resetdata to SECTIONS (needed by linker during linking process).
Eric - (PG config storage changes)
-
config_eeprom.c
- Line 25: Added #include <stdio.h> for printf statement.
- Line 93: Added printf statement to display value of flashStartAddress
- Line 261: Added printf statement to check if flash read failed
- Line 280: Added printf statement to check EEPROM version valid
- Line 393: Added printf statement to check if all PGs initialized from EEPROM
- Line 458: Added printf statement to check if configs correctly loaded into EEPROM from flash
- Line 467: Added printf statement to check if overall config_eeprom.c successful
-
init.c
- Line 444: Added printf statement to check whether config load failed
-
main.c
- Put original main.c code back in
-
source.mk
- Added to COMMON_SRC:
- main.c \
- config/config.c \
- config/config_eeprom.c \
- config/config_streamer.c \
- drivers/flash.c \
- fc/init.c \
- pg/pg.c
- Added to COMMON_SRC:
-
target.h
- Undefined all PG macros except those needed for compilation:
- USE_DMA
- USE_PWM_OUTPUT
- USE_TIMER
- USE_MOTOR
- Undefined all PG macros except those needed for compilation:
Eric
- MAIXBIT.mk
- Uncommented ASFLAGS
Eric - (Gyst of changes: Before, ALL our source files were coming in through TARGET_SRC in target.mk. These included main.c, as well as source files for K210 peripherals found in lib/main/RISC_K210. Now, the peripheral source files are coming in through MAIXBIT.mk, and main.c is coming in through source.mk, similar to all the other BF boards.)
-
Target.mk
- Commented all source files out of TARGET_SRC
-
MAIXBIT.mk
- Added all source files in bsp and driver folders to STDPERIPH_SRC
- STDPERIPH_SRC gets assigned to DEVICE_STDPERIPH_SRC
- Uncommented STARTUP_SRC, assigned it crt.S
-
source.mk
- Uncommented COMMON_DEVICE_SRC (gets DEVICE_STDPERIPH_SRC from target.mk)
- Uncommented SRC += $(COMMON_SRC) at the bottom of source.mk
Eric - (Gyst of changes: Removed hard-coded K210 directories and tool locations. Reintroduced ARM gcc tools so hopefully Makefile is still compatable with ARM MPUs)
-
Makefile
- Uncommented LD_FLAGS
- Removed
$(ROOT)/lib/main/RISCV_K210/bsp and $ (ROOT)/lib/main/RISCV_K210/drivers from SRC_DIR (ln 61). Added to VPATH at the bottom of MAIXBIT.mk. - Changed argument of CSOURCES back to SRC_DIR
- Reintroduced ARM gcc toolchain (ln 224)
- Added control statement to determine whether ARM or RISCV gcc tools get used (line 232).
-
MAIXBIT.mk
- Commented ASFLAGS (looks like this is being overwritten in the Makefile anyway)
This file is a running log of our port process for the K210, and will be helpful when compiling final documentation. Actions are identified in sequential order, separated by dates. Screenshots of file edits/changes have been added for clarity.
- Create Maixbit folder within src/main/target
- Create target.h, target.c, target.mk for MAIXBIT
- Store in src/main/target/MAIXBIT
- Add K210 drivers to project directory
- Create folder for drivers: lib/main/RISCV-K210/drivers
- Store drivers here.
- Create mcu makefile for Maixbit board: MAIXBIT.mk
- Store in make/mcu/MAIXBIT.mk
- Add Maixbit board to targets.mk (make/targets.mk):
- Add K210 linker script to project directory (src/link/riscv_flash_k210_128k.ld)
- Add Maixbit board to OpenOCD makefile (make/openocd.mk):
Download and install Kendryte’s RISC-V toolchain (See capstone/K210/Kendryte_RISC_V_GNU_Compiler_Toolchain.md for steps)
- Modify BF Makefile to point to Kendryte’s RISC-V toolchain:
- Add flag for EEPROM memory configuration into MAIXBIT.mk:
- Add flag for memory configuration to target.h (src/main/target/MAIXBIT/target.h):
Added K210 BSP folder to BF directory (lib/main/RISCV_K210/bsp)
- Edit make/mcu/MAIXBIT.mk
- Fix the INCLUDE_DIRS to point to the .h files for bsp/include, drivers/include, added
$(ROOT)/src/main/target/$ (TARGET) (to make target.h visible)
- Add DEVICE_FLAGS to point to RISCV_K210, added TARGET_FLAGS to point to MAIXBIT
- Fix MCU_FLASH_SIZE to reflect correct size..it was 128 bytes before but it should be 16384 bytes which is 16MB
- Add logic for RISCV_K210 section in src/main/platform.h
- This will include the API header files (list is still incomplete)
- It defines the MCU selection
-
Rename file lib/main/RISCV_K210/bsp/include/platform.h to platform_k210.h
-
Add to file lib/main/RISCV_K210/bsp/include/platform_k210.h
-
Define RISCVK210