Hardfault handler + FPGA abort/interrupt collision fix
This commit is contained in:
parent
5536d3b89b
commit
6e5f2635d1
@ -14,6 +14,7 @@ static FPGA::HaltedCallback halted_cb;
|
|||||||
static uint16_t SysCtrlReg = 0x0000;
|
static uint16_t SysCtrlReg = 0x0000;
|
||||||
static uint16_t ISRMaskReg = 0x0000;
|
static uint16_t ISRMaskReg = 0x0000;
|
||||||
static uint32_t ADC_samplerate;
|
static uint32_t ADC_samplerate;
|
||||||
|
static volatile bool busy_reading = false;
|
||||||
|
|
||||||
using namespace FPGAHAL;
|
using namespace FPGAHAL;
|
||||||
|
|
||||||
@ -86,6 +87,7 @@ bool FPGA::Configure(uint32_t start_address, uint32_t bitstream_size) {
|
|||||||
|
|
||||||
bool FPGA::Init(HaltedCallback cb) {
|
bool FPGA::Init(HaltedCallback cb) {
|
||||||
halted_cb = cb;
|
halted_cb = cb;
|
||||||
|
busy_reading = false;
|
||||||
SysCtrlReg = 0;
|
SysCtrlReg = 0;
|
||||||
ISRMaskReg = 0;
|
ISRMaskReg = 0;
|
||||||
// Reset FPGA
|
// Reset FPGA
|
||||||
@ -180,6 +182,11 @@ void FPGA::DisableInterrupt(Interrupt i) {
|
|||||||
WriteRegister(Reg::InterruptMask, ISRMaskReg);
|
WriteRegister(Reg::InterruptMask, ISRMaskReg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FPGA::DisableAllInterrupts() {
|
||||||
|
ISRMaskReg = 0x0000;
|
||||||
|
WriteRegister(Reg::InterruptMask, ISRMaskReg);
|
||||||
|
}
|
||||||
|
|
||||||
void FPGA::WriteMAX2871Default(uint32_t *DefaultRegs) {
|
void FPGA::WriteMAX2871Default(uint32_t *DefaultRegs) {
|
||||||
WriteRegister(Reg::MAX2871Def0LSB, DefaultRegs[0] & 0xFFFF);
|
WriteRegister(Reg::MAX2871Def0LSB, DefaultRegs[0] & 0xFFFF);
|
||||||
WriteRegister(Reg::MAX2871Def0MSB, DefaultRegs[0] >> 16);
|
WriteRegister(Reg::MAX2871Def0MSB, DefaultRegs[0] >> 16);
|
||||||
@ -259,19 +266,21 @@ static inline int64_t sign_extend_64(int64_t x, uint16_t bits) {
|
|||||||
static FPGA::ReadCallback callback;
|
static FPGA::ReadCallback callback;
|
||||||
static uint8_t raw[40];
|
static uint8_t raw[40];
|
||||||
static FPGA::SamplingResult result;
|
static FPGA::SamplingResult result;
|
||||||
static bool busy_reading = false;
|
|
||||||
|
|
||||||
bool FPGA::InitiateSampleRead(ReadCallback cb) {
|
bool FPGA::InitiateSampleRead(ReadCallback cb) {
|
||||||
if(busy_reading) {
|
if(busy_reading) {
|
||||||
LOG_ERR("ISR while still reading old data");
|
LOG_ERR("ISR while SPI is busy");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
callback = cb;
|
callback = cb;
|
||||||
uint8_t cmd[40] = {0xC0, 0x00};
|
static uint8_t cmd[40] = {0xC0, 0x00};
|
||||||
// Start data read
|
// Start data read
|
||||||
Low(CS);
|
Low(CS);
|
||||||
busy_reading = true;
|
busy_reading = true;
|
||||||
HAL_SPI_TransmitReceive_DMA(&FPGA_SPI, cmd, raw, 40);
|
if(HAL_SPI_TransmitReceive_DMA(&FPGA_SPI, cmd, raw, 40) != HAL_OK) {
|
||||||
|
LOG_ERR("Failed to start SPI DMA");
|
||||||
|
busy_reading = false;
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -313,7 +322,11 @@ void FPGA::StartSweep() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void FPGA::AbortSweep() {
|
void FPGA::AbortSweep() {
|
||||||
|
// abort any FPGA operation by pulling sweep pin low
|
||||||
Low(AUX3);
|
Low(AUX3);
|
||||||
|
// data transfer of a datapoint might still be active, abort
|
||||||
|
HAL_SPI_DMAStop(&FPGA_SPI);
|
||||||
|
busy_reading = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FPGA::SetMode(Mode mode) {
|
void FPGA::SetMode(Mode mode) {
|
||||||
|
@ -121,6 +121,7 @@ bool IsEnabled(Periphery p);
|
|||||||
void SetWindow(Window w);
|
void SetWindow(Window w);
|
||||||
void EnableInterrupt(Interrupt i);
|
void EnableInterrupt(Interrupt i);
|
||||||
void DisableInterrupt(Interrupt i);
|
void DisableInterrupt(Interrupt i);
|
||||||
|
void DisableAllInterrupts();
|
||||||
void WriteMAX2871Default(uint32_t *DefaultRegs);
|
void WriteMAX2871Default(uint32_t *DefaultRegs);
|
||||||
void WriteSweepConfig(uint16_t pointnum, bool lowband, uint32_t *SourceRegs, uint32_t *LORegs,
|
void WriteSweepConfig(uint16_t pointnum, bool lowband, uint32_t *SourceRegs, uint32_t *LORegs,
|
||||||
uint8_t attenuation, uint64_t frequency, SettlingTime settling, Samples samples, bool halt = false, LowpassFilter filter = LowpassFilter::Auto);
|
uint8_t attenuation, uint64_t frequency, SettlingTime settling, Samples samples, bool halt = false, LowpassFilter filter = LowpassFilter::Auto);
|
||||||
|
@ -236,6 +236,7 @@ void HW::SetIdle() {
|
|||||||
Trigger::SetInput(false);
|
Trigger::SetInput(false);
|
||||||
FPGA::AbortSweep();
|
FPGA::AbortSweep();
|
||||||
FPGA::SetMode(FPGA::Mode::FPGA);
|
FPGA::SetMode(FPGA::Mode::FPGA);
|
||||||
|
FPGA::DisableAllInterrupts();
|
||||||
FPGA::DisableHardwareOverwrite();
|
FPGA::DisableHardwareOverwrite();
|
||||||
FPGA::Enable(FPGA::Periphery::SourceChip, false);
|
FPGA::Enable(FPGA::Periphery::SourceChip, false);
|
||||||
FPGA::Enable(FPGA::Periphery::SourceRF, false);
|
FPGA::Enable(FPGA::Periphery::SourceRF, false);
|
||||||
|
@ -88,6 +88,54 @@ void vApplicationGetIdleTaskMemory( StaticTask_t **ppxIdleTaskTCBBuffer, StackTy
|
|||||||
|
|
||||||
/* Private application code --------------------------------------------------*/
|
/* Private application code --------------------------------------------------*/
|
||||||
/* USER CODE BEGIN Application */
|
/* USER CODE BEGIN Application */
|
||||||
|
/* The prototype shows it is a naked function - in effect this is just an
|
||||||
|
assembly function. */
|
||||||
|
void HardFault_Handler( void ) __attribute__( ( naked ) );
|
||||||
|
|
||||||
|
void prvGetRegistersFromStack( uint32_t *pulFaultStackAddress )
|
||||||
|
{
|
||||||
|
/* These are volatile to try and prevent the compiler/linker optimising them
|
||||||
|
away as the variables never actually get used. If the debugger won't show the
|
||||||
|
values of the variables, make them global my moving their declaration outside
|
||||||
|
of this function. */
|
||||||
|
volatile uint32_t r0;
|
||||||
|
volatile uint32_t r1;
|
||||||
|
volatile uint32_t r2;
|
||||||
|
volatile uint32_t r3;
|
||||||
|
volatile uint32_t r12;
|
||||||
|
volatile uint32_t lr; /* Link register. */
|
||||||
|
volatile uint32_t pc; /* Program counter. */
|
||||||
|
volatile uint32_t psr;/* Program status register. */
|
||||||
|
|
||||||
|
r0 = pulFaultStackAddress[ 0 ];
|
||||||
|
r1 = pulFaultStackAddress[ 1 ];
|
||||||
|
r2 = pulFaultStackAddress[ 2 ];
|
||||||
|
r3 = pulFaultStackAddress[ 3 ];
|
||||||
|
|
||||||
|
r12 = pulFaultStackAddress[ 4 ];
|
||||||
|
lr = pulFaultStackAddress[ 5 ];
|
||||||
|
pc = pulFaultStackAddress[ 6 ];
|
||||||
|
psr = pulFaultStackAddress[ 7 ];
|
||||||
|
|
||||||
|
/* When the following line is hit, the variables contain the register values. */
|
||||||
|
for( ;; );
|
||||||
|
}
|
||||||
|
|
||||||
|
/* The fault handler implementation calls a function called
|
||||||
|
prvGetRegistersFromStack(). */
|
||||||
|
void HardFault_Handler(void)
|
||||||
|
{
|
||||||
|
__asm volatile
|
||||||
|
(
|
||||||
|
" tst lr, #4 \n"
|
||||||
|
" ite eq \n"
|
||||||
|
" mrseq r0, msp \n"
|
||||||
|
" mrsne r0, psp \n"
|
||||||
|
" ldr r1, [r0, #24] \n"
|
||||||
|
" ldr r2, handler2_address_const \n"
|
||||||
|
" bx r2 \n"
|
||||||
|
" handler2_address_const: .word prvGetRegistersFromStack \n"
|
||||||
|
);
|
||||||
|
}
|
||||||
/* USER CODE END Application */
|
/* USER CODE END Application */
|
||||||
|
|
||||||
|
@ -85,17 +85,17 @@ void NMI_Handler(void)
|
|||||||
/**
|
/**
|
||||||
* @brief This function handles Hard fault interrupt.
|
* @brief This function handles Hard fault interrupt.
|
||||||
*/
|
*/
|
||||||
void HardFault_Handler(void)
|
//void HardFault_Handler(void)
|
||||||
{
|
//{
|
||||||
/* USER CODE BEGIN HardFault_IRQn 0 */
|
// /* USER CODE BEGIN HardFault_IRQn 0 */
|
||||||
|
//
|
||||||
/* USER CODE END HardFault_IRQn 0 */
|
// /* USER CODE END HardFault_IRQn 0 */
|
||||||
while (1)
|
// while (1)
|
||||||
{
|
// {
|
||||||
/* USER CODE BEGIN W1_HardFault_IRQn 0 */
|
// /* USER CODE BEGIN W1_HardFault_IRQn 0 */
|
||||||
/* USER CODE END W1_HardFault_IRQn 0 */
|
// /* USER CODE END W1_HardFault_IRQn 0 */
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief This function handles Memory management fault.
|
* @brief This function handles Memory management fault.
|
||||||
|
@ -0,0 +1,80 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<launchConfiguration type="com.st.stm32cube.ide.mcu.debug.launch.launchConfigurationType">
|
||||||
|
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.launch.access_port_id" value="0"/>
|
||||||
|
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.launch.enable_live_expr" value="true"/>
|
||||||
|
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.launch.enable_swv" value="false"/>
|
||||||
|
<intAttribute key="com.st.stm32cube.ide.mcu.debug.launch.formatVersion" value="2"/>
|
||||||
|
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.launch.ip_address_local" value="localhost"/>
|
||||||
|
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.launch.limit_swo_clock.enabled" value="false"/>
|
||||||
|
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.launch.limit_swo_clock.value" value=""/>
|
||||||
|
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.launch.loadList" value="{"fItems":[{"fIsFromMainTab":true,"fPath":"Debug/VNA_embedded.elf","fProjectName":"VNA_embedded","fPerformBuild":true,"fDownload":false,"fLoadSymbols":true}]}"/>
|
||||||
|
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.launch.override_start_address_mode" value="default"/>
|
||||||
|
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.launch.remoteCommand" value="target remote"/>
|
||||||
|
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.launch.startServer" value="true"/>
|
||||||
|
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.launch.startuptab.exception.divby0" value="true"/>
|
||||||
|
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.launch.startuptab.exception.unaligned" value="false"/>
|
||||||
|
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.launch.startuptab.haltonexception" value="true"/>
|
||||||
|
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.launch.swd_mode" value="true"/>
|
||||||
|
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.launch.swv_port" value="61235"/>
|
||||||
|
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.launch.swv_trace_hclk" value="16000000"/>
|
||||||
|
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.launch.useRemoteTarget" value="true"/>
|
||||||
|
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.launch.vector_table" value=""/>
|
||||||
|
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.launch.verify_flash_download" value="false"/>
|
||||||
|
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.cti_allow_halt" value="false"/>
|
||||||
|
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.cti_signal_halt" value="false"/>
|
||||||
|
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.enable_external_loader" value="false"/>
|
||||||
|
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.enable_logging" value="false"/>
|
||||||
|
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.enable_max_halt_delay" value="false"/>
|
||||||
|
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.enable_shared_stlink" value="false"/>
|
||||||
|
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.external_loader" value=""/>
|
||||||
|
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.external_loader_init" value="false"/>
|
||||||
|
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.frequency" value="0"/>
|
||||||
|
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.halt_all_on_reset" value="false"/>
|
||||||
|
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.log_file" value="/home/jan/Projekte/LibreVNA/Software/VNA_embedded/Debug/st-link_gdbserver_log.txt"/>
|
||||||
|
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.low_power_debug" value="disable"/>
|
||||||
|
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.max_halt_delay" value="2"/>
|
||||||
|
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.reset_strategy" value="no_reset"/>
|
||||||
|
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.stlink_check_serial_number" value="false"/>
|
||||||
|
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.stlink_txt_serial_number" value=""/>
|
||||||
|
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.watchdog_config" value="none"/>
|
||||||
|
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.stlinkenable_rtos" value="false"/>
|
||||||
|
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.stlinkrestart_configurations" value="{"fItems":[{"fDisplayName":"Reset","fIsSuppressible":false,"fResetAttribute":"Software system reset","fResetStrategies":[{"fDisplayName":"Software system reset","fLaunchAttribute":"system_reset","fGdbCommands":["monitor reset\n"],"fCmdOptions":["-g"]},{"fDisplayName":"Hardware reset","fLaunchAttribute":"hardware_reset","fGdbCommands":["monitor reset hardware\n"],"fCmdOptions":["-g"]},{"fDisplayName":"Core reset","fLaunchAttribute":"core_reset","fGdbCommands":["monitor reset core\n"],"fCmdOptions":["-g"]},{"fDisplayName":"None","fLaunchAttribute":"no_reset","fGdbCommands":[],"fCmdOptions":["-g"]}],"fGdbCommandGroup":{"name":"Additional commands","commands":[]}}]}"/>
|
||||||
|
<booleanAttribute key="com.st.stm32cube.ide.mcu.rtosproxy.enableRtosProxy" value="false"/>
|
||||||
|
<stringAttribute key="com.st.stm32cube.ide.mcu.rtosproxy.rtosProxyCustomProperties" value=""/>
|
||||||
|
<stringAttribute key="com.st.stm32cube.ide.mcu.rtosproxy.rtosProxyDriver" value="threadx"/>
|
||||||
|
<booleanAttribute key="com.st.stm32cube.ide.mcu.rtosproxy.rtosProxyDriverAuto" value="false"/>
|
||||||
|
<stringAttribute key="com.st.stm32cube.ide.mcu.rtosproxy.rtosProxyDriverPort" value="cortex_m0"/>
|
||||||
|
<intAttribute key="com.st.stm32cube.ide.mcu.rtosproxy.rtosProxyPort" value="60000"/>
|
||||||
|
<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.doHalt" value="false"/>
|
||||||
|
<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.doReset" value="false"/>
|
||||||
|
<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.initCommands" value=""/>
|
||||||
|
<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.ipAddress" value="localhost"/>
|
||||||
|
<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.jtagDeviceId" value="com.st.stm32cube.ide.mcu.debug.stlink"/>
|
||||||
|
<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.pcRegister" value=""/>
|
||||||
|
<intAttribute key="org.eclipse.cdt.debug.gdbjtag.core.portNumber" value="61234"/>
|
||||||
|
<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.runCommands" value=""/>
|
||||||
|
<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.setPcRegister" value="false"/>
|
||||||
|
<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.setResume" value="true"/>
|
||||||
|
<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.setStopAt" value="false"/>
|
||||||
|
<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.stopAt" value="main"/>
|
||||||
|
<stringAttribute key="org.eclipse.cdt.dsf.gdb.DEBUG_NAME" value="arm-none-eabi-gdb"/>
|
||||||
|
<booleanAttribute key="org.eclipse.cdt.dsf.gdb.NON_STOP" value="false"/>
|
||||||
|
<booleanAttribute key="org.eclipse.cdt.dsf.gdb.UPDATE_THREADLIST_ON_SUSPEND" value="false"/>
|
||||||
|
<intAttribute key="org.eclipse.cdt.launch.ATTR_BUILD_BEFORE_LAUNCH_ATTR" value="0"/>
|
||||||
|
<stringAttribute key="org.eclipse.cdt.launch.COREFILE_PATH" value=""/>
|
||||||
|
<stringAttribute key="org.eclipse.cdt.launch.DEBUGGER_START_MODE" value="remote"/>
|
||||||
|
<booleanAttribute key="org.eclipse.cdt.launch.DEBUGGER_STOP_AT_MAIN" value="false"/>
|
||||||
|
<stringAttribute key="org.eclipse.cdt.launch.DEBUGGER_STOP_AT_MAIN_SYMBOL" value="main"/>
|
||||||
|
<stringAttribute key="org.eclipse.cdt.launch.PROGRAM_NAME" value="Debug/VNA_embedded.elf"/>
|
||||||
|
<stringAttribute key="org.eclipse.cdt.launch.PROJECT_ATTR" value="VNA_embedded"/>
|
||||||
|
<booleanAttribute key="org.eclipse.cdt.launch.PROJECT_BUILD_CONFIG_AUTO_ATTR" value="true"/>
|
||||||
|
<stringAttribute key="org.eclipse.cdt.launch.PROJECT_BUILD_CONFIG_ID_ATTR" value="com.st.stm32cube.ide.mcu.gnu.managedbuild.config.exe.debug.1089561694"/>
|
||||||
|
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
|
||||||
|
<listEntry value="/VNA_embedded"/>
|
||||||
|
</listAttribute>
|
||||||
|
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
|
||||||
|
<listEntry value="4"/>
|
||||||
|
</listAttribute>
|
||||||
|
<stringAttribute key="org.eclipse.dsf.launch.MEMORY_BLOCKS" value="<?xml version="1.0" encoding="UTF-8" standalone="no"?><memoryBlockExpressionList context="reserved-for-future-use"><gdbmemoryBlockExpression address="3758157096" label="0xE000ED28"/><gdbmemoryBlockExpression address="3758157108" label="0xE000ED34"/><gdbmemoryBlockExpression address="536897460" label="0x200067B4"/></memoryBlockExpressionList>"/>
|
||||||
|
<stringAttribute key="process_factory_id" value="com.st.stm32cube.ide.mcu.debug.launch.HardwareDebugProcessFactory"/>
|
||||||
|
</launchConfiguration>
|
Loading…
Reference in New Issue
Block a user