|
| 1 | +// Copyright 2024 Khalil Estell |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +#include <libhal-arm-mcu/dwt_counter.hpp> |
| 16 | +#include <libhal-arm-mcu/startup.hpp> |
| 17 | +#include <libhal-arm-mcu/stm32f411/clock.hpp> |
| 18 | +#include <libhal-arm-mcu/stm32f411/constants.hpp> |
| 19 | +#include <libhal-arm-mcu/stm32f411/i2c.hpp> |
| 20 | +#include <libhal-arm-mcu/stm32f411/output_pin.hpp> |
| 21 | +#include <libhal-arm-mcu/stm32f411/uart.hpp> |
| 22 | +#include <libhal-arm-mcu/system_control.hpp> |
| 23 | +#include <libhal/io_waiter.hpp> |
| 24 | +#include <libhal/units.hpp> |
| 25 | + |
| 26 | +#include <resource_list.hpp> |
| 27 | + |
| 28 | +void initialize_platform(resource_list& p_resources) |
| 29 | +{ |
| 30 | + using namespace hal::literals; |
| 31 | + |
| 32 | + // Set the MCU to the maximum clock speed |
| 33 | + hal::stm32f411::maximum_speed_using_internal_oscillator(); |
| 34 | + |
| 35 | + auto const cpu_frequency = |
| 36 | + hal::stm32f411::frequency(hal::stm32f411::peripheral::cpu); |
| 37 | + static hal::cortex_m::dwt_counter steady_clock(cpu_frequency); |
| 38 | + |
| 39 | + static hal::stm32f411::i2c i2c(1, |
| 40 | + hal::i2c::settings{ .clock_rate = 100_kHz }); |
| 41 | + |
| 42 | + static hal::stm32f411::uart uart2( |
| 43 | + hal::port<2>, hal::buffer<128>, { .baud_rate = 115200 }); |
| 44 | + |
| 45 | + static hal::stm32f411::output_pin led(hal::stm32f411::peripheral::gpio_a, 5); |
| 46 | + |
| 47 | + p_resources.clock = &steady_clock; |
| 48 | + p_resources.console = &uart2; |
| 49 | + p_resources.i2c = &i2c; |
| 50 | + p_resources.status_led = &led; |
| 51 | +} |
0 commit comments