Skip to content

Commit

Permalink
update for v1.12.1
Browse files Browse the repository at this point in the history
  • Loading branch information
TDA-2030 committed Feb 5, 2023
1 parent 4b53920 commit 46ea57c
Show file tree
Hide file tree
Showing 14 changed files with 135 additions and 19 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/build-firmware.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ jobs:
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
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
4 changes: 4 additions & 0 deletions Firmware/FFBoard/Src/flash_helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@ bool Flash_Write(uint16_t adr,uint16_t dat){
bool res = false;
if(readRes == 1 || (readRes == 0 && buf != dat) ){ // Only write if var updated
HAL_FLASH_Unlock();
#ifndef HW_ESP32SX
// Clear all the error flags
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP);
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_OPERR);
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_WRPERR);
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_PGAERR);
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_PGPERR);
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_PGSERR);
#endif
if(EE_WriteVariable(adr, dat) == HAL_OK){
res = true;
}
Expand Down Expand Up @@ -60,13 +62,15 @@ bool Flash_ReadWriteDefault(uint16_t adr,uint16_t *buf,uint16_t def){
if(EE_ReadVariable(adr, buf) != 0){
*buf = def;
HAL_FLASH_Unlock();
#ifndef HW_ESP32SX
// Clear all the error flags
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP);
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_OPERR);
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_WRPERR);
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_PGAERR);
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_PGPERR);
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_PGSERR);
#endif
EE_WriteVariable(adr, def);
HAL_FLASH_Lock();
return false;
Expand Down
4 changes: 4 additions & 0 deletions Firmware/FFBoard/UserExtensions/Inc/TMC4671.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,13 @@
#ifdef HW_ESP32SX
#define TMC_THREAD_MEM 4096
#define TMC_THREAD_PRIO 25*25/56
#define TMCENC_THREAD_MEM 2048
#define TMCENC_THREAD_PRIO 33*25/56
#else
#define TMC_THREAD_MEM 256
#define TMC_THREAD_PRIO 25 // Must be higher than main thread
#define TMCENC_THREAD_MEM 80
#define TMCENC_THREAD_PRIO 33
#endif

#define TMC_ADCOFFSETFAIL 5000 // How much offset from 0x7fff to allow before a calibration is failed
Expand Down
2 changes: 1 addition & 1 deletion Firmware/FFBoard/UserExtensions/Src/TMC4671.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2996,7 +2996,7 @@ void TMC4671::setUpExtEncTimer(){
/**
* Medium priority task to update external encoders
*/
TMC4671::TMC_ExternalEncoderUpdateThread::TMC_ExternalEncoderUpdateThread(TMC4671* tmc) : cpp_freertos::Thread("TMCENC",80,33),tmc(tmc){
TMC4671::TMC_ExternalEncoderUpdateThread::TMC_ExternalEncoderUpdateThread(TMC4671* tmc) : cpp_freertos::Thread("TMCENC",TMCENC_THREAD_MEM,TMCENC_THREAD_PRIO),tmc(tmc){
this->Start();
}

Expand Down
2 changes: 1 addition & 1 deletion Firmware/Targets/ESP32SX/firmware/generate_bin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ build_and_generate_bin(){
cd firmware
}

SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
SCRIPT_DIR=$(dirname $(readlink -f "$0"))
cd $SCRIPT_DIR
rm -f ../firmware/*.bin

Expand Down
Binary file modified Firmware/Targets/ESP32SX/firmware/openffb-esp32s2-hw_v1.0.bin
Binary file not shown.
Binary file modified Firmware/Targets/ESP32SX/firmware/openffb-esp32s2-hw_v1.1.bin
Binary file not shown.
Binary file modified Firmware/Targets/ESP32SX/firmware/openffb-esp32s3-hw_v1.1.bin
Binary file not shown.
35 changes: 21 additions & 14 deletions Firmware/Targets/ESP32SX/main/cpp_target_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,25 @@ CANPort canport{CANPORT};

#ifdef PWMDRIVER
// CCR and channels must match!
const PWMConfig pwmTimerConfig = {
.channel_1 = TIM_CHANNEL_1,
.channel_2 = TIM_CHANNEL_2,
.channel_3 = TIM_CHANNEL_3,
.channel_4 = TIM_CHANNEL_4,

.ccr_1 = 1,
.ccr_2 = 2,
.ccr_3 = 3,
.ccr_4 = 4,

.timer = &TIM_PWM,
.timerFreq = APB_CLK_FREQ
};
const PWMConfig pwmTimerConfig =
{
.channel_1 = TIM_CHANNEL_1,
.channel_2 = TIM_CHANNEL_2,
.channel_3 = TIM_CHANNEL_3,
.channel_4 = TIM_CHANNEL_4,

.pwm_chan = 1,
.dir_chan = 3,
.dir_chan_n = 4,

.centerpwm_chan = 1,

.rcpwm_chan = 1,

.dualpwm1 = 1,
.dualpwm2 = 2,

.timer = &TIM_PWM,
.timerFreq = APB_CLK_FREQ
};
#endif
37 changes: 35 additions & 2 deletions Firmware/Targets/ESP32SX/main/glue.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
static const char *TAG = "glue";

ADC_HandleTypeDef hadc1;
ADC_HandleTypeDef hadc2;
SPI_HandleTypeDef hspi1;
#if defined(SHIFTERBUTTONS) || defined(SPIBUTTONS)
SPI_HandleTypeDef hspi2;
Expand All @@ -25,6 +24,20 @@ CAN_HandleTypeDef hcan1;
TIM_HandleTypeDef htim1;
I2C_HandleTypeDef hi2c1;


void HAL_GPIO_Init(GPIO_TypeDef *GPIOx, GPIO_InitTypeDef *GPIO_Init)
{
gpio_config_t io_conf = {0};
io_conf.intr_type = GPIO_INTR_DISABLE;
io_conf.mode = GPIO_Init->Mode;
io_conf.pin_bit_mask = (BIT64(LED_CLIP_Pin) | BIT64(LED_ERR_Pin) \
| BIT64(LED_SYS_Pin) | BIT64(DRV_ENABLE_Pin) \
| BIT64(DRV_BRAKE_Pin) | BIT64(CAN_S_Pin));
io_conf.pull_down_en = 0;
io_conf.pull_up_en = 0;
gpio_config(&io_conf);
}

GPIO_PinState HAL_GPIO_ReadPin(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin)
{
return gpio_ll_get_level(&GPIO, GPIO_Pin);
Expand Down Expand Up @@ -125,7 +138,7 @@ HAL_StatusTypeDef HAL_SPI_Init(SPI_HandleTypeDef *hspi)
.sclk_io_num = SPI1_SCK_Pin,
.quadwp_io_num = -1,
.quadhd_io_num = -1,
.max_transfer_sz = 256,
.max_transfer_sz = 4096,
};
hspi->Init.BaudRatePrescaler >>= 3;
uint32_t freq = (84 * 1000 * 1000) / (uint32_t)(powf(2, hspi->Init.BaudRatePrescaler + 1));
Expand Down Expand Up @@ -158,6 +171,11 @@ HAL_StatusTypeDef HAL_SPI_Transmit(SPI_HandleTypeDef *hspi, uint8_t *pData, uint
return HAL_OK;
}

HAL_StatusTypeDef HAL_SPI_Transmit_DMA(SPI_HandleTypeDef *hspi, uint8_t *pData, uint16_t Size)
{
return HAL_SPI_Transmit(hspi, pData, Size, 500);
}

HAL_StatusTypeDef HAL_SPI_Transmit_IT(SPI_HandleTypeDef *hspi, uint8_t *pData, uint16_t Size)
{
ESP_LOGW(TAG, "%s: Unsupported", __FUNCTION__);
Expand Down Expand Up @@ -216,6 +234,21 @@ HAL_StatusTypeDef HAL_UART_Receive(UART_HandleTypeDef *huart, uint8_t *pData, ui
ESP_LOGW(TAG, "%s: Unsupported", __FUNCTION__);
return HAL_OK;
}
HAL_StatusTypeDef HAL_UART_Receive_DMA(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size)
{
ESP_LOGW(TAG, "%s: Unsupported", __FUNCTION__);
return HAL_OK;
}
HAL_StatusTypeDef HAL_UART_AbortReceive(UART_HandleTypeDef *huart)
{
ESP_LOGW(TAG, "%s: Unsupported", __FUNCTION__);
return HAL_OK;
}
HAL_StatusTypeDef HAL_UART_AbortTransmit(UART_HandleTypeDef *huart)
{
ESP_LOGW(TAG, "%s: Unsupported", __FUNCTION__);
return HAL_OK;
}

HAL_StatusTypeDef HAL_I2C_Init(I2C_HandleTypeDef *hi2c)
{
Expand Down
21 changes: 21 additions & 0 deletions Firmware/Targets/ESP32SX/main/glue.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,23 @@ extern "C" {
#define HAL_FLASH_Unlock()
#define HAL_FLASH_Lock()

/**
\brief Reverse byte order (16 bit)
\details Reverses the byte order in a 16-bit value and returns the signed 16-bit result. For example, 0x0080 becomes 0x8000.
\param [in] value Value to reverse
\return Reversed value
*/
static inline int16_t __REVSH(int16_t value)
{
#if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
return (int16_t)__builtin_bswap16(value);
#else
int16_t result;

__ASM volatile ("revsh %0, %1" : __CMSIS_GCC_OUT_REG (result) : __CMSIS_GCC_USE_REG (value) );
return result;
#endif
}

#define TIM_CHANNEL_1 LEDC_CHANNEL_0
#define TIM_CHANNEL_2 LEDC_CHANNEL_1
Expand All @@ -46,6 +63,7 @@ extern "C" {
#endif
#endif

void HAL_GPIO_Init(GPIO_TypeDef *GPIOx, GPIO_InitTypeDef *GPIO_Init);
GPIO_PinState HAL_GPIO_ReadPin(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin);
void HAL_GPIO_WritePin(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin, GPIO_PinState PinState);
void HAL_GPIO_TogglePin(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin);
Expand Down Expand Up @@ -89,6 +107,9 @@ HAL_StatusTypeDef HAL_UART_Transmit_DMA(UART_HandleTypeDef *huart, uint8_t *pDat
HAL_StatusTypeDef HAL_UART_Transmit(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint32_t Timeout);
HAL_StatusTypeDef HAL_UART_Transmit_IT(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size);
HAL_StatusTypeDef HAL_UART_Receive(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint32_t Timeout);
HAL_StatusTypeDef HAL_UART_Receive_DMA(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size);
HAL_StatusTypeDef HAL_UART_AbortReceive(UART_HandleTypeDef *huart);
HAL_StatusTypeDef HAL_UART_AbortTransmit(UART_HandleTypeDef *huart);

HAL_StatusTypeDef HAL_ADC_Start_DMA(ADC_HandleTypeDef *hadc, uint32_t *pData, uint32_t Length);

Expand Down
35 changes: 35 additions & 0 deletions Firmware/Targets/ESP32SX/main/stm32f4xx_hal.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,40 @@ typedef enum
#define GPIO_PIN_47 (47)
#define GPIO_PIN_48 (48)

/**
* @brief GPIO Init structure definition
*/
typedef struct
{
uint32_t Pin; /*!< Specifies the GPIO pins to be configured.
This parameter can be any value of @ref GPIO_pins_define */

uint32_t Mode; /*!< Specifies the operating mode for the selected pins.
This parameter can be a value of @ref GPIO_mode_define */

uint32_t Pull; /*!< Specifies the Pull-up or Pull-Down activation for the selected pins.
This parameter can be a value of @ref GPIO_pull_define */

uint32_t Speed; /*!< Specifies the speed for the selected pins.
This parameter can be a value of @ref GPIO_speed_define */

uint32_t Alternate; /*!< Peripheral to be connected to the selected pins.
This parameter can be a value of @ref GPIO_Alternate_function_selection */
}GPIO_InitTypeDef;

#define GPIO_MODE_INPUT GPIO_MODE_INPUT /*!< Input Floating Mode */
#define GPIO_MODE_OUTPUT_PP GPIO_MODE_OUTPUT /*!< Output Push Pull Mode */
#define GPIO_MODE_OUTPUT_OD GPIO_MODE_OUTPUT_OD /*!< Output Open Drain Mode */

#define GPIO_NOPULL GPIO_PULLUP_DISABLE /*!< No Pull-up or Pull-down activation */
#define GPIO_PULLUP GPIO_PULLUP_ENABLE /*!< Pull-up activation */
#define GPIO_PULLDOWN GPIO_PULLDOWN_ENABLE /*!< Pull-down activation */

#define GPIO_SPEED_FREQ_LOW 0x00000000U /*!< IO works at 2 MHz, please refer to the product datasheet */
#define GPIO_SPEED_FREQ_MEDIUM 0x00000001U /*!< range 12,5 MHz to 50 MHz, please refer to the product datasheet */
#define GPIO_SPEED_FREQ_HIGH 0x00000002U /*!< range 25 MHz to 100 MHz, please refer to the product datasheet */
#define GPIO_SPEED_FREQ_VERY_HIGH 0x00000003U /*!< range 50 MHz to 200 MHz, please refer to the product datasheet */

typedef struct {
twai_timing_config_t t_config;
TaskHandle_t task;
Expand Down Expand Up @@ -431,6 +465,7 @@ typedef struct
typedef struct {
UART_InitTypeDef Init;
uint32_t a;
uint32_t ErrorCode;
} UART_HandleTypeDef;


Expand Down
8 changes: 8 additions & 0 deletions Firmware/Targets/ESP32SX/main/target_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#ifndef INC_TARGET_CONSTANTS_H_
#define INC_TARGET_CONSTANTS_H_

#include "sdkconfig.h"
/*
* Add settings and peripheral maps for this specific target here
*/
Expand All @@ -17,6 +18,10 @@
#define HW_TYPE_INT 2
#define FW_DEVID 0x413 // F407

#if !(defined(CONFIG_IDF_TARGET_ESP32S2)) && !(defined(CONFIG_IDF_TARGET_ESP32S3))
#error "The target chip is not supported, you should select a proper target by 'idf.py set-target esp32s2/3'"
#endif

#define HW_ESP32SX // Defining this macro will implement the STM32 HAL library using some of the functions of ESP-IDF

#ifdef HW_ESP32SX
Expand Down Expand Up @@ -98,6 +103,9 @@ extern ADC_HandleTypeDef hadc1;
#define BUTTON_PINS 3
#endif

extern SPI_HandleTypeDef hspi1;
#define HSPIDRV hspi1

// CAN
#ifdef CANBUS
extern CAN_HandleTypeDef hcan1;
Expand Down

0 comments on commit 46ea57c

Please sign in to comment.