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

Stm32f3: add flash support #2083

Merged
merged 24 commits into from
Sep 17, 2020
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
8b833af
add register struct for flash controller
krady21 Jul 13, 2020
fd64f8f
Added Flash base address, OptionByte register and implemented part of
krady21 Jul 14, 2020
a0e6521
Use crate::flash in chip.rs
krady21 Jul 15, 2020
a7a915c
Add erase_page, erase_all and write_page implementations
krady21 Jul 16, 2020
0ab0030
Added read_page function
krady21 Jul 20, 2020
bed050d
Fix byte iteration
krady21 Jul 20, 2020
9973e12
Merge branch 'master' of https://github.com/tock/tock into stm32f3-flash
krady21 Jul 20, 2020
b768af7
Fix return type of is_locked
krady21 Jul 20, 2020
6e7dce3
Add crate definition in lib.rs and handle_interrupt function in flash.rs
krady21 Jul 22, 2020
39a90e1
Merge branch 'master' of https://github.com/tock/tock into stm32f3-flash
krady21 Jul 25, 2020
81389a3
Use hardware interrupts for write and erase instead of deferred calls.
krady21 Aug 24, 2020
cd5f2a2
Merge branch 'master' of https://github.com/tock/tock into stm32f3-flash
krady21 Aug 24, 2020
fec7459
Fix comments and run make prepush
krady21 Aug 24, 2020
aa7916f
Update chips/stm32f303xc/src/flash.rs
krady21 Aug 24, 2020
00d5d4a
1. Changed as some comments as requested.
krady21 Aug 24, 2020
0b3ca18
Chang some comments as requested and add callbacks to PGERR and WRPRTERR
krady21 Aug 24, 2020
183b8b5
Merge branch 'stm32f3-flash' of https://github.com/krady21/tock into …
krady21 Aug 24, 2020
479b5ae
Remove last while loop waiting on the BSY bit
krady21 Aug 24, 2020
a996d10
add nonvolatile_storage capsule using the stm32 flash driver
krady21 Aug 24, 2020
0d018ba
change addresses used by nonvolatile component
krady21 Aug 26, 2020
82a983a
fix whitespace
krady21 Aug 26, 2020
1b7e4e0
change wrong userspace length
krady21 Aug 27, 2020
319d2f6
move mod flash to peripherals section
krady21 Sep 11, 2020
e131a13
add comments and change wrong page number
krady21 Sep 11, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 15 additions & 0 deletions boards/stm32f3discovery/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ struct STM32F3Discovery {
VirtualMuxAlarm<'static, stm32f303xc::tim2::Tim2<'static>>,
>,
adc: &'static capsules::adc::Adc<'static, stm32f303xc::adc::Adc>,
nonvolatile_storage: &'static capsules::nonvolatile_storage_driver::NonvolatileStorage<'static>,
}

/// Mapping of integer syscalls to objects that implement syscalls.
Expand All @@ -82,6 +83,7 @@ impl Platform for STM32F3Discovery {
capsules::temperature::DRIVER_NUM => f(Some(self.temp)),
kernel::ipc::DRIVER_NUM => f(Some(&self.ipc)),
capsules::adc::DRIVER_NUM => f(Some(self.adc)),
capsules::nonvolatile_storage_driver::DRIVER_NUM => f(Some(self.nonvolatile_storage)),
_ => f(None),
}
}
Expand Down Expand Up @@ -607,6 +609,18 @@ pub unsafe fn reset_handler() {
);
stm32f303xc::adc::ADC1.set_client(adc);

let nonvolatile_storage = components::nonvolatile_storage::NonvolatileStorageComponent::new(
board_kernel,
&stm32f303xc::flash::FLASH,
0x08020000,
0x20000,
0x08000000,
0x20000,
krady21 marked this conversation as resolved.
Show resolved Hide resolved
)
.finalize(components::nv_storage_component_helper!(
stm32f303xc::flash::Flash
));

let stm32f3discovery = STM32F3Discovery {
console: console,
ipc: kernel::ipc::IPC::new(board_kernel, &memory_allocation_capability),
Expand All @@ -619,6 +633,7 @@ pub unsafe fn reset_handler() {
ninedof: ninedof,
temp: temp,
adc: adc,
nonvolatile_storage: nonvolatile_storage,
};

// // Optional kernel tests
Expand Down
10 changes: 9 additions & 1 deletion chips/stm32f303xc/src/chip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ use kernel::common::deferred_call;
use kernel::Chip;

use crate::adc;
use crate::deferred_call_tasks::DeferredCallTask;
use crate::exti;
use crate::flash;
use crate::i2c;
use crate::nvic;
use crate::spi;
Expand Down Expand Up @@ -38,14 +40,20 @@ impl Chip for Stm32f3xx {
fn service_pending_interrupts(&self) {
unsafe {
loop {
if let Some(interrupt) = cortexm4::nvic::next_pending() {
if let Some(task) = deferred_call::DeferredCall::next_pending() {
match task {
DeferredCallTask::Flash => flash::FLASH.handle_interrupt(),
}
} else if let Some(interrupt) = cortexm4::nvic::next_pending() {
match interrupt {
nvic::USART1 => usart::USART1.handle_interrupt(),

nvic::TIM2 => tim2::TIM2.handle_interrupt(),

nvic::SPI1 => spi::SPI1.handle_interrupt(),

nvic::FLASH => flash::FLASH.handle_interrupt(),

nvic::I2C1_EV => i2c::I2C1.handle_event(),
nvic::I2C1_ER => i2c::I2C1.handle_error(),
nvic::ADC1_2 => adc::ADC1.handle_interrupt(),
Expand Down
30 changes: 30 additions & 0 deletions chips/stm32f303xc/src/deferred_call_tasks.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//! Definition of Deferred Call tasks.
//!
//! Deferred calls also peripheral drivers to register pseudo interrupts.
//! These are the definitions of which deferred calls this chip needs.

use core::convert::Into;
use core::convert::TryFrom;

/// A type of task to defer a call for
#[derive(Copy, Clone)]
pub enum DeferredCallTask {
Flash = 0,
}

impl TryFrom<usize> for DeferredCallTask {
type Error = ();

fn try_from(value: usize) -> Result<DeferredCallTask, ()> {
match value {
0 => Ok(DeferredCallTask::Flash),
_ => Err(()),
}
}
}

impl Into<usize> for DeferredCallTask {
fn into(self) -> usize {
self as usize
}
}