-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Configure STM32 system clock speed and flash size
Configures main system clock and flash size based on the target device. The console uart may be configured by using the `-DAVM_CFG_CONSOLE=` option, or for Nucleo devices the on board TTL->USB-COM can be configured with the `-DBOARD=nucleo` cmake option. Previously these values were hard coded in the C sources and needed to be changed manually if a device other than the default target was used. Closes #454 Signed-off-by: Winford <winford@object.stream>
- Loading branch information
1 parent
49630ab
commit aa749ec
Showing
15 changed files
with
730 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# | ||
# This file is part of AtomVM. | ||
# | ||
# Copyright 2023 Winford <winford@object.stream> | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later | ||
# | ||
|
||
# Generate config information for device. | ||
if (NOT DEVICE) | ||
message(FATAL_ERROR "No DEVICE specified for device config generator") | ||
endif () | ||
|
||
find_program(ESCRIPT escript) | ||
if (NOT ESCRIPT) | ||
message(FATAL_ERROR "Erlang/OTP 'escript' not found in PATH. Check your Erlang/OTP installation.") | ||
endif () | ||
mark_as_advanced(ESCRIPT) | ||
|
||
set(DEVCONFIG_SCRIPT "${CMAKE_SOURCE_DIR}/tools/atomvm_stm32_config_query.erl") | ||
execute_process( | ||
COMMAND "${ESCRIPT}" "${DEVCONFIG_SCRIPT}" "${DEVICE}" "clock" | ||
OUTPUT_VARIABLE DEVCONFIG_CLOCK_HZ | ||
) | ||
add_compile_definitions(${DEVCONFIG_CLOCK_HZ}) | ||
execute_process( | ||
COMMAND "${ESCRIPT}" "${DEVCONFIG_SCRIPT}" "${DEVICE}" "rom" | ||
OUTPUT_VARIABLE DEVCONFIG_FLASH_SIZE | ||
) | ||
add_compile_definitions(${DEVCONFIG_FLASH_SIZE}) | ||
## also needs to be set for correct optomization flags to be used. | ||
set(CMAKE_FLASH_SIZE "${DEVCONFIG_FLASH_SIZE}") | ||
|
||
if (AVM_CFG_CONSOLE) | ||
set(AVM_CFG_CONSOLE ${AVM_CFG_CONSOLE} CACHE STRING "AtomVM system console uart") | ||
set_property(CACHE AVM_CFG_CONSOLE PROPERTY STRINGS CONSOLE_1 CONSOLE_2 CONSOLE_3 CONSOLE_4 CONSOLE_5 CONSOLE_6 CONSOLE_7 CONSOLE_8) | ||
add_compile_definitions(${AVM_CFG_CONSOLE}) | ||
elseif (BOARD) | ||
execute_process( | ||
COMMAND "${ESCRIPT}" "${DEVCONFIG_SCRIPT}" "${DEVICE}" "${BOARD}_com" | ||
OUTPUT_VARIABLE DEVCONFIG_CONSOLE | ||
) | ||
add_compile_definitions(${DEVCONFIG_CONSOLE}) | ||
set(AVM_CFG_CONSOLE ${DEVCONFIG_CONSOLE} CACHE STRING "AtomVM system console uart") | ||
set(BOARD ${BOARD} CACHE STRING "Board variant configuration") | ||
set_property(CACHE AVM_CFG_CONSOLE PROPERTY STRINGS CONSOLE_1 CONSOLE_2 CONSOLE_3 CONSOLE_4 CONSOLE_5 CONSOLE_6 CONSOLE_7 CONSOLE_8) | ||
else() | ||
add_compile_definitions(CONSOLE_2) | ||
set(AVM_CFG_CONSOLE CONSOLE_2 CACHE STRING "AtomVM system console uart") | ||
set_property(CACHE AVM_CFG_CONSOLE PROPERTY STRINGS CONSOLE_1 CONSOLE_2 CONSOLE_3 CONSOLE_4 CONSOLE_5 CONSOLE_6 CONSOLE_7 CONSOLE_8) | ||
endif() | ||
|
||
message("----------------------------------------") | ||
message(STATUS "Device : ${DEVICE}") | ||
if (BOARD) | ||
message(STATUS "Board : ${BOARD}") | ||
endif() | ||
message("--------Device Configuration Info-------") | ||
message(STATUS "Clock Hz : ${DEVCONFIG_CLOCK_HZ}") | ||
message(STATUS "Flash Size : ${DEVCONFIG_FLASH_SIZE}") | ||
message(STATUS "Console : ${AVM_CFG_CONSOLE}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
/* This file is part of AtomVM. | ||
* | ||
* Copyright 2023 Winford (Uncle Grumpy) <winford@object.stream> | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later | ||
*/ | ||
|
||
#ifndef _AVM_DEVCFG_H_ | ||
#define _AVM_DEVCFG_H_ | ||
|
||
#include <libopencm3/stm32/gpio.h> | ||
#include <libopencm3/stm32/rcc.h> | ||
#include <libopencm3/stm32/usart.h> | ||
|
||
#if (defined(STM32F4) || defined(STM32F7)) | ||
#define FLASH_START_ADDRESS (0x08000000U) | ||
#endif | ||
|
||
#if defined(ROM_512K) | ||
#define CFG_FLASH_END (FLASH_START_ADDRESS + 0x80000U) | ||
#define AVM_APP_ADDRESS (FLASH_START_ADDRESS + 0x60000U) | ||
#elif defined(ROM_768K) | ||
#define CFG_FLASH_END (FLASH_START_ADDRESS + 0xC0000U) | ||
#elif defined(ROM_1024K) | ||
#define CFG_FLASH_END (FLASH_START_ADDRESS + 0x100000U) | ||
#elif defined(ROM_1536K) | ||
#define CFG_FLASH_END (FLASH_START_ADDRESS + 0x180000U) | ||
#elif defined(ROM_2048K) | ||
#define CFG_FLASH_END (FLASH_START_ADDRESS + 0x200000U) | ||
#elif defined(ROM_4096K) | ||
#define CFG_FLASH_END (FLASH_START_ADDRESS + 0x400000U) | ||
#endif | ||
|
||
#ifndef AVM_APP_ADDRESS | ||
#define AVM_APP_ADDRESS (FLASH_START_ADDRESS + 0x80000U) | ||
#endif | ||
|
||
#if defined(MHZ_84) | ||
#define AVM_CLOCK_HZ (84000000U) | ||
#define AVM_CLOCK_CONFIGURATION (&rcc_hse_25mhz_3v3[(RCC_CLOCK_3V3_84MHZ)]) | ||
#elif defined(MHZ_100) | ||
#define AVM_CLOCK_HZ (100000000U) | ||
#define AVM_CLOCK_CONFIGURATION (&rcc_hse_25mhz_3v3[(RCC_CLOCK_3V3_84MHZ)]) | ||
#elif defined(MHZ_168) | ||
#define AVM_CLOCK_HZ (168000000U) | ||
#define AVM_CLOCK_CONFIGURATION (&rcc_hse_8mhz_3v3[(RCC_CLOCK_3V3_168MHZ)]) | ||
#elif defined(MHZ_180) | ||
#define AVM_CLOCK_HZ (180000000U) | ||
#define AVM_CLOCK_CONFIGURATION (&rcc_hse_8mhz_3v3[(RCC_CLOCK_3V3_180MHZ)]) | ||
#elif defined(MHZ_216) | ||
#define AVM_CLOCK_HZ (216000000U) | ||
#define AVM_CLOCK_CONFIGURATION (&rcc_hse_8mhz_3v3[(RCC_CLOCK_3V3_216MHZ)]) | ||
#endif | ||
|
||
#if defined(CONSOLE_1) | ||
#define AVM_CONSOLE (USART1) | ||
#define AVM_CONSOLE_TX (GPIO9) | ||
#define AVM_CONSOLE_GPIO (GPIOA) | ||
#define AVM_CONSOLE_RCC (RCC_USART1) | ||
#elif defined(CONSOLE_2) | ||
#define AVM_CONSOLE (USART2) | ||
#define AVM_CONSOLE_TX (GPIO2) | ||
#define AVM_CONSOLE_GPIO (GPIOA) | ||
#define AVM_CONSOLE_RCC (RCC_USART2) | ||
#elif defined(CONSOLE_3) | ||
#define AVM_CONSOLE (USART3) | ||
#define AVM_CONSOLE_TX (GPIO8) | ||
#define AVM_CONSOLE_GPIO (GPIOD) | ||
#define AVM_CONSOLE_RCC (RCC_USART3) | ||
#elif defined(CONSOLE_4) | ||
#define AVM_CONSOLE (UART4) | ||
#define AVM_CONSOLE_TX (GPIO10) | ||
#define AVM_CONSOLE_GPIO (GPIOC) | ||
#define AVM_CONSOLE_RCC (RCC_UART4) | ||
#elif defined(CONSOLE_5) | ||
#define AVM_CONSOLE (UART5) | ||
#define AVM_CONSOLE_TX (GPIO12) | ||
#define AVM_CONSOLE_GPIO (GPIOC) | ||
#define AVM_CONSOLE_RCC (RCC_UART5) | ||
#ifdef LIBOPENCM3_USART_COMMON_F24_H | ||
#elif defined(CONSOLE_6) | ||
#define AVM_CONSOLE (USART6) | ||
#define AVM_CONSOLE_TX (GPIO6) | ||
#define AVM_CONSOLE_GPIO (GPIOC) | ||
#define AVM_CONSOLE_RCC (RCC_USART6) | ||
#elif defined(CONSOLE_7) | ||
#define AVM_CONSOLE (UART7) | ||
#define AVM_CONSOLE_TX (GPIO7) | ||
#define AVM_CONSOLE_GPIO (GPIOF) | ||
#define AVM_CONSOLE_RCC (RCC_UART7) | ||
#elif defined(CONSOLE_8) | ||
#define AVM_CONSOLE (UART8) | ||
#define AVM_CONSOLE_TX (GPIO8) | ||
#define AVM_CONSOLE_GPIO (GPIOJ) | ||
#define AVM_CONSOLE_RCC (RCC_UART8) | ||
#endif /* LIBOPENCM3_USART_COMMON_F24_H */ | ||
#endif | ||
|
||
#endif /* _AVM_DEVCFG_H_ */ |
Oops, something went wrong.