Skip to content

STM32: Fix usart irq index #5962

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Jan 31, 2018
Merged

STM32: Fix usart irq index #5962

merged 18 commits into from
Jan 31, 2018

Conversation

bcostm
Copy link
Contributor

@bcostm bcostm commented Jan 29, 2018

Description

Status

READY

Migrations

NO

Todos

  • Tests

@marcemmers can you please test it in your application for the STM32L0 ?

irq_handler(serial_irq_ids[id], TxIrq);
int8_t id = get_uart_index(uart_name);

if (id >= 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what happens if uart_name is out of defined BASES ? I can see that get uart index returns -1 if not there, but this is not handled here, can it happen?

Copy link
Contributor Author

@bcostm bcostm Jan 29, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we have well written all the usarts available in the device it should not happen... Before this it was worse because in some case we could access out of the arrays (uart_handlers[id] and serial_irq_ids[id]).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An assert has been added in commit b6efdd5 to check this index.

@@ -92,43 +101,43 @@ static void uart3_8_irq(void)
#if defined(TARGET_STM32F091RC)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was wondering if the target necessary defines were still necessary? Haven't looked at the specific processor yet.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes it is required because the IRQ vector name is different and also the __HAL_GET_PENDING_IT macro is available only on F09x devices

@marcemmers
Copy link
Contributor

I will test on the L073, will let you know what i find.

@marcemmers
Copy link
Contributor

This worked fine for me on the L073RZ-Nucleo. Have tested all available uarts both on 9600 and 115k.

Did notice this however:

// Warning: the list of UART/USART in this function must be aligned with the list
// written in serial_init function.
int8_t get_uart_index(UARTName uart_name)

Why not remove the increment numbering from serial_init and also use get_uart_index instead? So:

#if defined(USART1_BASE)
    if (obj_s->uart == UART_1) {
        __HAL_RCC_USART1_FORCE_RESET();
        __HAL_RCC_USART1_RELEASE_RESET();
        __HAL_RCC_USART1_CLK_ENABLE();
    }
#endif

    obj_s->index = get_uart_index(obj_s->uart);    
    MBED_ASSERT(obj_s->index >= 0);

instead of

#if defined(USART1_BASE)
    if (obj_s->uart == UART_1) {
        __HAL_RCC_USART1_FORCE_RESET();
        __HAL_RCC_USART1_RELEASE_RESET();
        __HAL_RCC_USART1_CLK_ENABLE();
        obj_s->index = IndexNumber;
    }
    IndexNumber++;
#endif

@bcostm
Copy link
Contributor Author

bcostm commented Jan 29, 2018

Yep I think you're right and it should work. It's even better that way ! 👍

I'll send a new commit with your proposal.

And the assert adresses this remark:

what happens if uart_name is out of defined BASES ? I can see that get uart index returns -1 if not there, but this is not handled here, can it happen?

@0xc0170
Copy link
Contributor

0xc0170 commented Jan 30, 2018

@bcostm Please check travis failures

@bcostm
Copy link
Contributor Author

bcostm commented Jan 30, 2018

Should be ok now with commit eb4b339

@0xc0170
Copy link
Contributor

0xc0170 commented Jan 30, 2018

/morph build

@mbed-ci
Copy link

mbed-ci commented Jan 30, 2018

Build : SUCCESS

Build number : 1009
Build artifacts/logs : http://mbed-os.s3-website-eu-west-1.amazonaws.com/?prefix=builds/5962/

Triggering tests

/morph test
/morph uvisor-test
/morph export-build

@mbed-ci
Copy link

mbed-ci commented Jan 30, 2018

@mbed-ci
Copy link

mbed-ci commented Jan 30, 2018

@0xc0170
Copy link
Contributor

0xc0170 commented Jan 31, 2018

/morph uvisor-test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants