You guys are great. Thank you. I am really feeling my way with this at the moment.
I seem to have some kind of weirdness going on. I am not even convinced that the connection to the debugger is good. It seems flaky.
I took out any attempts to disable/enable interrupts, and went into STMCube again and turned off all IOs except the LEDs and switch (all I want now). I also found interrupts were enabled for TIM1, I removed those. now there are only interrupts for things that look important, and SYSTICK.
If I load and start and hit main I have this:
int main(void)
{
/* USER CODE BEGIN 1 */
timer_flag = 0;
#define NUM_TASKS 1
task tasks[NUM_TASKS];
// define tasks
tasks[0].elapsedTime = 0;
tasks[0].period = 1000;
tasks[0].TickFct = &T_blink;
/* USER CODE END 1 */
/* MCU Configuration----------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* Configure the system clock */
SystemClock_Config();
/* Initialize all configured peripherals */
MX_GPIO_Init();
/* USER CODE BEGIN 2 */
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
// Scheduler
for (unsigned char t = 0; t < NUM_TASKS; ++t) {
if (tasks[t].elapsedTime >= tasks[t].period) { // Ready
tasks[t].TickFct(); // Go
tasks[t].elapsedTime = 0;
}
tasks[t].elapsedTime++;
}
timer_flag = 0;
while (!timer_flag) {}
}
/* USER CODE END 3 */
}
timer_flag is just a global, all the SysTick ISR should do (for now) is set it:
/**
* @brief This function handles System tick timer.
*/
void SysTick_Handler(void)
{
/* USER CODE BEGIN SysTick_IRQn 0 */
/* USER CODE END SysTick_IRQn 0 */
HAL_SYSTICK_IRQHandler();
/* USER CODE BEGIN SysTick_IRQn 1 */
if (timer_flag){
// error! tasks not completed, handle this better later on
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_6, GPIO_PIN_SET); // red light on
} else {
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_6, GPIO_PIN_RESET); // red light off
}
timer_flag = 1; // must be reset by scheduler
/* USER CODE END SysTick_IRQn 1 */
}
When I step through, my debugger seems to lose it at the end of MX_GPIO_Init()
static void MX_GPIO_Init(void)
{
GPIO_InitTypeDef GPIO_InitStruct;
/* GPIO Ports Clock Enable */
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(GPIOB, LD_U_Pin|LD_D_Pin|LD_L_Pin|LD_R_Pin, GPIO_PIN_RESET);
/*Configure GPIO pin : B_USER_Pin */
GPIO_InitStruct.Pin = B_USER_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_EVT_RISING;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(B_USER_GPIO_Port, &GPIO_InitStruct);
/*Configure GPIO pins : LD_U_Pin LD_D_Pin LD_L_Pin LD_R_Pin */
GPIO_InitStruct.Pin = LD_U_Pin|LD_D_Pin|LD_L_Pin|LD_R_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
}
When it gets the last instruction, instead of going back to main() it seems to hang. In fact I seem to now end up here:
.section .text.Default_Handler,"ax",%progbits
Default_Handler:
Infinite_Loop:
b Infinite_Loop
.size Default_Handler, .-Default_Handler
/******************************************************************************
*
* The minimal vector table for a Cortex-M4. Note that the proper constructs
* must be placed on this to ensure that it ends up at physical address
* 0x0000.0000.
*
******************************************************************************/
.section .isr_vector,"a",%progbits
.type g_pfnVectors, %object
.size g_pfnVectors, .-g_pfnVectors
which I think is the default handler Andy mentioned. but if I break here, and look at registers - no IPSR register ... (see screenshot attached).
Meh. this is obviously something silly, but it's late and I am gonna get some sleep. Sorry if this is confused or silly - but if you can give me some pointers, that will be appreciated.
cheers!