Skip to content

Dev spi asynch stm #2888

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 6 commits into from
Oct 13, 2016
Merged

Dev spi asynch stm #2888

merged 6 commits into from
Oct 13, 2016

Conversation

LMESTM
Copy link
Contributor

@LMESTM LMESTM commented Oct 3, 2016

Notes:

  • Pull requests will not be accepted until the submitter has agreed to the contributer agreement.
  • This is just a template, so feel free to use/remove the unnecessary things

Description

SPI ASYNCH was already supported on STM32F4 targets.
This PR makes it generic for all STM32 based targets.
While doing this, the spi_api.c files that were more or less duplicated over several targets have now been moved into a single stm_spi_api.c file, except for the SPI peripheral frequency which is target depandant.

The ASYNCH has then been been enabled on all STM32 except L0 and L1 because there are limiations on those targets when SPI frequency gets @ 1MHz or higher while this works ok at lower frequencies like 500kHz (as asynch mode requires a high interrupt rate). This may be enabled in a later stage if we can get rid of the limitations.

Status

READY

Migrations

no change of API

Related PRs

No known dependency

Todos

  • Tests results

Test using SPI MOSI/MISO LOOP and doing
spi.write loops then checking results
spi.transfer loops then checking results (in case of SPI_ASYNCH support)
spi_write loops again, then checking results
tested at 3 different frequencies on 1 board per family.

Already tests before mbed directory structure have changed (in #2878). Tests restarted now, will update the PR with results, but I want to send it now to start review and hopefully minimize number of rebase to be done ...

  • Documentation
    documented in commits and PR description

Deploy notes

Notes regarding the deployment of this PR. These should note any
required changes in the build environment, tools, compilers, etc.

Steps to test or reproduce

Outline the steps to test or reproduce the PR here.

@LMESTM
Copy link
Contributor Author

LMESTM commented Oct 3, 2016

updated tests results
image

@LMESTM
Copy link
Contributor Author

LMESTM commented Oct 3, 2016

@bcostm @adustm

@sg-
Copy link
Contributor

sg- commented Oct 7, 2016

@LMESTM can you resolve the conflict?

@0xc0170
Copy link
Contributor

0xc0170 commented Oct 10, 2016

Just minor things, but having one spi for any STM device is a big 👍

@LMESTM
Copy link
Contributor Author

LMESTM commented Oct 11, 2016

@0xc0170

Just minor things,

when you mention minor things: are their comments I need to take into account ?
I'm about to rebase, if anything to change as well let me know
And thanks for the feedback !

@0xc0170
Copy link
Contributor

0xc0170 commented Oct 11, 2016

when you mention minor things: are their comments I need to take into account ?

yes ! minor should be taken into account. Please fix the style. Let's be consistent within this code base.

@LMESTM
Copy link
Contributor Author

LMESTM commented Oct 11, 2016

@0xc0170 I'm fine with correcting any comments, I just can't seen them right now ...

SPI_BAUDRATEPRESCALER_128,
SPI_BAUDRATEPRESCALER_256};

void spi_frequency(spi_t *obj, int hz) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you fix formatting in this function ? Indentation is off for almost all lines below

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok - indeed there were tabs around :-(


obj->spi.transfer_type = transfer_type;

if (is16bit) words = length / 2;
Copy link
Contributor

Choose a reason for hiding this comment

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

if () {

} else {

}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

NVIC_EnableIRQ(irq_n);

// enable the right hal transfer
//static uint16_t sink;
Copy link
Contributor

Choose a reason for hiding this comment

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

remove?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done


if (event) DEBUG_PRINTF("SPI: Event: 0x%x\n", event);

return (event & (obj->spi.event | SPI_EVENT_INTERNAL_TRANSFER_COMPLETE));
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this correct here | SPI_EVENT_INTERNAL_TRANSFER_COMPLETE ? It's set above if we are done or event error?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it is correct.
we're filtering the current possible local events (complete, error, ...) with the registered events from application (can be all, or only complete ...). The appl registered events are stored in spi.event in spi _master_transfer function.
If we don't add internal event to the mask, the internal event will not be sent back, even might be though needed internally.

struct spi_s *spiobj = SPI_S(obj);
SPI_HandleTypeDef *handle = &(spiobj->handle);
while (!ssp_writeable(obj));
//spi->DR = (uint16_t)value;
Copy link
Contributor

Choose a reason for hiding this comment

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

remove?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yep

@0xc0170
Copy link
Contributor

0xc0170 commented Oct 11, 2016

@LMESTM Sorry, I did not send those for review. I corrected it now, should be visible

@LMESTM
Copy link
Contributor Author

LMESTM commented Oct 11, 2016

@0xc0170 no pb - I started wondering what I was missing .. I'll update in line with your comments !

@LMESTM LMESTM force-pushed the dev_spi_asynch_stm branch from 2cb8b30 to 3e55ff8 Compare October 11, 2016 17:08
@LMESTM
Copy link
Contributor Author

LMESTM commented Oct 11, 2016

@sg-
rebased
@0xc0170 thanks for reviewing - comments taken into account

@sg-
Copy link
Contributor

sg- commented Oct 11, 2016

@LMESTM
Copy link
Contributor Author

LMESTM commented Oct 12, 2016

@sg- corrected now. I don't know how this wasn't seen before ...

@sg-
Copy link
Contributor

sg- commented Oct 12, 2016

@LMESTM can you resolve the targets.json conflict?

Laurent MEUNIER and others added 6 commits October 13, 2016 14:18
the SPI_ASYNCH feature has been already activated for STM32F4.
This patchset makes it supported on all STM32 families by:
- moving spi_s structure at family level instead of board level
- using the F4 spi_api.c reference implementation and making it a common
stm_spi_api.c file which makes maintenance a lot easier.
- the only part that needs to be implemented for each family is the computation
of the clock frequency input to the spi peripheral which is not the same
accross families. So this is what remains in the spi_api.c of each family.

Because of the introduction of the common file, all the above modifications
needs to be done at once.
ASYNCH SPI transfer support has been added based on STM HAL services.
To have both ASYNCH and SYNCH work together, we're also moving the
write API to STM HAL instead of direct registers access.
Now that SPI_ASYNCH is supported on all STM32 based boards,
let's activate the feature.

Using a default SPI QUEUE of size 2 - this can be later modified if this
prives to be to low. (or too high)
Let's swap default PA_4 pin mapping to SPI_3 otherwise SPI3 cannot be used
Fix indentation issues, remove useless comments, correct if/else format
STM32F303ZE was introduced in parallel to the changes which consist in
having family wide definitions like device.h file and a common objects
definition.

This target is updated accordingly now to benefit of SPI definitions.
@LMESTM LMESTM force-pushed the dev_spi_asynch_stm branch from 68ec05d to aeac255 Compare October 13, 2016 12:23
@LMESTM
Copy link
Contributor Author

LMESTM commented Oct 13, 2016

@sg- rebased again
conflicts mostly always come from targets.json - wouldn't there we a way to limit those conflicts ?
e.g. would that be okay if we split the device_has lines over many different lines ? that would be maybe a bit less readable but would probably limit conflicts cases - let me know if any idea

@sg-
Copy link
Contributor

sg- commented Oct 13, 2016

I know, its annoying. Will have a look into maknig this better

@LMESTM
Copy link
Contributor Author

LMESTM commented Oct 13, 2016

@sg-

I know, its annoying. Will have a look into maknig this better

as I mentioned, I think that moving each feature of device_has line into a single separate line (and same for macros) would avoid most of the conflicts. maybe worth a try ?

@sg- sg- merged commit 81beeb1 into ARMmbed:master Oct 13, 2016
@sg-
Copy link
Contributor

sg- commented Oct 13, 2016

Yeah and I'd also like to have a think about single target.json for each target but needs a bit more thinking around inheritance etc...

@LMESTM LMESTM deleted the dev_spi_asynch_stm branch May 23, 2017 15:06
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.

3 participants