Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 46 additions & 1 deletion .github/workflows/build-firmware.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ on:
branches:
- master
- development
- feature/*
pull_request:
branches:
- master
Expand Down Expand Up @@ -40,6 +41,49 @@ jobs:
name: OpenFFBoard-Firmware-${{ matrix.target }}
path: ./Firmware/Output

Build-ESP32SX:
strategy:
fail-fast: false
matrix:
target: ['esp32s2', 'esp32s3'] # Targets to build
runs-on: ubuntu-latest
env:
PROJECT_PATH: Firmware/Targets/ESP32SX
container: espressif/idf:release-v4.4
steps:
- name: Checkout repo
uses: actions/checkout@v2

- name: esp-idf build
run: |
pwd
ls -al
git config --global --add safe.directory $GITHUB_WORKSPACE
git log -n1
cd /opt/esp/idf
git checkout c29343eb94d
git submodule update --init --recursive
git status
tools/idf_tools.py --non-interactive install cmake
rm $IDF_TOOLS_PATH/idf-env.json
./install.sh
source ./export.sh
cd $GITHUB_WORKSPACE/$PROJECT_PATH
idf.py set-target ${{ matrix.target }}
idf.py build
esptool.py --chip ${{ matrix.target }} merge_bin -o build/OpenFFBoard-Firmware-${{ matrix.target }}.bin --flash_mode dio --flash_size 4MB 0x1000 build/bootloader/bootloader.bin 0x10000 build/openffboard.bin 0x8000 build/partition_table/partition-table.bin
shell: bash

- name: Upload a Build Artifact
uses: actions/upload-artifact@v3.0.0
with:
# Artifact name
name: OpenFFBoard-Firmware-${{ matrix.target }}
# A file, directory or wildcard pattern that describes what to upload
path: |
Firmware/Targets/ESP32SX/build/OpenFFBoard-Firmware-*.bin
retention-days: 90

# Release:
# needs: [Build_firmware] # Requires build first
# name: Release if tagged
Expand All @@ -60,4 +104,5 @@ jobs:
# if: startsWith(github.ref, 'refs/tags/')
# with:
# body_path: ${{ github.workspace }}/CHANGELOG.txt
# body: "Release notes coming soon"
# body: "Release notes coming soon"

2 changes: 1 addition & 1 deletion Firmware/FFBoard/Inc/CAN.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ typedef struct{

typedef struct{
uint8_t data[8] = {0};
CAN_RxHeaderTypeDef header = {0,0,0,0,0,0};
CAN_RxHeaderTypeDef header = {0,0,0,0,0,0,0};
} CAN_rx_msg;


Expand Down
11 changes: 11 additions & 0 deletions Firmware/FFBoard/Inc/CommandInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@
#include "thread.hpp"
#include "CommandHandler.h"

#ifdef HW_ESP32SX
#define CDC_COMMANDINTERFACE_THREAD_MEM 4096
#define CDC_COMMANDINTERFACE_THREAD_PRIO (37*25/56)
#define UART_COMMANDINTERFACE_THREAD_MEM CDC_COMMANDINTERFACE_THREAD_MEM
#define UART_COMMANDINTERFACE_THREAD_PRIO CDC_COMMANDINTERFACE_THREAD_PRIO
#else
#define CDC_COMMANDINTERFACE_THREAD_MEM 512
#define CDC_COMMANDINTERFACE_THREAD_PRIO 36
#define UART_COMMANDINTERFACE_THREAD_MEM 150
#define UART_COMMANDINTERFACE_THREAD_PRIO CDC_COMMANDINTERFACE_THREAD_PRIO
#endif

class FFBoardMainCommandThread;

Expand Down
40 changes: 40 additions & 0 deletions Firmware/FFBoard/Inc/DebugLog.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@

#ifndef DEBUGLOG_H_
#define DEBUGLOG_H_

#include "target_constants.h"

#ifdef __cplusplus
extern "C" {
#endif

// LOG DEBUG
#ifdef HW_ESP32SX
#define FFB_LOGI(format, ...) do { \
ESP_LOGI(__FUNCTION__, "%s:%d -- " format, __FILE__, __LINE__ __VA_OPT__(,) __VA_ARGS__); \
} while(0)
#define FFB_LOGW(format, ...) do { \
ESP_LOGW(__FUNCTION__, "%s:%d -- " format, __FILE__, __LINE__ __VA_OPT__(,) __VA_ARGS__); \
} while(0)
#define FFB_LOGE(format, ...) do { \
ESP_LOGE(__FUNCTION__, "%s:%d -- " format, __FILE__, __LINE__ __VA_OPT__(,) __VA_ARGS__); \
} while(0)
#define FFB_LOGD(format, ...) do { \
ESP_LOGD(__FUNCTION__, "%s:%d -- " format, __FILE__, __LINE__ __VA_OPT__(,) __VA_ARGS__); \
} while(0)

#else

#define FFB_LOGI(format, ...)
#define FFB_LOGW(format, ...)
#define FFB_LOGE(format, ...)
#define FFB_LOGD(format, ...)

#endif


#ifdef __cplusplus
}
#endif

#endif /* DEBUGLOG_H_ */
9 changes: 9 additions & 0 deletions Firmware/FFBoard/Inc/ErrorHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@
#include <string>
#include "thread.hpp"
#include "CommandHandler.h"
#include "target_constants.h"

#ifdef HW_ESP32SX
#define ERROR_PRINTER_MEM 4096
#define ERROR_PRINTER_PRIO 19*25/56
#else
#define ERROR_PRINTER_MEM 512
#define ERROR_PRINTER_PRIO 19
#endif

/*
* Error code definitions
Expand Down
10 changes: 8 additions & 2 deletions Firmware/FFBoard/Inc/FFBoardMainCommandThread.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@

#include <CmdParser.h>
#include "cppmain.h"
#include "main.h"
#include <string>
#include "cdc_device.h"
#include "ChoosableClass.h"
#include "CommandHandler.h"
#include <vector>
Expand All @@ -24,6 +22,14 @@

#include "CommandInterface.h"

#ifdef HW_ESP32SX
#define FFBOARDMAINCOMMANDTHREAD_MEM 4096
#define FFBOARDMAINCOMMANDTHREAD_PRIO 32*25/56
#else
#define FFBOARDMAINCOMMANDTHREAD_MEM 700
#define FFBOARDMAINCOMMANDTHREAD_PRIO 32
#endif

class FFBoardMain;
//class CommandInterface;

Expand Down
8 changes: 8 additions & 0 deletions Firmware/FFBoard/Inc/HidCommandInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@
#include "ffb_defs.h"
#include "CommandHandler.h"

#ifdef HW_ESP32SX
#define HID_COMMANDINTERFACE_MEM 2048
#define HID_COMMANDINTERFACE_PRIO 18*25/56
#else
#define HID_COMMANDINTERFACE_MEM 128
#define HID_COMMANDINTERFACE_PRIO 18
#endif

enum class HidCmdType : uint8_t {write = 0, request = 1, info = 2, writeAddr = 3, requestAddr = 4,ACK = 10, notFound = 13, notification = 14, err = 15};


Expand Down
4 changes: 3 additions & 1 deletion Firmware/FFBoard/Inc/OutputPin.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ class OutputPin {
return(this->port == b.port && this->pin == b.pin);
}

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
/**
* Sets a pin into output mode in case it was previously reconfigured
*/
Expand All @@ -48,7 +50,7 @@ class OutputPin {
GPIO_InitStruct.Speed = speed;
HAL_GPIO_Init(port, &GPIO_InitStruct);
}

#pragma GCC diagnostic pop
//const std::string getName(){return name;}


Expand Down
8 changes: 7 additions & 1 deletion Firmware/FFBoard/Inc/USBdevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@

#define USB_STRING_DESC_BUF_SIZE 32


#ifdef HW_ESP32SX
#define USBDEVICE_MEM 4096
#define USBDEVICE_PRIO 40*25/56
#else
#define USBDEVICE_MEM 256
#define USBDEVICE_PRIO 40
#endif

/**
* This class defines a usb device and implements callbacks for getting the basic
Expand Down
17 changes: 12 additions & 5 deletions Firmware/FFBoard/Inc/cppmain.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,23 @@ extern "C" {

#include "eeprom_addresses.h"
#include "main.h"
#include "cmsis_compiler.h"

#include "DebugLog.h"

void cppmain();
#ifndef HW_ESP32SX
#include "cmsis_compiler.h"
void usb_init();
void tudThread(void *argument);

#endif
#ifdef __cplusplus
}

static inline bool inIsr(){
#ifdef HW_ESP32SX
return xPortInIsrContext();
#else
return (__get_PRIMASK() != 0U) || (__get_IPSR() != 0U);
#endif
}

template<class T,class C>
Expand All @@ -53,12 +58,14 @@ T clip(T v, C l, C h)
{
return { v > h ? h : v < l ? l : v };
}

#ifdef HW_ESP32SX
#define micros() esp_timer_get_time() // Returns microsecond scaled time
#else
uint32_t micros(); // Returns microsecond scaled time
unsigned long getRunTimeCounterValue(void); // RTOS

void refreshWatchdog(); // Refreshes the watchdog

#endif
#endif


Expand Down
4 changes: 4 additions & 0 deletions Firmware/FFBoard/Inc/critical.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,19 @@ class CriticalSection {
*/
static inline void Enter()
{
#ifndef HW_ESP32SX
taskENTER_CRITICAL();
#endif
}

/**
* Re-enable context switches.
*/
static inline void Exit()
{
#ifndef HW_ESP32SX
taskEXIT_CRITICAL();
#endif
}

/**
Expand Down
2 changes: 1 addition & 1 deletion Firmware/FFBoard/Inc/tickhook.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
#include "task.h"
#include <list>

#if ( configUSE_TICK_HOOK == 1 )
#if ( configUSE_TICK_HOOK == 1) && !defined(HW_ESP32SX)

/**
* FreeRTOS expects this function to exist and requires it to be
Expand Down
5 changes: 5 additions & 0 deletions Firmware/FFBoard/Src/CAN.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,12 @@ void CANPort::setSpeedPreset(uint8_t preset){
takeSemaphore();
HAL_CAN_Stop(this->hcan);
HAL_CAN_AbortTxRequest(hcan, txMailbox);
#ifdef HW_ESP32SX
const uint32_t rate[6]={50000, 100000, 125000, 250000, 500000, 1000000}; //bit/s
glue_can_set_speed(this->hcan, rate[preset]);
#else
this->hcan->Instance->BTR = canSpeedBTR_preset[preset];
#endif
HAL_CAN_ResetError(hcan);

HAL_CAN_Start(this->hcan);
Expand Down
15 changes: 12 additions & 3 deletions Firmware/FFBoard/Src/CDCcomm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ CDCcomm::~CDCcomm() {
* Global callback if cdc transfer is finished. Used to retry a failed transfer
*/
void CDCcomm::cdcFinished(uint8_t itf){
cdcSems[itf].Give();
bool ret = cdcSems[itf].Give();
if (true != ret){
// FFB_LOGE("cdcSem give error\n");
return;
}

if(CDCcomm::usb_busy_retry && CDCcomm::remainingStrs[itf].length() > 0){
cdcSend(&CDCcomm::remainingStrs[itf], itf); // Retry with remaining string
}
Expand Down Expand Up @@ -67,8 +72,12 @@ uint16_t CDCcomm::cdcSend(std::string* reply,uint8_t itf){
cdcSems[itf].Take();
uint32_t bufferRemaining = tud_cdc_n_write_available(itf);
uint32_t cdc_sent = tud_cdc_n_write(itf,reply->c_str(), std::min<uint16_t>(reply->length(),bufferRemaining));
if(!usb_busy_retry) // We did not retransmit so flush now. otherwise TUD will flush if we were in the callback before
tud_cdc_n_write_flush(itf);
if(!usb_busy_retry){ // We did not retransmit so flush now. otherwise TUD will flush if we were in the callback before
int res = tud_cdc_n_write_flush(itf);
if (!res) {
FFB_LOGW("flush failed (res: %d, len=%d)", res, reply->length());
}
}

// If we can't write the whole reply copy remainder to send later
if(cdc_sent < reply->length()){
Expand Down
4 changes: 2 additions & 2 deletions Firmware/FFBoard/Src/CmdParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ bool CmdParser::parse(std::vector<ParsedCommand>& commands){
cmd.type = CMDtype::err;

}else{
uint32_t peq = word.find('=', 0); // set
uint32_t pqm = word.find('?', 0); // read with var
int32_t peq = word.find('=', 0); // set
int32_t pqm = word.find('?', 0); // read with var

// <cmd>\n
if(pqm == std::string::npos && peq == std::string::npos){
Expand Down
2 changes: 1 addition & 1 deletion Firmware/FFBoard/Src/CommandHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ std::string CommandHandler::getCsvHelpstring(){
for(CmdHandlerCommanddef& cmd : registeredCommands){
if(cmd.helpstring != nullptr && cmd.cmd != nullptr){
char cmdhex[11];
std::snprintf(cmdhex,11,"0x%lX",cmd.cmdId);
std::snprintf(cmdhex,11,"0x%X",cmd.cmdId);
helpstring.append(cmd.cmd);
helpstring += ',';
helpstring += std::string(cmdhex);
Expand Down
6 changes: 4 additions & 2 deletions Firmware/FFBoard/Src/CommandInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ void StringCommandInterface::generateReplyFromCmd(std::string& replyPart,const P
*/


CDC_CommandInterface::CDC_CommandInterface() : StringCommandInterface(1024), Thread("CDCCMD", 512, 37) {
CDC_CommandInterface::CDC_CommandInterface() : StringCommandInterface(1024), Thread("CDCCMD", CDC_COMMANDINTERFACE_THREAD_MEM, CDC_COMMANDINTERFACE_THREAD_PRIO) {
parser.setClearBufferTimeout(parserTimeout);
this->Start();
}
Expand Down Expand Up @@ -273,11 +273,13 @@ void CDC_CommandInterface::sendReplies(const std::vector<CommandResult>& results

if(HAL_GetTick() - lastSendTime > parserTimeout){
bufferLength = 0;
FFB_LOGE("parserTimeout");
resultsBuffer.clear(); // Empty buffer because we were not able to reply in time to prevent the full buffer from blocking future commands
//CDCcomm::clearRemainingBuffer(0);
}

if( (!enableBroadcastFromOtherInterfaces && originalInterface != this) ){
FFB_LOGW("not originalInterface");
return;
}
for(const CommandResult& r : results){
Expand Down Expand Up @@ -324,7 +326,7 @@ bool CDC_CommandInterface::readyToSend(){
*/

extern UARTPort external_uart; // defined in cpp_target_config.cpp
UART_CommandInterface::UART_CommandInterface(uint32_t baud) : UARTDevice(external_uart),Thread("UARTCMD", 150, 36),StringCommandInterface(512), baud(baud){ //
UART_CommandInterface::UART_CommandInterface(uint32_t baud) : UARTDevice(external_uart),Thread("UARTCMD", UART_COMMANDINTERFACE_THREAD_MEM, UART_COMMANDINTERFACE_THREAD_PRIO),StringCommandInterface(512), baud(baud){ //
uartconfig = uartport->getConfig();
if(baud != 0){
uartconfig.BaudRate = this->baud;
Expand Down
2 changes: 1 addition & 1 deletion Firmware/FFBoard/Src/ErrorHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ void ErrorHandler::errorCallback(const Error &error, bool cleared){
// return info;
//}

ErrorPrinter::ErrorPrinter() : Thread("errprint",256,19){ // Higher than default task but low.
ErrorPrinter::ErrorPrinter() : Thread("errprint",ERROR_PRINTER_MEM,ERROR_PRINTER_PRIO){ // Higher than default task but low.
this->Start();
}

Expand Down
Loading