-
Notifications
You must be signed in to change notification settings - Fork 31
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
Adds STM32G0B1 port. #810
Merged
+2,226
−39
Merged
Adds STM32G0B1 port. #810
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
7307764
initial copy from f0x
6d23706
updated interunt vectors
a854ae5
adding g0 hal compilation
e208f76
adding target for g0 nucleo
358e5e4
Merge branch 'master' of https://github.com/bakerstu/openMRN into bjb…
db7670e
Fixes G0B1 compilation.
297342d
added cube subfolders for g0
5a7c4ef
formatting updates
6528508
formatting updates
3bda9c2
Added includes for G0B1 processor
8032f8c
updated functions for G0 processor, now compiles, but still a work in…
76ae2ff
Corrected compile errors for STM32G0B1; todo: FDCAN
e07a1d5
Fixed linker errors with clock settings.
dcebf41
Merge branch 'master' into bjb-stm32g0b1
balazsracz b22858d
Fixes compilation errors.
balazsracz 0435541
Moves some files to a generic directory.
balazsracz f271237
Recreates symlinks.
balazsracz c075fd8
Adds find emulator to g0b1 directory.
balazsracz 136630c
Removes SysTick implementations from the HAL compiled sources for the…
balazsracz a5339af
References find-emulator.mk for debug access.
balazsracz 8032258
Adds board support files for the G0B1 railcom board.
balazsracz 119b366
Adds blink_raw target for the G0B1 railcom board.
balazsracz c31592d
Revert undesired change in F091 application.
balazsracz 2e21c33
Updates in default_handler.h:
balazsracz 5cbc162
Fixes RAM size for G0B1 (it is 128K RAM, not 64k).
balazsracz 5b13d08
Fix broken sentence in comments.
balazsracz e5247a5
Adds makefile code to factory reset a G0B1.
balazsracz 5630c5d
Fixes clock_setup and blinker functions for G0B1.
balazsracz 72a25c8
Fix comment.
balazsracz c3709fa
Adds io-board port for g0b1 railcom (in serial mode only).
balazsracz fee0a11
Adds generated makefiles.
balazsracz 2769f5f
Fixes HwInit of the nucleo-g0b1 board as well.
balazsracz 8c25b66
Adds missing find-emulator symlink
balazsracz 38c464f
Switches railcom board to crystal HSE.
balazsracz 482c589
Adds a warning about poor clock accuracy.
balazsracz 6c23c39
Reverts (meaningful) changes in Stm32Can.hxx.
balazsracz 02b6587
Fixes I2C clock rate.
balazsracz a1e9046
Updates file header comments.
balazsracz f6174b8
removes dead code.
balazsracz b69f9b2
Fixes file header comments.
balazsracz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
initial copy from f0x
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,260 @@ | ||
/** \copyright | ||
* Copyright (c) 2018, Balazs Racz | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions are met: | ||
* | ||
* - Redistributions of source code must retain the above copyright notice, | ||
* this list of conditions and the following disclaimer. | ||
* | ||
* - Redistributions in binary form must reproduce the above copyright notice, | ||
* this list of conditions and the following disclaimer in the documentation | ||
* and/or other materials provided with the distribution. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | ||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
* POSSIBILITY OF SUCH DAMAGE. | ||
* | ||
* \file HwInit.cxx | ||
* | ||
* This file represents the hardware initialization for the STM32F303RE Nucelo | ||
* board (bare). | ||
* | ||
* @author Balazs Racz | ||
* @date April 18, 2018 | ||
*/ | ||
|
||
#include <new> | ||
#include <cstdint> | ||
|
||
#include "stm32f3xx_hal_conf.h" | ||
#include "stm32f3xx_hal.h" | ||
|
||
#include "os/OS.hxx" | ||
#include "Stm32Uart.hxx" | ||
#include "Stm32Can.hxx" | ||
#include "Stm32EEPROMEmulation.hxx" | ||
#include "hardware.hxx" | ||
|
||
/** override stdin */ | ||
const char *STDIN_DEVICE = "/dev/ser0"; | ||
|
||
/** override stdout */ | ||
const char *STDOUT_DEVICE = "/dev/ser0"; | ||
|
||
/** override stderr */ | ||
const char *STDERR_DEVICE = "/dev/ser0"; | ||
|
||
/** UART 0 serial driver instance */ | ||
static Stm32Uart uart0("/dev/ser0", USART2, USART2_IRQn); | ||
|
||
/** CAN 0 CAN driver instance */ | ||
static Stm32Can can0("/dev/can0"); | ||
|
||
/** EEPROM emulation driver. The file size might be made bigger. */ | ||
static Stm32EEPROMEmulation eeprom0("/dev/eeprom", 512); | ||
|
||
const size_t EEPROMEmulation::SECTOR_SIZE = 2048; | ||
|
||
extern "C" { | ||
|
||
/** Blink LED */ | ||
uint32_t blinker_pattern = 0; | ||
static uint32_t rest_pattern = 0; | ||
|
||
void hw_set_to_safe(void) | ||
{ | ||
} | ||
|
||
void reboot() | ||
{ | ||
NVIC_SystemReset(); | ||
} | ||
|
||
void resetblink(uint32_t pattern) | ||
{ | ||
blinker_pattern = pattern; | ||
rest_pattern = pattern ? 1 : 0; | ||
BLINKER_RAW_Pin::set(pattern ? true : false); | ||
/* make a timer event trigger immediately */ | ||
} | ||
|
||
void setblink(uint32_t pattern) | ||
{ | ||
resetblink(pattern); | ||
} | ||
|
||
|
||
/// TIM17 shares this interrupt with certain features of timer1 | ||
void tim1_trg_com_interrupt_handler(void) | ||
{ | ||
// | ||
// Clear the timer interrupt. | ||
// | ||
TIM17->SR = ~TIM_IT_UPDATE; | ||
|
||
// Set output LED. | ||
BLINKER_RAW_Pin::set(rest_pattern & 1); | ||
|
||
// Shift and maybe reset pattern. | ||
rest_pattern >>= 1; | ||
if (!rest_pattern) | ||
{ | ||
rest_pattern = blinker_pattern; | ||
} | ||
} | ||
|
||
void diewith(uint32_t pattern) | ||
{ | ||
// vPortClearInterruptMask(0x20); | ||
asm("cpsie i\n"); | ||
|
||
resetblink(pattern); | ||
while (1) | ||
; | ||
} | ||
|
||
/** CPU clock speed. */ | ||
const unsigned long cm3_cpu_clock_hz = 72000000; | ||
uint32_t SystemCoreClock; | ||
const uint8_t AHBPrescTable[16] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9}; | ||
const uint8_t APBPrescTable[8] = {0, 0, 0, 0, 1, 2, 3, 4}; | ||
|
||
/** | ||
* @brief System Clock Configuration | ||
* The system Clock is configured as follow : | ||
* System Clock source = PLL (HSE) | ||
* SYSCLK(Hz) = 72000000 | ||
* HCLK(Hz) = 72000000 | ||
* AHB Prescaler = 1 | ||
* APB1 Prescaler = 2 | ||
* APB2 Prescaler = 1 | ||
* HSE Frequency(Hz) = 8000000 | ||
* HSE PREDIV = 1 | ||
* PLLMUL = 9 | ||
* Flash Latency(WS) = 2 | ||
* @param None | ||
* @retval None | ||
*/ | ||
static void clock_setup(void) | ||
{ | ||
HAL_RCC_DeInit(); | ||
|
||
RCC_ClkInitTypeDef RCC_ClkInitStruct; | ||
RCC_OscInitTypeDef RCC_OscInitStruct; | ||
|
||
/* Enable HSE Oscillator and activate PLL with HSE as source on bypass | ||
* mode. This allows using the MCO clock output from the ST_Link part of | ||
* the nucleo board and freeing up the other clock pin for GPIO. */ | ||
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; | ||
RCC_OscInitStruct.HSEState = RCC_HSE_BYPASS; | ||
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; | ||
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; | ||
RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9; | ||
RCC_OscInitStruct.PLL.PREDIV = RCC_PREDIV_DIV1; | ||
|
||
HAL_RCC_OscConfig(&RCC_OscInitStruct); | ||
|
||
/* Select PLL as system clock source and configure the HCLK, PCLK1 and | ||
* PCLK2 clocks dividers | ||
*/ | ||
RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | | ||
RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2); | ||
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; | ||
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; | ||
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2; | ||
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; | ||
|
||
HASSERT(HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) == HAL_OK); | ||
|
||
// This will fail if the clocks are somehow misconfigured. | ||
HASSERT(SystemCoreClock == cm3_cpu_clock_hz); | ||
} | ||
|
||
/** Initialize the processor hardware. | ||
*/ | ||
void hw_preinit(void) | ||
{ | ||
/* Globally disables interrupts until the FreeRTOS scheduler is up. */ | ||
asm("cpsid i\n"); | ||
|
||
/* these FLASH settings enable opertion at 72 MHz */ | ||
__HAL_FLASH_PREFETCH_BUFFER_ENABLE(); | ||
__HAL_FLASH_SET_LATENCY(FLASH_LATENCY_2); | ||
|
||
/* setup the system clock */ | ||
clock_setup(); | ||
|
||
/* enable peripheral clocks */ | ||
__HAL_RCC_GPIOA_CLK_ENABLE(); | ||
__HAL_RCC_GPIOB_CLK_ENABLE(); | ||
__HAL_RCC_GPIOC_CLK_ENABLE(); | ||
__HAL_RCC_USART2_CLK_ENABLE(); | ||
__HAL_RCC_CAN1_CLK_ENABLE(); | ||
__HAL_RCC_TIM17_CLK_ENABLE(); | ||
|
||
/* setup pinmux */ | ||
GPIO_InitTypeDef gpio_init; | ||
memset(&gpio_init, 0, sizeof(gpio_init)); | ||
|
||
/* USART2 pinmux on PA2 and PA3 */ | ||
gpio_init.Mode = GPIO_MODE_AF_PP; | ||
gpio_init.Pull = GPIO_PULLUP; | ||
gpio_init.Speed = GPIO_SPEED_FREQ_HIGH; | ||
gpio_init.Alternate = GPIO_AF7_USART2; | ||
gpio_init.Pin = GPIO_PIN_2; | ||
HAL_GPIO_Init(GPIOA, &gpio_init); | ||
gpio_init.Pin = GPIO_PIN_3; | ||
HAL_GPIO_Init(GPIOA, &gpio_init); | ||
|
||
/* CAN pinmux on PB8 and PB9 */ | ||
gpio_init.Mode = GPIO_MODE_AF_PP; | ||
gpio_init.Pull = GPIO_PULLUP; | ||
gpio_init.Speed = GPIO_SPEED_FREQ_HIGH; | ||
gpio_init.Alternate = GPIO_AF9_CAN; | ||
gpio_init.Pin = GPIO_PIN_8; | ||
HAL_GPIO_Init(GPIOB, &gpio_init); | ||
gpio_init.Pin = GPIO_PIN_9; | ||
HAL_GPIO_Init(GPIOB, &gpio_init); | ||
|
||
GpioInit::hw_init(); | ||
|
||
/* Initializes the blinker timer. */ | ||
TIM_HandleTypeDef TimHandle; | ||
memset(&TimHandle, 0, sizeof(TimHandle)); | ||
TimHandle.Instance = TIM17; | ||
TimHandle.Init.Period = configCPU_CLOCK_HZ / 10000 / 8; | ||
TimHandle.Init.Prescaler = 10000; | ||
TimHandle.Init.ClockDivision = 0; | ||
TimHandle.Init.CounterMode = TIM_COUNTERMODE_UP; | ||
TimHandle.Init.RepetitionCounter = 0; | ||
if (HAL_TIM_Base_Init(&TimHandle) != HAL_OK) | ||
{ | ||
/* Initialization Error */ | ||
HASSERT(0); | ||
} | ||
if (HAL_TIM_Base_Start_IT(&TimHandle) != HAL_OK) | ||
{ | ||
/* Starting Error */ | ||
HASSERT(0); | ||
} | ||
__HAL_DBGMCU_FREEZE_TIM17(); | ||
SetInterruptPriority(TIM17_IRQn, 0); | ||
NVIC_EnableIRQ(TIM17_IRQn); | ||
} | ||
|
||
void usart2_interrupt_handler(void) | ||
{ | ||
Stm32Uart::interrupt_handler(1); | ||
} | ||
|
||
} |
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,56 @@ | ||
APP_PATH ?= $(realpath ../..) | ||
-include $(APP_PATH)/config.mk | ||
-include local_config.mk | ||
|
||
OPENMRNPATH ?= $(shell \ | ||
sh -c "if [ \"X`printenv OPENMRNPATH`\" != \"X\" ]; then printenv OPENMRNPATH; \ | ||
elif [ -d /opt/openmrn/src ]; then echo /opt/openmrn; \ | ||
elif [ -d ~/openmrn/src ]; then echo ~/openmrn; \ | ||
elif [ -d ../../../src ]; then echo ../../..; \ | ||
else echo OPENMRNPATH not found; fi" \ | ||
) | ||
|
||
# Find STM32CubeF3 libraries | ||
include $(OPENMRNPATH)/etc/stm32cubef3.mk | ||
|
||
LDFLAGSEXTRA += | ||
SYSLIBRARIESEXTRA += -lfreertos_drivers_stm32cubef303xe | ||
OBJEXTRA += | ||
|
||
CFLAGS += -DSTM32F303xE | ||
CXXFLAGS += -DSTM32F303xE | ||
OPENOCDARGS = -f board/st_nucleo_f3.cfg | ||
|
||
ifndef TARGET | ||
export TARGET := freertos.armv7m | ||
endif | ||
include $(OPENMRNPATH)/etc/prog.mk | ||
|
||
ifndef DEFAULT_ADDRESS | ||
DEFAULT_ADDRESS=0x16 | ||
endif | ||
|
||
include $(OPENMRNPATH)/etc/node_id.mk | ||
|
||
# How to use: make multibin ADDRESS=0x20 ADDRHIGH=0x45 NUM=3 | ||
# starting address, high bits (user range), count | ||
multibin: | ||
for i in $$(seq 1 $(NUM)) ; do $(MAKE) $(EXECUTABLE).bin ADDRESS=$$(printf 0x%02x $$(($(ADDRESS)+$$i))) ; cp $(EXECUTABLE).bin $(EXECUTABLE).f303.$$(printf %02x%02x $(ADDRHIGH) $$(($(ADDRESS)+$$i-1))).bin ; done | ||
|
||
ifeq ($(call find_missing_deps,OPENOCDPATH OPENOCDSCRIPTSPATH),) | ||
all: $(EXECUTABLE).bin | ||
|
||
flash: $(EXECUTABLE)$(EXTENTION) $(EXECUTABLE).lst | ||
@if ps ax -o comm | grep -q openocd ; then echo openocd already running. quit existing first. ; exit 1 ; fi | ||
$(GDB) $< -ex "target remote | $(OPENOCDPATH)/openocd -c \"gdb_port pipe\" --search $(OPENOCDSCRIPTSPATH) $(OPENOCDARGS)" -ex "monitor reset halt" -ex "load" -ex "monitor reset init" -ex "monitor reset run" -ex "detach" -ex "quit" | ||
|
||
gdb: | ||
@if ps ax -o comm | grep -q openocd ; then echo openocd already running. quit existing first. ; exit 1 ; fi | ||
$(GDB) $(EXECUTABLE)$(EXTENTION) -ex "target remote | $(OPENOCDPATH)/openocd -c \"gdb_port pipe\" --search $(OPENOCDSCRIPTSPATH) $(OPENOCDARGS)" -ex "continue" # -ex "monitor reset halt" | ||
|
||
else | ||
|
||
flash gdb: | ||
echo OPENOCD not found ; exit 1 | ||
|
||
endif |
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,13 @@ | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing file block header. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
#include "Stm32Gpio.hxx" | ||
#include "utils/GpioInitializer.hxx" | ||
#include "BlinkerGPIO.hxx" | ||
|
||
GPIO_PIN(LED_GREEN_RAW, LedPin, A, 5); | ||
|
||
GPIO_PIN(SW_USER, GpioInputPU, C, 13); | ||
|
||
typedef GpioInitializer<LED_GREEN_RAW_Pin,SW_USER_Pin> GpioInit; | ||
|
||
typedef LED_GREEN_RAW_Pin BLINKER_RAW_Pin; | ||
typedef BLINKER_Pin LED_GREEN_Pin; |
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,15 @@ | ||
MEMORY | ||
{ | ||
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 472K | ||
EEPROMEMU (r) : ORIGIN = 0x08076000, LENGTH = 32K | ||
BOOTLOADER (rx) : ORIGIN = 0x0807E000, LENGTH = 8K | ||
RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 64K | ||
} | ||
|
||
__flash_start = ORIGIN(FLASH); | ||
__flash_end = ORIGIN(FLASH) + LENGTH(FLASH); | ||
__eeprom_start = ORIGIN(EEPROMEMU); | ||
__eeprom_end = ORIGIN(EEPROMEMU) + LENGTH(EEPROMEMU); | ||
__bootloader_start = ORIGIN(BOOTLOADER); | ||
__app_header_offset = 0x270; | ||
__bootloader_magic_ptr = ORIGIN(RAM); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we update the dates?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done