Skip to content

Commit

Permalink
more formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed Nov 26, 2023
1 parent 1a99d78 commit d88416c
Show file tree
Hide file tree
Showing 24 changed files with 109 additions and 96 deletions.
4 changes: 4 additions & 0 deletions Marlin/src/HAL/HC32/inc/Conditionals_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,7 @@
*
*/
#pragma once

#ifndef TEMP_SOC_PIN
#define TEMP_SOC_PIN 0xFF // Dummy that is not a valid GPIO, HAL checks for this
#endif
4 changes: 4 additions & 0 deletions Marlin/src/HAL/HC32/inc/SanityCheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
*/
#pragma once

#ifndef BOARD_XTAL_FREQUENCY
#error "BOARD_XTAL_FREQUENCY is required for HC32F460."
#endif

#if ENABLED(FAST_PWM_FAN)
#error "FAST_PWM_FAN is not yet implemented for this platform."
#endif
Expand Down
48 changes: 17 additions & 31 deletions Marlin/src/HAL/HC32/sdio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

#define SDIO_PERIPHERAL M4_SDIOC1

// use DMA2 channel 0
// Use DMA2 channel 0
#define SDIO_DMA_PERIPHERAL M4_DMA2
#define SDIO_DMA_CHANNEL DmaCh0

Expand Down Expand Up @@ -77,20 +77,18 @@ bool SDIO_Init() {
handle->enDevMode = SdCardDmaMode;
handle->pstcDmaInitCfg = dmaConf;

// create card configuration
// this should be a fairly safe configuration for most cards
// Create card configuration
// This should be a fairly safe configuration for most cards
stc_sdcard_init_t cardConf = {
.enBusWidth = SdiocBusWidth4Bit,
.enClkFreq = SdiocClk400K,
.enSpeedMode = SdiocNormalSpeedMode,
//.pstcInitCfg = NULL,
.enBusWidth = SdiocBusWidth4Bit,
.enClkFreq = SdiocClk400K,
.enSpeedMode = SdiocNormalSpeedMode,
//.pstcInitCfg = NULL,
};

// initialize sd card
// Initialize sd card
en_result_t rc = SDCARD_Init(handle, &cardConf);
if (rc != Ok) {
printf("SDIO_Init() error (rc=%u)\n", rc);
}
if (rc != Ok) printf("SDIO_Init() error (rc=%u)\n", rc);

return rc == Ok;
}
Expand All @@ -101,12 +99,8 @@ bool SDIO_ReadBlock(uint32_t block, uint8_t *dst) {

WITH_RETRY(SDIO_READ_RETRIES, {
en_result_t rc = SDCARD_ReadBlocks(handle, block, 1, dst, SDIO_READ_TIMEOUT);
if (rc == Ok) {
return true;
}
else {
printf("SDIO_ReadBlock error (rc=%u; ErrorCode=%lu)\n", rc, handle->u32ErrorCode);
}
if (rc == Ok) return true;
printf("SDIO_ReadBlock error (rc=%u; ErrorCode=%lu)\n", rc, handle->u32ErrorCode);
})

return false;
Expand All @@ -118,12 +112,8 @@ bool SDIO_WriteBlock(uint32_t block, const uint8_t *src) {

WITH_RETRY(SDIO_WRITE_RETRIES, {
en_result_t rc = SDCARD_WriteBlocks(handle, block, 1, (uint8_t *)src, SDIO_WRITE_TIMEOUT);
if (rc == Ok) {
return true;
}
else {
printf("SDIO_WriteBlock error (rc=%u; ErrorCode=%lu)\n", rc, handle->u32ErrorCode);
}
if (rc == Ok) return true;
printf("SDIO_WriteBlock error (rc=%u; ErrorCode=%lu)\n", rc, handle->u32ErrorCode);
})

return false;
Expand All @@ -137,15 +127,11 @@ bool SDIO_IsReady() {
uint32_t SDIO_GetCardSize() {
CORE_ASSERT(handle != NULL, "SDIO not initialized");

// multiply number of blocks with block size to get size in bytes
uint64_t cardSizeBytes = uint64_t(handle->stcSdCardInfo.u32LogBlockNbr) * uint64_t(handle->stcSdCardInfo.u32LogBlockSize);

// if the card is bigger than ~4Gb (maximum a 32bit integer can hold), clamp to the maximum value of a 32 bit integer
if (cardSizeBytes >= UINT32_MAX) {
return UINT32_MAX;
}
// Multiply number of blocks with block size to get size in bytes
const uint64_t cardSizeBytes = uint64_t(handle->stcSdCardInfo.u32LogBlockNbr) * uint64_t(handle->stcSdCardInfo.u32LogBlockSize);

return uint32_t(cardSizeBytes);
// If the card is bigger than ~4Gb (maximum a 32bit integer can hold), clamp to the maximum value of a 32 bit integer
return _MAX(cardSizeBytes, UINT32_MAX);
}

#endif // ARDUINO_ARCH_HC32
32 changes: 27 additions & 5 deletions Marlin/src/HAL/HC32/sysclock.cpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,39 @@
/**
* Marlin 3D Printer Firmware
* Copyright (c) 2023 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/

/**
* HC32f460 system clock configuration
*/

#ifdef ARDUINO_ARCH_HC32

// get BOARD_XTAL_FREQUENCY from configuration / pins
// Get BOARD_XTAL_FREQUENCY from configuration / pins
#include "../../inc/MarlinConfig.h"

#include <core_hooks.h>
#include <drivers/sysclock/sysclock_util.h>


void core_hook_sysclock_init() {
// set wait cycles, as we are about to switch to 200 MHz HCLK
// Set wait cycles, as we are about to switch to 200 MHz HCLK
sysclock_configure_flash_wait_cycles();
sysclock_configure_sram_wait_cycles();

Expand Down Expand Up @@ -69,8 +91,8 @@ void core_hook_sysclock_init() {
panic("HRC is not 16 MHz");
}

#if defined(BOARD_XTAL_FREQUENCY)
#warning "no valid XTAL frequency defined, falling back to HRC."
#ifdef BOARD_XTAL_FREQUENCY
#warning "No valid XTAL frequency defined, falling back to HRC."
#endif
#endif

Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/HAL/NATIVE_SIM/timers.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Marlin 3D Printer Firmware
* Copyright (c) 2023 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
* Copyright (c) 2021 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/HAL/STM32/HAL.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Marlin 3D Printer Firmware
* Copyright (c) 2023 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/HAL/STM32/HAL.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Marlin 3D Printer Firmware
* Copyright (c) 2023 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/HAL/STM32/timers.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Marlin 3D Printer Firmware
* Copyright (c) 2023 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/HAL/STM32/timers.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Marlin 3D Printer Firmware
* Copyright (c) 2023 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/HAL/STM32F1/HAL.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Marlin 3D Printer Firmware
* Copyright (c) 2023 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/HAL/STM32F1/HAL.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Marlin 3D Printer Firmware
* Copyright (c) 2023 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/HAL/STM32F1/sdio.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Marlin 3D Printer Firmware
* Copyright (c) 2023 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/HAL/STM32F1/timers.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Marlin 3D Printer Firmware
* Copyright (c) 2023 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/HAL/STM32F1/timers.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Marlin 3D Printer Firmware
* Copyright (c) 2023 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/HAL/TEENSY31_32/HAL.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Marlin 3D Printer Firmware
* Copyright (c) 2023 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/HAL/TEENSY35_36/HAL.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Marlin 3D Printer Firmware
* Copyright (c) 2023 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/HAL/TEENSY35_36/timers.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Marlin 3D Printer Firmware
* Copyright (c) 2023 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/HAL/TEENSY40_41/HAL.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Marlin 3D Printer Firmware
* Copyright (c) 2023 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/HAL/TEENSY40_41/timers.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Marlin 3D Printer Firmware
* Copyright (c) 2023 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/HAL/shared/eeprom_if.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Marlin 3D Printer Firmware
* Copyright (c) 2023 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
* 0x0000 and 0xFFFE. A single 0xFFFF in the data stream indicates the
* start of a new closed path.
*/
#pragma once
'''

Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/libs/BL24CXX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
#endif

// IO direction setting
#if defined(__STM32F1__)
#ifdef __STM32F1__
#define SDA_IN() do{ PIN_MAP[IIC_EEPROM_SDA].gpio_device->regs->CRH &= 0XFFFF0FFF; PIN_MAP[IIC_EEPROM_SDA].gpio_device->regs->CRH |= 8 << 12; }while(0)
#define SDA_OUT() do{ PIN_MAP[IIC_EEPROM_SDA].gpio_device->regs->CRH &= 0XFFFF0FFF; PIN_MAP[IIC_EEPROM_SDA].gpio_device->regs->CRH |= 3 << 12; }while(0)
#elif defined(STM32F1) || defined(STM32F4) || defined(ARDUINO_ARCH_HC32)
Expand Down
4 changes: 0 additions & 4 deletions Marlin/src/pins/hc32f460/env_validate.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,3 @@
#ifndef ARDUINO_ARCH_HC32
#error "Oops! Select an HC32F460 board in 'Tools > Board.'"
#endif

#ifndef TEMP_SOC_PIN
#define TEMP_SOC_PIN 0xff // dummy that is not a valid GPIO, HAL checks for this
#endif
Loading

0 comments on commit d88416c

Please sign in to comment.