Skip to content
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

Flash bank customisation #1293

Merged
merged 2 commits into from
Jun 6, 2023

Conversation

peterharperuk
Copy link
Contributor

Defaults to true. Can be set to false if the flash bank offset is dynamically generated, e.g. to be inside the binary itself.

Fixes #1278

@kilograham
Copy link
Contributor

Frankly, i'd just be tempted to use __builtin_constant_p() in an ifdef around the static assertions

@peterharperuk
Copy link
Contributor Author

Nice. I literally didn't know that existed

@peterharperuk
Copy link
Contributor Author

I've used __builtin_constant_p()
Not sure what you meant by using it in a ifdef as it's a compiler not preprocessor thing?

@kilograham
Copy link
Contributor

Not sure what you meant by using it in a ifdef as it's a compiler not preprocessor thing?

uh yeah, duh, good point ;-) too little sleep!

@peterharperuk peterharperuk changed the title Add PICO_FLASH_BANK_FIXED_OFFSET Flash bank customisation Mar 3, 2023
@peterharperuk
Copy link
Contributor Author

Unless I'm mistaken this still isn't going to work without modifying files in the sdk?

They want to define the flash bank storage offset with pointer arithmetic. Which means the variable has to be defined in the btstack_flash_bank.h file. It can't go in pico_w.h because that's included in assembler.

Maybe we just need to make it possible to use an alternate version of pico_flash_bank_instance maybe via a #define specifying the function name or a cmake variable specifying a different source file. @kilograham are there any other examples for enabling customisation like this?

@peterharperuk peterharperuk force-pushed the bt_flash_bank_dynamic branch 2 times, most recently from ae7694a to 70ea92f Compare March 3, 2023 12:16
@peterharperuk
Copy link
Contributor Author

I've fixed this differently. Now if you define pico_flash_bank_get_offset_func you can change the function used to get the offset.
Some example code here peterharperuk/pico-examples@4f26716

@peterharperuk
Copy link
Contributor Author

@earlephilhower you better tell me if you're happy with this.

@earlephilhower
Copy link
Contributor

earlephilhower commented Mar 3, 2023

@peterharperuk, first thanks a bunch for your support. That's a neat solution , but is it safe to assume the size in the SDK when this is called? (I assume you'll need to adjust the SDK to call this as well?) --edit-- I see it's still a `#define, ignore this question --edit--

I'm also thinking, maybe this and #1278 can also be dropped. The reason is that the current TVL flash bank implementation isn't multicore safe, and I think lots of folks are going to use that 2nd core. The SDK can't really cater to all use cases, but it can be a simple example for folks to build off of for their own TLV implementations, maybe?

@peterharperuk
Copy link
Contributor Author

I don't think you should be using sizeof to set the size of the flash area. I can't see the need. Just set PICO_FLASH_BANK_TOTAL_SIZE to the number of sectors you want to reserve.

Are you saying you don't need this change? If the flash bank implementation isn't multicore safe (you're probably right) we can just fix that.

@earlephilhower
Copy link
Contributor

I don't think you should be using sizeof to set the size of the flash area. I can't see the need. Just set PICO_FLASH_BANK_TOTAL_SIZE to the number of sectors you want to reserve.

Agreed, I edited afterwards which probably wasn't obvious once I realized the same thing. Sorry, it was pre-coffee in the morning for me!

Are you saying you don't need this change? If the flash bank implementation isn't multicore safe (you're probably right) we can just fix that.

Well, this is necessary but not sufficient for my use case. The multicore safety needs to be there, too, but then I think I could use the stock version, yes.

But, my comment was more that you're moving into the application-side of things here, while most of the SDK is low-level tools. TLV could be in a fixed flash sector, it could be in a dynamic one like this patch, it could be a file (if you have a FS you could spread out flash wear), etc. So you've shown how to do it already, and since BT is really an app-level thing it's up to the end user to implement the right TLV store for their app.

@peterharperuk
Copy link
Contributor Author

Understood. I agree we're straying into the app side of things. We just want to provide the minimum necessary for the users who just want their code to work. And we don't want to get in the way of "power users" like yourself. I'll look into the multicore safety issue as that was an open issue that needs to be resolved.

Copy link
Contributor

@kilograham kilograham left a comment

Choose a reason for hiding this comment

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

seems like this should be documented somewhere (either PICO_CONFIG, or perhaps in the header)

@peterharperuk peterharperuk added this to the 1.5.1 milestone May 10, 2023
@kilograham kilograham marked this pull request as draft May 25, 2023 20:08
@kilograham
Copy link
Contributor

just marking this as a draft so i don't merge it yet... will likely add some help for multicore in 1.5.1 too

@kilograham
Copy link
Contributor

now dependent on #1412 (with some merge fun)

@peterharperuk
Copy link
Contributor Author

Needs to be rebased on top of #1412

@peterharperuk
Copy link
Contributor Author

Seems to be working okay

@kilograham kilograham marked this pull request as ready for review June 6, 2023 16:25
Allow the pico_flash_bank_get_offset function to be changed by
defining pico_flash_bank_get_offset_func

Fixes raspberrypi#1278
@peterharperuk
Copy link
Contributor Author

Rebase done!

@kilograham kilograham merged commit f3ebd62 into raspberrypi:develop Jun 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants