当前位置:   article > 正文

关于STM32 FLASH上运行ecos的内存配置的一点解释_stm32可以运行ecos

stm32可以运行ecos

最近很多网友问了关于STM32上运行ecos失败的一些问题,这里简要回答。

1、选择运行方式

cortexm3的ecos,有三种运行方式ram, rom和jtag

ram和jtag是用于调试的,ram方式会把你的执行代码也放到ram中,jtag的代码放在rom中,这个内存模板主要是为了解决jtag连接不上的问题。

rom运行就是我们最后完成项目时候烧入到norflash中运行的方式,代码需要烧入到flash中。

2、完成内存映射

如果你有jlink这样的调试工具,可以直接用rom的方式,调试起来并不复杂。

mlt_cortexm_stm3210e_eval_rom.h

mlt_cortexm_stm3210e_eval_rom.ldi

这两个文件定义了内存布局,下面这个例子是在内部flash中运行的示例文件

  1. // eCos memory layout
  2. #include <pkgconf/hal.h>
  3. #include <cyg/infra/cyg_type.inc>
  4. MEMORY
  5. {
  6. sram : ORIGIN = 0x20000000, LENGTH = 0x00010000-CYGNUM_HAL_COMMON_INTERRUPTS_STACK_SIZE
  7. flash : ORIGIN = 0x08000000, LENGTH = 0x00080000
  8. rom : ORIGIN = 0x64000000, LENGTH = 0x01000000
  9. ram : ORIGIN = 0x68000000, LENGTH = 0x00100000
  10. }
  11. SECTIONS
  12. {
  13. SECTIONS_BEGIN
  14. SECTION_rom_vectors (flash, 0x08000000, LMA_EQ_VMA)
  15. SECTION_RELOCS (flash, ALIGN (0x8), LMA_EQ_VMA)
  16. SECTION_text (flash, ALIGN (0x8), LMA_EQ_VMA)
  17. SECTION_fini (flash, ALIGN (0x8), LMA_EQ_VMA)
  18. SECTION_rodata (flash, ALIGN (0x8), LMA_EQ_VMA)
  19. SECTION_rodata1 (flash, ALIGN (0x8), LMA_EQ_VMA)
  20. SECTION_fixup (flash, ALIGN (0x8), LMA_EQ_VMA)
  21. SECTION_gcc_except_table (flash, ALIGN (0x8), LMA_EQ_VMA)
  22. SECTION_eh_frame (flash, ALIGN (0x8), LMA_EQ_VMA)
  23. SECTION_got (flash, ALIGN (0x8), LMA_EQ_VMA)
  24. SECTION_sram (sram, 0x20000400, FOLLOWING (.got))
  25. SECTION_data (ram, 0x68000000, FOLLOWING (.sram))
  26. SECTION_bss (ram, ALIGN (0x8), LMA_EQ_VMA)
  27. CYG_LABEL_DEFN(__heap1) = ALIGN (0x8);
  28. SECTIONS_END
  29. }
  30. hal_vsr_table = 0x20000000;
  31. hal_virtual_vector_table = hal_vsr_table + 128*4;
  32. hal_startup_stack = 0x20000000 + 1024*64;

hal_virtual_vector_table放在内部的sram中,这样有利于中断的快速响应。

3、完成代码中关于内存总线初始化

这部分直观重要,实际上这部分的内容和ecos本身没有关系,是对STM32芯片的外部总线的配置,

设想一下如果你要访问外部的ram,前提当然要设定好响应的芯片引脚和总线读写时序。

 

  1. __externC void hal_system_init( void )
  2. {
  3. CYG_ADDRESS base;
  4. #if defined(CYG_HAL_STARTUP_ROM) | defined(CYG_HAL_STARTUP_SRAM)
  5. // Enable peripheral clocks in RCC
  6. base = CYGHWR_HAL_STM32_RCC;
  7. HAL_WRITE_UINT32(base+CYGHWR_HAL_STM32_RCC_AHBENR,
  8. CYGHWR_HAL_STM32_RCC_AHBENR_FSMC |
  9. CYGHWR_HAL_STM32_RCC_AHBENR_FLITF|
  10. CYGHWR_HAL_STM32_RCC_AHBENR_SRAM );
  11. HAL_WRITE_UINT32(base+CYGHWR_HAL_STM32_RCC_APB2ENR,
  12. CYGHWR_HAL_STM32_RCC_APB2ENR_IOPA |
  13. CYGHWR_HAL_STM32_RCC_APB2ENR_IOPB |
  14. CYGHWR_HAL_STM32_RCC_APB2ENR_IOPC |
  15. CYGHWR_HAL_STM32_RCC_APB2ENR_IOPD |
  16. CYGHWR_HAL_STM32_RCC_APB2ENR_IOPE |
  17. CYGHWR_HAL_STM32_RCC_APB2ENR_IOPF |
  18. CYGHWR_HAL_STM32_RCC_APB2ENR_IOPG);
  19. // Set all unused GPIO lines to input with pull down to prevent
  20. // them floating and annoying any external hardware.
  21. base = CYGHWR_HAL_STM32_GPIOA;
  22. HAL_WRITE_UINT32( base+CYGHWR_HAL_STM32_GPIO_CRL, 0x88888888 );
  23. HAL_WRITE_UINT32( base+CYGHWR_HAL_STM32_GPIO_CRH, 0x88888888 );
  24. base = CYGHWR_HAL_STM32_GPIOB;
  25. HAL_WRITE_UINT32( base+CYGHWR_HAL_STM32_GPIO_CRL, 0x88888888 );
  26. HAL_WRITE_UINT32( base+CYGHWR_HAL_STM32_GPIO_CRH, 0x88888888 );
  27. base = CYGHWR_HAL_STM32_GPIOC;
  28. HAL_WRITE_UINT32( base+CYGHWR_HAL_STM32_GPIO_CRL, 0x88888888 );
  29. HAL_WRITE_UINT32( base+CYGHWR_HAL_STM32_GPIO_CRH, 0x88888888 );
  30. // Set up GPIO lines for external bus
  31. base = CYGHWR_HAL_STM32_GPIOD;
  32. HAL_WRITE_UINT32( base+CYGHWR_HAL_STM32_GPIO_CRL, 0x44bb44bb );
  33. HAL_WRITE_UINT32( base+CYGHWR_HAL_STM32_GPIO_CRH, 0xbbbbbbbb );
  34. base = CYGHWR_HAL_STM32_GPIOE;
  35. HAL_WRITE_UINT32( base+CYGHWR_HAL_STM32_GPIO_CRL, 0xbbbbb4bb );
  36. HAL_WRITE_UINT32( base+CYGHWR_HAL_STM32_GPIO_CRH, 0xbbbbbbbb );
  37. base = CYGHWR_HAL_STM32_GPIOF;
  38. HAL_WRITE_UINT32( base+CYGHWR_HAL_STM32_GPIO_CRL, 0x44bbbbbb );
  39. HAL_WRITE_UINT32( base+CYGHWR_HAL_STM32_GPIO_CRH, 0xbbbb4444 );
  40. base = CYGHWR_HAL_STM32_GPIOG;
  41. HAL_WRITE_UINT32( base+CYGHWR_HAL_STM32_GPIO_CRL, 0x44bbbbbb );
  42. HAL_WRITE_UINT32( base+CYGHWR_HAL_STM32_GPIO_CRH, 0x444b4bb4 );
  43. // Set up FSMC NOR/SRAM bank 2 for NOR Flash
  44. base = CYGHWR_HAL_STM32_FSMC;
  45. HAL_WRITE_UINT32( base+CYGHWR_HAL_STM32_FSMC_BCR2, 0x00001059 );
  46. HAL_WRITE_UINT32( base+CYGHWR_HAL_STM32_FSMC_BTR2, 0x10000705 );
  47. // Set up FSMC NOR/SRAM bank 3 for SRAM
  48. HAL_WRITE_UINT32( base+CYGHWR_HAL_STM32_FSMC_BCR3, 0x00001011 );
  49. HAL_WRITE_UINT32( base+CYGHWR_HAL_STM32_FSMC_BTR3, 0x00000200 );
  50. // Set up FSMC NOR/SRAM bank 4 for TFT LCD
  51. HAL_WRITE_UINT32( base+CYGHWR_HAL_STM32_FSMC_BCR4, 0x00001011 );
  52. HAL_WRITE_UINT32( base+CYGHWR_HAL_STM32_FSMC_BTR4, 0x00000201 );
  53. #endif
  54. // Enable flash prefetch buffer and set latency to 2 wait states.
  55. {
  56. cyg_uint32 acr;
  57. base = CYGHWR_HAL_STM32_FLASH;
  58. HAL_READ_UINT32( base+CYGHWR_HAL_STM32_FLASH_ACR, acr );
  59. acr |= CYGHWR_HAL_STM32_FLASH_ACR_PRFTBE;
  60. acr |= CYGHWR_HAL_STM32_FLASH_ACR_LATENCY(2);
  61. HAL_WRITE_UINT32( base+CYGHWR_HAL_STM32_FLASH_ACR, acr );
  62. }
  63. }

 

整个过程,需要先配置内部总线控制器,配置引脚属性,然后就是对外部RAM时序的配置。

 

经过了以上几个过程你的外部RAM才能被ecos启用,这个是ecos启动的必要条件。


Set up FSMC NOR/SRAM bank 3 for SRAM

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/程序自动化专家/article/detail/60629
推荐阅读
相关标签
  

闽ICP备14008679号