rusEFI
The most advanced open source ECU
Typedefs | Functions | Variables
at32_common.cpp File Reference

Detailed Description

Low level common Artery AT32 code.

Date
Oct 29, 2023
Author
Andrey Gusakov, (c) 2023

Definition in file at32_common.cpp.

Typedefs

typedef struct port_intctx intctx_t
 

Functions

int at32GetMcuType (uint32_t id, const char **pn, const char **package, uint32_t *flashSize)
 
int at32GetRamSizeKb (void)
 
static void reset_and_jump (void)
 
void jump_to_bootloader ()
 
void jump_to_openblt ()
 
BOR_Level_t BOR_Get (void)
 
BOR_Result_t BOR_Set (BOR_Level_t BORValue)
 
void startWatchdog (int)
 
void tryResetWatchdog ()
 
void setWatchdogResetPeriod (int)
 
void baseMCUInit (void)
 
bool isStm32F42x (void)
 
EXTERNC int getRemainingStack (thread_t *otp)
 
 __attribute__ ((weak)) void boardPrepareForStandby()
 
Reset_Cause_t getMCUResetCause ()
 
const char * getMCUResetCause (Reset_Cause_t)
 

Variables

uint32_t __main_stack_base__
 

Typedef Documentation

◆ intctx_t

typedef struct port_intctx intctx_t

Definition at line 159 of file at32_common.cpp.

Function Documentation

◆ __attribute__()

__attribute__ ( (weak)  )

Definition at line 185 of file at32_common.cpp.

185  {
186 }

◆ at32GetMcuType()

int at32GetMcuType ( uint32_t  id,
const char **  pn,
const char **  package,
uint32_t *  flashSize 
)

Definition at line 11 of file at32_common.cpp.

12 {
13  const struct {
14  uint32_t uid;
15  const char *pn;
16  uint32_t flashSize;
17  const char *package;
18  } at32f43x_types[] = {
19  { 0x70084540, "AT32F435ZMT7", 4032, "LQFP144" },
20  { 0x70083341, "AT32F435ZGT7", 1024, "LQFP144" },
21  { 0x70084598, "AT32F435ZDT7", 448, "LQFP144" },
22  { 0x70083242, "AT32F435ZCT7", 256, "LQFP144" },
23  { 0x70084543, "AT32F435VMT7", 4032, "LQFP100" },
24  { 0x70083344, "AT32F435VGT7", 1024, "LQFP100" },
25  { 0x70084599, "AT32F435VDT7", 448, "LQFP100" },
26  { 0x70083245, "AT32F435VCT7", 256, "LQFP100" },
27  { 0x70084546, "AT32F435RMT7", 4032, "LQFP64" },
28  { 0x70083347, "AT32F435RGT7", 1024, "LQFP64" },
29  { 0x7008459A, "AT32F435RDT7", 448, "LQFP64" },
30  { 0x70083248, "AT32F435RCT7", 256, "LQFP64" },
31  { 0x70084549, "AT32F435CMT7", 4032, "LQFP48" },
32  { 0x7008334A, "AT32F435CGT7", 1024, "LQFP48" },
33  { 0x7008459B, "AT32F435CDT7", 448, "LQFP48" },
34  { 0x7008324B, "AT32F435CCT7", 256, "LQFP48" },
35  { 0x7008454C, "AT32F435CMU7", 4032, "QFN48" },
36  { 0x7008334D, "AT32F435CGU7", 1024, "QFN48" },
37  { 0x7008459C, "AT32F435CDU7", 448, "QFN48" },
38  { 0x7008324E, "AT32F435CCU7", 256, "QFN48" },
39  { 0x7008454F, "AT32F437ZMT7", 4032, "LQFP144" },
40  { 0x70083350, "AT32F437ZGT7", 1024, "LQFP144" },
41  { 0x7008459D, "AT32F437ZDT7", 448, "LQFP144" },
42  { 0x70083251, "AT32F437ZCT7", 256, "LQFP144" },
43  { 0x70084552, "AT32F437VMT7", 4032, "LQFP100" },
44  { 0x70083353, "AT32F437VGT7", 1024, "LQFP100" },
45  { 0x7008459E, "AT32F437VDT7", 448, "LQFP100" },
46  { 0x70083254, "AT32F437VCT7", 256, "LQFP100" },
47  { 0x70084555, "AT32F437RMT7", 4032, "LQFP64" },
48  { 0x70083356, "AT32F437RGT7", 1024, "LQFP64" },
49  { 0x7008459F, "AT32F437RDT7", 448, "LQFP64" },
50  { 0x70083257, "AT32F437RCT7", 256, "LQFP64" },
51  };
52 
53  for (size_t i = 0; i < efi::size(at32f43x_types); i++) {
54  if (id == at32f43x_types[i].uid) {
55  if (pn)
56  *pn = at32f43x_types[i].pn;
57  if (package)
58  *package = at32f43x_types[i].package;
59  if (flashSize)
60  *flashSize = at32f43x_types[i].flashSize;
61  return 0;
62  }
63  }
64 
65  /* unknown */
66  return -1;
67 }
static uint16_t flashSize()
Definition: mpu_util.cpp:17
composite packet size

Referenced by sayHello().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ at32GetRamSizeKb()

int at32GetRamSizeKb ( void  )

Definition at line 69 of file at32_common.cpp.

70 {
71  uint8_t EOPB0 = *(__IO uint16_t *) (0x1FFFC010);
72  /* TODO: check inverted value */
73 
74  switch ((*(__IO uint16_t *) (FLASHSIZE_BASE))) {
75  case 256:
76  EOPB0 &= 0x03;
77  if (EOPB0 == 3)
78  EOPB0 = 2;
79  return 512 - (64 * EOPB0);
80  case 448:
81  EOPB0 &= 0x07;
82  if (EOPB0 > 5)
83  EOPB0 = 5;
84  return 512 - (64 * EOPB0);
85  case 1024:
86  case 4032:
87  EOPB0 &= 0x07;
88  if (EOPB0 > 6)
89  EOPB0 = 6;
90  return 512 - (64 * EOPB0);
91  default:
92  return 0;
93  }
94  return 0;
95 }

Referenced by sayHello().

Here is the caller graph for this function:

◆ baseMCUInit()

void baseMCUInit ( void  )

Definition at line 145 of file at32_common.cpp.

145  {
146  // looks like this holds a random value on start? Let's set a nice clean zero
147  DWT->CYCCNT = 0;
148 
149  BOR_Set(BOR_Level_1); // one step above default value
150 }
BOR_Result_t BOR_Set(BOR_Level_t BORValue)
@ BOR_Level_1
Definition: port_mpu_util.h:21

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ BOR_Get()

BOR_Level_t BOR_Get ( void  )

Definition at line 125 of file at32_common.cpp.

125  {
126  /* TODO: Artery */
127  /* Fake */
128  return BOR_Level_None;
129 }
@ BOR_Level_None
Definition: port_mpu_util.h:20

◆ BOR_Set()

BOR_Result_t BOR_Set ( BOR_Level_t  BORValue)

Definition at line 131 of file at32_common.cpp.

131  {
132  /* NOP */
133  return BOR_Result_Ok;
134 }
@ BOR_Result_Ok
Definition: mpu_util.h:88

Referenced by baseMCUInit(), and setBor().

Here is the caller graph for this function:

◆ getMCUResetCause() [1/2]

Reset_Cause_t getMCUResetCause ( )

Definition at line 188 of file at32_common.cpp.

188  {
189  return Reset_Cause_Unknown;
190 }
@ Reset_Cause_Unknown
Definition: mpu_util.h:97

Referenced by checkLastResetCause().

Here is the caller graph for this function:

◆ getMCUResetCause() [2/2]

const char* getMCUResetCause ( Reset_Cause_t  cause)

Definition at line 192 of file at32_common.cpp.

192  {
193  return "Unknown";
194 }

◆ getRemainingStack()

EXTERNC int getRemainingStack ( thread_t *  otp)

Of note is that interrupts are NOT serviced on the stack of the thread that was running when the interrupt occurred. The only thing that happens on that thread's stack is that its registers are pushed (by hardware) when an interrupt occurs, just before swapping the stack pointer out for the main stack (currently 0x400=1024 bytes), where the ISR actually runs. see also main_stack_size see also process_stack_size

see also http://www.chibios.org/dokuwiki/doku.php?id=chibios:kb:stacks

In the firmware we are using 'extern *Engine' - in the firmware Engine is a singleton

On the other hand, in order to have a meaningful unit test we are passing Engine * engine as a parameter

Definition at line 163 of file at32_common.cpp.

163  {
164 #if CH_DBG_ENABLE_STACK_CHECK
165  // this would dismiss coverity warning - see http://rusefi.com/forum/viewtopic.php?f=5&t=655
166  // coverity[uninit_use]
167  register intctx_t *r13 asm ("r13");
168  otp->activeStack = r13;
169 
170  int remainingStack;
171  if (ch.dbg.isr_cnt > 0) {
172  // ISR context
173  remainingStack = (int)(r13 - 1) - (int)&__main_stack_base__;
174  } else {
175  remainingStack = (int)(r13 - 1) - (int)otp->wabase;
176  }
177  otp->remainingStack = remainingStack;
178  return remainingStack;
179 #else
180  UNUSED(otp);
181  return 99999;
182 #endif /* CH_DBG_ENABLE_STACK_CHECK */
183 }
uint32_t __main_stack_base__
struct port_intctx intctx_t
pwm_settings ch[2]
UNUSED(samplingTimeSeconds)

◆ isStm32F42x()

bool isStm32F42x ( void  )

Definition at line 155 of file at32_common.cpp.

155  {
156  return false;
157 }

Referenced by sayHello(), and startLua().

Here is the caller graph for this function:

◆ jump_to_bootloader()

void jump_to_bootloader ( )

Definition at line 105 of file at32_common.cpp.

105  {
106  // leave DFU breadcrumb which assembly startup code would check, see [rusefi][DFU] section in assembly code
107 
108  *((unsigned long *)0x2001FFF0) = 0xDEADBEEF; // End of RAM
109 
110  reset_and_jump();
111 }
static void reset_and_jump(void)
Definition: at32_common.cpp:99

Referenced by executeTSCommand(), and runRusEfi().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ jump_to_openblt()

void jump_to_openblt ( )

Definition at line 114 of file at32_common.cpp.

114  {
115 #if EFI_USE_OPENBLT
116  /* safe to call on already inited shares area */
118  /* Store sing to stay in OpenBLT */
119  SharedParamsWriteByIndex(0, 0x01);
120 
121  reset_and_jump();
122 #endif
123 }
bool SharedParamsWriteByIndex(uint32_t idx, uint8_t value)
Writes a data byte to the shared parameter buffer at the specified index.
void SharedParamsInit(void)
Initializes the shared RAM parameters module.
Definition: shared_params.c:83

Referenced by executeTSCommand(), processCanRxMessage(), and runRusEfi().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ reset_and_jump()

static void reset_and_jump ( void  )
static

Definition at line 99 of file at32_common.cpp.

99  {
100  // and now reboot
101  NVIC_SystemReset();
102 }

Referenced by jump_to_bootloader(), and jump_to_openblt().

Here is the caller graph for this function:

◆ setWatchdogResetPeriod()

void setWatchdogResetPeriod ( int  resetMs)

Definition at line 142 of file at32_common.cpp.

142  {
143 }

Referenced by initializeConsole().

Here is the caller graph for this function:

◆ startWatchdog()

void startWatchdog ( int  timeoutMs)

Definition at line 136 of file at32_common.cpp.

136  {
137 }

Referenced by initializeConsole(), and writeToFlashNow().

Here is the caller graph for this function:

◆ tryResetWatchdog()

void tryResetWatchdog ( )

Definition at line 139 of file at32_common.cpp.

139  {
140 }

Referenced by doPeriodicSlowCallback().

Here is the caller graph for this function:

Variable Documentation

◆ __main_stack_base__

uint32_t __main_stack_base__
extern

Referenced by getRemainingStack().

Go to the source code of this file.