4

If main process execute WFI with AL bit set in CFG_GCR, changing I1/I0 priority bits in the ISR cause CPU stalled when nested IRQ occured.

Preconditions: all ITC_SPR1 registers has default value 0xFF.

Enable TIM4 with generate interrupts on overflow. ISR for TIM4 contain only code for clear TIM_SR1_UIF bit in the TIM4_SR1 register. Unlock EEPROM for write, initiate byte write procedure and enable IRQ for EEPROM write operation complete. In the ISR for EEPROM raise IRQ level by RIM instruction or direct specify I1/I0 bits by PUSH #8,POP CC (for example). Main programm set AL bit into GCR register and execute WFI instruction.

If in the EEPROM ISR IRQ level raised by RIM or PUSH/POP CC instructions and then occured IRQ from TIM4, then after IRET from TIM4 ISR core is stalled and EEPROM's ISR is not continued.

Workaround 1. Clear AL bit into GCR before execute WFI instruction in main loop.

Workaround 2. Clear AL bit into GCR in EEPROM ISR before execute RIM or PUSH/POP CC instructions

Workaround 3. Set IRQ level for EEPROM other than I1=1, I0=1 (for example ITC->ISPR1 = 0b11110111; before initiate EEPROM write operation).

I don't found this bug in current errata sheet ES019.

I see this bug on STM8L-Discovery board with chip stm8l152c6t6. Can someone reproduce this bug on same or different chips? Please confirm or decline it.

Example:

tim4ISR() {
    /* clear UIF */
    TIM4->SR1 &= (uint8_t)(~TIM_SR1_UIF);
}

eepromISR() {
    (void)FLASH->IAPSR; /* or other manner read IAPSR */

    /* Set some pin to indicate in-ISR state */

    __ASM("rim"); /* or __ASM("push #8\npop cc\n"); */

    /* delay into ISR */
    for(int i = 0;i < delayN;i++) ;

    /* clear AL for leave WFI after IRET and initiate next byte write */
    CFG->GCR &= ~CFG_GCR_AL;

    /* Clear some pin to indicate leave ISR */
}

main() {
    /* Set TIM4 for generate periodic IRQ */

    /* Unlock MASS */

    while(1) {
        /* Initiate EEPROM byte or word write operation */

        /* IRET stay on wait mode */
        CFG->GCR |= CFG_GCR_AL; 

       __ASM("wfi");
    }
}

0 Answers0