diff --git a/README.md b/README.md
index fa778f92..4ef625e9 100644
--- a/README.md
+++ b/README.md
@@ -9,7 +9,7 @@ Currently OpenRTX is being actively developed for the TYT MD-380/390 and MD-UV38
This firmware is *highly experimental* and is not in a usable state right now,
however contributions and testing are welcome and accepted.
-## Installation
+## Compilation
To build and install the firmware, first clone this repository:
@@ -17,6 +17,24 @@ To build and install the firmware, first clone this repository:
git clone https://github.com/n1zzo/OpenRTX
```
+The following steps depend on the selected platform:
+
+### Linux
+
+The OpenRTX linux build depends on libSDL, on Ubuntu you can install it with:
+```
+sudo apt install libsdl2-dev
+```
+
+The firmware can be compiled with:
+
+```
+meson builddir
+meson compile -C builddir openrtx-linux
+```
+
+### TYT MD-380 / TYT MD-UV380
+
To build the firmware you need to have a toolchain for the ARM ISA installed
on you system, you can install one using your package manager.
@@ -28,8 +46,8 @@ sudo apt install gcc-arm-none-eabi
You can then proceed in building the firmware:
```
-meson builddir
-meson compile -C builddir linux
+meson builddir --cross-file cross_arm.txt
+meson compile -C builddir openrtx-md380
```
If everything compiled without errors you can connect your radio via USB,
diff --git a/cross_arm.txt b/cross_arm.txt
new file mode 100644
index 00000000..ffbe346f
--- /dev/null
+++ b/cross_arm.txt
@@ -0,0 +1,43 @@
+[binaries]
+c = 'arm-none-eabi-gcc'
+cpp = 'arm-none-eabi-g++'
+ld = 'arm-none-eabi-ld'
+ar = 'arm-none-eabi-ar'
+as = 'arm-none-eabi-as'
+size = 'arm-none-eabi-size'
+objdump = 'arm-none-eabi-objdump'
+objcopy = 'arm-none-eabi-objcopy'
+strip = 'arm-none-eabi-strip'
+gdb = 'arm-none-eabi-gdb'
+terminal= 'x-terminal-emulator'
+openocd = '/usr/local/bin/openocd'
+
+[properties]
+c_args = [
+ '-mcpu=cortex-m4', # Cortex-M4 CPU
+ '-mthumb', # ARM Thumb2 ISA
+ '-mfloat-abi=hard', # Hard floating point support
+ '-mfpu=fpv4-sp-d16',
+ ]
+
+c_link_args = [
+ '-mcpu=cortex-m4',
+ '-mthumb',
+ '-mfloat-abi=hard',
+ '-mfpu=fpv4-sp-d16',
+ '-Wl,--gc-sections',
+ '-Wl,-Map,main.map',
+ '-nostdlib',
+ '-Wl,-T../platform/mcu/STM32F4xx/linker_script.ld',
+ '-Wl,--start-group',
+ '-lc',
+ '-lgcc',
+ '-lm',
+ '-Wl,--end-group'
+ ]
+
+[host_machine]
+system = 'none'
+cpu_family = 'arm'
+cpu = 'cortex-m4'
+endian = 'little'
diff --git a/meson.build b/meson.build
index 0f2da238..91655e54 100644
--- a/meson.build
+++ b/meson.build
@@ -25,10 +25,8 @@ rtos_src = ['rtos/uC-OS3/Source/__dbg_uCOS-III.c',
'rtos/uC-OS3/Source/os_time.c',
'rtos/uC-OS3/Source/os_tmr.c',
'rtos/uC-OS3/Source/os_var.c',
- 'rtos/uC-OS3/Ports/POSIX/os_cpu_c.c',
'rtos/uC-OS3/Cfg/os_app_hooks.c',
'rtos/uC-CPU/cpu_core.c',
- 'rtos/uC-CPU/Posix/cpu_c.c',
'rtos/uC-LIB/lib_ascii.c',
'rtos/uC-LIB/lib_math.c',
'rtos/uC-LIB/lib_mem.c',
@@ -36,12 +34,15 @@ rtos_src = ['rtos/uC-OS3/Source/__dbg_uCOS-III.c',
src = rtos_src
##
-## Headers
+## Includes
##
interfaces = ['openrtx/include/interfaces']
-rtos_inc = ['rtos/uC-OS3/Source', 'rtos/uC-OS3/Ports/POSIX', 'rtos/uC-OS3/Cfg',
- 'rtos/uC-CPU/Posix', 'rtos/uC-CPU', 'rtos/uC-CPU/Cfg', \
- 'rtos/uC-LIB', 'rtos/uC-LIB/Cfg']
+rtos_inc = ['rtos/uC-OS3/Source',
+ 'rtos/uC-OS3/Cfg',
+ 'rtos/uC-CPU',
+ 'rtos/uC-CPU/Cfg',
+ 'rtos/uC-LIB',
+ 'rtos/uC-LIB/Cfg']
inc = interfaces + rtos_inc
##
@@ -50,34 +51,98 @@ inc = interfaces + rtos_inc
def = {'DONT_USE_CMSIS_INIT': ''}
##
-## Dependencies
+## Platform specializations
##
-sdl_dep = dependency('SDL2')
-threads_dep = dependency('threads')
-dep = [sdl_dep, threads_dep]
-##
-## Platform specialization
-##
+## Linux
linux_src = src + ['tests/platform/x64_uC.c',
'platform/drivers/display/display_libSDL.c',
- 'openrtx/src/graphics/graphics_rgb565.c']
-linux_def = def + {'SCREEN_WIDTH': 160, 'SCREEN_HEIGHT': 128}
+ 'openrtx/src/graphics/graphics_rgb565.c',
+ 'rtos/uC-OS3/Ports/POSIX/os_cpu_c.c',
+ 'rtos/uC-CPU/Posix/cpu_c.c']
+
+
+linux_def = def + {'SCREEN_WIDTH': '160', 'SCREEN_HEIGHT': '128'}
+
+linux_inc = inc + ['rtos/uC-OS3/Ports/POSIX',
+ 'rtos/uC-CPU/Posix']
+
+if not meson.is_cross_build()
+ sdl_dep = dependency('SDL2')
+ threads_dep = dependency('threads')
+ linux_dep = [sdl_dep, threads_dep]
+else
+ linux_dep = []
+endif
+
+
+## TYT MD380
+md380_src = src + ['tests/platform/stm32f4_uC.c',
+ 'platform/mcu/STM32F4xx/boot/startup.c',
+ 'platform/mcu/STM32F4xx/boot/libc_integration.c',
+ 'platform/mcu/STM32F4xx/drivers/usb/usb_bsp.c',
+ 'platform/mcu/STM32F4xx/drivers/usb/usb_core.c',
+ 'platform/mcu/STM32F4xx/drivers/usb/usb_dcd.c',
+ 'platform/mcu/STM32F4xx/drivers/usb/usb_dcd_int.c',
+ 'platform/mcu/STM32F4xx/drivers/usb/usbd_desc.c',
+ 'platform/mcu/STM32F4xx/drivers/usb/usbd_core.c',
+ 'platform/mcu/STM32F4xx/drivers/usb/usbd_ioreq.c',
+ 'platform/mcu/STM32F4xx/drivers/usb/usbd_req.c',
+ 'platform/mcu/STM32F4xx/drivers/usb/usbd_usr.c',
+ 'platform/mcu/STM32F4xx/drivers/gpio.c',
+ 'platform/mcu/STM32F4xx/drivers/usb_vcom.c',
+ 'platform/mcu/STM32F4xx/drivers/delays.c',
+ 'platform/mcu/STM32F4xx/drivers/gpio.c',
+ 'platform/mcu/CMSIS/Device/ST/STM32F4xx/Source/system_stm32f4xx.c',
+ 'platform/drivers/display/HX83XX_md380.c',
+ 'openrtx/src/graphics/graphics_rgb565.c',
+ 'rtos/uC-OS3/Ports/ARM-Cortex-M/ARMv7-M/os_cpu_c.c',
+ 'rtos/uC-OS3/Ports/ARM-Cortex-M/ARMv7-M/os_cpu_a.s',
+ 'rtos/uC-CPU/ARM-Cortex-M/ARMv7-M/cpu_c.c',
+ 'rtos/uC-CPU/ARM-Cortex-M/ARMv7-M/cpu_a.s']
+
+md380_def = def + {'SCREEN_WIDTH': '160', 'SCREEN_HEIGHT': '128', 'STM32F40_41xxx': ''}
+
+md380_inc = inc + ['platform/mcu/CMSIS/Include',
+ 'platform/mcu/CMSIS/Device/ST/STM32F4xx/Include',
+ 'platform/mcu/STM32F4xx',
+ 'platform/mcu/STM32F4xx/drivers/usb',
+ 'rtos/uC-OS3/Ports/ARM-Cortex-M/ARMv7-M',
+ 'rtos/uC-CPU/ARM-Cortex-M/ARMv7-M']
##
-## Compute define string
+## Compilation defines
##
linux_args = []
foreach k, v : linux_def
- linux_args += '-D@0@=@1@'.format(k, v)
+ if v == ''
+ linux_args += '-D@0@'.format(k)
+ else
+ linux_args += '-D@0@=@1@'.format(k, v)
+ endif
+endforeach
+
+md380_args = []
+foreach k, v : md380_def
+ if v == ''
+ md380_args += '-D@0@'.format(k)
+ else
+ md380_args += '-D@0@=@1@'.format(k, v)
+ endif
endforeach
linux = {'sources': linux_src,
'c_args': linux_args,
- 'include_directories': inc,
- 'dependencies': dep}
+ 'include_directories': linux_inc,
+ 'dependencies': linux_dep}
+
+md380 = {'sources': md380_src,
+ 'c_args': md380_args,
+ 'include_directories': md380_inc}
##
## Select your radio model among the supported ones: MD-380, MD-UV380
##
executable('openrtx-linux', kwargs:linux)
+executable('openrtx-md380', kwargs:md380)
+executable('openrtx-mduv380', kwargs:md380)
diff --git a/platform/mcu/STM32F4xx/drivers/gpio.h b/platform/mcu/STM32F4xx/drivers/gpio.h
deleted file mode 100644
index 07c558bd..00000000
--- a/platform/mcu/STM32F4xx/drivers/gpio.h
+++ /dev/null
@@ -1,110 +0,0 @@
-/***************************************************************************
- * Copyright (C) 2020 by Silvano Seva IU2KWO *
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 3 of the License, or *
- * (at your option) any later version. *
- * *
- * This program is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License *
- * along with this program; if not, see *
- ***************************************************************************/
-
-#ifndef GPIO_H
-#define GPIO_H
-
-#include
-#include "stm32f4xx.h"
-
-/**
- * GPIO functional modes.
- * For more details see microcontroller's reference manual.
- */
-enum Mode
-{
- INPUT = 0, ///Floating Input
- INPUT_PULL_UP = 1, ///Pullup Input
- INPUT_PULL_DOWN = 2, ///Pulldown Input
- INPUT_ANALOG = 3, ///Analog Input
- OUTPUT = 4, ///Push Pull Output
- OPEN_DRAIN = 5, ///Open Drain Output
- ALTERNATE = 6, ///Alternate function
- ALTERNATE_OD = 7, ///Alternate Open Drain
-};
-
-/**
- * Maximum GPIO switching speed.
- * For more details see microcontroller's reference manual and datasheet.
- */
-enum Speed
-{
- LOW = 0x0, /// 2MHz for STM32
- MEDIUM = 0x1, /// 25MHz for STM32
- FAST = 0x2, /// 50MHz for STM32
- HIGH = 0x3 /// 100MHz for STM32
-};
-
-/**
- * Configure GPIO pin functional mode.
- * @param port: GPIO port, it has to be equal to GPIOA_BASE, GPIOB_BASE, ...
- * @param pin: GPIO pin number, between 0 and 15.
- * @param mode: GPIO functional mode to be set.
- */
-void gpio_setMode(GPIO_TypeDef *port, uint8_t pin, enum Mode mode);
-
-/**
- * Map alternate function to GPIO pin. The pin has to be configured in alternate
- * mode by calling 'gpio_setMode'.
- * @param port: GPIO port, it has to be equal to GPIOA_BASE, GPIOB_BASE, ...
- * @param pin: GPIO pin number, between 0 and 15.
- * @param afNum: alternate function number, retrieved from mapping table in
- * microcontroller's datasheet.
- */
-void gpio_setAlternateFunction(GPIO_TypeDef *port, uint8_t pin, uint8_t afNum);
-
-/**
- * Configure GPIO pin maximum output speed.
- * @param port: GPIO port, it has to be equal to GPIOA_BASE, GPIOB_BASE, ...
- * @param pin: GPIO pin number, between 0 and 15.
- * @param spd: GPIO output speed to be set.
- */
-void gpio_setOutputSpeed(GPIO_TypeDef *port, uint8_t pin, enum Speed spd);
-
-/**
- * Set GPIO pin to high logic level.
- * NOTE: this operation is performed atomically.
- * @param port: GPIO port, it has to be equal to GPIOA_BASE, GPIOB_BASE, ...
- * @param pin: GPIO pin number, between 0 and 15.
- */
-void gpio_setPin(GPIO_TypeDef *port, uint8_t pin);
-
-/**
- * Set GPIO pin to low logic level.
- * NOTE: this operation is performed atomically.
- * @param port: GPIO port, it has to be equal to GPIOA_BASE, GPIOB_BASE, ...
- * @param pin: GPIO pin number, between 0 and 15.
- */
-void gpio_clearPin(GPIO_TypeDef *port, uint8_t pin);
-
-/**
- * Toggle logic level of a GPIO pin, with respect to its state before calling
- * this function.
- * @param port: GPIO port, it has to be equal to GPIOA_BASE, GPIOB_BASE, ...
- * @param pin: GPIO pin number, between 0 and 15.
- */
-void gpio_togglePin(GPIO_TypeDef *port, uint8_t pin);
-
-/**
- * Read GPIO pin's logic level.
- * @param port: GPIO port, it has to be equal to GPIOA_BASE, GPIOB_BASE, ...
- * @param pin: GPIO pin number, between 0 and 15.
- * @return 1 if pin is at high logic level, 0 if pin is at low logic level.
- */
-uint8_t gpio_readPin(const GPIO_TypeDef *port, uint8_t pin);
-
-#endif /* GPIO_H */