Skip to content

Commit

Permalink
stm32/mboot: Add support for G0 MCUs.
Browse files Browse the repository at this point in the history
Signed-off-by: Damien George <[email protected]>
  • Loading branch information
dpgeorge committed Mar 22, 2023
1 parent c7923b1 commit 3163847
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
1 change: 1 addition & 0 deletions ports/stm32/boards/stm32g0b1xe.ld
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ MEMORY
{
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 352K
FLASH_APP (rx) : ORIGIN = 0x08008000, LENGTH = 320K
FLASH_FS (rx) : ORIGIN = 0x08058000, LENGTH = 160K /* starting @ 352K */
}

Expand Down
4 changes: 4 additions & 0 deletions ports/stm32/i2cslave.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ static inline void i2c_slave_init(i2c_slave_t *i2c, int irqn, int irq_pri, int a
RCC->APB1ENR |= 1 << (RCC_APB1ENR_I2C1EN_Pos + i2c_idx);
volatile uint32_t tmp = RCC->APB1ENR; // Delay after enabling clock
(void)tmp;
#elif defined(STM32G0)
RCC->APBENR1 |= 1 << (RCC_APBENR1_I2C1EN_Pos + i2c_idx);
volatile uint32_t tmp = RCC->APBENR1; // Delay after enabling clock
(void)tmp;
#elif defined(STM32H7)
RCC->APB1LENR |= 1 << (RCC_APB1LENR_I2C1EN_Pos + i2c_idx);
volatile uint32_t tmp = RCC->APB1LENR; // Delay after enabling clock
Expand Down
7 changes: 6 additions & 1 deletion ports/stm32/mboot/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,12 @@ SRC_C += \
SRC_O += \
$(STARTUP_FILE) \
$(SYSTEM_FILE) \
ports/stm32/resethandler.o \

ifeq ($(MCU_SERIES),$(filter $(MCU_SERIES),f0 g0 l0))
SRC_O += ports/stm32/resethandler_m0.o
else
SRC_O += ports/stm32/resethandler.o
endif

ifeq ($(MBOOT_ENABLE_PACKING), 1)

Expand Down
19 changes: 17 additions & 2 deletions ports/stm32/mboot/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,9 @@ void SystemClock_Config(void) {
#if defined(STM32F4) || defined(STM32F7)
#define AHBxENR AHB1ENR
#define AHBxENR_GPIOAEN_Pos RCC_AHB1ENR_GPIOAEN_Pos
#elif defined(STM32G0)
#define AHBxENR IOPENR
#define AHBxENR_GPIOAEN_Pos RCC_IOPENR_GPIOAEN_Pos
#elif defined(STM32H7)
#define AHBxENR AHB4ENR
#define AHBxENR_GPIOAEN_Pos RCC_AHB4ENR_GPIOAEN_Pos
Expand Down Expand Up @@ -406,7 +409,9 @@ void mp_hal_pin_config_speed(uint32_t port_pin, uint32_t speed) {
/******************************************************************************/
// FLASH

#if defined(STM32WB)
#if defined(STM32G0)
#define FLASH_END (FLASH_BASE + FLASH_SIZE - 1)
#elif defined(STM32WB)
#define FLASH_END FLASH_END_ADDR
#endif

Expand All @@ -426,6 +431,8 @@ void mp_hal_pin_config_speed(uint32_t port_pin, uint32_t speed) {
#define FLASH_LAYOUT_STR "@Internal Flash /0x08000000/04*016Kg,01*064Kg,07*128Kg" MBOOT_SPIFLASH_LAYOUT MBOOT_SPIFLASH2_LAYOUT
#elif defined(STM32F765xx) || defined(STM32F767xx) || defined(STM32F769xx)
#define FLASH_LAYOUT_STR "@Internal Flash /0x08000000/04*032Kg,01*128Kg,07*256Kg" MBOOT_SPIFLASH_LAYOUT MBOOT_SPIFLASH2_LAYOUT
#elif defined(STM32G0)
#define FLASH_LAYOUT_STR "@Internal Flash /0x08000000/256*02Kg" MBOOT_SPIFLASH_LAYOUT MBOOT_SPIFLASH2_LAYOUT
#elif defined(STM32H743xx)
#define FLASH_LAYOUT_STR "@Internal Flash /0x08000000/16*128Kg" MBOOT_SPIFLASH_LAYOUT MBOOT_SPIFLASH2_LAYOUT
#elif defined(STM32H750xx)
Expand Down Expand Up @@ -1349,7 +1356,9 @@ void stm32_main(uint32_t initial_r0) {
#endif
#endif

#if __CORTEX_M >= 0x03
NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_4);
#endif

#if USE_CACHE && defined(STM32F7)
SCB_EnableICache();
Expand Down Expand Up @@ -1547,7 +1556,13 @@ void I2Cx_EV_IRQHandler(void) {

#if !USE_USB_POLLING

#if defined(STM32WB)
#if defined(STM32G0)

void USB_UCPD1_2_IRQHandler(void) {
HAL_PCD_IRQHandler(&pcd_fs_handle);
}

#elif defined(STM32WB)

void USB_LP_IRQHandler(void) {
HAL_PCD_IRQHandler(&pcd_fs_handle);
Expand Down

0 comments on commit 3163847

Please sign in to comment.