178 lines
5.6 KiB
C
178 lines
5.6 KiB
C
/*
|
|
* Copyright (c) 2015 Travis Geiselbrecht
|
|
*
|
|
* Permission is hereby granted, free of charge, to any person obtaining
|
|
* a copy of this software and associated documentation files
|
|
* (the "Software"), to deal in the Software without restriction,
|
|
* including without limitation the rights to use, copy, modify, merge,
|
|
* publish, distribute, sublicense, and/or sell copies of the Software,
|
|
* and to permit persons to whom the Software is furnished to do so,
|
|
* subject to the following conditions:
|
|
*
|
|
* The above copyright notice and this permission notice shall be
|
|
* included in all copies or substantial portions of the Software.
|
|
*
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
*/
|
|
#include <err.h>
|
|
#include <debug.h>
|
|
#include <trace.h>
|
|
#include <target.h>
|
|
#include <compiler.h>
|
|
#include <lib/gfx.h>
|
|
#include <dev/gpio.h>
|
|
#include <platform/stm32.h>
|
|
#include <platform/gpio.h>
|
|
#include <target/debugconfig.h>
|
|
#include <target/gpioconfig.h>
|
|
#include <reg.h>
|
|
|
|
extern uint8_t BSP_SDRAM_Init(void);
|
|
extern uint8_t BSP_LCD_Init(void);
|
|
extern uint8_t BSP_SRAM_Init(void);
|
|
static void MPU_RegionConfig(void);
|
|
|
|
void target_early_init(void)
|
|
{
|
|
#if DEBUG_UART == 1
|
|
/* configure usart 1 pins */
|
|
gpio_config(GPIO_USART1_TX, GPIO_STM32_AF | GPIO_STM32_AFn(GPIO_AF7_USART1) | GPIO_PULLUP);
|
|
gpio_config(GPIO_USART1_RX, GPIO_STM32_AF | GPIO_STM32_AFn(GPIO_AF7_USART1) | GPIO_PULLUP);
|
|
#else
|
|
#error need to configure gpio pins for debug uart
|
|
#endif
|
|
|
|
/* now that the uart gpios are configured, enable the debug uart */
|
|
stm32_debug_early_init();
|
|
|
|
/* initialize sdram */
|
|
BSP_SDRAM_Init();
|
|
|
|
/* initialize external sram */
|
|
BSP_SRAM_Init();
|
|
|
|
/* initialize the mpu */
|
|
MPU_RegionConfig();
|
|
|
|
/* initialize the lcd panel */
|
|
BSP_LCD_Init();
|
|
}
|
|
|
|
/**
|
|
* @brief Configures the main MPU regions.
|
|
* @param None
|
|
* @retval None
|
|
*/
|
|
static void MPU_RegionConfig(void)
|
|
{
|
|
MPU_Region_InitTypeDef MPU_InitStruct;
|
|
|
|
/* Disable MPU */
|
|
HAL_MPU_Disable();
|
|
|
|
uint region_num = 0;
|
|
|
|
#if 1
|
|
// SDRAM
|
|
MPU_InitStruct.Enable = MPU_REGION_ENABLE;
|
|
MPU_InitStruct.BaseAddress = SDRAM_BASE;
|
|
MPU_InitStruct.Size = MPU_REGION_SIZE_32MB;
|
|
MPU_InitStruct.AccessPermission = MPU_REGION_PRIV_RW;
|
|
MPU_InitStruct.IsBufferable = MPU_ACCESS_BUFFERABLE;
|
|
MPU_InitStruct.IsCacheable = MPU_ACCESS_CACHEABLE;
|
|
MPU_InitStruct.IsShareable = MPU_ACCESS_NOT_SHAREABLE;
|
|
MPU_InitStruct.Number = region_num++;
|
|
MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL1;
|
|
MPU_InitStruct.SubRegionDisable = 0x00;
|
|
MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_ENABLE;
|
|
|
|
HAL_MPU_ConfigRegion(&MPU_InitStruct);
|
|
#endif
|
|
|
|
// SRAM
|
|
#if 1
|
|
MPU_InitStruct.Enable = MPU_REGION_ENABLE;
|
|
MPU_InitStruct.BaseAddress = EXT_SRAM_BASE;
|
|
MPU_InitStruct.Size = MPU_REGION_SIZE_2MB;
|
|
MPU_InitStruct.AccessPermission = MPU_REGION_PRIV_RW;
|
|
MPU_InitStruct.IsBufferable = MPU_ACCESS_BUFFERABLE;
|
|
MPU_InitStruct.IsCacheable = MPU_ACCESS_CACHEABLE;
|
|
MPU_InitStruct.IsShareable = MPU_ACCESS_NOT_SHAREABLE;
|
|
MPU_InitStruct.Number = region_num++;
|
|
MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL1;
|
|
MPU_InitStruct.SubRegionDisable = 0x00;
|
|
MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_ENABLE;
|
|
|
|
HAL_MPU_ConfigRegion(&MPU_InitStruct);
|
|
#endif
|
|
|
|
/* don't have to enable these if we let the MPU use default permissions for stuff other than SDRAM */
|
|
#if 0
|
|
/* Configure RAM region as Region N°0, 1MB of size and R/W region */
|
|
MPU_InitStruct.Enable = MPU_REGION_ENABLE;
|
|
MPU_InitStruct.BaseAddress = 0x20000000;
|
|
MPU_InitStruct.Size = MPU_REGION_SIZE_1MB;
|
|
MPU_InitStruct.AccessPermission = MPU_REGION_PRIV_RW;
|
|
MPU_InitStruct.IsBufferable = MPU_ACCESS_NOT_BUFFERABLE;
|
|
MPU_InitStruct.IsCacheable = MPU_ACCESS_NOT_CACHEABLE;
|
|
MPU_InitStruct.IsShareable = MPU_ACCESS_NOT_SHAREABLE;
|
|
MPU_InitStruct.Number = 0;
|
|
MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL0;
|
|
MPU_InitStruct.SubRegionDisable = 0x00;
|
|
MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_ENABLE;
|
|
|
|
HAL_MPU_ConfigRegion(&MPU_InitStruct);
|
|
|
|
/* Configure FLASH region as REGION N°1, 1MB of size and R/W region */
|
|
MPU_InitStruct.BaseAddress = 0x02000000; // FLASH_ADDRESS_START;
|
|
MPU_InitStruct.Size = MPU_REGION_SIZE_1MB; // FLASH_SIZE;
|
|
MPU_InitStruct.Number = 1;
|
|
|
|
HAL_MPU_ConfigRegion(&MPU_InitStruct);
|
|
|
|
/* Configure Peripheral region as REGION N°2, 0.5GB of size, R/W and Execute
|
|
Never region */
|
|
MPU_InitStruct.BaseAddress = 0x40000000; // PERIPH_ADDRESS_START;
|
|
MPU_InitStruct.Size = MPU_REGION_SIZE_512KB; // PERIPH_SIZE;
|
|
MPU_InitStruct.Number = 2; // PERIPH_REGION_NUMBER;
|
|
MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_DISABLE;
|
|
|
|
HAL_MPU_ConfigRegion(&MPU_InitStruct);
|
|
#endif
|
|
|
|
/* Enable MPU */
|
|
HAL_MPU_Enable(MPU_HFNMI_PRIVDEF);
|
|
}
|
|
|
|
|
|
void target_init(void)
|
|
{
|
|
stm32_debug_init();
|
|
}
|
|
|
|
#if 0
|
|
void target_set_debug_led(unsigned int led, bool on)
|
|
{
|
|
switch (led) {
|
|
case 0:
|
|
gpio_set(GPIO_LED0, on);
|
|
break;
|
|
case 1:
|
|
gpio_set(GPIO_LED1, on);
|
|
break;
|
|
case 2:
|
|
gpio_set(GPIO_LED2, on);
|
|
break;
|
|
case 3:
|
|
gpio_set(GPIO_LED3, on);
|
|
break;
|
|
}
|
|
}
|
|
#endif
|