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

Adding ADC support for stm323f4xx #2004

Merged
merged 5 commits into from
Jul 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 7 additions & 1 deletion boards/stm32f3discovery/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ include ../Makefile.common
OPENOCD=openocd
OPENOCD_OPTIONS=-f openocd.cfg

APP=../../../libtock-c/examples/c_hello/build/cortex-m4/cortex-m4.tbf
KERNEL=$(TOCK_ROOT_DIRECTORY)/target/$(TARGET)/debug/$(PLATFORM).elf
KERNEL_WITH_APP=$(TOCK_ROOT_DIRECTORY)/target/$(TARGET)/debug/$(PLATFORM)-app.elf

.PHONY: flash-debug
flash-debug: $(TOCK_ROOT_DIRECTORY)target/$(TARGET)/debug/$(PLATFORM).elf
$(OPENOCD) $(OPENOCD_OPTIONS) -c "init; reset halt; flash write_image erase $<; verify_image $<; reset; shutdown"
Expand All @@ -18,4 +22,6 @@ flash: $(TOCK_ROOT_DIRECTORY)target/$(TARGET)/release/$(PLATFORM).elf

.PHONY: program
program: $(TOCK_ROOT_DIRECTORY)target/$(TARGET)/debug/$(PLATFORM).elf
$(error See README.md and update this section accordingly)
arm-none-eabi-objcopy --update-section .apps=$(APP) $(KERNEL) $(KERNEL_WITH_APP)
$(OPENOCD) $(OPENOCD_OPTIONS) -c "init; reset halt; flash write_image erase $(KERNEL_WITH_APP); verify_image $(KERNEL_WITH_APP); reset; shutdown"

7 changes: 1 addition & 6 deletions boards/stm32f412gdiscovery/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ include ../Makefile.common
OPENOCD=openocd
OPENOCD_OPTIONS=-f openocd.cfg

APP=../../../libtock-c/examples/buttons/build/cortex-m4/cortex-m4.tbf
KERNEL=$(TOCK_ROOT_DIRECTORY)/target/$(TARGET)/debug/$(PLATFORM).elf
KERNEL_WITH_APP=$(TOCK_ROOT_DIRECTORY)/target/$(TARGET)/debug/$(PLATFORM)-app.elf

.PHONY: flash-debug
flash-debug: $(TOCK_ROOT_DIRECTORY)target/$(TARGET)/debug/$(PLATFORM).elf
$(OPENOCD) $(OPENOCD_OPTIONS) -c "init; reset halt; flash write_image erase $<; verify_image $<; reset; shutdown"
Expand All @@ -22,5 +18,4 @@ flash: $(TOCK_ROOT_DIRECTORY)target/$(TARGET)/release/$(PLATFORM).elf

.PHONY: program
program: $(TOCK_ROOT_DIRECTORY)target/$(TARGET)/debug/$(PLATFORM).elf
arm-none-eabi-objcopy --update-section .apps=$(APP) $(KERNEL) $(KERNEL_WITH_APP)
$(OPENOCD) $(OPENOCD_OPTIONS) -c "init; reset halt; flash write_image erase $(KERNEL_WITH_APP); verify_image $(KERNEL_WITH_APP); reset; shutdown"
$(error See README.md and update this section accordingly)
62 changes: 62 additions & 0 deletions boards/stm32f412gdiscovery/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ struct STM32F412GDiscovery {
>,
gpio: &'static capsules::gpio::GPIO<'static, stm32f412g::gpio::Pin<'static>>,
ft6206: &'static capsules::ft6206::Ft6206<'static>,
adc: &'static capsules::adc::Adc<'static, stm32f412g::adc::Adc>,
}

/// Mapping of integer syscalls to objects that implement syscalls.
Expand All @@ -71,6 +72,7 @@ impl Platform for STM32F412GDiscovery {
kernel::ipc::DRIVER_NUM => f(Some(&self.ipc)),
capsules::gpio::DRIVER_NUM => f(Some(self.gpio)),
capsules::ft6206::DRIVER_NUM => f(Some(self.ft6206)),
capsules::adc::DRIVER_NUM => f(Some(self.adc)),
_ => f(None),
}
}
Expand Down Expand Up @@ -236,6 +238,39 @@ unsafe fn set_pin_primary_functions() {
// the rest.
EXTI.associate_line_gpiopin(LineId::Exti5, pin);
});

// ADC

// Arduino A0
PinId::PA01.get_pin().as_ref().map(|pin| {
pin.set_mode(stm32f412g::gpio::Mode::AnalogMode);
});

// Arduino A1
PinId::PC01.get_pin().as_ref().map(|pin| {
pin.set_mode(stm32f412g::gpio::Mode::AnalogMode);
});

// Arduino A2
PinId::PC03.get_pin().as_ref().map(|pin| {
pin.set_mode(stm32f412g::gpio::Mode::AnalogMode);
});

// Arduino A3
PinId::PC04.get_pin().as_ref().map(|pin| {
pin.set_mode(stm32f412g::gpio::Mode::AnalogMode);
});

// Arduino A4
PinId::PC05.get_pin().as_ref().map(|pin| {
pin.set_mode(stm32f412g::gpio::Mode::AnalogMode);
});

// Arduino A5
PinId::PB00.get_pin().as_ref().map(|pin| {
pin.set_mode(stm32f412g::gpio::Mode::AnalogMode);
});

// EXTI9_5 interrupts is delivered at IRQn 23 (EXTI9_5)
cortexm4::nvic::Nvic::new(stm32f412g::nvic::EXTI9_5).enable();
}
Expand Down Expand Up @@ -456,6 +491,32 @@ pub unsafe fn reset_handler() {

ft6206.is_present();

let adc_channels = static_init!(
[&'static stm32f412g::adc::Channel; 6],
[
&stm32f412g::adc::Channel::Channel1,
&stm32f412g::adc::Channel::Channel11,
&stm32f412g::adc::Channel::Channel13,
&stm32f412g::adc::Channel::Channel14,
&stm32f412g::adc::Channel::Channel15,
&stm32f412g::adc::Channel::Channel8,
]
);
let grant_cap = create_capability!(capabilities::MemoryAllocationCapability);
let grant_adc = board_kernel.create_grant(&grant_cap);
let adc = static_init!(
capsules::adc::Adc<'static, stm32f412g::adc::Adc>,
capsules::adc::Adc::new(
&stm32f412g::adc::ADC1,
grant_adc,
adc_channels,
&mut capsules::adc::ADC_BUFFER1,
&mut capsules::adc::ADC_BUFFER2,
&mut capsules::adc::ADC_BUFFER3
)
);
stm32f412g::adc::ADC1.set_client(adc);

let nucleo_f412g = STM32F412GDiscovery {
console: console,
ipc: kernel::ipc::IPC::new(board_kernel, &memory_allocation_capability),
Expand All @@ -464,6 +525,7 @@ pub unsafe fn reset_handler() {
alarm: alarm,
gpio: gpio,
ft6206: ft6206,
adc: adc,
};

// // Optional kernel tests
Expand Down
2 changes: 1 addition & 1 deletion chips/stm32f412g/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use cortexm4::generic_isr;

pub use stm32f4xx::{chip, dbg, dma1, exti, gpio, i2c, nvic, rcc, spi, syscfg, tim2, usart};
pub use stm32f4xx::{adc, chip, dbg, dma1, exti, gpio, i2c, nvic, rcc, spi, syscfg, tim2, usart};

pub mod stm32f412g_nvic;

Expand Down