at32: at32_common: reuse some parts from STM32

This is temporally, some parts are quite different and need rework
This commit is contained in:
Andrey Gusakov 2023-11-12 19:22:30 +03:00 committed by rusefillc
parent 5a11a2a2b4
commit 4634a741c2
12 changed files with 127 additions and 32 deletions

View File

@ -54,15 +54,6 @@ typedef enum {
adc_channel_mode_e getAdcMode(adc_channel_e hwChannel);
void initAdcInputs();
// deprecated - migrate to 'getAdcChannelBrainPin'
int getAdcChannelPin(adc_channel_e hwChannel);
// deprecated - migrate to 'getAdcChannelBrainPin'
ioportid_t getAdcChannelPort(const char *msg, adc_channel_e hwChannel);
adc_channel_e getAdcChannel(brain_pin_e pin);
brain_pin_e getAdcChannelBrainPin(const char *msg, adc_channel_e hwChannel);
// wait until at least 1 slowADC sampling is complete
void waitForSlowAdc(uint32_t lastAdcCounter = 0);
// get a number of completed slowADC samples

View File

@ -50,7 +50,7 @@ int at32GetMcuType(uint32_t id, const char **pn, const char **package, uint32_t
{ 0x70083257, "AT32F437RCT7", 256, "LQFP64" },
};
for (int i = 0; i < efi::size(at32f43x_types); i++) {
for (size_t i = 0; i < efi::size(at32f43x_types); i++) {
if (id == at32f43x_types[i].uid) {
if (pn)
*pn = at32f43x_types[i].pn;
@ -93,3 +93,78 @@ int at32GetRamSizeKb(void)
}
return 0;
}
#if EFI_PROD_CODE
static void reset_and_jump(void) {
// and now reboot
NVIC_SystemReset();
}
void jump_to_bootloader() {
// leave DFU breadcrumb which assembly startup code would check, see [rusefi][DFU] section in assembly code
*((unsigned long *)0x2001FFF0) = 0xDEADBEEF; // End of RAM
reset_and_jump();
}
void jump_to_openblt() {
#if EFI_USE_OPENBLT
/* safe to call on already inited shares area */
SharedParamsInit();
/* Store sing to stay in OpenBLT */
SharedParamsWriteByIndex(0, 0x01);
reset_and_jump();
#endif
}
BOR_Level_t BOR_Get(void) {
/* TODO: Artery */
/* Fake */
return BOR_Level_None;
}
BOR_Result_t BOR_Set(BOR_Level_t BORValue) {
/* NOP */
return BOR_Result_Ok;
}
void baseMCUInit(void) {
// looks like this holds a random value on start? Let's set a nice clean zero
DWT->CYCCNT = 0;
BOR_Set(BOR_Level_1); // one step above default value
}
extern uint32_t __main_stack_base__;
typedef struct port_intctx intctx_t;
EXTERNC int getRemainingStack(thread_t *otp) {
#if CH_DBG_ENABLE_STACK_CHECK
// this would dismiss coverity warning - see http://rusefi.com/forum/viewtopic.php?f=5&t=655
// coverity[uninit_use]
register intctx_t *r13 asm ("r13");
otp->activeStack = r13;
int remainingStack;
if (ch.dbg.isr_cnt > 0) {
// ISR context
remainingStack = (int)(r13 - 1) - (int)&__main_stack_base__;
} else {
remainingStack = (int)(r13 - 1) - (int)otp->wabase;
}
otp->remainingStack = remainingStack;
return remainingStack;
#else
UNUSED(otp);
return 99999;
#endif /* CH_DBG_ENABLE_STACK_CHECK */
}
__attribute__((weak)) void boardPrepareForStandby() {
}
#endif /* EFI_PROD_CODE */

View File

@ -3,3 +3,33 @@ HW_AT32_PORT_DIR = $(PROJECT_DIR)/hw_layer/ports/at32
HW_LAYER_PORT_CPP += \
$(HW_AT32_PORT_DIR)/at32_common.cpp \
$(HW_AT32_PORT_DIR)/at32f4/mpu_util.cpp
HW_INC += \
$(HW_AT32_PORT_DIR)
#
# Use some stuff from STM32
#
HW_STM32_PORT_DIR = $(PROJECT_DIR)/hw_layer/ports/stm32
HW_LAYER_PORT_CPP += \
$(HW_STM32_PORT_DIR)/serial_over_usb/usbconsole.cpp \
$(HW_STM32_PORT_DIR)/serial_over_usb/usbcfg.cpp \
$(HW_STM32_PORT_DIR)/stm32_pins.cpp \
$(HW_STM32_PORT_DIR)/stm32_adc.cpp \
$(HW_STM32_PORT_DIR)/stm32_can.cpp \
$(HW_STM32_PORT_DIR)/stm32_pwm.cpp \
$(HW_STM32_PORT_DIR)/stm32_serial.cpp \
$(HW_STM32_PORT_DIR)/stm32_spi.cpp \
$(HW_STM32_PORT_DIR)/stm32_icu.cpp \
$(HW_STM32_PORT_DIR)/microsecond_timer_stm32.cpp
#RUSEFIASM = \
# $(HW_STM32_PORT_DIR)/rusEfiStartup.S
HW_STM32_PORT_DIR = $(PROJECT_DIR)/hw_layer/ports/stm32
HW_INC += \
$(HW_STM32_PORT_DIR) \
$(HW_STM32_PORT_DIR)/serial_over_usb

View File

@ -21,6 +21,15 @@ bool isStm32F42x();
// ADC
#if HAL_USE_ADC
adc_channel_e getAdcChannel(brain_pin_e pin);
brain_pin_e getAdcChannelBrainPin(const char *msg, adc_channel_e hwChannel);
// deprecated - migrate to 'getAdcChannelBrainPin'
ioportid_t getAdcChannelPort(const char *msg, adc_channel_e hwChannel);
// deprecated - migrate to 'getAdcChannelBrainPin'
int getAdcChannelPin(adc_channel_e hwChannel);
void portInitAdc();
float getMcuTemperature();
// Convert all slow ADC inputs. Returns true if the conversion succeeded, false if a failure occured.
@ -34,8 +43,11 @@ bool isValidCanRxPin(brain_pin_e pin);
CANDriver* detectCanDevice(brain_pin_e pinRx, brain_pin_e pinTx);
#endif // HAL_USE_CAN
// Serial
#if EFI_AUX_SERIAL
bool isValidSerialTxPin(brain_pin_e pin);
bool isValidSerialRxPin(brain_pin_e pin);
#endif //EFI_AUX_SERIAL
// SPI
#if HAL_USE_SPI

View File

@ -67,18 +67,6 @@ void jump_to_openblt() {
#if EFI_PROD_CODE
#ifdef AT32F4XX
BOR_Level_t BOR_Get(void) {
/* TODO: Artery */
/* Fake */
return BOR_Level_None;
}
BOR_Result_t BOR_Set(BOR_Level_t BORValue) {
/* NOP */
return BOR_Result_Ok;
}
#else
BOR_Level_t BOR_Get(void) {
FLASH_OBProgramInitTypeDef FLASH_Handle;
@ -114,7 +102,6 @@ BOR_Result_t BOR_Set(BOR_Level_t BORValue) {
return BOR_Result_Ok;
}
#endif
void baseMCUInit(void) {
// looks like this holds a random value on start? Let's set a nice clean zero

View File

@ -4,11 +4,11 @@ HW_LAYER_PORT_CPP += \
$(HW_STM32_PORT_DIR)/serial_over_usb/usbconsole.cpp \
$(HW_STM32_PORT_DIR)/stm32_pins.cpp \
$(HW_STM32_PORT_DIR)/stm32_common.cpp \
$(HW_STM32_PORT_DIR)/stm32_common_adc.cpp \
$(HW_STM32_PORT_DIR)/stm32_common_can.cpp \
$(HW_STM32_PORT_DIR)/stm32_common_pwm.cpp \
$(HW_STM32_PORT_DIR)/stm32_common_serial.cpp \
$(HW_STM32_PORT_DIR)/stm32_common_spi.cpp \
$(HW_STM32_PORT_DIR)/stm32_adc.cpp \
$(HW_STM32_PORT_DIR)/stm32_can.cpp \
$(HW_STM32_PORT_DIR)/stm32_pwm.cpp \
$(HW_STM32_PORT_DIR)/stm32_serial.cpp \
$(HW_STM32_PORT_DIR)/stm32_spi.cpp \
$(HW_STM32_PORT_DIR)/stm32_icu.cpp \
$(HW_STM32_PORT_DIR)/backup_ram.cpp \
$(HW_STM32_PORT_DIR)/microsecond_timer_stm32.cpp \

View File

@ -33,12 +33,12 @@ else
DDEFS += -DSTM32F407xx
endif
# Now add common stm32 stuff
include $(PROJECT_DIR)/hw_layer/ports/stm32/stm32_common.mk
# Add Artery AT32 common stuff
ifeq ($(IS_AT32F435),yes)
# Add Artery AT32 common stuff
include $(PROJECT_DIR)/hw_layer/ports/at32/at32_common.mk
else
# Or STM32 common stuff
include $(PROJECT_DIR)/hw_layer/ports/stm32/stm32_common.mk
endif
# TODO: remove, for efifeatures.h