Skip to content

Commit

Permalink
Used intptr_t for base address of hardware
Browse files Browse the repository at this point in the history
  • Loading branch information
martinbond7 committed Feb 21, 2024
1 parent a4bd731 commit 12905f7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
18 changes: 9 additions & 9 deletions drivers-cpp/Memory_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,25 @@ namespace STM32F407
{
// Base address for devices on the STM32F10x
//
constexpr uint32_t Flash_base { 0x08000000 }; // FLASH base address
constexpr uint32_t SRAM_base { 0x20000000 }; // SRAM base address in the alias region
constexpr uint32_t Peripheral_base { 0x40000000 }; // Peripheral base address in the alias region
constexpr uintptr_t Flash_base { 0x08000000 }; // FLASH base address
constexpr uintptr_t SRAM_base { 0x20000000 }; // SRAM base address in the alias region
constexpr uintptr_t Peripheral_base { 0x40000000 }; // Peripheral base address in the alias region

// Peripheral memory map
//
constexpr uint32_t APB1_base { Peripheral_base + 0x00000 }; // Advanced Peripheral Bus 1
constexpr uint32_t APB2_base { Peripheral_base + 0x10000 }; // Advanced Peripheral Bus 2
constexpr uint32_t AHB1_base { Peripheral_base + 0x20000 }; // Advanced High-performance Bus 1
constexpr uintptr_t APB1_base { Peripheral_base + 0x00000 }; // Advanced Peripheral Bus 1
constexpr uintptr_t APB2_base { Peripheral_base + 0x10000 }; // Advanced Peripheral Bus 2
constexpr uintptr_t AHB1_base { Peripheral_base + 0x20000 }; // Advanced High-performance Bus 1

constexpr uint32_t device_base_address(STM32F407::AHB1_Device device) {
constexpr uintptr_t device_base_address(STM32F407::AHB1_Device device) {
return STM32F407::AHB1_base + (0x400 * device);
}

constexpr uint32_t device_base_address(STM32F407::APB1_Device device) {
constexpr uintptr_t device_base_address(STM32F407::APB1_Device device) {
return STM32F407::APB1_base + (0x400 * device);
}

constexpr uint32_t device_base_address(STM32F407::APB2_Device device) {
constexpr uintptr_t device_base_address(STM32F407::APB2_Device device) {
return STM32F407::APB2_base + (0x400 * device);
}

Expand Down
4 changes: 2 additions & 2 deletions drivers-cpp/Peripherals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

#include "Peripherals.h"
#include "Memory_map.h"

#include <cstdint>

using std::uint32_t;

namespace
Expand All @@ -30,7 +30,7 @@ namespace STM32F407
// Use static consts to give the compiler
// the best opportunity to optimise
//
constexpr uint32_t RCC_base { AHB1_base + 0x3800 };
constexpr uintptr_t RCC_base { AHB1_base + 0x3800 };

static volatile uint32_t* RCC_AHB1_enable { reinterpret_cast<uint32_t*>(RCC_base + 0x30) };
static volatile uint32_t* RCC_APB1_enable { reinterpret_cast<uint32_t*>(RCC_base + 0x40) };
Expand Down

0 comments on commit 12905f7

Please sign in to comment.